From 65101886f97a47f5c27fbef2ca88f13bb588edda Mon Sep 17 00:00:00 2001 From: zaki Date: Fri, 20 Nov 2026 19:53:44 +0800 Subject: [PATCH] Rebuild as a Python-native framework for Apache Dubbo Replace the previous implementation with a new one built on asyncio and AnyIO, with uvloop optional, for Python 3.11 to 3.14: - the Triple protocol over HTTP/2, interoperable with gRPC, and the Dubbo protocol with Hessian 2, both in the default installation; - application-level and interface-level service discovery on ZooKeeper and Nacos, with metadata services and reports, and configuration centers; - clusters, load balancers, condition and tag routers, configurators and filters, as extension points loaded by entry points; - configuration from code, files and environment variables; - the protoc plugin that generates service stubs; - samples, from a first call to a small shop of services behind FastAPI, an agent of Pydantic AI whose tools are services, and calls to and from Dubbo Java and Dubbo Go, each with a README and run by the tests; - end-to-end benchmarks of servers on one core and on eight, beside Dubbo Java, Dubbo Go and the gRPC libraries of Python, and of a Dubbo Python consumer; - unit and integration tests on a virtual clock, CI on GitHub Actions, and release candidates for the release manager to sign. Extras add the ZooKeeper and Nacos clients, the YAML and properties configuration formats, uvloop and protoc. --- .asf.yaml | 41 +- .github/dependabot.yml | 33 + .github/workflows/ci.yml | 145 + .github/workflows/license-check.yaml | 19 - .github/workflows/release.yml | 55 + .github/workflows/test-suite.yaml | 30 - .gitignore | 99 +- .license-ignore | 21 - .licenserc.yaml | 50 + .pre-commit-config.yaml | 45 + .python-version | 1 + AGENTS.md | 36 + CONTRIBUTING.md | 296 ++ LICENSE | 2 +- NOTICE | 4 +- README.md | 287 +- benchmark/.gitignore | 19 + benchmark/README.md | 160 + benchmark/go/benchpb/bench.pb.go | 146 + benchmark/go/benchpb/bench.triple.go | 122 + benchmark/go/go.mod | 158 + benchmark/go/go.sum | 1422 +++++++++ benchmark/go/load/main.go | 281 ++ benchmark/go/server/main.go | 86 + benchmark/java/pom.xml | 84 + .../apache/dubbo/benchmark/BenchService.java | 24 + .../apache/dubbo/benchmark/JavaServer.java | 72 + benchmark/plot.py | 366 +++ benchmark/proto/bench.proto | 33 + benchmark/python/bench_pb2.py | 39 + benchmark/python/bench_pb2.pyi | 11 + benchmark/python/client.py | 178 ++ benchmark/python/contract.py | 64 + benchmark/python/dubbo_server.py | 49 + benchmark/python/grpcio_server.py | 54 + benchmark/python/grpclib_server.py | 53 + benchmark/ruff.toml | 24 + benchmark/run.py | 468 +++ benchmark/scenarios.toml | 66 + docs/CONTRIBUTING.md | 122 - docs/img/Architecture.svg | 2 - pyproject.toml | 313 +- requirements-dev.txt | 19 - samples/README.md | 67 +- samples/__init__.py | 15 - samples/basics/01_hello_world/README.md | 61 + samples/basics/01_hello_world/client.py | 44 + samples/basics/01_hello_world/greeter.py | 32 + samples/basics/01_hello_world/server.py | 55 + samples/basics/02_protobuf/README.md | 79 + samples/basics/02_protobuf/client.py | 40 + samples/basics/02_protobuf/greeter.proto | 33 + samples/basics/02_protobuf/greeter_dubbo.py | 29 + samples/basics/02_protobuf/greeter_pb2.py | 40 + samples/basics/02_protobuf/greeter_pb2.pyi | 17 + samples/basics/02_protobuf/server.py | 50 + samples/basics/03_streaming/README.md | 71 + samples/basics/03_streaming/client.py | 62 + samples/basics/03_streaming/greeter.proto | 38 + samples/basics/03_streaming/greeter_dubbo.py | 49 + samples/basics/03_streaming/greeter_pb2.py | 40 + samples/basics/03_streaming/greeter_pb2.pyi | 17 + samples/basics/03_streaming/server.py | 61 + samples/basics/04_registry/README.md | 142 + samples/basics/04_registry/client.py | 48 + samples/basics/04_registry/greeter.py | 32 + samples/basics/04_registry/server.py | 53 + samples/basics/04_registry/show_registry.py | 58 + samples/basics/05_configuration/README.md | 135 + samples/basics/05_configuration/client.py | 43 + samples/basics/05_configuration/client.yaml | 39 + samples/basics/05_configuration/greeter.py | 30 + samples/basics/05_configuration/server.py | 60 + samples/basics/05_configuration/server.yaml | 55 + samples/basics/06_logging/README.md | 150 + samples/basics/06_logging/client.py | 39 + samples/basics/06_logging/greeter.py | 27 + samples/basics/06_logging/logs.py | 74 + samples/basics/06_logging/server.py | 71 + samples/basics/06_logging/structlog_logs.py | 41 + samples/basics/07_graceful_shutdown/README.md | 76 + samples/basics/07_graceful_shutdown/client.py | 40 + .../basics/07_graceful_shutdown/greeter.py | 32 + samples/basics/07_graceful_shutdown/server.py | 93 + .../basics/08_errors_and_timeouts/README.md | 84 + .../basics/08_errors_and_timeouts/client.py | 75 + .../basics/08_errors_and_timeouts/server.py | 66 + .../basics/08_errors_and_timeouts/users.proto | 43 + .../08_errors_and_timeouts/users_dubbo.py | 40 + .../08_errors_and_timeouts/users_pb2.py | 44 + .../08_errors_and_timeouts/users_pb2.pyi | 29 + samples/basics/09_context/README.md | 83 + samples/basics/09_context/client.py | 44 + samples/basics/09_context/inventory_server.py | 51 + samples/basics/09_context/order_server.py | 63 + samples/basics/09_context/services.py | 33 + samples/basics/10_group_version/README.md | 75 + samples/basics/10_group_version/client.py | 49 + samples/basics/10_group_version/greeter.py | 32 + samples/basics/10_group_version/server_v1.py | 54 + samples/basics/10_group_version/server_v2.py | 55 + samples/basics/11_load_balancing/README.md | 81 + samples/basics/11_load_balancing/client.py | 68 + samples/basics/11_load_balancing/server.py | 67 + samples/basics/11_load_balancing/worker.py | 28 + samples/basics/12_config_center/README.md | 99 + samples/basics/12_config_center/client.py | 49 + samples/basics/12_config_center/greeter.py | 32 + samples/basics/12_config_center/publish.py | 86 + samples/basics/12_config_center/server.py | 53 + samples/basics/13_routing/README.md | 114 + samples/basics/13_routing/client.py | 55 + samples/basics/13_routing/greeter.py | 32 + samples/basics/13_routing/publish.py | 84 + samples/basics/13_routing/server.py | 67 + samples/basics/14_filters/README.md | 81 + samples/basics/14_filters/client.py | 47 + samples/basics/14_filters/filters.py | 81 + samples/basics/14_filters/greeter.py | 32 + samples/basics/14_filters/server.py | 59 + samples/basics/15_extensions/README.md | 88 + samples/basics/15_extensions/client.py | 44 + .../15_extensions/dubbo-toml/dubbo_toml.py | 32 + .../15_extensions/dubbo-toml/pyproject.toml | 35 + samples/basics/15_extensions/greeter.py | 32 + samples/basics/15_extensions/server.py | 46 + samples/basics/15_extensions/server.toml | 24 + samples/basics/16_tls/.gitignore | 19 + samples/basics/16_tls/README.md | 77 + samples/basics/16_tls/client.py | 60 + samples/basics/16_tls/greeter.proto | 33 + samples/basics/16_tls/greeter_dubbo.py | 29 + samples/basics/16_tls/greeter_pb2.py | 40 + samples/basics/16_tls/greeter_pb2.pyi | 17 + samples/basics/16_tls/make_certificates.py | 46 + samples/basics/16_tls/server.py | 59 + samples/basics/17_generic/README.md | 70 + samples/basics/17_generic/client.py | 47 + samples/basics/17_generic/server.py | 61 + samples/compose.yaml | 50 + samples/helloworld/__init__.py | 15 - samples/helloworld/client.py | 36 - samples/helloworld/server.py | 45 - samples/integrations/fastapi/README.md | 174 + samples/integrations/fastapi/app.py | 100 + samples/integrations/fastapi/backend.py | 77 + samples/integrations/fastapi/orders.py | 70 + samples/integrations/fastapi/shop.py | 77 + samples/integrations/pydantic_ai/README.md | 136 + samples/integrations/pydantic_ai/planner.py | 101 + samples/integrations/pydantic_ai/services.py | 99 + samples/integrations/pydantic_ai/supply.py | 105 + samples/interop/go/README.md | 156 + samples/interop/go/go/client/main.go | 70 + samples/interop/go/go/go.mod | 158 + samples/interop/go/go/go.sum | 1422 +++++++++ samples/interop/go/go/greeter/greeter.pb.go | 194 ++ .../interop/go/go/greeter/greeter.triple.go | 204 ++ samples/interop/go/go/server/main.go | 82 + samples/interop/go/greeter_dubbo.py | 40 + samples/interop/go/greeter_pb2.py | 41 + samples/interop/go/greeter_pb2.pyi | 17 + samples/interop/go/proto/greeter.proto | 38 + samples/interop/go/python_client.py | 55 + samples/interop/go/python_server.py | 60 + samples/interop/grpc/README.md | 96 + samples/interop/grpc/dubbo_client.py | 40 + samples/interop/grpc/dubbo_server.py | 51 + samples/interop/grpc/greeter.proto | 33 + samples/interop/grpc/greeter_dubbo.py | 29 + samples/interop/grpc/greeter_pb2.py | 40 + samples/interop/grpc/greeter_pb2.pyi | 17 + samples/interop/grpc/greeter_pb2_grpc.py | 100 + samples/interop/grpc/grpc_client.py | 36 + samples/interop/grpc/grpc_server.py | 49 + samples/interop/java/README.md | 175 + samples/interop/java/greeter_dubbo.py | 40 + samples/interop/java/greeter_pb2.py | 41 + samples/interop/java/greeter_pb2.pyi | 17 + samples/interop/java/java/.gitignore | 19 + samples/interop/java/java/pom.xml | 93 + .../org/apache/dubbo/samples/JavaClient.java | 80 + .../org/apache/dubbo/samples/JavaServer.java | 95 + .../java/org/apache/dubbo/samples/User.java | 54 + .../org/apache/dubbo/samples/UserService.java | 26 + samples/interop/java/proto/greeter.proto | 38 + samples/interop/java/python_client.py | 57 + samples/interop/java/python_server.py | 73 + samples/interop/java/users.py | 44 + samples/llm/README.md | 127 - samples/llm/__init__.py | 15 - samples/llm/chat.proto | 21 - samples/llm/chat_pb2.py | 32 - samples/llm/main.py | 106 - samples/proto/__init__.py | 15 - samples/proto/greeter.proto | 28 - samples/proto/greeter_pb2.py | 40 - samples/registry/README.md | 26 - samples/registry/__init__.py | 15 - samples/registry/zookeeper/__init__.py | 15 - samples/registry/zookeeper/client.py | 45 - samples/registry/zookeeper/server.py | 55 - samples/ruff.toml | 24 + samples/serialization/README.md | 190 -- samples/serialization/__init__.py | 15 - samples/serialization/json/__init__.py | 15 - samples/serialization/json/client.py | 50 - samples/serialization/json/server.py | 64 - samples/serialization/protobuf/__init__.py | 15 - samples/serialization/protobuf/client.py | 39 - samples/serialization/protobuf/server.py | 52 - samples/stream/README.md | 94 - samples/stream/__init__.py | 15 - samples/stream/bidi_stream/__init__.py | 15 - samples/stream/bidi_stream/client.py | 65 - samples/stream/bidi_stream/server.py | 61 - samples/stream/client_stream/__init__.py | 15 - samples/stream/client_stream/client.py | 46 - samples/stream/client_stream/server.py | 54 - samples/stream/server_stream/__init__.py | 15 - samples/stream/server_stream/client.py | 41 - samples/stream/server_stream/server.py | 55 - scripts/build.sh | 24 - scripts/check.sh | 30 - scripts/check_install.py | 78 + scripts/generate_protos.py | 93 + scripts/install-dev.sh | 27 - scripts/rat.sh | 80 - scripts/test.sh | 25 - src/dubbo/__about__.py | 17 - src/dubbo/__init__.py | 92 +- src/dubbo/_proto/__init__.py | 17 + src/dubbo/_proto/google/__init__.py | 16 + src/dubbo/_proto/google/rpc/__init__.py | 16 + src/dubbo/_proto/google/rpc/status.proto | 48 + src/dubbo/_proto/google/rpc/status_pb2.py | 38 + src/dubbo/_proto/google/rpc/status_pb2.pyi | 18 + src/dubbo/_proto/grpc/__init__.py | 16 + src/dubbo/_proto/grpc/health/__init__.py | 16 + src/dubbo/_proto/grpc/health/v1/__init__.py | 16 + src/dubbo/_proto/grpc/health/v1/health.proto | 92 + .../_proto/grpc/health/v1/health_dubbo.py | 121 + src/dubbo/_proto/grpc/health/v1/health_pb2.py | 51 + .../_proto/grpc/health/v1/health_pb2.pyi | 47 + src/dubbo/_proto/grpc/reflection/__init__.py | 16 + .../_proto/grpc/reflection/v1/__init__.py | 16 + .../grpc/reflection/v1/reflection.proto | 147 + .../grpc/reflection/v1/reflection_dubbo.py | 33 + .../grpc/reflection/v1/reflection_pb2.py | 53 + .../grpc/reflection/v1/reflection_pb2.pyi | 81 + .../grpc/reflection/v1alpha/__init__.py | 16 + .../grpc/reflection/v1alpha/reflection.proto | 145 + .../reflection/v1alpha/reflection_dubbo.py | 33 + .../grpc/reflection/v1alpha/reflection_pb2.py | 53 + .../reflection/v1alpha/reflection_pb2.pyi | 81 + src/dubbo/_proto/org/__init__.py | 16 + src/dubbo/_proto/org/apache/__init__.py | 16 + src/dubbo/_proto/org/apache/dubbo/__init__.py | 16 + .../org/apache/dubbo/metadata/__init__.py | 16 + .../dubbo/metadata/metadata_service_v2.proto | 105 + .../metadata/metadata_service_v2_dubbo.py | 40 + .../dubbo/metadata/metadata_service_v2_pb2.py | 57 + .../metadata/metadata_service_v2_pb2.pyi | 89 + .../org/apache/dubbo/triple/__init__.py | 16 + .../apache/dubbo/triple/triple_wrapper.proto | 38 + .../apache/dubbo/triple/triple_wrapper_pb2.py | 40 + .../dubbo/triple/triple_wrapper_pb2.pyi | 39 + src/dubbo/_proto/pool.py | 34 + src/dubbo/application.py | 522 +++ src/dubbo/bootstrap.py | 134 - src/dubbo/classes.py | 246 -- src/dubbo/client.py | 163 - src/dubbo/cluster/__init__.py | 46 +- src/dubbo/cluster/_interfaces.py | 75 - src/dubbo/cluster/available.py | 36 + src/dubbo/cluster/base.py | 173 + src/dubbo/cluster/broadcast.py | 77 + src/dubbo/cluster/configurator.py | 276 ++ src/dubbo/cluster/directories.py | 66 - src/dubbo/cluster/directory/__init__.py | 24 + src/dubbo/cluster/directory/base.py | 43 + src/dubbo/cluster/directory/dynamic.py | 158 + src/dubbo/cluster/directory/static.py | 58 + src/dubbo/cluster/failback.py | 133 + src/dubbo/cluster/failfast.py | 31 + src/dubbo/cluster/failfast_cluster.py | 70 - src/dubbo/cluster/failover.py | 76 + src/dubbo/cluster/failsafe.py | 49 + src/dubbo/cluster/forking.py | 87 + src/dubbo/cluster/loadbalance/__init__.py | 20 + src/dubbo/cluster/loadbalance/base.py | 162 + .../cluster/loadbalance/consistenthash.py | 106 + src/dubbo/cluster/loadbalance/leastactive.py | 71 + src/dubbo/cluster/loadbalance/random.py | 63 + src/dubbo/cluster/loadbalance/roundrobin.py | 85 + src/dubbo/cluster/loadbalances.py | 101 - src/dubbo/cluster/monitor/__init__.py | 15 - src/dubbo/cluster/monitor/cpu.py | 165 - src/dubbo/cluster/reference.py | 198 ++ src/dubbo/cluster/router/__init__.py | 21 + src/dubbo/cluster/router/base.py | 97 + src/dubbo/cluster/router/chain.py | 61 + src/dubbo/cluster/router/condition.py | 394 +++ src/dubbo/cluster/router/tag.py | 310 ++ src/dubbo/cluster/rule.py | 283 ++ src/dubbo/cluster/zoneaware.py | 63 + src/dubbo/compression/__init__.py | 32 +- src/dubbo/compression/_interfaces.py | 69 - src/dubbo/compression/base.py | 89 + src/dubbo/compression/bzip2.py | 37 + src/dubbo/compression/bzip2s.py | 56 - src/dubbo/compression/deflate.py | 39 + src/dubbo/compression/gzip.py | 61 + src/dubbo/compression/gzips.py | 58 - src/dubbo/compression/identities.py | 57 - src/dubbo/config/__init__.py | 64 + src/dubbo/config/data.py | 62 + src/dubbo/config/exceptions.py | 32 + src/dubbo/config/fields.py | 250 ++ src/dubbo/config/loading.py | 224 ++ src/dubbo/config/models.py | 1083 +++++++ src/dubbo/config/parsers/__init__.py | 20 + src/dubbo/config/parsers/base.py | 57 + src/dubbo/config/parsers/json.py | 40 + src/dubbo/config/parsers/properties.py | 91 + src/dubbo/config/parsers/yaml.py | 90 + src/dubbo/config/structure.py | 184 ++ src/dubbo/config/urls.py | 303 ++ src/dubbo/config_center/__init__.py | 20 + src/dubbo/config_center/base.py | 98 + src/dubbo/config_center/nacos.py | 66 + src/dubbo/config_center/zookeeper.py | 75 + src/dubbo/configs.py | 911 ------ src/dubbo/constants.py | 344 ++ src/dubbo/constants/__init__.py | 15 - src/dubbo/constants/common_constants.py | 68 - src/dubbo/constants/config_constants.py | 26 - src/dubbo/constants/logger_constants.py | 83 - src/dubbo/constants/registry_constants.py | 24 - src/dubbo/exceptions.py | 124 + src/dubbo/extension/__init__.py | 34 +- src/dubbo/extension/exceptions.py | 24 + src/dubbo/extension/extension_loader.py | 91 - src/dubbo/extension/loader.py | 173 + src/dubbo/extension/registries.py | 105 - src/dubbo/extension/resource.py | 49 + src/dubbo/extension/scope.py | 149 + src/dubbo/filter/__init__.py | 21 + src/dubbo/filter/accesslog.py | 78 + src/dubbo/filter/activecount.py | 112 + src/dubbo/filter/actives.py | 72 + src/dubbo/filter/base.py | 87 + src/dubbo/filter/chain.py | 138 + src/dubbo/filter/deprecated.py | 61 + src/dubbo/filter/executes.py | 64 + src/dubbo/filter/token.py | 42 + src/dubbo/filter/tps.py | 130 + src/dubbo/loadbalance/__init__.py | 19 - src/dubbo/loadbalance/_interfaces.py | 72 - src/dubbo/loggers.py | 234 -- src/dubbo/metadata/__init__.py | 27 + src/dubbo/metadata/info.py | 156 + src/dubbo/metadata/instance.py | 219 ++ src/dubbo/metadata/report/__init__.py | 22 + src/dubbo/metadata/report/base.py | 118 + src/dubbo/metadata/report/nacos.py | 88 + src/dubbo/metadata/report/zookeeper.py | 104 + src/dubbo/metadata/service/__init__.py | 18 + src/dubbo/metadata/service/client.py | 63 + src/dubbo/metadata/service/server.py | 159 + src/dubbo/metadata/service/v1.py | 165 + src/dubbo/metadata/service/v2.py | 86 + src/dubbo/node.py | 58 - src/dubbo/protoc/__init__.py | 22 + src/dubbo/protoc/plugin.py | 255 ++ src/dubbo/protocol/__init__.py | 29 +- src/dubbo/protocol/_interfaces.py | 123 - src/dubbo/protocol/base.py | 132 + src/dubbo/protocol/dubbo/__init__.py | 20 + src/dubbo/protocol/dubbo/body.py | 328 ++ src/dubbo/protocol/dubbo/client.py | 179 ++ src/dubbo/protocol/dubbo/connection.py | 397 +++ src/dubbo/protocol/dubbo/invoker.py | 187 ++ src/dubbo/protocol/dubbo/protocol.py | 145 + src/dubbo/protocol/dubbo/server.py | 492 +++ src/dubbo/protocol/exported.py | 138 + src/dubbo/protocol/generic.py | 219 ++ src/dubbo/protocol/invocation.py | 81 - src/dubbo/protocol/java.py | 211 ++ src/dubbo/protocol/served.py | 314 ++ src/dubbo/protocol/triple/__init__.py | 30 +- src/dubbo/protocol/triple/attachments.py | 120 + src/dubbo/protocol/triple/builtin/__init__.py | 21 + src/dubbo/protocol/triple/builtin/health.py | 113 + .../protocol/triple/builtin/reflection.py | 159 + src/dubbo/protocol/triple/call/__init__.py | 20 - src/dubbo/protocol/triple/call/_interfaces.py | 143 - src/dubbo/protocol/triple/call/client_call.py | 197 -- src/dubbo/protocol/triple/call/server_call.py | 232 -- src/dubbo/protocol/triple/coders.py | 256 -- src/dubbo/protocol/triple/constants.py | 125 - src/dubbo/protocol/triple/exceptions.py | 99 +- src/dubbo/protocol/triple/grpc/__init__.py | 23 + src/dubbo/protocol/triple/grpc/client.py | 377 +++ src/dubbo/protocol/triple/grpc/compression.py | 69 + src/dubbo/protocol/triple/grpc/framing.py | 84 + src/dubbo/protocol/triple/grpc/headers.py | 83 + src/dubbo/protocol/triple/grpc/server.py | 403 +++ src/dubbo/protocol/triple/grpc/status.py | 157 + src/dubbo/protocol/triple/headers.py | 88 + src/dubbo/protocol/triple/invoker.py | 378 ++- src/dubbo/protocol/triple/messages.py | 110 + src/dubbo/protocol/triple/metadata.py | 89 - src/dubbo/protocol/triple/protocol.py | 216 +- src/dubbo/protocol/triple/results.py | 54 - src/dubbo/protocol/triple/routes.py | 83 + src/dubbo/protocol/triple/server.py | 176 + src/dubbo/protocol/triple/settings.py | 84 + src/dubbo/protocol/triple/status.py | 152 - src/dubbo/protocol/triple/stream/__init__.py | 19 - .../protocol/triple/stream/_interfaces.py | 165 - .../protocol/triple/stream/client_stream.py | 300 -- .../protocol/triple/stream/server_stream.py | 315 -- src/dubbo/protocol/triple/streams.py | 284 -- src/dubbo/protocol/triple/wrapper.py | 98 + src/dubbo/proxy/__init__.py | 19 - src/dubbo/proxy/_interfaces.py | 56 - src/dubbo/proxy/callables.py | 70 - src/dubbo/proxy/handlers.py | 216 -- src/dubbo/py.typed | 0 src/dubbo/registry/__init__.py | 43 +- src/dubbo/registry/_interfaces.py | 105 - src/dubbo/registry/base.py | 222 ++ src/dubbo/registry/consumer.py | 252 ++ src/dubbo/registry/discovery.py | 394 +++ src/dubbo/registry/nacos/__init__.py | 21 + src/dubbo/registry/nacos/instance.py | 81 + src/dubbo/registry/nacos/interface.py | 161 + src/dubbo/registry/protocol.py | 67 - src/dubbo/registry/provider.py | 452 +++ src/dubbo/registry/registration.py | 153 + src/dubbo/registry/zookeeper/__init__.py | 42 +- src/dubbo/registry/zookeeper/_interfaces.py | 274 -- src/dubbo/registry/zookeeper/instance.py | 190 ++ src/dubbo/registry/zookeeper/interface.py | 135 + .../registry/zookeeper/kazoo_transport.py | 413 --- src/dubbo/registry/zookeeper/zk_registry.py | 197 -- src/dubbo/remoting/__init__.py | 19 - src/dubbo/remoting/_interfaces.py | 108 - src/dubbo/remoting/aio/__init__.py | 19 - src/dubbo/remoting/aio/_interfaces.py | 50 - src/dubbo/remoting/aio/aio_transporter.py | 282 -- src/dubbo/remoting/aio/constants.py | 28 - src/dubbo/remoting/aio/event_loop.py | 176 - src/dubbo/remoting/aio/exceptions.py | 46 - src/dubbo/remoting/aio/http2/__init__.py | 15 - src/dubbo/remoting/aio/http2/controllers.py | 389 --- src/dubbo/remoting/aio/http2/frames.py | 200 -- src/dubbo/remoting/aio/http2/headers.py | 167 - src/dubbo/remoting/aio/http2/protocol.py | 368 --- src/dubbo/remoting/aio/http2/registries.py | 298 -- src/dubbo/remoting/aio/http2/stream.py | 277 -- .../remoting/aio/http2/stream_handler.py | 174 - src/dubbo/remoting/aio/http2/utils.py | 82 - src/dubbo/rpc/__init__.py | 57 + src/dubbo/rpc/client.py | 220 ++ src/dubbo/rpc/context.py | 180 ++ src/dubbo/rpc/definition.py | 595 ++++ src/dubbo/rpc/invocation.py | 128 + src/dubbo/rpc/server.py | 103 + src/dubbo/rpc/stream.py | 136 + src/dubbo/serialization/__init__.py | 40 +- src/dubbo/serialization/_interfaces.py | 91 - src/dubbo/serialization/base.py | 169 + src/dubbo/serialization/custom_serializers.py | 87 - src/dubbo/serialization/direct_serializers.py | 58 - src/dubbo/serialization/hessian2.py | 223 ++ src/dubbo/serialization/protobuf.py | 75 + src/dubbo/server.py | 84 - src/dubbo/transport/__init__.py | 16 + src/dubbo/transport/h2/__init__.py | 46 + src/dubbo/transport/h2/aio/__init__.py | 22 + src/dubbo/transport/h2/aio/bdp.py | 129 + src/dubbo/transport/h2/aio/client.py | 243 ++ src/dubbo/transport/h2/aio/connection.py | 819 +++++ src/dubbo/transport/h2/aio/keep_alive.py | 111 + src/dubbo/transport/h2/aio/server.py | 248 ++ src/dubbo/transport/h2/aio/stream.py | 426 +++ src/dubbo/transport/h2/aio/tasks.py | 41 + src/dubbo/transport/h2/base.py | 417 +++ src/dubbo/transport/h2/exceptions.py | 87 + src/dubbo/transport/listener.py | 67 + src/dubbo/transport/nacos/__init__.py | 36 + src/dubbo/transport/nacos/base.py | 228 ++ src/dubbo/transport/nacos/exceptions.py | 27 + src/dubbo/transport/nacos/sdk/__init__.py | 21 + src/dubbo/transport/nacos/sdk/config.py | 145 + src/dubbo/transport/nacos/sdk/connection.py | 100 + src/dubbo/transport/nacos/sdk/naming.py | 213 ++ src/dubbo/transport/tls.py | 123 + src/dubbo/transport/zookeeper/__init__.py | 21 + src/dubbo/transport/zookeeper/base.py | 155 + src/dubbo/transport/zookeeper/exceptions.py | 27 + src/dubbo/transport/zookeeper/kazoo.py | 392 +++ src/dubbo/types.py | 60 - src/dubbo/url.py | 573 ++-- src/dubbo/utils.py | 387 --- src/dubbo/utils/__init__.py | 46 + src/dubbo/utils/annotations.py | 28 + src/dubbo/utils/async_.py | 247 ++ src/dubbo/utils/backoff.py | 31 + src/dubbo/utils/converters.py | 65 + src/dubbo/utils/dialer.py | 139 + src/dubbo/utils/mapping.py | 33 + src/dubbo/utils/net.py | 159 + src/dubbo/utils/optional.py | 38 + tests/__init__.py | 15 - tests/certificates/localhost-cert.pem | 20 + .../certificates/localhost-key-encrypted.pem | 30 + tests/certificates/localhost-key.pem | 28 + tests/conftest.py | 368 +++ tests/integration/compose.yaml | 54 + tests/integration/config/parsers/test_base.py | 48 + tests/integration/config_center/test_nacos.py | 68 + .../config_center/test_zookeeper.py | 61 + tests/integration/conftest.py | 140 + .../integration/metadata/report/test_nacos.py | 94 + .../metadata/report/test_zookeeper.py | 46 + tests/integration/protocol/dubbo/conftest.py | 198 ++ .../integration/protocol/dubbo/test_client.py | 428 +++ .../protocol/dubbo/test_connection.py | 116 + .../protocol/dubbo/test_protocol.py | 173 + .../integration/protocol/dubbo/test_server.py | 448 +++ .../protocol/triple/builtin/test_health.py | 159 + .../triple/builtin/test_reflection.py | 126 + tests/integration/protocol/triple/conftest.py | 180 ++ .../protocol/triple/grpc/test_client.py | 223 ++ .../protocol/triple/grpc/test_server.py | 192 ++ .../protocol/triple/test_client.py | 390 +++ .../protocol/triple/test_protocol.py | 231 ++ .../triple/test_pure_python_protobuf.py | 42 + .../protocol/triple/test_server.py | 207 ++ .../protocol/triple/test_wrapper.py | 157 + tests/integration/registry/conftest.py | 225 ++ tests/integration/registry/nacos/conftest.py | 64 + .../registry/nacos/test_application.py | 60 + .../registry/nacos/test_instance.py | 68 + .../registry/nacos/test_interface.py | 191 ++ .../integration/registry/test_application.py | 1228 +++++++ .../registry/zookeeper/test_instance.py | 59 + .../registry/zookeeper/test_interface.py | 83 + tests/integration/rpc/test_client.py | 354 +++ tests/integration/test_application.py | 751 +++++ tests/integration/test_application_imports.py | 37 + tests/integration/test_application_signals.py | 92 + tests/integration/test_samples.py | 552 ++++ .../integration/transport/h2/aio/conftest.py | 57 + .../integration/transport/h2/aio/test_bdp.py | 91 + .../transport/h2/aio/test_client.py | 161 + .../transport/h2/aio/test_connection.py | 423 +++ .../transport/h2/aio/test_server.py | 396 +++ .../transport/h2/aio/test_stream.py | 254 ++ tests/integration/transport/h2/test_base.py | 35 + tests/integration/transport/test_kazoo.py | 176 + tests/integration/transport/test_nacos_sdk.py | 142 + tests/integration/transport/test_zookeeper.py | 30 + .../transport/test_zookeeper_client.py | 144 + tests/test_url.py | 76 - tests/unit/cluster/conftest.py | 105 + tests/unit/cluster/directory/test_dynamic.py | 277 ++ tests/unit/cluster/directory/test_static.py | 62 + tests/unit/cluster/loadbalance/conftest.py | 39 + .../loadbalance/data/consistenthash.json | 26 + .../loadbalance/data/consistenthash.md | 13 + tests/unit/cluster/loadbalance/test_base.py | 144 + .../loadbalance/test_consistenthash.py | 94 + .../cluster/loadbalance/test_leastactive.py | 81 + tests/unit/cluster/loadbalance/test_random.py | 70 + .../cluster/loadbalance/test_roundrobin.py | 68 + tests/unit/cluster/router/conftest.py | 55 + tests/unit/cluster/router/test_chain.py | 93 + tests/unit/cluster/router/test_condition.py | 268 ++ tests/unit/cluster/router/test_tag.py | 269 ++ tests/unit/cluster/test_available.py | 50 + tests/unit/cluster/test_base.py | 230 ++ tests/unit/cluster/test_broadcast.py | 73 + tests/unit/cluster/test_configurator.py | 289 ++ tests/unit/cluster/test_failback.py | 117 + tests/unit/cluster/test_failfast.py | 29 + tests/unit/cluster/test_failover.py | 115 + tests/unit/cluster/test_failsafe.py | 51 + tests/unit/cluster/test_forking.py | 124 + tests/unit/cluster/test_zoneaware.py | 87 + tests/unit/compression/test_base.py | 120 + tests/unit/config/parsers/test_base.py | 27 + tests/unit/config/parsers/test_json.py | 60 + tests/unit/config/parsers/test_properties.py | 89 + tests/unit/config/parsers/test_yaml.py | 87 + tests/unit/config/test_fields.py | 65 + tests/unit/config/test_loading.py | 438 +++ tests/unit/config/test_models.py | 191 ++ tests/unit/config/test_structure.py | 108 + tests/unit/config/test_urls.py | 427 +++ tests/unit/config_center/test_base.py | 55 + tests/unit/config_center/test_zookeeper.py | 66 + tests/unit/extension/test_loader.py | 350 ++ tests/unit/extension/test_scope.py | 272 ++ tests/unit/filter/conftest.py | 87 + tests/unit/filter/test_accesslog.py | 105 + tests/unit/filter/test_activecount.py | 52 + tests/unit/filter/test_actives.py | 85 + tests/unit/filter/test_base.py | 159 + tests/unit/filter/test_deprecated.py | 48 + tests/unit/filter/test_executes.py | 88 + tests/unit/filter/test_token.py | 46 + tests/unit/filter/test_tps.py | 68 + .../metadata/service/data/Capture.java.txt | 48 + .../metadata/service/data/metadata_info.md | 24 + .../service/data/metadata_info_java.hessian | 1 + .../service/data/metadata_info_python.hessian | 3 + tests/unit/metadata/service/test_client.py | 59 + tests/unit/metadata/service/test_v1.py | 131 + tests/unit/metadata/service/test_v2.py | 32 + tests/unit/metadata/test_info.py | 66 + tests/unit/metadata/test_instance.py | 104 + tests/unit/protoc/data/README.md | 7 + .../unit/protoc/data/greeter_v1_dubbo.py.txt | 83 + tests/unit/protoc/test_plugin.py | 165 + tests/unit/protocol/dubbo/test_body.py | 262 ++ tests/unit/protocol/dubbo/test_client.py | 183 ++ tests/unit/protocol/dubbo/test_connection.py | 112 + tests/unit/protocol/test_generic.py | 141 + tests/unit/protocol/test_java.py | 249 ++ tests/unit/protocol/test_served.py | 124 + tests/unit/protocol/triple/conftest.py | 57 + .../protocol/triple/grpc/test_compression.py | 34 + .../unit/protocol/triple/grpc/test_framing.py | 106 + .../unit/protocol/triple/grpc/test_headers.py | 65 + .../unit/protocol/triple/grpc/test_status.py | 162 + .../unit/protocol/triple/test_attachments.py | 128 + tests/unit/protocol/triple/test_headers.py | 28 + tests/unit/protocol/triple/test_messages.py | 72 + tests/unit/protocol/triple/test_protocol.py | 130 + tests/unit/protocol/triple/test_settings.py | 31 + tests/unit/protocol/triple/test_wrapper.py | 70 + tests/unit/registry/nacos/test_interface.py | 65 + tests/unit/registry/test_consumer.py | 213 ++ tests/unit/registry/test_discovery.py | 238 ++ tests/unit/registry/test_provider.py | 259 ++ tests/unit/registry/test_registration.py | 47 + .../unit/registry/zookeeper/test_instance.py | 71 + .../unit/registry/zookeeper/test_interface.py | 48 + tests/unit/rpc/conftest.py | 84 + tests/unit/rpc/test_client.py | 243 ++ tests/unit/rpc/test_context.py | 98 + tests/unit/rpc/test_definition.py | 283 ++ tests/unit/rpc/test_server.py | 176 + tests/unit/serialization/test_base.py | 40 + tests/unit/serialization/test_hessian2.py | 318 ++ tests/unit/serialization/test_protobuf.py | 67 + tests/unit/test_application.py | 541 ++++ tests/unit/test_url.py | 219 ++ tests/unit/transport/h2/aio/conftest.py | 203 ++ tests/unit/transport/h2/aio/test_bdp.py | 128 + tests/unit/transport/h2/aio/test_client.py | 552 ++++ .../unit/transport/h2/aio/test_connection.py | 278 ++ tests/unit/transport/h2/aio/test_server.py | 230 ++ tests/unit/transport/h2/aio/test_stream.py | 232 ++ tests/unit/transport/h2/test_exceptions.py | 41 + tests/unit/transport/nacos/sdk/test_config.py | 133 + .../transport/nacos/sdk/test_connection.py | 62 + tests/unit/transport/nacos/sdk/test_naming.py | 178 ++ tests/unit/transport/nacos/test_base.py | 54 + tests/unit/transport/test_tls.py | 144 + tests/unit/transport/zookeeper/test_base.py | 86 + tests/unit/transport/zookeeper/test_kazoo.py | 497 +++ tests/unit/utils/test_async.py | 303 ++ tests/unit/utils/test_converters.py | 43 + tests/unit/utils/test_dialer.py | 177 ++ tests/unit/utils/test_net.py | 132 + tests/unit/utils/test_optional.py | 53 + uv.lock | 2827 +++++++++++++++++ 682 files changed, 69540 insertions(+), 13578 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/license-check.yaml create mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/test-suite.yaml delete mode 100644 .license-ignore create mode 100644 .licenserc.yaml create mode 100644 .pre-commit-config.yaml create mode 100644 .python-version create mode 100644 AGENTS.md create mode 100644 CONTRIBUTING.md create mode 100644 benchmark/.gitignore create mode 100644 benchmark/README.md create mode 100644 benchmark/go/benchpb/bench.pb.go create mode 100644 benchmark/go/benchpb/bench.triple.go create mode 100644 benchmark/go/go.mod create mode 100644 benchmark/go/go.sum create mode 100644 benchmark/go/load/main.go create mode 100644 benchmark/go/server/main.go create mode 100644 benchmark/java/pom.xml create mode 100644 benchmark/java/src/main/java/org/apache/dubbo/benchmark/BenchService.java create mode 100644 benchmark/java/src/main/java/org/apache/dubbo/benchmark/JavaServer.java create mode 100644 benchmark/plot.py create mode 100644 benchmark/proto/bench.proto create mode 100644 benchmark/python/bench_pb2.py create mode 100644 benchmark/python/bench_pb2.pyi create mode 100644 benchmark/python/client.py create mode 100644 benchmark/python/contract.py create mode 100644 benchmark/python/dubbo_server.py create mode 100644 benchmark/python/grpcio_server.py create mode 100644 benchmark/python/grpclib_server.py create mode 100644 benchmark/ruff.toml create mode 100644 benchmark/run.py create mode 100644 benchmark/scenarios.toml delete mode 100755 docs/CONTRIBUTING.md delete mode 100644 docs/img/Architecture.svg delete mode 100644 requirements-dev.txt delete mode 100644 samples/__init__.py create mode 100644 samples/basics/01_hello_world/README.md create mode 100644 samples/basics/01_hello_world/client.py create mode 100644 samples/basics/01_hello_world/greeter.py create mode 100644 samples/basics/01_hello_world/server.py create mode 100644 samples/basics/02_protobuf/README.md create mode 100644 samples/basics/02_protobuf/client.py create mode 100644 samples/basics/02_protobuf/greeter.proto create mode 100644 samples/basics/02_protobuf/greeter_dubbo.py create mode 100644 samples/basics/02_protobuf/greeter_pb2.py create mode 100644 samples/basics/02_protobuf/greeter_pb2.pyi create mode 100644 samples/basics/02_protobuf/server.py create mode 100644 samples/basics/03_streaming/README.md create mode 100644 samples/basics/03_streaming/client.py create mode 100644 samples/basics/03_streaming/greeter.proto create mode 100644 samples/basics/03_streaming/greeter_dubbo.py create mode 100644 samples/basics/03_streaming/greeter_pb2.py create mode 100644 samples/basics/03_streaming/greeter_pb2.pyi create mode 100644 samples/basics/03_streaming/server.py create mode 100644 samples/basics/04_registry/README.md create mode 100644 samples/basics/04_registry/client.py create mode 100644 samples/basics/04_registry/greeter.py create mode 100644 samples/basics/04_registry/server.py create mode 100644 samples/basics/04_registry/show_registry.py create mode 100644 samples/basics/05_configuration/README.md create mode 100644 samples/basics/05_configuration/client.py create mode 100644 samples/basics/05_configuration/client.yaml create mode 100644 samples/basics/05_configuration/greeter.py create mode 100644 samples/basics/05_configuration/server.py create mode 100644 samples/basics/05_configuration/server.yaml create mode 100644 samples/basics/06_logging/README.md create mode 100644 samples/basics/06_logging/client.py create mode 100644 samples/basics/06_logging/greeter.py create mode 100644 samples/basics/06_logging/logs.py create mode 100644 samples/basics/06_logging/server.py create mode 100644 samples/basics/06_logging/structlog_logs.py create mode 100644 samples/basics/07_graceful_shutdown/README.md create mode 100644 samples/basics/07_graceful_shutdown/client.py create mode 100644 samples/basics/07_graceful_shutdown/greeter.py create mode 100644 samples/basics/07_graceful_shutdown/server.py create mode 100644 samples/basics/08_errors_and_timeouts/README.md create mode 100644 samples/basics/08_errors_and_timeouts/client.py create mode 100644 samples/basics/08_errors_and_timeouts/server.py create mode 100644 samples/basics/08_errors_and_timeouts/users.proto create mode 100644 samples/basics/08_errors_and_timeouts/users_dubbo.py create mode 100644 samples/basics/08_errors_and_timeouts/users_pb2.py create mode 100644 samples/basics/08_errors_and_timeouts/users_pb2.pyi create mode 100644 samples/basics/09_context/README.md create mode 100644 samples/basics/09_context/client.py create mode 100644 samples/basics/09_context/inventory_server.py create mode 100644 samples/basics/09_context/order_server.py create mode 100644 samples/basics/09_context/services.py create mode 100644 samples/basics/10_group_version/README.md create mode 100644 samples/basics/10_group_version/client.py create mode 100644 samples/basics/10_group_version/greeter.py create mode 100644 samples/basics/10_group_version/server_v1.py create mode 100644 samples/basics/10_group_version/server_v2.py create mode 100644 samples/basics/11_load_balancing/README.md create mode 100644 samples/basics/11_load_balancing/client.py create mode 100644 samples/basics/11_load_balancing/server.py create mode 100644 samples/basics/11_load_balancing/worker.py create mode 100644 samples/basics/12_config_center/README.md create mode 100644 samples/basics/12_config_center/client.py create mode 100644 samples/basics/12_config_center/greeter.py create mode 100644 samples/basics/12_config_center/publish.py create mode 100644 samples/basics/12_config_center/server.py create mode 100644 samples/basics/13_routing/README.md create mode 100644 samples/basics/13_routing/client.py create mode 100644 samples/basics/13_routing/greeter.py create mode 100644 samples/basics/13_routing/publish.py create mode 100644 samples/basics/13_routing/server.py create mode 100644 samples/basics/14_filters/README.md create mode 100644 samples/basics/14_filters/client.py create mode 100644 samples/basics/14_filters/filters.py create mode 100644 samples/basics/14_filters/greeter.py create mode 100644 samples/basics/14_filters/server.py create mode 100644 samples/basics/15_extensions/README.md create mode 100644 samples/basics/15_extensions/client.py create mode 100644 samples/basics/15_extensions/dubbo-toml/dubbo_toml.py create mode 100644 samples/basics/15_extensions/dubbo-toml/pyproject.toml create mode 100644 samples/basics/15_extensions/greeter.py create mode 100644 samples/basics/15_extensions/server.py create mode 100644 samples/basics/15_extensions/server.toml create mode 100644 samples/basics/16_tls/.gitignore create mode 100644 samples/basics/16_tls/README.md create mode 100644 samples/basics/16_tls/client.py create mode 100644 samples/basics/16_tls/greeter.proto create mode 100644 samples/basics/16_tls/greeter_dubbo.py create mode 100644 samples/basics/16_tls/greeter_pb2.py create mode 100644 samples/basics/16_tls/greeter_pb2.pyi create mode 100644 samples/basics/16_tls/make_certificates.py create mode 100644 samples/basics/16_tls/server.py create mode 100644 samples/basics/17_generic/README.md create mode 100644 samples/basics/17_generic/client.py create mode 100644 samples/basics/17_generic/server.py create mode 100644 samples/compose.yaml delete mode 100644 samples/helloworld/__init__.py delete mode 100644 samples/helloworld/client.py delete mode 100644 samples/helloworld/server.py create mode 100644 samples/integrations/fastapi/README.md create mode 100644 samples/integrations/fastapi/app.py create mode 100644 samples/integrations/fastapi/backend.py create mode 100644 samples/integrations/fastapi/orders.py create mode 100644 samples/integrations/fastapi/shop.py create mode 100644 samples/integrations/pydantic_ai/README.md create mode 100644 samples/integrations/pydantic_ai/planner.py create mode 100644 samples/integrations/pydantic_ai/services.py create mode 100644 samples/integrations/pydantic_ai/supply.py create mode 100644 samples/interop/go/README.md create mode 100644 samples/interop/go/go/client/main.go create mode 100644 samples/interop/go/go/go.mod create mode 100644 samples/interop/go/go/go.sum create mode 100644 samples/interop/go/go/greeter/greeter.pb.go create mode 100644 samples/interop/go/go/greeter/greeter.triple.go create mode 100644 samples/interop/go/go/server/main.go create mode 100644 samples/interop/go/greeter_dubbo.py create mode 100644 samples/interop/go/greeter_pb2.py create mode 100644 samples/interop/go/greeter_pb2.pyi create mode 100644 samples/interop/go/proto/greeter.proto create mode 100644 samples/interop/go/python_client.py create mode 100644 samples/interop/go/python_server.py create mode 100644 samples/interop/grpc/README.md create mode 100644 samples/interop/grpc/dubbo_client.py create mode 100644 samples/interop/grpc/dubbo_server.py create mode 100644 samples/interop/grpc/greeter.proto create mode 100644 samples/interop/grpc/greeter_dubbo.py create mode 100644 samples/interop/grpc/greeter_pb2.py create mode 100644 samples/interop/grpc/greeter_pb2.pyi create mode 100644 samples/interop/grpc/greeter_pb2_grpc.py create mode 100644 samples/interop/grpc/grpc_client.py create mode 100644 samples/interop/grpc/grpc_server.py create mode 100644 samples/interop/java/README.md create mode 100644 samples/interop/java/greeter_dubbo.py create mode 100644 samples/interop/java/greeter_pb2.py create mode 100644 samples/interop/java/greeter_pb2.pyi create mode 100644 samples/interop/java/java/.gitignore create mode 100644 samples/interop/java/java/pom.xml create mode 100644 samples/interop/java/java/src/main/java/org/apache/dubbo/samples/JavaClient.java create mode 100644 samples/interop/java/java/src/main/java/org/apache/dubbo/samples/JavaServer.java create mode 100644 samples/interop/java/java/src/main/java/org/apache/dubbo/samples/User.java create mode 100644 samples/interop/java/java/src/main/java/org/apache/dubbo/samples/UserService.java create mode 100644 samples/interop/java/proto/greeter.proto create mode 100644 samples/interop/java/python_client.py create mode 100644 samples/interop/java/python_server.py create mode 100644 samples/interop/java/users.py delete mode 100644 samples/llm/README.md delete mode 100644 samples/llm/__init__.py delete mode 100644 samples/llm/chat.proto delete mode 100644 samples/llm/chat_pb2.py delete mode 100644 samples/llm/main.py delete mode 100644 samples/proto/__init__.py delete mode 100644 samples/proto/greeter.proto delete mode 100644 samples/proto/greeter_pb2.py delete mode 100644 samples/registry/README.md delete mode 100644 samples/registry/__init__.py delete mode 100644 samples/registry/zookeeper/__init__.py delete mode 100644 samples/registry/zookeeper/client.py delete mode 100644 samples/registry/zookeeper/server.py create mode 100644 samples/ruff.toml delete mode 100644 samples/serialization/README.md delete mode 100644 samples/serialization/__init__.py delete mode 100644 samples/serialization/json/__init__.py delete mode 100644 samples/serialization/json/client.py delete mode 100644 samples/serialization/json/server.py delete mode 100644 samples/serialization/protobuf/__init__.py delete mode 100644 samples/serialization/protobuf/client.py delete mode 100644 samples/serialization/protobuf/server.py delete mode 100644 samples/stream/README.md delete mode 100644 samples/stream/__init__.py delete mode 100644 samples/stream/bidi_stream/__init__.py delete mode 100644 samples/stream/bidi_stream/client.py delete mode 100644 samples/stream/bidi_stream/server.py delete mode 100644 samples/stream/client_stream/__init__.py delete mode 100644 samples/stream/client_stream/client.py delete mode 100644 samples/stream/client_stream/server.py delete mode 100644 samples/stream/server_stream/__init__.py delete mode 100644 samples/stream/server_stream/client.py delete mode 100644 samples/stream/server_stream/server.py delete mode 100755 scripts/build.sh delete mode 100755 scripts/check.sh create mode 100644 scripts/check_install.py create mode 100644 scripts/generate_protos.py delete mode 100755 scripts/install-dev.sh delete mode 100755 scripts/rat.sh delete mode 100755 scripts/test.sh delete mode 100644 src/dubbo/__about__.py create mode 100644 src/dubbo/_proto/__init__.py create mode 100644 src/dubbo/_proto/google/__init__.py create mode 100644 src/dubbo/_proto/google/rpc/__init__.py create mode 100644 src/dubbo/_proto/google/rpc/status.proto create mode 100644 src/dubbo/_proto/google/rpc/status_pb2.py create mode 100644 src/dubbo/_proto/google/rpc/status_pb2.pyi create mode 100644 src/dubbo/_proto/grpc/__init__.py create mode 100644 src/dubbo/_proto/grpc/health/__init__.py create mode 100644 src/dubbo/_proto/grpc/health/v1/__init__.py create mode 100644 src/dubbo/_proto/grpc/health/v1/health.proto create mode 100644 src/dubbo/_proto/grpc/health/v1/health_dubbo.py create mode 100644 src/dubbo/_proto/grpc/health/v1/health_pb2.py create mode 100644 src/dubbo/_proto/grpc/health/v1/health_pb2.pyi create mode 100644 src/dubbo/_proto/grpc/reflection/__init__.py create mode 100644 src/dubbo/_proto/grpc/reflection/v1/__init__.py create mode 100644 src/dubbo/_proto/grpc/reflection/v1/reflection.proto create mode 100644 src/dubbo/_proto/grpc/reflection/v1/reflection_dubbo.py create mode 100644 src/dubbo/_proto/grpc/reflection/v1/reflection_pb2.py create mode 100644 src/dubbo/_proto/grpc/reflection/v1/reflection_pb2.pyi create mode 100644 src/dubbo/_proto/grpc/reflection/v1alpha/__init__.py create mode 100644 src/dubbo/_proto/grpc/reflection/v1alpha/reflection.proto create mode 100644 src/dubbo/_proto/grpc/reflection/v1alpha/reflection_dubbo.py create mode 100644 src/dubbo/_proto/grpc/reflection/v1alpha/reflection_pb2.py create mode 100644 src/dubbo/_proto/grpc/reflection/v1alpha/reflection_pb2.pyi create mode 100644 src/dubbo/_proto/org/__init__.py create mode 100644 src/dubbo/_proto/org/apache/__init__.py create mode 100644 src/dubbo/_proto/org/apache/dubbo/__init__.py create mode 100644 src/dubbo/_proto/org/apache/dubbo/metadata/__init__.py create mode 100644 src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2.proto create mode 100644 src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2_dubbo.py create mode 100644 src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2_pb2.py create mode 100644 src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2_pb2.pyi create mode 100644 src/dubbo/_proto/org/apache/dubbo/triple/__init__.py create mode 100644 src/dubbo/_proto/org/apache/dubbo/triple/triple_wrapper.proto create mode 100644 src/dubbo/_proto/org/apache/dubbo/triple/triple_wrapper_pb2.py create mode 100644 src/dubbo/_proto/org/apache/dubbo/triple/triple_wrapper_pb2.pyi create mode 100644 src/dubbo/_proto/pool.py create mode 100644 src/dubbo/application.py delete mode 100644 src/dubbo/bootstrap.py delete mode 100644 src/dubbo/classes.py delete mode 100644 src/dubbo/client.py delete mode 100644 src/dubbo/cluster/_interfaces.py create mode 100644 src/dubbo/cluster/available.py create mode 100644 src/dubbo/cluster/base.py create mode 100644 src/dubbo/cluster/broadcast.py create mode 100644 src/dubbo/cluster/configurator.py delete mode 100644 src/dubbo/cluster/directories.py create mode 100644 src/dubbo/cluster/directory/__init__.py create mode 100644 src/dubbo/cluster/directory/base.py create mode 100644 src/dubbo/cluster/directory/dynamic.py create mode 100644 src/dubbo/cluster/directory/static.py create mode 100644 src/dubbo/cluster/failback.py create mode 100644 src/dubbo/cluster/failfast.py delete mode 100644 src/dubbo/cluster/failfast_cluster.py create mode 100644 src/dubbo/cluster/failover.py create mode 100644 src/dubbo/cluster/failsafe.py create mode 100644 src/dubbo/cluster/forking.py create mode 100644 src/dubbo/cluster/loadbalance/__init__.py create mode 100644 src/dubbo/cluster/loadbalance/base.py create mode 100644 src/dubbo/cluster/loadbalance/consistenthash.py create mode 100644 src/dubbo/cluster/loadbalance/leastactive.py create mode 100644 src/dubbo/cluster/loadbalance/random.py create mode 100644 src/dubbo/cluster/loadbalance/roundrobin.py delete mode 100644 src/dubbo/cluster/loadbalances.py delete mode 100644 src/dubbo/cluster/monitor/__init__.py delete mode 100644 src/dubbo/cluster/monitor/cpu.py create mode 100644 src/dubbo/cluster/reference.py create mode 100644 src/dubbo/cluster/router/__init__.py create mode 100644 src/dubbo/cluster/router/base.py create mode 100644 src/dubbo/cluster/router/chain.py create mode 100644 src/dubbo/cluster/router/condition.py create mode 100644 src/dubbo/cluster/router/tag.py create mode 100644 src/dubbo/cluster/rule.py create mode 100644 src/dubbo/cluster/zoneaware.py delete mode 100644 src/dubbo/compression/_interfaces.py create mode 100644 src/dubbo/compression/base.py create mode 100644 src/dubbo/compression/bzip2.py delete mode 100644 src/dubbo/compression/bzip2s.py create mode 100644 src/dubbo/compression/deflate.py create mode 100644 src/dubbo/compression/gzip.py delete mode 100644 src/dubbo/compression/gzips.py delete mode 100644 src/dubbo/compression/identities.py create mode 100644 src/dubbo/config/__init__.py create mode 100644 src/dubbo/config/data.py create mode 100644 src/dubbo/config/exceptions.py create mode 100644 src/dubbo/config/fields.py create mode 100644 src/dubbo/config/loading.py create mode 100644 src/dubbo/config/models.py create mode 100644 src/dubbo/config/parsers/__init__.py create mode 100644 src/dubbo/config/parsers/base.py create mode 100644 src/dubbo/config/parsers/json.py create mode 100644 src/dubbo/config/parsers/properties.py create mode 100644 src/dubbo/config/parsers/yaml.py create mode 100644 src/dubbo/config/structure.py create mode 100644 src/dubbo/config/urls.py create mode 100644 src/dubbo/config_center/__init__.py create mode 100644 src/dubbo/config_center/base.py create mode 100644 src/dubbo/config_center/nacos.py create mode 100644 src/dubbo/config_center/zookeeper.py delete mode 100644 src/dubbo/configs.py create mode 100644 src/dubbo/constants.py delete mode 100644 src/dubbo/constants/__init__.py delete mode 100644 src/dubbo/constants/common_constants.py delete mode 100644 src/dubbo/constants/config_constants.py delete mode 100644 src/dubbo/constants/logger_constants.py delete mode 100644 src/dubbo/constants/registry_constants.py create mode 100644 src/dubbo/exceptions.py create mode 100644 src/dubbo/extension/exceptions.py delete mode 100644 src/dubbo/extension/extension_loader.py create mode 100644 src/dubbo/extension/loader.py delete mode 100644 src/dubbo/extension/registries.py create mode 100644 src/dubbo/extension/resource.py create mode 100644 src/dubbo/extension/scope.py create mode 100644 src/dubbo/filter/__init__.py create mode 100644 src/dubbo/filter/accesslog.py create mode 100644 src/dubbo/filter/activecount.py create mode 100644 src/dubbo/filter/actives.py create mode 100644 src/dubbo/filter/base.py create mode 100644 src/dubbo/filter/chain.py create mode 100644 src/dubbo/filter/deprecated.py create mode 100644 src/dubbo/filter/executes.py create mode 100644 src/dubbo/filter/token.py create mode 100644 src/dubbo/filter/tps.py delete mode 100644 src/dubbo/loadbalance/__init__.py delete mode 100644 src/dubbo/loadbalance/_interfaces.py delete mode 100644 src/dubbo/loggers.py create mode 100644 src/dubbo/metadata/__init__.py create mode 100644 src/dubbo/metadata/info.py create mode 100644 src/dubbo/metadata/instance.py create mode 100644 src/dubbo/metadata/report/__init__.py create mode 100644 src/dubbo/metadata/report/base.py create mode 100644 src/dubbo/metadata/report/nacos.py create mode 100644 src/dubbo/metadata/report/zookeeper.py create mode 100644 src/dubbo/metadata/service/__init__.py create mode 100644 src/dubbo/metadata/service/client.py create mode 100644 src/dubbo/metadata/service/server.py create mode 100644 src/dubbo/metadata/service/v1.py create mode 100644 src/dubbo/metadata/service/v2.py delete mode 100644 src/dubbo/node.py create mode 100644 src/dubbo/protoc/__init__.py create mode 100644 src/dubbo/protoc/plugin.py delete mode 100644 src/dubbo/protocol/_interfaces.py create mode 100644 src/dubbo/protocol/base.py create mode 100644 src/dubbo/protocol/dubbo/__init__.py create mode 100644 src/dubbo/protocol/dubbo/body.py create mode 100644 src/dubbo/protocol/dubbo/client.py create mode 100644 src/dubbo/protocol/dubbo/connection.py create mode 100644 src/dubbo/protocol/dubbo/invoker.py create mode 100644 src/dubbo/protocol/dubbo/protocol.py create mode 100644 src/dubbo/protocol/dubbo/server.py create mode 100644 src/dubbo/protocol/exported.py create mode 100644 src/dubbo/protocol/generic.py delete mode 100644 src/dubbo/protocol/invocation.py create mode 100644 src/dubbo/protocol/java.py create mode 100644 src/dubbo/protocol/served.py create mode 100644 src/dubbo/protocol/triple/attachments.py create mode 100644 src/dubbo/protocol/triple/builtin/__init__.py create mode 100644 src/dubbo/protocol/triple/builtin/health.py create mode 100644 src/dubbo/protocol/triple/builtin/reflection.py delete mode 100644 src/dubbo/protocol/triple/call/__init__.py delete mode 100644 src/dubbo/protocol/triple/call/_interfaces.py delete mode 100644 src/dubbo/protocol/triple/call/client_call.py delete mode 100644 src/dubbo/protocol/triple/call/server_call.py delete mode 100644 src/dubbo/protocol/triple/coders.py delete mode 100644 src/dubbo/protocol/triple/constants.py create mode 100644 src/dubbo/protocol/triple/grpc/__init__.py create mode 100644 src/dubbo/protocol/triple/grpc/client.py create mode 100644 src/dubbo/protocol/triple/grpc/compression.py create mode 100644 src/dubbo/protocol/triple/grpc/framing.py create mode 100644 src/dubbo/protocol/triple/grpc/headers.py create mode 100644 src/dubbo/protocol/triple/grpc/server.py create mode 100644 src/dubbo/protocol/triple/grpc/status.py create mode 100644 src/dubbo/protocol/triple/headers.py create mode 100644 src/dubbo/protocol/triple/messages.py delete mode 100644 src/dubbo/protocol/triple/metadata.py delete mode 100644 src/dubbo/protocol/triple/results.py create mode 100644 src/dubbo/protocol/triple/routes.py create mode 100644 src/dubbo/protocol/triple/server.py create mode 100644 src/dubbo/protocol/triple/settings.py delete mode 100644 src/dubbo/protocol/triple/status.py delete mode 100644 src/dubbo/protocol/triple/stream/__init__.py delete mode 100644 src/dubbo/protocol/triple/stream/_interfaces.py delete mode 100644 src/dubbo/protocol/triple/stream/client_stream.py delete mode 100644 src/dubbo/protocol/triple/stream/server_stream.py delete mode 100644 src/dubbo/protocol/triple/streams.py create mode 100644 src/dubbo/protocol/triple/wrapper.py delete mode 100644 src/dubbo/proxy/__init__.py delete mode 100644 src/dubbo/proxy/_interfaces.py delete mode 100644 src/dubbo/proxy/callables.py delete mode 100644 src/dubbo/proxy/handlers.py create mode 100644 src/dubbo/py.typed delete mode 100644 src/dubbo/registry/_interfaces.py create mode 100644 src/dubbo/registry/base.py create mode 100644 src/dubbo/registry/consumer.py create mode 100644 src/dubbo/registry/discovery.py create mode 100644 src/dubbo/registry/nacos/__init__.py create mode 100644 src/dubbo/registry/nacos/instance.py create mode 100644 src/dubbo/registry/nacos/interface.py delete mode 100644 src/dubbo/registry/protocol.py create mode 100644 src/dubbo/registry/provider.py create mode 100644 src/dubbo/registry/registration.py delete mode 100644 src/dubbo/registry/zookeeper/_interfaces.py create mode 100644 src/dubbo/registry/zookeeper/instance.py create mode 100644 src/dubbo/registry/zookeeper/interface.py delete mode 100644 src/dubbo/registry/zookeeper/kazoo_transport.py delete mode 100644 src/dubbo/registry/zookeeper/zk_registry.py delete mode 100644 src/dubbo/remoting/__init__.py delete mode 100644 src/dubbo/remoting/_interfaces.py delete mode 100644 src/dubbo/remoting/aio/__init__.py delete mode 100644 src/dubbo/remoting/aio/_interfaces.py delete mode 100644 src/dubbo/remoting/aio/aio_transporter.py delete mode 100644 src/dubbo/remoting/aio/constants.py delete mode 100644 src/dubbo/remoting/aio/event_loop.py delete mode 100644 src/dubbo/remoting/aio/exceptions.py delete mode 100644 src/dubbo/remoting/aio/http2/__init__.py delete mode 100644 src/dubbo/remoting/aio/http2/controllers.py delete mode 100644 src/dubbo/remoting/aio/http2/frames.py delete mode 100644 src/dubbo/remoting/aio/http2/headers.py delete mode 100644 src/dubbo/remoting/aio/http2/protocol.py delete mode 100644 src/dubbo/remoting/aio/http2/registries.py delete mode 100644 src/dubbo/remoting/aio/http2/stream.py delete mode 100644 src/dubbo/remoting/aio/http2/stream_handler.py delete mode 100644 src/dubbo/remoting/aio/http2/utils.py create mode 100644 src/dubbo/rpc/__init__.py create mode 100644 src/dubbo/rpc/client.py create mode 100644 src/dubbo/rpc/context.py create mode 100644 src/dubbo/rpc/definition.py create mode 100644 src/dubbo/rpc/invocation.py create mode 100644 src/dubbo/rpc/server.py create mode 100644 src/dubbo/rpc/stream.py delete mode 100644 src/dubbo/serialization/_interfaces.py create mode 100644 src/dubbo/serialization/base.py delete mode 100644 src/dubbo/serialization/custom_serializers.py delete mode 100644 src/dubbo/serialization/direct_serializers.py create mode 100644 src/dubbo/serialization/hessian2.py create mode 100644 src/dubbo/serialization/protobuf.py delete mode 100644 src/dubbo/server.py create mode 100644 src/dubbo/transport/__init__.py create mode 100644 src/dubbo/transport/h2/__init__.py create mode 100644 src/dubbo/transport/h2/aio/__init__.py create mode 100644 src/dubbo/transport/h2/aio/bdp.py create mode 100644 src/dubbo/transport/h2/aio/client.py create mode 100644 src/dubbo/transport/h2/aio/connection.py create mode 100644 src/dubbo/transport/h2/aio/keep_alive.py create mode 100644 src/dubbo/transport/h2/aio/server.py create mode 100644 src/dubbo/transport/h2/aio/stream.py create mode 100644 src/dubbo/transport/h2/aio/tasks.py create mode 100644 src/dubbo/transport/h2/base.py create mode 100644 src/dubbo/transport/h2/exceptions.py create mode 100644 src/dubbo/transport/listener.py create mode 100644 src/dubbo/transport/nacos/__init__.py create mode 100644 src/dubbo/transport/nacos/base.py create mode 100644 src/dubbo/transport/nacos/exceptions.py create mode 100644 src/dubbo/transport/nacos/sdk/__init__.py create mode 100644 src/dubbo/transport/nacos/sdk/config.py create mode 100644 src/dubbo/transport/nacos/sdk/connection.py create mode 100644 src/dubbo/transport/nacos/sdk/naming.py create mode 100644 src/dubbo/transport/tls.py create mode 100644 src/dubbo/transport/zookeeper/__init__.py create mode 100644 src/dubbo/transport/zookeeper/base.py create mode 100644 src/dubbo/transport/zookeeper/exceptions.py create mode 100644 src/dubbo/transport/zookeeper/kazoo.py delete mode 100644 src/dubbo/types.py delete mode 100644 src/dubbo/utils.py create mode 100644 src/dubbo/utils/__init__.py create mode 100644 src/dubbo/utils/annotations.py create mode 100644 src/dubbo/utils/async_.py create mode 100644 src/dubbo/utils/backoff.py create mode 100644 src/dubbo/utils/converters.py create mode 100644 src/dubbo/utils/dialer.py create mode 100644 src/dubbo/utils/mapping.py create mode 100644 src/dubbo/utils/net.py create mode 100644 src/dubbo/utils/optional.py delete mode 100644 tests/__init__.py create mode 100644 tests/certificates/localhost-cert.pem create mode 100644 tests/certificates/localhost-key-encrypted.pem create mode 100644 tests/certificates/localhost-key.pem create mode 100644 tests/conftest.py create mode 100644 tests/integration/compose.yaml create mode 100644 tests/integration/config/parsers/test_base.py create mode 100644 tests/integration/config_center/test_nacos.py create mode 100644 tests/integration/config_center/test_zookeeper.py create mode 100644 tests/integration/conftest.py create mode 100644 tests/integration/metadata/report/test_nacos.py create mode 100644 tests/integration/metadata/report/test_zookeeper.py create mode 100644 tests/integration/protocol/dubbo/conftest.py create mode 100644 tests/integration/protocol/dubbo/test_client.py create mode 100644 tests/integration/protocol/dubbo/test_connection.py create mode 100644 tests/integration/protocol/dubbo/test_protocol.py create mode 100644 tests/integration/protocol/dubbo/test_server.py create mode 100644 tests/integration/protocol/triple/builtin/test_health.py create mode 100644 tests/integration/protocol/triple/builtin/test_reflection.py create mode 100644 tests/integration/protocol/triple/conftest.py create mode 100644 tests/integration/protocol/triple/grpc/test_client.py create mode 100644 tests/integration/protocol/triple/grpc/test_server.py create mode 100644 tests/integration/protocol/triple/test_client.py create mode 100644 tests/integration/protocol/triple/test_protocol.py create mode 100644 tests/integration/protocol/triple/test_pure_python_protobuf.py create mode 100644 tests/integration/protocol/triple/test_server.py create mode 100644 tests/integration/protocol/triple/test_wrapper.py create mode 100644 tests/integration/registry/conftest.py create mode 100644 tests/integration/registry/nacos/conftest.py create mode 100644 tests/integration/registry/nacos/test_application.py create mode 100644 tests/integration/registry/nacos/test_instance.py create mode 100644 tests/integration/registry/nacos/test_interface.py create mode 100644 tests/integration/registry/test_application.py create mode 100644 tests/integration/registry/zookeeper/test_instance.py create mode 100644 tests/integration/registry/zookeeper/test_interface.py create mode 100644 tests/integration/rpc/test_client.py create mode 100644 tests/integration/test_application.py create mode 100644 tests/integration/test_application_imports.py create mode 100644 tests/integration/test_application_signals.py create mode 100644 tests/integration/test_samples.py create mode 100644 tests/integration/transport/h2/aio/conftest.py create mode 100644 tests/integration/transport/h2/aio/test_bdp.py create mode 100644 tests/integration/transport/h2/aio/test_client.py create mode 100644 tests/integration/transport/h2/aio/test_connection.py create mode 100644 tests/integration/transport/h2/aio/test_server.py create mode 100644 tests/integration/transport/h2/aio/test_stream.py create mode 100644 tests/integration/transport/h2/test_base.py create mode 100644 tests/integration/transport/test_kazoo.py create mode 100644 tests/integration/transport/test_nacos_sdk.py create mode 100644 tests/integration/transport/test_zookeeper.py create mode 100644 tests/integration/transport/test_zookeeper_client.py delete mode 100644 tests/test_url.py create mode 100644 tests/unit/cluster/conftest.py create mode 100644 tests/unit/cluster/directory/test_dynamic.py create mode 100644 tests/unit/cluster/directory/test_static.py create mode 100644 tests/unit/cluster/loadbalance/conftest.py create mode 100644 tests/unit/cluster/loadbalance/data/consistenthash.json create mode 100644 tests/unit/cluster/loadbalance/data/consistenthash.md create mode 100644 tests/unit/cluster/loadbalance/test_base.py create mode 100644 tests/unit/cluster/loadbalance/test_consistenthash.py create mode 100644 tests/unit/cluster/loadbalance/test_leastactive.py create mode 100644 tests/unit/cluster/loadbalance/test_random.py create mode 100644 tests/unit/cluster/loadbalance/test_roundrobin.py create mode 100644 tests/unit/cluster/router/conftest.py create mode 100644 tests/unit/cluster/router/test_chain.py create mode 100644 tests/unit/cluster/router/test_condition.py create mode 100644 tests/unit/cluster/router/test_tag.py create mode 100644 tests/unit/cluster/test_available.py create mode 100644 tests/unit/cluster/test_base.py create mode 100644 tests/unit/cluster/test_broadcast.py create mode 100644 tests/unit/cluster/test_configurator.py create mode 100644 tests/unit/cluster/test_failback.py create mode 100644 tests/unit/cluster/test_failfast.py create mode 100644 tests/unit/cluster/test_failover.py create mode 100644 tests/unit/cluster/test_failsafe.py create mode 100644 tests/unit/cluster/test_forking.py create mode 100644 tests/unit/cluster/test_zoneaware.py create mode 100644 tests/unit/compression/test_base.py create mode 100644 tests/unit/config/parsers/test_base.py create mode 100644 tests/unit/config/parsers/test_json.py create mode 100644 tests/unit/config/parsers/test_properties.py create mode 100644 tests/unit/config/parsers/test_yaml.py create mode 100644 tests/unit/config/test_fields.py create mode 100644 tests/unit/config/test_loading.py create mode 100644 tests/unit/config/test_models.py create mode 100644 tests/unit/config/test_structure.py create mode 100644 tests/unit/config/test_urls.py create mode 100644 tests/unit/config_center/test_base.py create mode 100644 tests/unit/config_center/test_zookeeper.py create mode 100644 tests/unit/extension/test_loader.py create mode 100644 tests/unit/extension/test_scope.py create mode 100644 tests/unit/filter/conftest.py create mode 100644 tests/unit/filter/test_accesslog.py create mode 100644 tests/unit/filter/test_activecount.py create mode 100644 tests/unit/filter/test_actives.py create mode 100644 tests/unit/filter/test_base.py create mode 100644 tests/unit/filter/test_deprecated.py create mode 100644 tests/unit/filter/test_executes.py create mode 100644 tests/unit/filter/test_token.py create mode 100644 tests/unit/filter/test_tps.py create mode 100644 tests/unit/metadata/service/data/Capture.java.txt create mode 100644 tests/unit/metadata/service/data/metadata_info.md create mode 100644 tests/unit/metadata/service/data/metadata_info_java.hessian create mode 100644 tests/unit/metadata/service/data/metadata_info_python.hessian create mode 100644 tests/unit/metadata/service/test_client.py create mode 100644 tests/unit/metadata/service/test_v1.py create mode 100644 tests/unit/metadata/service/test_v2.py create mode 100644 tests/unit/metadata/test_info.py create mode 100644 tests/unit/metadata/test_instance.py create mode 100644 tests/unit/protoc/data/README.md create mode 100644 tests/unit/protoc/data/greeter_v1_dubbo.py.txt create mode 100644 tests/unit/protoc/test_plugin.py create mode 100644 tests/unit/protocol/dubbo/test_body.py create mode 100644 tests/unit/protocol/dubbo/test_client.py create mode 100644 tests/unit/protocol/dubbo/test_connection.py create mode 100644 tests/unit/protocol/test_generic.py create mode 100644 tests/unit/protocol/test_java.py create mode 100644 tests/unit/protocol/test_served.py create mode 100644 tests/unit/protocol/triple/conftest.py create mode 100644 tests/unit/protocol/triple/grpc/test_compression.py create mode 100644 tests/unit/protocol/triple/grpc/test_framing.py create mode 100644 tests/unit/protocol/triple/grpc/test_headers.py create mode 100644 tests/unit/protocol/triple/grpc/test_status.py create mode 100644 tests/unit/protocol/triple/test_attachments.py create mode 100644 tests/unit/protocol/triple/test_headers.py create mode 100644 tests/unit/protocol/triple/test_messages.py create mode 100644 tests/unit/protocol/triple/test_protocol.py create mode 100644 tests/unit/protocol/triple/test_settings.py create mode 100644 tests/unit/protocol/triple/test_wrapper.py create mode 100644 tests/unit/registry/nacos/test_interface.py create mode 100644 tests/unit/registry/test_consumer.py create mode 100644 tests/unit/registry/test_discovery.py create mode 100644 tests/unit/registry/test_provider.py create mode 100644 tests/unit/registry/test_registration.py create mode 100644 tests/unit/registry/zookeeper/test_instance.py create mode 100644 tests/unit/registry/zookeeper/test_interface.py create mode 100644 tests/unit/rpc/conftest.py create mode 100644 tests/unit/rpc/test_client.py create mode 100644 tests/unit/rpc/test_context.py create mode 100644 tests/unit/rpc/test_definition.py create mode 100644 tests/unit/rpc/test_server.py create mode 100644 tests/unit/serialization/test_base.py create mode 100644 tests/unit/serialization/test_hessian2.py create mode 100644 tests/unit/serialization/test_protobuf.py create mode 100644 tests/unit/test_application.py create mode 100644 tests/unit/test_url.py create mode 100644 tests/unit/transport/h2/aio/conftest.py create mode 100644 tests/unit/transport/h2/aio/test_bdp.py create mode 100644 tests/unit/transport/h2/aio/test_client.py create mode 100644 tests/unit/transport/h2/aio/test_connection.py create mode 100644 tests/unit/transport/h2/aio/test_server.py create mode 100644 tests/unit/transport/h2/aio/test_stream.py create mode 100644 tests/unit/transport/h2/test_exceptions.py create mode 100644 tests/unit/transport/nacos/sdk/test_config.py create mode 100644 tests/unit/transport/nacos/sdk/test_connection.py create mode 100644 tests/unit/transport/nacos/sdk/test_naming.py create mode 100644 tests/unit/transport/nacos/test_base.py create mode 100644 tests/unit/transport/test_tls.py create mode 100644 tests/unit/transport/zookeeper/test_base.py create mode 100644 tests/unit/transport/zookeeper/test_kazoo.py create mode 100644 tests/unit/utils/test_async.py create mode 100644 tests/unit/utils/test_converters.py create mode 100644 tests/unit/utils/test_dialer.py create mode 100644 tests/unit/utils/test_net.py create mode 100644 tests/unit/utils/test_optional.py create mode 100644 uv.lock diff --git a/.asf.yaml b/.asf.yaml index 7ebda11d..1cbf3f04 100644 --- a/.asf.yaml +++ b/.asf.yaml @@ -1,34 +1,45 @@ -notifications: - commits: commits@dubbo.apache.org - issues: notifications@dubbo.apache.org - pullrequests: notifications@dubbo.apache.org - jira_options: link label link label +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +notifications: + commits: commits@dubbo.apache.org + issues: notifications@dubbo.apache.org + pullrequests: notifications@dubbo.apache.org + jira_options: link label github: homepage: https://dubbo.apache.org/ - description: "The python Implementation For Apache Dubbo." + description: Python-native microservice RPC framework for Apache Dubbo. features: - # Enable wiki for documentation wiki: false - # Enable issue management issues: false - # Enable projects for project management boards projects: false collaborators: - cnzakii enabled_merge_buttons: - # enable squash button: squash: true - # enable merge button: merge: false - # disable rebase button: rebase: false labels: - dubbo - python - rpc - - framework + - microservices + - grpc - http2 - - h2 - - grpc \ No newline at end of file + - asyncio + - distributed-systems diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..aa065e94 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly + groups: + actions: + patterns: ["*"] + - package-ecosystem: uv + directory: / + schedule: + interval: weekly + groups: + python: + patterns: ["*"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..5e81aad4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,145 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name: CI + +on: + pull_request: + push: + branches: [main] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + lint: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + - run: uv lock --check + - run: uv sync --locked --all-extras + - run: uv run --no-sync ruff check + - run: uv run --no-sync ruff format --check + - run: uv run --no-sync ty check + + license: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: apache/skywalking-eyes/header@a196742f472feaffafea537ce5a2a4c3c53a8de4 # v0.9.0 + with: + mode: check + + test: + name: test (${{ matrix.os }}, Python ${{ matrix.python }}) + runs-on: ${{ matrix.os }} + timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + python: ["3.11", "3.12", "3.13", "3.14"] + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + with: + python-version: ${{ matrix.python }} + # The type group brings ty, which a test of the extension types runs. + - run: uv sync --locked --all-extras --no-dev --group test --group type + - run: uv run --no-sync pytest tests/unit tests/integration -m "not zookeeper and not nacos and not samples" + + install: + name: default install + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + with: + python-version: "3.14" + - run: uv sync --locked --no-dev --no-default-groups + - run: uv run --no-sync python scripts/check_install.py + + integration: + name: integration (Python ${{ matrix.python }}, ZooKeeper ${{ matrix.zookeeper }}, Nacos ${{ matrix.nacos }}) + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + # Each pair takes the oldest or the newest of the supported releases, so two jobs cover both ends. + include: + - { python: "3.11", zookeeper: 3.8.8, nacos: v2.4.3 } + - { python: "3.14", zookeeper: 3.9.7, nacos: v2.5.5 } + env: + ZOOKEEPER_TAG: ${{ matrix.zookeeper }} + NACOS_TAG: ${{ matrix.nacos }} + DUBBO_TEST_ZOOKEEPER: 127.0.0.1:2181 + DUBBO_TEST_NACOS: 127.0.0.1:8848 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + with: + python-version: ${{ matrix.python }} + - run: docker compose -f tests/integration/compose.yaml up -d --wait + - run: uv sync --locked --all-extras --no-dev --group test + - run: uv run --no-sync pytest tests/integration -m "zookeeper or nacos or samples" + - if: failure() + run: docker compose -f tests/integration/compose.yaml logs --no-color > compose.log + - if: failure() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: compose-logs-${{ matrix.python }} + path: compose.log + + build: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + - run: uv build + - name: The wheel and the sdist carry LICENSE and NOTICE + run: | + for artifact in dist/*.whl dist/*.tar.gz; do + listing=$(python3 -c 'import sys, tarfile, zipfile; p = sys.argv[1]; print("\n".join(zipfile.ZipFile(p).namelist() if p.endswith(".whl") else tarfile.open(p).getnames()))' "$artifact") + for name in LICENSE NOTICE; do + grep -q "/$name$" <<< "$listing" || { echo "$artifact has no $name"; exit 1; } + done + done + # shortcut: without --strict, which fails while the project declares no readme; add it with the README. + - run: uvx twine check dist/* diff --git a/.github/workflows/license-check.yaml b/.github/workflows/license-check.yaml deleted file mode 100644 index abf37543..00000000 --- a/.github/workflows/license-check.yaml +++ /dev/null @@ -1,19 +0,0 @@ -name: License Template Check - -on: [push, pull_request] - - -jobs: - license-check: - runs-on: ubuntu-latest - permissions: write-all - steps: - - uses: actions/checkout@v4 - - - name: Set up Java - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '11' - - name: Check License Header - run: "scripts/rat.sh" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..832150cc --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,55 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Builds the candidates of a release: the source release that the PMC votes on, and the sdist and wheel built from +# it. The release manager signs them, puts them to the vote, and uploads the sdist and wheel to PyPI after it passes. +name: Release + +on: + push: + tags: ["v*"] + workflow_dispatch: + +permissions: + contents: read + +jobs: + candidates: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + - name: Read the version + run: echo "VERSION=$(uv version --short)" >> "$GITHUB_ENV" + - name: The tag names the version + if: github.ref_type == 'tag' + run: test "${GITHUB_REF_NAME#v}" = "$VERSION" + - run: uv build + - name: Build the source release + run: >- + git archive --format=tar.gz --prefix="apache-dubbo-python-$VERSION/" + -o "dist/apache-dubbo-python-$VERSION-src.tar.gz" HEAD + - name: Write the checksums + working-directory: dist + run: for file in *; do sha512sum "$file" > "$file.sha512"; done + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: release-candidates-${{ env.VERSION }} + path: dist/ diff --git a/.github/workflows/test-suite.yaml b/.github/workflows/test-suite.yaml deleted file mode 100644 index cc2bb7cf..00000000 --- a/.github/workflows/test-suite.yaml +++ /dev/null @@ -1,30 +0,0 @@ -name: Check and test -on: [push, pull_request] - - -jobs: - tests: - name: "Python ${{ matrix.python-version }}" - runs-on: "ubuntu-latest" - - strategy: - matrix: - python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] - - steps: - - uses: "actions/checkout@v4" - - uses: "actions/setup-python@v5" - with: - python-version: "${{ matrix.python-version }}" - - - name: "Install dependencies" - run: "scripts/install-dev.sh" - - - name: "Check Code Style" - run: "scripts/check.sh" - - - name: "Build package" - run: "scripts/build.sh" - - - name: "Run tests and report coverage" - run: "scripts/test.sh" diff --git a/.gitignore b/.gitignore index 1daa1a7b..1c10b979 100644 --- a/.gitignore +++ b/.gitignore @@ -1,66 +1,61 @@ -# Compiler -.idea/ -.vscode/ - -# Byte-compiled / optimized / DLL files / logs +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Entries follow https://github.com/github/gitignore/blob/main/Python.gitignore, +# limited to the tools this project uses. + +# Byte-compiled / optimized / DLL files __pycache__/ -*.py[cod] -*$py.class -*.log - +*.py[codz] # Distribution / packaging -.Python build/ -develop-eggs/ dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ *.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt # Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ +.pytest_cache/ .coverage .coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ +htmlcov/ # Environments +.venv/ .env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ +.env.* +!.env.example + +# Ruff stuff +.ruff_cache/ -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json +# PyPI configuration file +.pypirc + +# Editors +.idea/ +*.iml +.vscode/ +*.swp +*.swo +*~ + +# Operating system metadata +.DS_Store +._* +Thumbs.db +[Dd]esktop.ini +.directory diff --git a/.license-ignore b/.license-ignore deleted file mode 100644 index f8980ab1..00000000 --- a/.license-ignore +++ /dev/null @@ -1,21 +0,0 @@ -# This file is used to ignore files and directories from the license scan -# Note: these patterns are applied to single files or directories, not full paths - -# file extensions -.*md -.*proto -.*_pb2.py - -# files -.asf.yaml -LICENSE -NOTICE -requirements-dev.txt - -# directories -.vscode -.idea -.github -.gitignore -.license-ignore -docs \ No newline at end of file diff --git a/.licenserc.yaml b/.licenserc.yaml new file mode 100644 index 00000000..0b8a0241 --- /dev/null +++ b/.licenserc.yaml @@ -0,0 +1,50 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +header: + license: + spdx-id: Apache-2.0 + copyright-owner: Apache Software Foundation + paths-ignore: + - LICENSE + - NOTICE + - uv.lock + - dist + - "**/*.md" + - "**/py.typed" + - .python-version + # Generated, and the gRPC and googleapis definitions they come from. + - "src/dubbo/_proto/**/*_pb2.py" + - "src/dubbo/_proto/**/*_pb2.pyi" + - "src/dubbo/_proto/**/*_dubbo.py" + - "src/dubbo/_proto/google/**" + - "src/dubbo/_proto/grpc/**" + - "benchmark/**/*_pb2.py" + - "benchmark/**/*_pb2.pyi" + - "benchmark/**/*.pb.go" + - "benchmark/**/*.triple.go" + - "benchmark/**/go.sum" + - "samples/**/*_pb2.py" + - "samples/**/*_pb2.pyi" + - "samples/**/*_pb2_grpc.py" + - "samples/**/*_dubbo.py" + - "samples/**/*.pb.go" + - "samples/**/*.triple.go" + - "samples/**/go.sum" + - "tests/certificates/**" + - "tests/**/data/**" + comment: on-failure diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..852b3468 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,45 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +repos: + - repo: local + hooks: + - id: uv-lock + name: Check uv lockfile + entry: uv lock --check + language: system + files: ^(pyproject\.toml|uv\.lock)$ + pass_filenames: false + + - id: ruff-check + name: Check Python lint + entry: uv run --locked ruff check + language: system + types_or: [python, pyi] + + - id: ruff-format + name: Check Python formatting + entry: uv run --locked ruff format --check + language: system + types_or: [python, pyi, markdown] + + - id: ty + name: Check Python types + entry: uv run --locked ty check + language: system + files: ^src/.*\.pyi?$ + pass_filenames: false diff --git a/.python-version b/.python-version new file mode 100644 index 00000000..24ee5b1b --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.13 diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000..e0515852 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,36 @@ +# Guidance for coding agents + +Read [CONTRIBUTING.md](CONTRIBUTING.md) first: its setup, checks, code +conventions and test rules apply to every change. This file adds what an +agent needs beyond them. + +## Product boundary + +- This repository is a Python-native RPC framework for the Apache Dubbo + ecosystem. It owns the end-to-end Python experience of defining, exposing, + discovering and invoking Dubbo services. +- Interoperable formats, observable behavior, shared Dubbo roles and + vocabulary, and public extension contracts belong to the cross-language + Dubbo model; keep each at the fidelity its consumers need, and let Python + own the SDK mechanics. +- Treat Dubbo Java and Go as related implementations, not independent + specifications. Split an upstream construct into its shared commitment and + its language-specific mechanism before reusing its structure, and compare + references only at the same actor, capability and layer. +- Treat adoption and mainstream practice as evidence about tradeoffs, not as + authority; check the underlying constraint and how it fits this project. + +## Working rules + +- Read the affected implementation, its callers, tests, exports and + configuration before editing. +- Establish the requested outcome and its non-goals before adding files or + abstractions. +- Stop and ask before any change that CONTRIBUTING.md says to discuss first: + public API, package boundaries, protocol or serialization behavior, + dependencies, tooling or layout. +- Run the checks of CONTRIBUTING.md on what you touch, and report exactly + which ran and their results. Never claim that a check passed without + running it. +- Keep generated output, local environments, editor state, reports and + personal instructions out of version control. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..70afbe3d --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,296 @@ +# Contributing to Apache Dubbo for Python + +Thank you for helping. This guide covers how to set up a development +environment, the checks a change passes, and the conventions of the code and +its tests. + +## Before you start + +- Report bugs and propose features in the + [Apache Dubbo issue tracker](https://github.com/apache/dubbo/issues), + saying that they concern Dubbo for Python; this repository has no issue + tracker of its own. Discuss larger topics on the + [dev@dubbo.apache.org](mailto:dev@dubbo.apache.org) mailing list; the + [subscription guide](https://github.com/apache/dubbo/wiki/Mailing-list-subscription-guide) + explains how to join it. +- Report security vulnerabilities privately to + [security@dubbo.apache.org](mailto:security@dubbo.apache.org), never in + public; the [Apache security process](https://www.apache.org/security/) + describes what follows. +- Discuss first, in an issue or on the mailing list, any change to the + public API, the boundaries between packages, protocol or serialization + behavior, dependencies, or the repository tooling and layout. +- Before a non-trivial contribution is accepted, you need to sign the + [Individual Contributor License Agreement](https://www.apache.org/licenses/contributor-agreements.html#clas). + +## Development setup + +You need Python 3.11 to 3.14, [uv](https://docs.astral.sh/uv/), and Docker +for the registry tests. + +```shell +git clone https://github.com/apache/dubbo-python.git +cd dubbo-python +uv sync --all-extras +uv run pre-commit install +``` + +## Checks + +CI runs these on every pull request; run them before you push: + +```shell +uv run ruff check +uv run ruff format --check +uv run ty check +uv run pytest tests/unit tests/integration +``` + +The registry tests need a real ZooKeeper and Nacos. Start the versions CI +uses, and point the tests at them: + +```shell +docker compose -f tests/integration/compose.yaml up -d --wait +DUBBO_TEST_ZOOKEEPER=127.0.0.1:2181 DUBBO_TEST_NACOS=127.0.0.1:8848 \ + uv run pytest tests/integration -m "zookeeper or nacos or samples" +``` + +A test marked `zookeeper` or `nacos` is skipped while its variable is +unset. CI runs the samples, marked `samples`, with these, on Linux. + +Two scripts cover what tests cannot: + +- `uv run --group proto python scripts/generate_protos.py` regenerates the + modules of the protos in `src/dubbo/_proto`; +- `python scripts/check_install.py` checks that a fresh install with the + default dependencies serves and calls over each built-in protocol. + +## Code conventions + +### Scope + +- Derive behavior from Dubbo contracts and the needs of Python users. What + crosses languages, such as wire formats, registry data, metadata and rule + formats, follows Dubbo Java and Go exactly; everything else follows + mainstream Python practice. +- When a change follows Dubbo Java or Go, a specification or a library + contract, link the source it follows in the pull request. +- Prefer the standard library and existing dependencies. Add a dependency + only for a current need. +- While the project is in beta, an incorrect design is replaced directly, + without compatibility aliases or shims. + +### Layout + +- Packages follow Dubbo domains: `rpc` for the call model, `application.py` + for the application, then `registry`, `metadata`, `cluster`, `protocol`, + `transport` and the other extension domains. The code that connects a + domain to the application lives in that domain, such as provider + registration in `registry`. +- An `__init__.py` only re-exports. An extension point keeps its contract in + `base.py` and its implementations in sibling modules named after them, + such as `kazoo.py`; a package's exceptions live in `exceptions.py`. An + implementation of several extension points of one domain is a package + named after it, with a module per extension point, such as + `registry/zookeeper/interface.py`. +- Module names have no leading underscore; private names inside a module + do. Only generated code, such as `_proto`, keeps one on its package. + +### Naming + +Name a function by what the caller gets and who closes it, as the standard +library does: + +- a `get` method looks up something that exists, such as `extensions.get`; +- `get_` or a noun returns what its arguments determine: an equal value, such + as `inspect.signature`, or the same instance for the same arguments, such + as `logging.getLogger`, which its owner opens on first use and closes; +- `create_` builds a new resource that the caller closes, such as + `anyio.create_task_group`; +- `connect` or `open_` is a context manager holding a connection or a stream + until it exits, such as `anyio.open_file`; +- a verb names a context manager that keeps a state while its block runs and + returns no handle, such as `contextlib.suppress`; +- a `from_` class method is an alternate constructor, and a `replace` method + returns a changed copy of an immutable value. + +The function that returns an instance of an extension point lives in that +point's `base.py`, such as `get_serialization`. A hook that only subclasses +implement has a leading underscore. Names and errors that users see use +plain Python vocabulary. + +### Concurrency + +- The framework runs on asyncio, with uvloop optional; trio is not a target. +- Use AnyIO for task groups, timeouts, cancel scopes, shielding, events, + locks, sleeping and thread offload. Use asyncio directly only for the I/O + layer AnyIO does not cover, such as protocols, transports and servers, and + on per-call paths where a measurement shows the cost of AnyIO; say so where + it is used. +- Wait for one condition with one kind of primitive. Keep runtime types such + as futures, tasks and events out of extension contracts. + +### Lifetimes + +Nothing outlives its owner, as in AnyIO structured concurrency: + +- Each thing with a lifetime, such as a connection, server, task, watch, + session or worker thread, has one owner that closes it. It is entered with + `async with`, or registered on the owner's exit stack as soon as it is + acquired. +- A lifetime is entered and exited in one task, so a public lifetime is a + context manager, never a `start` and `stop` pair. Background work runs + only in a task group that such a lifetime owns. A pool may close a pooled + resource from another task when the resource holds no task group or cancel + scope of the tasks that use it, as httpcore and asyncpg pools do. +- Opening is all or nothing: a failure or a cancellation part way releases + what was acquired. +- Closing has two phases. The graceful waits, such as draining calls or + waiting for a peer, stay cancellable and are bounded by configuration or a + module constant. Once cancelled, release at once by what waits on no peer, + such as cancelling tasks and aborting transports, under a short, bounded + shield. Never shield a graceful wait. +- Stop gracefully only when asked, by leaving `async with` normally; a + cancellation means stop now. + +### Data, configuration and constants + +- Declarative data models use attrs, declared with `attrs.define` and + explicit options, such as `@attrs.define(frozen=True, kw_only=True)`. + Ordinary classes need no model decorator. +- Only the configuration layer reads environment variables. A variable + shared with other languages, such as `DUBBO_IP_TO_REGISTRY`, sets a + configuration field that names it in its metadata; components read the + field or the URL it becomes. +- `dubbo.constants` holds only Dubbo vocabulary shared with other languages, + such as URL parameter keys named `*_KEY`, and the values that + configuration fields left as `None` stand for, named `DEFAULT_*`. + Constants private to one module stay in it. + +### Logging + +Log as the Python logging HOWTO advises libraries: + +- each module logs through `_logger = logging.getLogger(__name__)`, and the + framework never adds handlers or configures logging; +- pass the arguments of `%` placeholders instead of formatting the message; +- write a sentence without a final period that says what happened and, when + the reader cannot tell, what follows, such as + `"Cannot read the rule %s; the one before stays"`; +- use `debug` for detail, `info` for lifecycle events, `warning` for a + failure the framework recovers from, and `error` or `exception` for one + that loses work; +- attach the traceback when it helps, and never log secrets; the `str` of a + URL hides its password. + +### Style + +- Ruff formats and lints the code; ty checks types. +- Order the members of a class: class attributes, `__init__` and the `from_` + constructors, properties, public methods, protocol methods such as + `__aenter__` and `__repr__`, then private methods. +- Separate the logical steps of a function with a single blank line: after a + guard clause, and between setup, processing and returning. Formatters keep + these lines but never add them. +- Comments state what the code does, or why when the code cannot show it. + They do not discuss alternatives, history or other implementations. + Docstrings state the contract: what a function returns, raises and owns. + +## Tests + +A test states one claim about a contract and fails when that claim breaks. + +### What to test + +- Start from a contract the code owns: a public docstring, a cross-language + format such as wire bytes, registry nodes, metadata JSON or rule YAML, a + lifecycle promise, or an error the caller can act on. +- Name the plausible wrong implementation the test would catch; if no + realistic bug fails it, do not write it. +- Test at the layer that owns the claim, once, and end to end only where the + wiring itself can break. +- Take edge cases from the input domain and the states the contract defines: + boundaries, lifecycle states, the interleavings the contract promises, the + failures the layer owns, and values that other Dubbo languages produce. Do + not invent inputs the public path cannot produce. +- Do not test library behavior, private helpers, annotation spelling, or log + text that is not a contract. + +### Tests never justify defensive code + +Do not add guards, `isinstance` checks or fallback branches to `src` so that +a test passes with an impossible input. Validate once where data enters from +outside: network bytes, files, environment variables, registry and +configuration center content, and the arguments of public entry points. +Inside, trust the value. + +### How to write a test + +- Name the test as its claim: `test_failover_retries_another_provider_after_unavailable`. +- Separate arrange, act and assert with single blank lines, and assert the + whole observable result with equality where possible. +- Use `pytest.raises` with the specific exception and a `match` on the part + the caller relies on, and `pytest.mark.parametrize` with readable ids for + one rule over many inputs. +- Prefer small fakes that implement an extension contract over patching + internals. Use real loopback sockets for connection semantics, and real + ZooKeeper or Nacos for registry semantics. +- Async tests use the AnyIO pytest plugin on asyncio. Synchronize on events, + never on a delay that guesses whether another task is ready, and bound + waits with `anyio.fail_after`. +- Async tests run on a virtual clock that starts at 0 and, while every task + waits, jumps to the next timer. Assert exactly the time a deadline, timeout + or grace period promises, such as + `assert anyio.current_time() - started == pytest.approx(0.2)`, and step + through time with `anyio.sleep`, never by looping until the clock passes a + point. The clock holds still while a thread of AnyIO or of the event loop + works, so a test never waits in a thread for the event loop: it reads raw + sockets with `loop.sock_recv`. A test that waits for other threads, a + process or the operating system is marked `real_clock` and runs in real + time. +- Close every resource. Warnings are errors, and a test asserts that the + tasks, watches and listeners its subject owns have exited. +- Interoperability evidence captured from a Java or Go peer becomes a golden + file under the test package's `data` directory, with a note giving the + peer, its version, and the commands that produced it. +- For a contract whose failure is costly, such as a lifecycle or a wire + format, break the code once by hand and confirm that a test fails. + +### Layout + +- `tests/unit//test_.py` mirrors `src/dubbo`, with no + network and no external processes. +- `tests/integration/` uses loopback sockets, subprocesses, and real + ZooKeeper or Nacos behind markers. +- Shared fixtures live in the nearest `conftest.py`. Tests share one registry + server per run, so each keeps what it creates under a unique ZooKeeper + root or Nacos service and group. + +## Pull requests + +1. Fork the repository and create a branch from `main`. +2. Make one change per pull request, with its tests and documentation. +3. Run the checks above. CI also runs the tests on Linux, macOS and + Windows, against the oldest and newest supported ZooKeeper and Nacos, + and checks the license headers. +4. Open the pull request against `main`. Its title summarizes the change in + one line, and its description says why; link the issue it resolves, such + as `Fixes apache/dubbo#12345`. + +Pull requests are squash-merged, so the title becomes the commit message on +`main`. + +As the Apache Software Foundation requires: + +- every new source file starts with the Apache License header, copied from + an existing file; the license check of CI lists any that lack it; +- files carry no author names, such as `__author__`; the history records + who contributed; +- code from another project may be included only under a license + compatible with the Apache License, as the + [ASF third-party license policy](https://www.apache.org/legal/resolved.html) + defines; discuss it first; +- a contribution written with generative AI tools follows the + [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html), + which recommends naming the tool in the commit message, such as + `Generated-by: `. diff --git a/LICENSE b/LICENSE index 84262198..9e87f44c 100644 --- a/LICENSE +++ b/LICENSE @@ -199,4 +199,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file + limitations under the License. diff --git a/NOTICE b/NOTICE index 2744a490..ba635e5c 100644 --- a/NOTICE +++ b/NOTICE @@ -1,5 +1,5 @@ Apache Dubbo -Copyright 2018-2024 The Apache Software Foundation +Copyright 2018-2026 The Apache Software Foundation This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). +The Apache Software Foundation (https://www.apache.org/). diff --git a/README.md b/README.md index 1639f045..3b90c3cc 100644 --- a/README.md +++ b/README.md @@ -1,135 +1,190 @@ -# Apache Dubbo for Python +

+ Apache Dubbo +

-![License](https://img.shields.io/github/license/apache/dubbo-python?logo=apache&logoColor=red&label=LICENSE) -![GitHub last commit](https://img.shields.io/github/last-commit/apache/dubbo-python) -![GitHub branch check runs](https://img.shields.io/github/check-runs/apache/dubbo-python/main) -![PyPI - Version](https://img.shields.io/pypi/v/apache-dubbo?logo=pypi&logoColor=gold&label=PyPI&color=blue) -![PyPI - Python Version](https://img.shields.io/pypi/pyversions/apache-dubbo?logo=python&logoColor=gold&label=Python) +

Apache Dubbo for Python

- Logo + CI + PyPI + Python versions + License

-Apache Dubbo is an easy-to-use, high-performance WEB and RPC framework with builtin service discovery, traffic management, observability, security features, tools and best practices for building enterprise-level microservices. +Apache Dubbo for Python is a Python-native implementation of +[Apache Dubbo](https://dubbo.apache.org/), the RPC and microservice framework. +Python services join the same registries as Dubbo Java and Dubbo Go services +and call them, and are called by them, with the service discovery and +traffic management of Dubbo built in. + +> The project is in beta: the API may change. + +## Highlights + +- **Works with Dubbo Java and Go**: the Triple and Dubbo protocols, Protobuf + and Hessian 2, ZooKeeper and Nacos registries, and both application-level + and interface-level service discovery. +- **Compatible with gRPC**: Triple runs over HTTP/2, so gRPC clients and + servers, `grpcurl`, health checks and reflection work with it. +- **Pythonic**: a service is a `typing.Protocol` with type hints; calls are + `async`; an application runs inside `async with`, in any asyncio program, + with uvloop optional. +- **Governance built in**: load balancing, cluster fault tolerance, routing + rules and dynamic configuration, as in the other Dubbo languages. +- **Extensible**: every protocol, registry, load balancer, router and filter + is a plugin that a package can add through an entry point. -Dubbo-python is a Python implementation of the [triple protocol](https://dubbo.apache.org/zh-cn/overview/reference/protocols/triple-spec/) (a protocol fully compatible with gRPC and friendly to HTTP) and various features designed by Dubbo for constructing microservice architectures. +## Features -Visit [the official website](https://dubbo.apache.org/) for more information. +From the API down to the transport: -### 🚧 Early-Stage Project 🚧 +| Layer | What is supported | +|---|---| +| API | Contracts as `typing.Protocol`; unary, server streaming, client streaming and bidirectional streaming calls; generic calls; contracts generated from `.proto` files by `protoc-gen-python-dubbo` | +| Configuration | Code, YAML, JSON, properties files and environment variables, layered; configuration centers on ZooKeeper and Nacos | +| Service discovery | ZooKeeper and Nacos registries; application-level and interface-level discovery; local and remote metadata | +| Traffic management | Load balancing: random, round robin, least active, consistent hash. Cluster fault tolerance: failover, failfast, failsafe, failback, forking, broadcast, available, zone-aware. Routing: condition and tag rules, dynamic configuration rules. Filters | +| Protocols | Triple (HTTP/2, compatible with gRPC), with health checks and reflection; Dubbo. TLS and mutual TLS; gzip, deflate and bzip2 compression | +| Serialization | Protobuf, Hessian 2 | +| Runtime | asyncio, uvloop optional; Python 3.11 to 3.14 on Linux, macOS and Windows | -> **Disclaimer:** This project is in the early stages of development. Features are subject to change, and some components may not be fully stable. Contributions and feedback are welcome as the project evolves. +## Installation +```shell +pip install apache-dubbo +``` -## Architecture -Architecture +Or with [uv](https://docs.astral.sh/uv/): -## Features +```shell +uv add apache-dubbo +``` -- **Service Discovery**: Zookeeper -- **Load Balance**: Random, CPU -- **RPC Protocols**: Triple(gRPC compatible and HTTP-friendly) -- **Transport**: asyncio(uvloop) -- **Serialization**: Customizable(protobuf, json...) +The default installation serves and calls over both protocols. Extras add +optional parts, such as `pip install "apache-dubbo[zookeeper]"`: +| Extra | Adds | +|---|---| +| `zookeeper` | ZooKeeper registry, configuration center and metadata report | +| `nacos` | Nacos registry, configuration center and metadata report | +| `yaml` | YAML configuration files | +| `properties` | `.properties` configuration files | +| `uvloop` | [uvloop](https://github.com/MagicStack/uvloop), which an application runs on with `uvloop.run(main())`; not on Windows | +| `protoc` | `grpcio-tools`, to generate contracts from `.proto` files | -## Installation +## Quick start + +A service is declared once as a contract, which both sides import. +`greeter.py`: + +```python +import typing + +import dubbo + + +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + async def greet(self, name: str) -> str: ... +``` + +The provider implements the contract and serves it over the Dubbo protocol. +`server.py`: + +```python +import asyncio + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig + +from greeter import Greeter + + +class GreeterImpl(Greeter): + async def greet(self, name: str) -> str: + return f"Hello, {name}!" + + +async def main() -> None: + app = Dubbo( + application=ApplicationConfig(name="greeter-server"), + protocols={"dubbo": ProtocolConfig(port=20880)}, + ) + app.export(GreeterImpl()) + + async with app: + await app.serve_forever() + + +asyncio.run(main()) +``` + +The consumer refers to the contract and calls it like a local object. +`client.py`: + +```python +import asyncio + +from dubbo import Dubbo + +from greeter import Greeter + + +async def main() -> None: + app = Dubbo() + greeter = app.refer(Greeter, url="dubbo://127.0.0.1:20880") + + async with app: + print(await greeter.greet("Dubbo")) + + +asyncio.run(main()) +``` + +Run `python server.py`, then `python client.py` in another terminal: + +```console +$ python client.py +Hello, Dubbo! +``` + +To discover the provider through a registry instead of its address, install +`apache-dubbo[zookeeper]`, give both applications a name and the registry, +and drop the `url` of `refer`: + +```python +from dubbo.config import ApplicationConfig, RegistryConfig + +app = Dubbo( + application=ApplicationConfig(name="greeter-client"), + registries={"default": RegistryConfig(address="zookeeper://127.0.0.1:2181")}, +) +greeter = app.refer(Greeter) +``` + +## Learn more + +- [Samples](https://github.com/apache/dubbo-python/tree/main/samples): step by step, from a first call to streaming, + registries and traffic management; working with Java, Go and gRPC; and + using Dubbo with other Python libraries. +- [Dubbo documentation](https://dubbo.apache.org/): the concepts shared by + every Dubbo language. +- [Contributing](https://github.com/apache/dubbo-python/blob/main/CONTRIBUTING.md): development setup, checks and + conventions. + +## Community -Before you start, make sure you have **`python 3.9+`** installed. - -1. Install Directly - - ```sh - pip install apache-dubbo - ``` -2. Install from source - - ```sh - git clone https://github.com/apache/dubbo-python.git - cd dubbo-python && pip install . - ``` - -## Getting started - -Get up and running with Dubbo-Python in just 5 minutes by following our [Quick Start Guide](https://github.com/apache/dubbo-python/tree/main/samples). - -It's as simple as the code snippet below. With just a few lines of code, you can launch a fully functional point-to-point RPC service: - -1. Build and start the server - - ```python - import dubbo - from dubbo.configs import ServiceConfig - from dubbo.proxy.handlers import RpcMethodHandler, RpcServiceHandler - - - class UnaryServiceServicer: - def say_hello(self, message: bytes) -> bytes: - print(f"Received message from client: {message}") - return b"Hello from server" - - - def build_service_handler(): - # build a method handler - method_handler = RpcMethodHandler.unary( - method=UnaryServiceServicer().say_hello, method_name="unary" - ) - # build a service handler - service_handler = RpcServiceHandler( - service_name="org.apache.dubbo.samples.HelloWorld", - method_handlers=[method_handler], - ) - return service_handler - - - if __name__ == "__main__": - # build service config - service_handler = build_service_handler() - service_config = ServiceConfig( - service_handler=service_handler, host="127.0.0.1", port=50051 - ) - # start the server - server = dubbo.Server(service_config).start() - - input("Press Enter to stop the server...\n") - ``` - -1. Build and start the Client - - ```python - import dubbo - from dubbo.configs import ReferenceConfig - - - class UnaryServiceStub: - def __init__(self, client: dubbo.Client): - self.unary = client.unary(method_name="unary") - - def say_hello(self, message: bytes) -> bytes: - return self.unary(message) - - - if __name__ == "__main__": - # Create a client - reference_config = ReferenceConfig.from_url( - "tri://127.0.0.1:50051/org.apache.dubbo.samples.HelloWorld" - ) - dubbo_client = dubbo.Client(reference_config) - unary_service_stub = UnaryServiceStub(dubbo_client) - - # Call the remote method - result = unary_service_stub.say_hello(b"Hello from client") - print(result) - - ``` - -## Contributing - -We are excited to welcome contributions to the Dubbo-Python project! Whether you are fixing bugs, adding new features, or improving documentation, your input is highly valued. - -To ensure a smooth collaboration, please review our [Contributing Guide](./docs/CONTRIBUTING.md) for detailed instructions on how to get started, adhere to coding standards, and submit your contributions effectively. +- **Issues and feature requests**: this repository has no issue tracker of + its own; open them in the + [Apache Dubbo issue tracker](https://github.com/apache/dubbo/issues) and + say that they concern Dubbo for Python. +- **Questions and discussion**: the + [dev@dubbo.apache.org](mailto:dev@dubbo.apache.org) mailing list + ([how to subscribe](https://github.com/apache/dubbo/wiki/Mailing-list-subscription-guide)). +- **Security vulnerabilities**: report them privately to + [security@dubbo.apache.org](mailto:security@dubbo.apache.org), not in + public. ## License -Apache Dubbo-python software is licensed under the Apache License Version 2.0. See -the [LICENSE](https://github.com/apache/dubbo-python/blob/main/LICENSE) file for details. +Apache Dubbo for Python is licensed under the [Apache License 2.0](https://github.com/apache/dubbo-python/blob/main/LICENSE). diff --git a/benchmark/.gitignore b/benchmark/.gitignore new file mode 100644 index 00000000..28bc766f --- /dev/null +++ b/benchmark/.gitignore @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +results/ +java/target/ diff --git a/benchmark/README.md b/benchmark/README.md new file mode 100644 index 00000000..f52165c8 --- /dev/null +++ b/benchmark/README.md @@ -0,0 +1,160 @@ +# Benchmarks + +End-to-end benchmarks of Dubbo Python: what a call costs its server and its +consumer, beside Dubbo Java, Dubbo Go and the gRPC libraries of Python, over +the same service and under the same load. + +## What is measured + +Every implementation serves one service: an echo of bytes, as the `Bench` +service of `proto/bench.proto` over Triple, whose messages are Protobuf, and +as `BenchService.echo(byte[])` over Dubbo, whose bytes travel in Hessian 2. + +| Scenario | What runs | The load | +|---|---|---| +| `one-core` | Dubbo Python, Java and Go, grpcio and grpclib, each on one core | ghz over Triple; the Go load of `go/load` over Dubbo | +| `multi-core` | Dubbo Python, Java and Go, each on eight cores, of which a Python process uses one | the same, on the other cores | +| `client` | One Dubbo Python consumer on one core | it calls Dubbo Java over Triple and Dubbo Go over Dubbo, on the other cores; Dubbo Go would compress its Triple responses | + +Each scenario measures every payload size and number of calls in flight of +`scenarios.toml`, with a new server for each point, in each of the rounds: +64 points a round, about 80 minutes in all. The Python programs run on uvloop +when it is installed, else on asyncio, and the results say which. +A scenario with `cores` holds the side it measures to that many cores with +`taskset`, and the load to the others; Go to `GOMAXPROCS` and Java to +`ActiveProcessorCount` as many. Without `taskset`, as on macOS, only those +two settings hold, and the results say the server was not pinned. + +Each point counts: + +- **calls per second**; +- **CPU time per call** of the side measured, in microseconds: the CPU time + of its process over the counted calls, divided by their number, and the + **cores** it used meanwhile; +- **latency** percentiles, counted in buckets about 1% wide by the Python and + Go loads, and by ghz; +- the **RSS** of the server: its peak on Linux, its last value elsewhere; +- the **cores the load used**, of those it may use. A load that used most of + them may be what limits the throughput, and the charts mark its points. + +### The loads + +- **ghz** loads Triple, and waits for the calls in flight when the time is + up, so that none fails as its connections close. +- **`go/load`** loads Dubbo: a closed loop that sends a request body that + Hessian 2 encodes once, as Dubbo Python sends it, and counts a response + whose status is OK and which holds a value. Each connection writes the + requests queued together in one write, as clients do. It decodes nothing, + so that it adds next to nothing to what it measures. +- Each load opens `connections` connections, at most one for each call in + flight. Every implementation of a protocol takes the same load. + +## Layout + +| Path | What it holds | +|---|---| +| `scenarios.toml` | What `run.py` measures | +| `run.py` | Runs the scenarios into a directory of `results/` | +| `plot.py` | Charts and tabulates one or more runs | +| `proto/bench.proto` | The service over Triple, which every implementation and ghz read | +| `python/` | The Python servers, `dubbo_server.py`, `grpcio_server.py` and `grpclib_server.py`; `client.py`, the Python consumers; the code generated from `bench.proto` | +| `java/` | A Maven project: the Dubbo Java server | +| `go/` | A Go module: the Dubbo Go server in `server/`, the load over Dubbo in `load/` | + +## Set up + +From the root of the repository: + +```console +$ uv sync --inexact --extra uvloop --group benchmark +``` + +The other tools are optional; a point whose tools are missing is skipped, +and `env.json` says why: + +- **Go** 1.25 or later builds Dubbo Go, which the `client` scenario calls + over Dubbo, and the load over Dubbo. Without it, Python consumers in + `load_processes` processes load the Dubbo servers, and may run out of CPU + before a fast server does. +- **ghz** loads the Triple servers: + `go install github.com/bojand/ghz/cmd/ghz@latest`. Without it, Python + consumers load them, and Dubbo Go compresses its responses to them. +- **JDK** 17 or later and **Maven** build Dubbo Java, which the `client` + scenario calls over Triple. Without them, it calls Dubbo Go there. +- **taskset**, of util-linux on Linux, holds each side to its cores. + +## Run + +```console +$ python benchmark/run.py +$ python benchmark/plot.py benchmark/results/20261120-101500 +``` + +`run.py --scenario one-core` runs one scenario, and `--warmup`, +`--duration` and `--rounds` change its times; `--rounds 1` takes about +25 minutes. The rounds run one after +another over every point. A run writes, in its directory: + +- `results.jsonl`, a line for each point of each round; +- `env.json`: the machine, the commit, and the versions of everything that ran; +- `logs/`, the output of each server. + +`plot.py` writes into the directory of the first run, as SVG and as PNG, +each chart for one protocol and its serialization, `triple-protobuf` or +`dubbo-hessian2`; each shows the median of the rounds: + +| Chart | What it shows | +|---|---| +| `*-throughput-one-core` | The headline: the peak throughput of each server on one core, over the numbers of calls in flight; a group of bars per payload, one bar per implementation, with the range of the rounds | +| `*-latency` | The P99 latency of each server on one core at 64 calls in flight | +| `*-throughput-multi-core` | The peak throughput of each Dubbo server on eight cores, as the headline | +| `*-consumer` | The peak throughput of the Dubbo Python consumer on one core | +| `report.html` | Every chart, with the numbers of each bar on hover, the environment and every point; it opens with nothing else | +| `summary.md` | Every point, with all its numbers | + +## Compare two changes + +Run the scenarios on each, then give both runs to `plot.py`, the baseline +first: the charts show the baseline, and `summary.md` and `report.html` list +every point of both: + +```console +$ python benchmark/plot.py benchmark/results/before benchmark/results/after --out benchmark/results/compared +``` + +Alternate the runs of the two, so that a drift of the machine does not pass +for a change. + +## Publish + +Publish only numbers measured on Linux with `taskset`, on a machine that runs +nothing else, with the times of `scenarios.toml`, and give `env.json` with them. +On one core, Java runs its compiler and collector on the core it serves on: +say so beside its numbers, and give the multi-core ones with them. A laptop throttles +and runs other work: use it to compare two changes, not to quote. + +## Find where the time goes + +The benchmarks tell how much a call costs; a profiler tells where. Run a +server under load and record it with [py-spy](https://github.com/benfred/py-spy): + +```console +$ cd benchmark/python +$ python dubbo_server.py --protocol tri --port 50051 & server=$! +$ ghz --insecure --proto ../proto/bench.proto --call org.apache.dubbo.benchmark.Bench.Echo \ + --data '{"data":"aGk="}' --concurrency 64 --duration 30s 127.0.0.1:50051 & +$ py-spy record --pid $server --duration 20 --output profile.svg +``` + +## Generate the code again + +The generated code is included. After changing `proto/bench.proto`, from +`benchmark/`, with the `proto` group installed and the protoc plugins of Go on +`PATH`: + +```console +$ python -m grpc_tools.protoc -Iproto --python_out=python --pyi_out=python proto/bench.proto +$ cd go && python -m grpc_tools.protoc -I../proto --go_out=. --go_opt=module=bench --go-triple_out=. ../proto/bench.proto +``` + +Maven generates the Java code as it builds. diff --git a/benchmark/go/benchpb/bench.pb.go b/benchmark/go/benchpb/bench.pb.go new file mode 100644 index 00000000..38e7f569 --- /dev/null +++ b/benchmark/go/benchpb/bench.pb.go @@ -0,0 +1,146 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// The service that Triple carries in the benchmarks, for Python, Java, Go and ghz. + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.12 +// protoc v7.35.1 +// source: bench.proto + +package benchpb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// The bytes of a request, which the response echoes. +type Payload struct { + state protoimpl.MessageState `protogen:"open.v1"` + Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Payload) Reset() { + *x = Payload{} + mi := &file_bench_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Payload) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Payload) ProtoMessage() {} + +func (x *Payload) ProtoReflect() protoreflect.Message { + mi := &file_bench_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Payload.ProtoReflect.Descriptor instead. +func (*Payload) Descriptor() ([]byte, []int) { + return file_bench_proto_rawDescGZIP(), []int{0} +} + +func (x *Payload) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +var File_bench_proto protoreflect.FileDescriptor + +const file_bench_proto_rawDesc = "" + + "\n" + + "\vbench.proto\x12\x1aorg.apache.dubbo.benchmark\"\x1d\n" + + "\aPayload\x12\x12\n" + + "\x04data\x18\x01 \x01(\fR\x04data2Y\n" + + "\x05Bench\x12P\n" + + "\x04Echo\x12#.org.apache.dubbo.benchmark.Payload\x1a#.org.apache.dubbo.benchmark.PayloadB\x19P\x01Z\x15bench/benchpb;benchpbb\x06proto3" + +var ( + file_bench_proto_rawDescOnce sync.Once + file_bench_proto_rawDescData []byte +) + +func file_bench_proto_rawDescGZIP() []byte { + file_bench_proto_rawDescOnce.Do(func() { + file_bench_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_bench_proto_rawDesc), len(file_bench_proto_rawDesc))) + }) + return file_bench_proto_rawDescData +} + +var file_bench_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_bench_proto_goTypes = []any{ + (*Payload)(nil), // 0: org.apache.dubbo.benchmark.Payload +} +var file_bench_proto_depIdxs = []int32{ + 0, // 0: org.apache.dubbo.benchmark.Bench.Echo:input_type -> org.apache.dubbo.benchmark.Payload + 0, // 1: org.apache.dubbo.benchmark.Bench.Echo:output_type -> org.apache.dubbo.benchmark.Payload + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_bench_proto_init() } +func file_bench_proto_init() { + if File_bench_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_bench_proto_rawDesc), len(file_bench_proto_rawDesc)), + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_bench_proto_goTypes, + DependencyIndexes: file_bench_proto_depIdxs, + MessageInfos: file_bench_proto_msgTypes, + }.Build() + File_bench_proto = out.File + file_bench_proto_goTypes = nil + file_bench_proto_depIdxs = nil +} diff --git a/benchmark/go/benchpb/bench.triple.go b/benchmark/go/benchpb/bench.triple.go new file mode 100644 index 00000000..bfb03082 --- /dev/null +++ b/benchmark/go/benchpb/bench.triple.go @@ -0,0 +1,122 @@ +// Code generated by protoc-gen-triple. DO NOT EDIT. +// +// Source: bench.proto +package benchpb + +import ( + "context" +) + +import ( + "dubbo.apache.org/dubbo-go/v3" + "dubbo.apache.org/dubbo-go/v3/client" + "dubbo.apache.org/dubbo-go/v3/common" + "dubbo.apache.org/dubbo-go/v3/common/constant" + "dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol" + "dubbo.apache.org/dubbo-go/v3/server" +) + +// This is a compile-time assertion to ensure that this generated file and the Triple package +// are compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of Triple newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of Triple or updating the Triple +// version compiled into your binary. +const _ = triple_protocol.IsAtLeastVersion0_1_0 + +const ( + // BenchName is the fully-qualified name of the Bench service. + BenchName = "org.apache.dubbo.benchmark.Bench" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // BenchEchoProcedure is the fully-qualified name of the Bench's Echo RPC. + BenchEchoProcedure = "/org.apache.dubbo.benchmark.Bench/Echo" +) + +var ( + _ Bench = (*BenchImpl)(nil) +) + +// Bench is a client for the org.apache.dubbo.benchmark.Bench service. +type Bench interface { + Echo(ctx context.Context, req *Payload, opts ...client.CallOption) (*Payload, error) +} + +// NewBench constructs a client for the benchpb.Bench service. +func NewBench(cli *client.Client, opts ...client.ReferenceOption) (Bench, error) { + conn, err := cli.DialWithInfo("org.apache.dubbo.benchmark.Bench", &Bench_ClientInfo, opts...) + if err != nil { + return nil, err + } + return &BenchImpl{ + conn: conn, + }, nil +} + +func SetConsumerBench(srv common.RPCService) { + dubbo.SetConsumerServiceWithInfo(srv, &Bench_ClientInfo) +} + +// BenchImpl implements Bench. +type BenchImpl struct { + conn *client.Connection +} + +func (c *BenchImpl) Echo(ctx context.Context, req *Payload, opts ...client.CallOption) (*Payload, error) { + resp := new(Payload) + if err := c.conn.CallUnary(ctx, []interface{}{req}, resp, "Echo", opts...); err != nil { + return nil, err + } + return resp, nil +} + +var Bench_ClientInfo = client.ClientInfo{ + InterfaceName: "org.apache.dubbo.benchmark.Bench", + MethodNames: []string{"Echo"}, + ConnectionInjectFunc: func(dubboCliRaw interface{}, conn *client.Connection) { + dubboCli := dubboCliRaw.(*BenchImpl) + dubboCli.conn = conn + }, +} + +// BenchHandler is an implementation of the org.apache.dubbo.benchmark.Bench service. +type BenchHandler interface { + Echo(context.Context, *Payload) (*Payload, error) +} + +func RegisterBenchHandler(srv *server.Server, hdlr BenchHandler, opts ...server.ServiceOption) error { + return srv.Register(hdlr, &Bench_ServiceInfo, opts...) +} + +func SetProviderBench(srv common.RPCService) { + dubbo.SetProviderServiceWithInfo(srv, &Bench_ServiceInfo) +} + +var Bench_ServiceInfo = server.ServiceInfo{ + InterfaceName: "org.apache.dubbo.benchmark.Bench", + ServiceType: (*BenchHandler)(nil), + Methods: []server.MethodInfo{ + { + Name: "Echo", + Type: constant.CallUnary, + ReqInitFunc: func() interface{} { + return new(Payload) + }, + MethodFunc: func(ctx context.Context, args []interface{}, handler interface{}) (interface{}, error) { + req := args[0].(*Payload) + res, err := handler.(BenchHandler).Echo(ctx, req) + if err != nil { + return nil, err + } + return triple_protocol.NewResponse(res), nil + }, + }, + }, +} diff --git a/benchmark/go/go.mod b/benchmark/go/go.mod new file mode 100644 index 00000000..32b27f8f --- /dev/null +++ b/benchmark/go/go.mod @@ -0,0 +1,158 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +module bench + +go 1.25.0 + +require ( + dubbo.apache.org/dubbo-go/v3 v3.3.2 + google.golang.org/protobuf v1.34.2 +) + +require ( + github.com/RoaringBitmap/roaring v1.2.3 // indirect + github.com/Workiva/go-datastructures v1.0.52 // indirect + github.com/alibaba/sentinel-golang v1.0.4 // indirect + github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect + github.com/alibabacloud-go/tea v1.1.17 // indirect + github.com/alibabacloud-go/tea-utils v1.4.4 // indirect + github.com/aliyun/alibaba-cloud-sdk-go v1.61.1800 // indirect + github.com/aliyun/alibabacloud-dkms-gcs-go-sdk v0.2.2 // indirect + github.com/aliyun/alibabacloud-dkms-transfer-go-sdk v0.1.7 // indirect + github.com/apache/dubbo-getty v1.4.10 // indirect + github.com/apache/dubbo-go-hessian2 v1.12.5 // indirect + github.com/apolloconfig/agollo/v4 v4.4.0 // indirect + github.com/beorn7/perks v1.0.1 // indirect + github.com/bits-and-blooms/bitset v1.2.0 // indirect + github.com/buger/jsonparser v1.2.0 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/coreos/go-semver v0.3.0 // indirect + github.com/coreos/go-systemd/v22 v22.3.2 // indirect + github.com/creasty/defaults v1.5.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dlclark/regexp2 v1.7.0 // indirect + github.com/dop251/goja v0.0.0-20240220182346-e401ed450204 // indirect + github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5 // indirect + github.com/dubbogo/gost v1.14.3 // indirect + github.com/dubbogo/grpc-go v1.42.10 // indirect + github.com/dubbogo/triple v1.2.2-rc4 // indirect + github.com/dustin/go-humanize v1.0.1 // indirect + github.com/emicklei/go-restful/v3 v3.10.1 // indirect + github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/go-logr/logr v1.4.3 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.12.0 // indirect + github.com/go-resty/resty/v2 v2.7.0 // indirect + github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/mock v1.6.0 // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/golang/snappy v0.0.4 // indirect + github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/gorilla/websocket v1.4.2 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/hashicorp/golang-lru v0.5.4 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/hashicorp/vault/sdk v0.7.0 // indirect + github.com/influxdata/tdigest v0.0.1 // indirect + github.com/jmespath/go-jmespath v0.4.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/k0kubun/pp v3.0.1+incompatible // indirect + github.com/knadh/koanf v1.5.0 // indirect + github.com/leodido/go-urn v1.2.2 // indirect + github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect + github.com/magiconair/properties v1.8.5 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.16 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/mschoch/smat v0.2.0 // indirect + github.com/nacos-group/nacos-sdk-go/v2 v2.2.5 // indirect + github.com/natefinch/lumberjack v2.0.0+incompatible // indirect + github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 // indirect + github.com/opentracing/opentracing-go v1.2.0 // indirect + github.com/openzipkin/zipkin-go v0.4.2 // indirect + github.com/pelletier/go-toml v1.9.3 // indirect + github.com/pierrec/lz4 v2.6.1+incompatible // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/polarismesh/polaris-go v1.3.0 // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect + github.com/prometheus/client_golang v1.19.1 // indirect + github.com/prometheus/client_model v0.5.0 // indirect + github.com/prometheus/common v0.48.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect + github.com/quic-go/qpack v0.6.0 // indirect + github.com/quic-go/quic-go v0.59.1 // indirect + github.com/shirou/gopsutil/v3 v3.22.2 // indirect + github.com/sirupsen/logrus v1.9.4 // indirect + github.com/spaolacci/murmur3 v1.1.0 // indirect + github.com/spf13/afero v1.6.0 // indirect + github.com/spf13/cast v1.3.1 // indirect + github.com/spf13/jwalterweatherman v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/spf13/viper v1.8.1 // indirect + github.com/subosito/gotenv v1.2.0 // indirect + github.com/tklauser/go-sysconf v0.3.10 // indirect + github.com/tklauser/numcpus v0.4.0 // indirect + github.com/uber/jaeger-client-go v2.29.1+incompatible // indirect + github.com/uber/jaeger-lib v2.4.1+incompatible // indirect + github.com/ugorji/go/codec v1.2.6 // indirect + github.com/yusufpapurcu/wmi v1.2.2 // indirect + go.etcd.io/etcd/api/v3 v3.5.7 // indirect + go.etcd.io/etcd/client/pkg/v3 v3.5.7 // indirect + go.etcd.io/etcd/client/v3 v3.5.7 // indirect + go.opentelemetry.io/contrib/propagators/b3 v1.10.0 // indirect + go.opentelemetry.io/otel v1.21.0 // indirect + go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0 // indirect + go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.21.0 // indirect + go.opentelemetry.io/otel/exporters/zipkin v1.21.0 // indirect + go.opentelemetry.io/otel/metric v1.21.0 // indirect + go.opentelemetry.io/otel/sdk v1.21.0 // indirect + go.opentelemetry.io/otel/trace v1.21.0 // indirect + go.opentelemetry.io/proto/otlp v1.0.0 // indirect + go.uber.org/atomic v1.10.0 // indirect + go.uber.org/multierr v1.8.0 // indirect + go.uber.org/zap v1.21.0 // indirect + golang.org/x/crypto v0.53.0 // indirect + golang.org/x/net v0.56.0 // indirect + golang.org/x/sync v0.21.0 // indirect + golang.org/x/sys v0.46.0 // indirect + golang.org/x/text v0.39.0 // indirect + golang.org/x/time v0.15.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect + google.golang.org/grpc v1.64.1 // indirect + gopkg.in/ini.v1 v1.66.2 // indirect + gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/benchmark/go/go.sum b/benchmark/go/go.sum new file mode 100644 index 00000000..a7eef428 --- /dev/null +++ b/benchmark/go/go.sum @@ -0,0 +1,1422 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI= +cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk= +cloud.google.com/go v0.78.0/go.mod h1:QjdrLG0uq+YwhjoVOLsS1t7TW8fs36kLs4XO5R5ECHg= +cloud.google.com/go v0.79.0/go.mod h1:3bzgcEeQlzbuEAYu4mrWhKqWjmpprinYgKJLgKHnbb8= +cloud.google.com/go v0.81.0/go.mod h1:mk/AM35KwGk/Nm2YSeZbxXdrNK3KZOYHmLkOqC2V6E0= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +dubbo.apache.org/dubbo-go/v3 v3.3.2 h1:EGvql7w2vUtYFTqRbI+jcbaDg4JY7vUfKmc7Z+d8RoI= +dubbo.apache.org/dubbo-go/v3 v3.3.2/go.mod h1:TZIR3cVt1Gi1XX/wqU6YJ24Av8fqidlbNxgC18wdS8M= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/HdrHistogram/hdrhistogram-go v1.1.2 h1:5IcZpTvzydCQeHzK4Ef/D5rrSqwxob0t8PQPMybUNFM= +github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= +github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/RoaringBitmap/roaring v1.2.3 h1:yqreLINqIrX22ErkKI0vY47/ivtJr6n+kMhVOVmhWBY= +github.com/RoaringBitmap/roaring v1.2.3/go.mod h1:plvDsJQpxOC5bw8LRteu/MLWHsHez/3y6cubLI4/1yE= +github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= +github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= +github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= +github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= +github.com/Workiva/go-datastructures v1.0.52 h1:PLSK6pwn8mYdaoaCZEMsXBpBotr4HHn9abU0yMQt0NI= +github.com/Workiva/go-datastructures v1.0.52/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA= +github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= +github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= +github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= +github.com/agiledragon/gomonkey/v2 v2.11.0 h1:5oxSgA+tC1xuGsrIorR+sYiziYltmJyEZ9qA25b6l5U= +github.com/agiledragon/gomonkey/v2 v2.11.0/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY= +github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= +github.com/alibaba/sentinel-golang v1.0.4 h1:i0wtMvNVdy7vM4DdzYrlC4r/Mpk1OKUUBurKKkWhEo8= +github.com/alibaba/sentinel-golang v1.0.4/go.mod h1:Lag5rIYyJiPOylK8Kku2P+a23gdKMMqzQS7wTnjWEpk= +github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 h1:NqugFkGxx1TXSh/pBcU00Y6bljgDPaFdh5MUSeJ7e50= +github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68/go.mod h1:6pb/Qy8c+lqua8cFpEy7g39NRRqOWc3rOwAy8m5Y2BY= +github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg= +github.com/alibabacloud-go/tea v1.1.17 h1:05R5DnaJXe9sCNIe8KUgWHC/z6w/VZIwczgUwzRnul8= +github.com/alibabacloud-go/tea v1.1.17/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A= +github.com/alibabacloud-go/tea-utils v1.4.4 h1:lxCDvNCdTo9FaXKKq45+4vGETQUKNOW/qKTcX9Sk53o= +github.com/alibabacloud-go/tea-utils v1.4.4/go.mod h1:KNcT0oXlZZxOXINnZBs6YvgOd5aYp9U67G+E3R8fcQw= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.18/go.mod h1:v8ESoHo4SyHmuB4b1tJqDHxfTGEciD+yhvOU/5s1Rfk= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704/go.mod h1:RcDobYh8k5VP6TNybz9m++gL3ijVI5wueVr0EM10VsU= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.1800 h1:ie/8RxBOfKZWcrbYSJi2Z8uX8TcOlSMwPlEJh83OeOw= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.1800/go.mod h1:RcDobYh8k5VP6TNybz9m++gL3ijVI5wueVr0EM10VsU= +github.com/aliyun/alibabacloud-dkms-gcs-go-sdk v0.2.2 h1:rWkH6D2XlXb/Y+tNAQROxBzp3a0p92ni+pXcaHBe/WI= +github.com/aliyun/alibabacloud-dkms-gcs-go-sdk v0.2.2/go.mod h1:GDtq+Kw+v0fO+j5BrrWiUHbBq7L+hfpzpPfXKOZMFE0= +github.com/aliyun/alibabacloud-dkms-transfer-go-sdk v0.1.7 h1:olLiPI2iM8Hqq6vKnSxpM3awCrm9/BeOgHpzQkOYnI4= +github.com/aliyun/alibabacloud-dkms-transfer-go-sdk v0.1.7/go.mod h1:oDg1j4kFxnhgftaiLJABkGeSvuEvSF5Lo6UmRAMruX4= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/apache/dubbo-getty v1.4.10 h1:ZmkpHJa/qgS0evX2tTNqNCz6rClI/9Wwp7ctyMml82w= +github.com/apache/dubbo-getty v1.4.10/go.mod h1:V64WqLIxksEgNu5aBJBOxNIvpOZyfUJ7J/DXBlKSUoA= +github.com/apache/dubbo-go-hessian2 v1.9.1/go.mod h1:xQUjE7F8PX49nm80kChFvepA/AvqAZ0oh/UaB6+6pBE= +github.com/apache/dubbo-go-hessian2 v1.9.3/go.mod h1:xQUjE7F8PX49nm80kChFvepA/AvqAZ0oh/UaB6+6pBE= +github.com/apache/dubbo-go-hessian2 v1.12.5 h1:19lJz2Md0EYF2bOtEvFqXEQRYvLz04GfsoocsBWlLWQ= +github.com/apache/dubbo-go-hessian2 v1.12.5/go.mod h1:QP9Tc0w/B/mDopjusebo/c7GgEfl6Lz8jeuFg8JA6yw= +github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= +github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= +github.com/apolloconfig/agollo/v4 v4.4.0 h1:bIIRTEN4f7HgLx97/cNpduEvP9qQ7BkCyDOI2j800VM= +github.com/apolloconfig/agollo/v4 v4.4.0/go.mod h1:6WjI68IzqMk/Y6ghMtrj5AX6Uewo20ZnncvRhTceQqg= +github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A= +github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= +github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= +github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= +github.com/aws/aws-sdk-go-v2 v1.9.2/go.mod h1:cK/D0BBs0b/oWPIcX/Z/obahJK1TT7IPVjy53i/mX/4= +github.com/aws/aws-sdk-go-v2/config v1.8.3/go.mod h1:4AEiLtAb8kLs7vgw2ZV3p2VZ1+hBavOc84hqxVNpCyw= +github.com/aws/aws-sdk-go-v2/credentials v1.4.3/go.mod h1:FNNC6nQZQUuyhq5aE5c7ata8o9e4ECGmS4lAXC7o1mQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.6.0/go.mod h1:gqlclDEZp4aqJOancXK6TN24aKhT0W0Ae9MHk3wzTMM= +github.com/aws/aws-sdk-go-v2/internal/ini v1.2.4/go.mod h1:ZcBrrI3zBKlhGFNYWvju0I3TR93I7YIgAfy82Fh4lcQ= +github.com/aws/aws-sdk-go-v2/service/appconfig v1.4.2/go.mod h1:FZ3HkCe+b10uFZZkFdvf98LHW21k49W8o8J366lqVKY= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.3.2/go.mod h1:72HRZDLMtmVQiLG2tLfQcaWLCssELvGl+Zf2WVxMmR8= +github.com/aws/aws-sdk-go-v2/service/sso v1.4.2/go.mod h1:NBvT9R1MEF+Ud6ApJKM0G+IkPchKS7p7c2YPKwHmBOk= +github.com/aws/aws-sdk-go-v2/service/sts v1.7.2/go.mod h1:8EzeIqfWt2wWT4rJVu3f21TfrhJ8AEMzVybRNSb/b4g= +github.com/aws/smithy-go v1.8.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= +github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bits-and-blooms/bitset v1.2.0 h1:Kn4yilvwNtMACtf1eYDlG8H77R07mZSPbMjLyS07ChA= +github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= +github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= +github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= +github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= +github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= +github.com/buger/jsonparser v1.2.0 h1:4EFcvK1kD4jyj6YqNK6skK6w+y7FHHBR+XBCtxwu/6g= +github.com/buger/jsonparser v1.2.0/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= +github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= +github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= +github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= +github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo= +github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA= +github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= +github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= +github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI= +github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/creasty/defaults v1.5.2 h1:/VfB6uxpyp6h0fr7SPp7n8WJBoV8jfxQXPCnkVSjyls= +github.com/creasty/defaults v1.5.2/go.mod h1:FPZ+Y0WNrbqOVw+c6av63eyHUAl6pMHZwqLPvXUZGfY= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= +github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo= +github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= +github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= +github.com/dop251/goja v0.0.0-20240220182346-e401ed450204 h1:O7I1iuzEA7SG+dK8ocOBSlYAA9jBUmCYl/Qa7ey7JAM= +github.com/dop251/goja v0.0.0-20240220182346-e401ed450204/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4= +github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y= +github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d h1:W1n4DvpzZGOISgp7wWNtraLcHtnmnTwBlJidqtMIuwQ= +github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM= +github.com/dubbogo/go-zookeeper v1.0.3/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c= +github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5 h1:XoR8SSVziXe698dt4uZYDfsmHpKLemqAgFyndQsq5Kw= +github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c= +github.com/dubbogo/gost v1.9.0/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8= +github.com/dubbogo/gost v1.11.18/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI= +github.com/dubbogo/gost v1.13.1/go.mod h1:9HMXBv+WBMRWhF3SklpqDjkS/01AKWm2SrVdz/A0xJI= +github.com/dubbogo/gost v1.14.3 h1:bInkIjdImMo9ENTDdCcs4YlQ/vz5rP/rjcnLakK5x24= +github.com/dubbogo/gost v1.14.3/go.mod h1:WydBuEOkwKEm9mcWLlOnmsVe1ELFgrNPmC5SzXdPv4A= +github.com/dubbogo/grpc-go v1.42.9/go.mod h1:F1T9hnUvYGW4JLK1QNriavpOkhusU677ovPzLkk6zHM= +github.com/dubbogo/grpc-go v1.42.10 h1:CoyCdtqKJEar/3rPa6peZbDqYZ/mVsCqAxB6TfTSkhQ= +github.com/dubbogo/grpc-go v1.42.10/go.mod h1:JMkPt1mIHL96GAFeYsMoMjew6f1ROKycikGzZQH1s5U= +github.com/dubbogo/jsonparser v1.0.1/go.mod h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU= +github.com/dubbogo/net v0.0.4/go.mod h1:1CGOnM7X3he+qgGNqjeADuE5vKZQx/eMSeUkpU3ujIc= +github.com/dubbogo/triple v1.0.9/go.mod h1:1t9me4j4CTvNDcsMZy6/OGarbRyAUSY0tFXGXHCp7Iw= +github.com/dubbogo/triple v1.2.2-rc4 h1:zL15Fb6W/yNAFQve5eqpTOEWWD9dpTFq78mdeSKc2pk= +github.com/dubbogo/triple v1.2.2-rc4/go.mod h1:9pgEahtmsY/avYJp3dzUQE8CMMVe1NtGBmUhfICKLJk= +github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= +github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= +github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= +github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= +github.com/emicklei/go-restful/v3 v3.10.1 h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ= +github.com/emicklei/go-restful/v3 v3.10.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= +github.com/envoyproxy/go-control-plane v0.10.0/go.mod h1:AY7fTTXNdv/aJ2O5jwpxAPOWUZ7hQAEvzN5Pf27BkQQ= +github.com/envoyproxy/go-control-plane v0.10.1/go.mod h1:AY7fTTXNdv/aJ2O5jwpxAPOWUZ7hQAEvzN5Pf27BkQQ= +github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239/go.mod h1:Gdwt2ce0yfBxPvZrHkprdPPTTS3N5rwmLE8T22KBXlw= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= +github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= +github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= +github.com/form3tech-oss/jwt-go v3.2.2+incompatible h1:TcekIExNqud5crz4xD2pavyTgWiPvpYe4Xau31I0PRk= +github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= +github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= +github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= +github.com/frankban/quicktest v1.10.0 h1:Gfh+GAJZOAoKZsIZeZbdn2JF10kN1XHNvjsvQK8gVkE= +github.com/frankban/quicktest v1.10.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= +github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o= +github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= +github.com/go-ldap/ldap v3.0.2+incompatible/go.mod h1:qfd9rJvER9Q0/D/Sqn1DfHRoBp40uXYvFoEVrNEPqRc= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= +github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM= +github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.12.0 h1:E4gtWgxWxp8YSxExrQFv5BpCahla0PVF2oTTEYaWQGI= +github.com/go-playground/validator/v10 v10.12.0/go.mod h1:hCAPuzYvKdP33pxWa+2+6AIKXEKqjIUyqsNCtbsSJrA= +github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY= +github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I= +github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU= +github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= +github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-test/deep v1.0.2-0.20181118220953-042da051cf31/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= +github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68= +github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= +github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac/go.mod h1:P32wAyui1PQ58Oce/KYkOqQv8cVw1zAapXOl+dRFGbc= +github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82/go.mod h1:PxC8OnwL11+aosOB5+iEPoV3picfs8tUpkVd0pDo+Kg= +github.com/gonum/integrate v0.0.0-20181209220457-a422b5c0fdf2/go.mod h1:pDgmNM6seYpwvPos3q+zxlXMsbve6mOIPucUnUOrI7Y= +github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhSyOzRwuXkOgAvijx4o+4YMUJJo9OvPYMkks= +github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9/go.mod h1:XA3DeT6rxh2EAE789SSiSJNqxPaC0aE9J8NTOI0Jo/A= +github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9/go.mod h1:0EXg4mc1CNP0HCqCz+K4ts155PXIlUywf0wqN+GfPZw= +github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b/go.mod h1:Z4GIJBJO3Wa4gD4vbwQxXXZ+WHmW6E9ixmNrwvs0iZs= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20230207041349-798e818bf904 h1:4/hN5RUoecvl+RmJRE2YxKWtnnQls6rQjjW5oV7qg2U= +github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gopherjs/gopherjs v0.0.0-20190910122728-9d188e94fb99 h1:twflg0XRTjwKpxb/jFExr4HGq6on2dEOmnL6FV+fgPw= +github.com/gopherjs/gopherjs v0.0.0-20190910122728-9d188e94fb99/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= +github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 h1:FlFbCRLd5Jr4iYXZufAvgWN6Ao0JrI5chLINnUXDDr0= +github.com/grpc-ecosystem/go-grpc-middleware v1.2.2/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw= +github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= +github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= +github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= +github.com/hashicorp/consul/api v1.13.0/go.mod h1:ZlVrynguJKcYr54zGaDbaL3fOvKC9m72FhPvA8T35KQ= +github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= +github.com/hashicorp/go-hclog v0.8.0/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= +github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY= +github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= +github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= +github.com/hashicorp/go-rootcerts v1.0.1/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= +github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A= +github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= +github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= +github.com/hashicorp/mdns v1.0.4/go.mod h1:mtBihi+LeNXGtG8L9dX59gAEa12BDtBQSp4v/YAJqrc= +github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= +github.com/hashicorp/memberlist v0.3.0/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= +github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= +github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= +github.com/hashicorp/vault/api v1.0.4/go.mod h1:gDcqh3WGcR1cpF5AJz/B1UFheUEneMoIospckxBxk6Q= +github.com/hashicorp/vault/sdk v0.1.13/go.mod h1:B+hVj7TpuQY1Y/GPbCpffmgd+tSEwvhkWnjtSYCaS2M= +github.com/hashicorp/vault/sdk v0.7.0 h1:2pQRO40R1etpKkia5fb4kjrdYMx3BHklPxl1pxpxDHg= +github.com/hashicorp/vault/sdk v0.7.0/go.mod h1:KyfArJkhooyba7gYCKSq8v66QdqJmnbAxtV/OX1+JTs= +github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= +github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= +github.com/hjson/hjson-go/v4 v4.0.0 h1:wlm6IYYqHjOdXH1gHev4VoXCaW20HdQAGCxdOEEg2cs= +github.com/hjson/hjson-go/v4 v4.0.0/go.mod h1:KaYt3bTw3zhBjYqnXkYywcYctk0A2nxeEFTse3rH13E= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= +github.com/influxdata/tdigest v0.0.1 h1:XpFptwYmnEKUqmkcDjrzffswZ3nvNeevbUSLPP/ZzIY= +github.com/influxdata/tdigest v0.0.1/go.mod h1:Z0kXnxzbTC2qrx4NaIzYkE1k66+6oEDQTvL95hQFh5Y= +github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ= +github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= +github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM= +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= +github.com/k0kubun/pp v3.0.1+incompatible h1:3tqvf7QgUnZ5tXO6pNAZlrvHgl6DvifjDrd9g2S9Z40= +github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/knadh/koanf v1.5.0 h1:q2TSd/3Pyc/5yP9ldIrSdIz26MCcyNQzW0pEAugLPNs= +github.com/knadh/koanf v1.5.0/go.mod h1:Hgyjp4y8v44hpZtPzs7JZfRAW5AhN7KfZcwv1RYggDs= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-urn v1.2.2 h1:7z68G0FCGvDk646jz1AelTYNYWrTNm0bEcFAo147wt4= +github.com/leodido/go-urn v1.2.2/go.mod h1:kUaIbLZWttglzwNuG0pgsh5vuV6u2YcGBYz1hIPjtOQ= +github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570/go.mod h1:BLt8L9ld7wVsvEWQbuLrUZnCMnUmLZ+CGDzKtclrTlE= +github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f/go.mod h1:UGmTpUd3rjbtfIpwAPrcfmGf/Z1HS95TATB+m57TPB8= +github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042/go.mod h1:TPpsiPUEh0zFL1Snz4crhMlBe60PYxRHr5oFF3rRYg0= +github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= +github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= +github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls= +github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= +github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= +github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= +github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= +github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= +github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= +github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= +github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM= +github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/nacos-group/nacos-sdk-go v1.0.8/go.mod h1:hlAPn3UdzlxIlSILAyOXKxjFSvDJ9oLzTJ9hLAK1KzA= +github.com/nacos-group/nacos-sdk-go/v2 v2.1.2/go.mod h1:ys/1adWeKXXzbNWfRNbaFlX/t6HVLWdpsNDvmoWTw0g= +github.com/nacos-group/nacos-sdk-go/v2 v2.2.5 h1:r0wwT7PayEjvEHzWXwr1ROi/JSqzujM4w+1L5ikThzQ= +github.com/nacos-group/nacos-sdk-go/v2 v2.2.5/go.mod h1:OObBon0prVJVPoIbSZxpEkFiBfL0d1LcBtuAMiNn+8c= +github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM= +github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk= +github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= +github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= +github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= +github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= +github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= +github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= +github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/npillmayer/nestext v0.1.3/go.mod h1:h2lrijH8jpicr25dFY+oAJLyzlya6jhnuG+zWp9L0Uk= +github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= +github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= +github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 h1:Yl0tPBa8QPjGmesFh1D0rDy+q1Twx6FyU7VWHi8wZbI= +github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852/go.mod h1:eqOVx5Vwu4gd2mmMZvVZsgIqNSaW3xxRThUJ0k/TPk4= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= +github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= +github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= +github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= +github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= +github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA= +github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= +github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= +github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= +github.com/openzipkin/zipkin-go v0.4.2 h1:zjqfqHjUpPmB3c1GlCvvgsM1G4LkvqQbBDueDOCg/jA= +github.com/openzipkin/zipkin-go v0.4.2/go.mod h1:ZeVkFjuuBiSy13y8vpSDCjMi9GoI3hPpCJSBx/EYFhY= +github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= +github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ= +github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= +github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= +github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= +github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= +github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= +github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/polarismesh/polaris-go v1.3.0 h1:KZKX//ow4OPPoS5+s7h07ptprg+2AcNVGrN6WakC9QM= +github.com/polarismesh/polaris-go v1.3.0/go.mod h1:HsN0ierETIujHpmnnYJ3qkwQw4QGAECuHvBZTDaw1tI= +github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= +github.com/prometheus/client_golang v1.5.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= +github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= +github.com/prometheus/client_golang v1.9.0/go.mod h1:FqZLKOZnGdFAhOK4nqGHa7D66IdsO+O441Eve7ptJDU= +github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= +github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= +github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= +github.com/prometheus/client_golang v1.12.2/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= +github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= +github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= +github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= +github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= +github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= +github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= +github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= +github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= +github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= +github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= +github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8= +github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII= +github.com/quic-go/quic-go v0.59.1 h1:0Gmua0HW1Tv7ANR7hUYwRyD0MG5OJfgvYSZasGZzBic= +github.com/quic-go/quic-go v0.59.1/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU= +github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/rhnvrm/simples3 v0.6.1/go.mod h1:Y+3vYm2V7Y4VijFoJHHTrja6OgPrJ2cBti8dPGkC3sA= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/rwtodd/Go.Sed v0.0.0-20210816025313-55464686f9ef/go.mod h1:8AEUvGVi2uQ5b24BIhcr0GCcpd/RNAFWaN2CJFrWIIQ= +github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= +github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/shirou/gopsutil v3.20.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/shirou/gopsutil/v3 v3.21.6/go.mod h1:JfVbDpIBLVzT8oKbvMg9P3wEIMDDpVn+LwHTKj0ST88= +github.com/shirou/gopsutil/v3 v3.22.2 h1:wCrArWFkHYIdDxx/FSfF5RB4dpJYW6t7rcp3+zL8uks= +github.com/shirou/gopsutil/v3 v3.22.2/go.mod h1:WapW1AOOPlHyXr+yOyw3uYx36enocrtSoSBy0L5vUHY= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= +github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/soheilhy/cmux v0.1.5-0.20210205191134-5ec6847320e5 h1:GJTW+uNMIV1RKwox+T4aN0/sQlYRg78uHZf2H0aBcDw= +github.com/soheilhy/cmux v0.1.5-0.20210205191134-5ec6847320e5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= +github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY= +github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= +github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= +github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= +github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= +github.com/spf13/viper v1.8.1 h1:Kq1fyeebqsBfbjZj4EL7gj2IO0mMaiyjYUWcUsl2O44= +github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns= +github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= +github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= +github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tebeka/strftime v0.1.3/go.mod h1:7wJm3dZlpr4l/oVK0t1HYIc4rMzQ2XJlOMIUJUJH6XQ= +github.com/tevid/gohamcrest v1.1.1 h1:ou+xSqlIw1xfGTg1uq1nif/htZ2S3EzRqLm2BP+tYU0= +github.com/tevid/gohamcrest v1.1.1/go.mod h1:3UvtWlqm8j5JbwYZh80D/PVBt0mJ1eJiYgZMibh0H/k= +github.com/tklauser/go-sysconf v0.3.6/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= +github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs= +github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw= +github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= +github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM= +github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8= +github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o= +github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= +github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 h1:uruHq4dN7GR16kFc5fp3d1RIYzJW5onx8Ybykw2YQFA= +github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3/go.mod h1:QDlpd3qS71vYtakd2hmdpqhJ9nwv6mD6A30bQ1BPBFE= +github.com/uber/jaeger-client-go v2.29.1+incompatible h1:R9ec3zO3sGpzs0abd43Y+fBZRJ9uiH6lXyR/+u6brW4= +github.com/uber/jaeger-client-go v2.29.1+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= +github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg= +github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= +github.com/ugorji/go v1.2.6/go.mod h1:anCg0y61KIhDlPZmnH+so+RQbysYVyDko0IMgJv0Nn0= +github.com/ugorji/go/codec v1.2.6 h1:7kbGefxLoDBuYXOms4yD7223OpNMMPNPZxXk5TvFcyQ= +github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxWFFpvxTw= +github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= +github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0= +go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= +go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738 h1:VcrIfasaLFkyjk6KNlXQSzO+B0fZcnECiDrKJsfxka0= +go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= +go.etcd.io/etcd/api/v3 v3.5.0-alpha.0/go.mod h1:mPcW6aZJukV6Aa81LSKpBjQXTWlXB5r74ymPoSWa3Sw= +go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= +go.etcd.io/etcd/api/v3 v3.5.4/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A= +go.etcd.io/etcd/api/v3 v3.5.7 h1:sbcmosSVesNrWOJ58ZQFitHMdncusIifYcrBfwrlJSY= +go.etcd.io/etcd/api/v3 v3.5.7/go.mod h1:9qew1gCdDDLu+VwmeG+iFpL+QlpHTo7iubavdVDgCAA= +go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= +go.etcd.io/etcd/client/pkg/v3 v3.5.4/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= +go.etcd.io/etcd/client/pkg/v3 v3.5.7 h1:y3kf5Gbp4e4q7egZdn5T7W9TSHUvkClN6u+Rq9mEOmg= +go.etcd.io/etcd/client/pkg/v3 v3.5.7/go.mod h1:o0Abi1MK86iad3YrWhgUsbGx1pmTS+hrORWc2CamuhY= +go.etcd.io/etcd/client/v2 v2.305.0-alpha.0/go.mod h1:kdV+xzCJ3luEBSIeQyB/OEKkWKd8Zkux4sbDeANrosU= +go.etcd.io/etcd/client/v2 v2.305.0 h1:ftQ0nOOHMcbMS3KIaDQ0g5Qcd6bhaBrQT6b89DfwLTs= +go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= +go.etcd.io/etcd/client/v3 v3.5.0-alpha.0/go.mod h1:wKt7jgDgf/OfKiYmCq5WFGxOFAkVMLxiiXgLDFhECr8= +go.etcd.io/etcd/client/v3 v3.5.4/go.mod h1:ZaRkVgBZC+L+dLCjTcF1hRXpgZXQPOvnA/Ak/gq3kiY= +go.etcd.io/etcd/client/v3 v3.5.7 h1:u/OhpiuCgYY8awOHlhIhmGIGpxfBU/GZBUP3m/3/Iz4= +go.etcd.io/etcd/client/v3 v3.5.7/go.mod h1:sOWmj9DZUMyAngS7QQwCyAXXAL6WhgTOPLNS/NabQgw= +go.etcd.io/etcd/pkg/v3 v3.5.0-alpha.0 h1:3yLUEC0nFCxw/RArImOyRUI4OAFbg4PFpBbAhSNzKNY= +go.etcd.io/etcd/pkg/v3 v3.5.0-alpha.0/go.mod h1:tV31atvwzcybuqejDoY3oaNRTtlD2l/Ot78Pc9w7DMY= +go.etcd.io/etcd/raft/v3 v3.5.0-alpha.0 h1:DvYJotxV9q1Lkn7pknzAbFO/CLtCVidCr2K9qRLJ8pA= +go.etcd.io/etcd/raft/v3 v3.5.0-alpha.0/go.mod h1:FAwse6Zlm5v4tEWZaTjmNhe17Int4Oxbu7+2r0DiD3w= +go.etcd.io/etcd/server/v3 v3.5.0-alpha.0 h1:fYv7CmmdyuIu27UmKQjS9K/1GtcCa+XnPKqiKBbQkrk= +go.etcd.io/etcd/server/v3 v3.5.0-alpha.0/go.mod h1:tsKetYpt980ZTpzl/gb+UOJj9RkIyCb1u4wjzMg90BQ= +go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= +go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= +go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= +go.opentelemetry.io/contrib/propagators/b3 v1.10.0 h1:6AD2VV8edRdEYNaD8cNckpzgdMLU2kbV9OYyxt2kvCg= +go.opentelemetry.io/contrib/propagators/b3 v1.10.0/go.mod h1:oxvamQ/mTDFQVugml/uFS59+aEUnFLhmd1wsG+n5MOE= +go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc= +go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo= +go.opentelemetry.io/otel/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4= +go.opentelemetry.io/otel/exporters/jaeger v1.17.0/go.mod h1:nPCqOnEH9rNLKqH/+rrUjiMzHJdV1BlpKcTwRTyKkKI= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 h1:cl5P5/GIfFh4t6xyruOgJP5QiA1pw4fYYdv6nc6CBWw= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0/go.mod h1:zgBdWWAu7oEEMC06MMKc5NLbA/1YDXV1sMpSqEeLQLg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 h1:tIqheXEFWAZ7O8A7m+J0aPTmpJN3YQ7qetUAdkkkKpk= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0/go.mod h1:nUeKExfxAQVbiVFn32YXpXZZHZ61Cc3s3Rn1pDBGAb0= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0 h1:digkEZCJWobwBqMwC0cwCq8/wkkRy/OowZg5OArWZrM= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0/go.mod h1:/OpE/y70qVkndM0TrxT4KBoN3RsFZP0QaofcfYrj76I= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.21.0 h1:VhlEQAPp9R1ktYfrPk5SOryw1e9LDDTZCbIPFrho0ec= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.21.0/go.mod h1:kB3ufRbfU+CQ4MlUcqtW8Z7YEOBeK2DJ6CmR5rYYF3E= +go.opentelemetry.io/otel/exporters/zipkin v1.21.0 h1:D+Gv6lSfrFBWmQYyxKjDd0Zuld9SRXpIrEsKZvE4DO4= +go.opentelemetry.io/otel/exporters/zipkin v1.21.0/go.mod h1:83oMKR6DzmHisFOW3I+yIMGZUTjxiWaiBI8M8+TU5zE= +go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4= +go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM= +go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= +go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= +go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc= +go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= +go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= +go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= +go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/mock v0.5.2 h1:LbtPTcP8A5k9WPXj54PPPbjcI4Y6lhyOZXn+VS7wNko= +go.uber.org/mock v0.5.2/go.mod h1:wLlUxC2vVTPTaE3UD51E0BGOAElKrILxhVSDYQLld5o= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= +go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= +go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= +go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= +go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= +go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8= +go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto= +golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio= +golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5 h1:FR+oGxGfbQu1d+jglI3rCkjAjUnhRSZcUxr+DqlDLNo= +golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= +golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211105192438-b53810dc28af/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o= +golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM= +golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201223074533-0d417f636930/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211106132015-ebca88c72f68/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw= +golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.39.0 h1:UbZz4pLOvn600D6Oh6GGEI6VAmndrEBLv8/6BEXzyus= +golang.org/x/text v0.39.0/go.mod h1:3UwRclnC2g0TU9x8PZiyfOajCd1zaUNHF9cvqcQZ+ZM= +golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= +golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= +golang.org/x/tools v0.0.0-20201014170642-d1624618ad65/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= +golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= +gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= +gonum.org/v1/gonum v0.8.2 h1:CCXrcPKiGGotvnN6jfUsKk4rRqm7q09/YbKb5xCEvtM= +gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0= +gonum.org/v1/netlib v0.0.0-20181029234149-ec6d1f5cefe6/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= +gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= +gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc= +google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= +google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE= +google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= +google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= +google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= +google.golang.org/api v0.44.0/go.mod h1:EBOGZqzyhtvMDoxwS97ctnh0zUmYY6CxqXsc1AvkYD8= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200806141610-86f49bd18e98/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210106152847-07624b53cd92/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210222152913-aa3ee6e6a81c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210303154014-9728d6b83eeb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= +google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20211104193956-4c6863e31247/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20220504150022-98cd25cafc72/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= +google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d h1:VBu5YqKPv6XiJ199exd8Br+Aetz+o08F+PLMnwJQHAY= +google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d/go.mod h1:yZTlhN0tQnXo3h00fuXNCxJdLdIdnVFVBaRJ5LWBbw4= +google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 h1:RFiFrvy37/mpSpdySBDrUdipW/dHwsRwh3J3+A9VgT4= +google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237/go.mod h1:Z5Iiy3jtmioajWHDGFk7CeugTyHtPvMHA4UTmUkyalE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= +google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= +google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= +google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= +google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= +google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= +gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI= +gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= +gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= +gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= +honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= +sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= +sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= +sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= diff --git a/benchmark/go/load/main.go b/benchmark/go/load/main.go new file mode 100644 index 00000000..6786bdff --- /dev/null +++ b/benchmark/go/load/main.go @@ -0,0 +1,281 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// A closed-loop load over Dubbo that adds next to nothing to what it +// measures: each of --concurrency goroutines sends the request body of the +// file --body again as soon as its response comes, over --connections +// connections. A response counts when its status is OK and it holds a +// value. It prints "started" once each connection has answered; calls during +// --warmup are not counted. It prints the result as JSON, as client.py does: +// the calls and errors counted, the calls per second, the CPU microseconds +// of the process for each call meanwhile, and the latency percentiles in +// microseconds, from buckets about 1% wide. +package main + +import ( + "encoding/binary" + "encoding/json" + "flag" + "fmt" + "io" + "math" + "net" + "os" + "sort" + "sync" + "syscall" + "time" +) + +const ( + headerSize = 16 + // A two-way request in Hessian 2. + requestFlags = 0xC2 + statusOK = 20 + // Bucket b holds the latencies of e^(b/100) to e^((b+1)/100) nanoseconds. + bucketsPerE = 100 +) + +// The names of the statuses of a response other than OK. +var statuses = map[byte]string{ + 30: "CLIENT_TIMEOUT", 31: "SERVER_TIMEOUT", 35: "CHANNEL_INACTIVE", 40: "BAD_REQUEST", 50: "BAD_RESPONSE", + 60: "SERVICE_NOT_FOUND", 70: "SERVICE_ERROR", 80: "SERVER_ERROR", 90: "CLIENT_ERROR", + 100: "SERVER_THREADPOOL_EXHAUSTED_ERROR", +} + +var wanted = []float64{50, 90, 99, 99.9} + +type connection struct { + conn net.Conn + // The frames to send, which the writer sends together as they queue up, as clients do. + frames chan []byte + // The outcome of each worker's call in flight, by the worker's index, its request id. + outcomes map[int64]chan string +} + +func main() { + address := flag.String("address", "127.0.0.1:20880", "the provider to call") + bodyFile := flag.String("body", "", "the file of the request body") + concurrency := flag.Int("concurrency", 16, "calls in flight") + connections := flag.Int("connections", 1, "connections the calls share") + warmup := flag.Float64("warmup", 3, "seconds before counting") + duration := flag.Float64("duration", 10, "seconds counted") + flag.Parse() + + body, err := os.ReadFile(*bodyFile) + if err != nil { + panic(err) + } + count := min(*connections, *concurrency) + pool := make([]*connection, count) + for i := range pool { + conn, err := net.Dial("tcp", *address) + if err != nil { + panic(err) + } + pool[i] = &connection{conn: conn, frames: make(chan []byte, *concurrency), outcomes: map[int64]chan string{}} + } + frames := make([][]byte, *concurrency) + for id := range frames { + frame := make([]byte, headerSize+len(body)) + binary.BigEndian.PutUint16(frame, 0xDABB) + frame[2] = requestFlags + binary.BigEndian.PutUint64(frame[4:], uint64(id)) + binary.BigEndian.PutUint32(frame[12:], uint32(len(body))) + copy(frame[headerSize:], body) + frames[id] = frame + pool[id%count].outcomes[int64(id)] = make(chan string, 1) + } + for _, each := range pool { + go each.read() + go each.write() + } + // Each connection answers once before the start. + for id := range count { + if outcome := pool[id].call(int64(id), frames[id]); outcome != "" { + panic(outcome) + } + } + fmt.Println("started") + + counted := time.Now().Add(seconds(*warmup)) + end := counted.Add(seconds(*duration)) + histograms := make([]map[int]int64, *concurrency) + errors := make([]map[string]int64, *concurrency) + var group sync.WaitGroup + for id := range *concurrency { + histogram, failed := map[int]int64{}, map[string]int64{} + histograms[id], errors[id] = histogram, failed + own := pool[id%count] + group.Add(1) + go func() { + defer group.Done() + for { + sent := time.Now() + if !sent.Before(end) { + return + } + outcome := own.call(int64(id), frames[id]) + if sent.Before(counted) { + continue + } + if outcome != "" { + failed[outcome]++ + continue + } + histogram[bucket(time.Since(sent))]++ + } + }() + } + time.Sleep(time.Until(counted)) + cpu := cpuSeconds() + time.Sleep(time.Until(end)) + cpu = cpuSeconds() - cpu + group.Wait() + + histogram, failures := map[int]int64{}, map[string]int64{} + var calls int64 + for id := range *concurrency { + for key, n := range histograms[id] { + histogram[key] += n + calls += n + } + for key, n := range errors[id] { + failures[key] += n + } + } + var cpuPerCall any + if calls > 0 { + cpuPerCall = math.Round(cpu/float64(calls)*1e8) / 100 + } + result := map[string]any{ + "calls": calls, + "errors": failures, + "rps": math.Round(float64(calls)/(*duration)*10) / 10, + "client_cpu_us": cpuPerCall, + "latency_us": percentiles(histogram), + } + if err := json.NewEncoder(os.Stdout).Encode(result); err != nil { + panic(err) + } +} + +// Send the frame of the worker id and return the outcome of its call: empty for one that succeeded. +func (c *connection) call(id int64, frame []byte) string { + c.frames <- frame + return <-c.outcomes[id] +} + +// Send the frames as they queue up, those queued together in one write. +func (c *connection) write() { + var buffer []byte + for frame := range c.frames { + buffer = append(buffer[:0], frame...) + more: + for { + select { + case frame := <-c.frames: + buffer = append(buffer, frame...) + default: + break more + } + } + if _, err := c.conn.Write(buffer); err != nil { + panic(err) + } + } +} + +// Read the responses, telling each worker the outcome of its call. +func (c *connection) read() { + header := make([]byte, headerSize) + body := make([]byte, 64*1024) + for { + if _, err := io.ReadFull(c.conn, header); err != nil { + panic(err) + } + length := int(binary.BigEndian.Uint32(header[12:])) + if length > len(body) { + body = make([]byte, length) + } + if _, err := io.ReadFull(c.conn, body[:length]); err != nil { + panic(err) + } + outcome, waiting := c.outcomes[int64(binary.BigEndian.Uint64(header[4:]))] + if header[2]&0x80 != 0 || !waiting { + // A request of the server, such as a heartbeat, or no call of ours. + continue + } + outcome <- result(header[3], body[:length]) + } +} + +func result(status byte, body []byte) string { + if status != statusOK { + if name, known := statuses[status]; known { + return name + } + return fmt.Sprintf("status %d", status) + } + // The Hessian 2 integer that starts the body: 1 for a value, 4 for a value with attachments. + if len(body) == 0 || (body[0] != 0x91 && body[0] != 0x94) { + return "EXCEPTION" + } + return "" +} + +func seconds(value float64) time.Duration { + return time.Duration(value * float64(time.Second)) +} + +func bucket(elapsed time.Duration) int { + return int(math.Log(math.Max(float64(elapsed.Nanoseconds()), 1)) * bucketsPerE) +} + +func microseconds(bucket int) float64 { + return math.Round(math.Exp((float64(bucket)+0.5)/bucketsPerE)/100) / 10 +} + +func percentiles(histogram map[int]int64) map[string]float64 { + keys := make([]int, 0, len(histogram)) + var total int64 + for key, n := range histogram { + keys = append(keys, key) + total += n + } + sort.Ints(keys) + result := map[string]float64{} + var seen int64 + next := 0 + for _, key := range keys { + seen += histogram[key] + for next < len(wanted) && float64(seen) >= float64(total)*wanted[next]/100 { + result[fmt.Sprintf("p%g", wanted[next])] = microseconds(key) + next++ + } + } + if len(keys) > 0 { + result["max"] = microseconds(keys[len(keys)-1]) + } + return result +} + +func cpuSeconds() float64 { + var usage syscall.Rusage + _ = syscall.Getrusage(syscall.RUSAGE_SELF, &usage) + return float64(usage.Utime.Nano()+usage.Stime.Nano()) / 1e9 +} diff --git a/benchmark/go/server/main.go b/benchmark/go/server/main.go new file mode 100644 index 00000000..a7a31b1f --- /dev/null +++ b/benchmark/go/server/main.go @@ -0,0 +1,86 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// Dubbo Go serving the benchmark service over one protocol: the Bench +// service of bench.proto over Triple, or BenchService over Dubbo, whose +// echo carries bytes in Hessian 2. +package main + +import ( + "context" + "flag" + "fmt" + + "dubbo.apache.org/dubbo-go/v3" + _ "dubbo.apache.org/dubbo-go/v3/imports" + "dubbo.apache.org/dubbo-go/v3/logger" + "dubbo.apache.org/dubbo-go/v3/protocol" + "dubbo.apache.org/dubbo-go/v3/server" + + "bench/benchpb" +) + +type BenchImpl struct{} + +func (BenchImpl) Echo(_ context.Context, request *benchpb.Payload) (*benchpb.Payload, error) { + return request, nil +} + +type BenchService struct{} + +func (BenchService) Echo(_ context.Context, data []byte) ([]byte, error) { + return data, nil +} + +func main() { + name := flag.String("protocol", "tri", "the protocol to serve: tri or dubbo") + port := flag.Int("port", 50051, "the port to serve on") + flag.Parse() + + serving := protocol.WithTriple() + if *name != "tri" { + serving = protocol.WithDubbo() + } + instance, err := dubbo.NewInstance( + dubbo.WithName("bench-server"), + dubbo.WithProtocol(serving, protocol.WithPort(*port)), + dubbo.WithLogger(logger.WithLevel("warn")), + ) + if err != nil { + panic(err) + } + srv, err := instance.NewServer() + if err != nil { + panic(err) + } + if *name == "tri" { + err = benchpb.RegisterBenchHandler(srv, BenchImpl{}) + } else { + err = srv.RegisterService( + BenchService{}, + server.WithInterface("org.apache.dubbo.benchmark.BenchService"), + server.WithSerialization("hessian2"), + ) + } + if err != nil { + panic(err) + } + fmt.Printf("Serving %s on port %d\n", *name, *port) + if err := srv.Serve(); err != nil { + panic(err) + } +} diff --git a/benchmark/java/pom.xml b/benchmark/java/pom.xml new file mode 100644 index 00000000..40fd7f06 --- /dev/null +++ b/benchmark/java/pom.xml @@ -0,0 +1,84 @@ + + + + 4.0.0 + + org.apache.dubbo.benchmark + benchmark-java + 1.0.0 + + + 17 + UTF-8 + 3.3.7 + + + + + + org.apache.dubbo + dubbo-dependencies-bom + ${dubbo.version} + pom + import + + + + + + + org.apache.dubbo + dubbo + ${dubbo.version} + + + com.google.protobuf + protobuf-java + + + org.slf4j + slf4j-simple + 1.7.36 + + + + + + + + org.apache.dubbo + dubbo-maven-plugin + ${dubbo.version} + + ${project.basedir}/../proto + + + + + compile + + + + + + + diff --git a/benchmark/java/src/main/java/org/apache/dubbo/benchmark/BenchService.java b/benchmark/java/src/main/java/org/apache/dubbo/benchmark/BenchService.java new file mode 100644 index 00000000..aab1940e --- /dev/null +++ b/benchmark/java/src/main/java/org/apache/dubbo/benchmark/BenchService.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.dubbo.benchmark; + +/** The service the benchmarks call over Dubbo: an echo of bytes, which travel in Hessian 2. */ +public interface BenchService { + byte[] echo(byte[] data); +} diff --git a/benchmark/java/src/main/java/org/apache/dubbo/benchmark/JavaServer.java b/benchmark/java/src/main/java/org/apache/dubbo/benchmark/JavaServer.java new file mode 100644 index 00000000..405105f3 --- /dev/null +++ b/benchmark/java/src/main/java/org/apache/dubbo/benchmark/JavaServer.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.dubbo.benchmark; + +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ProtocolConfig; +import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.config.ServiceConfig; +import org.apache.dubbo.config.bootstrap.DubboBootstrap; + +/** + * Dubbo Java serving the benchmark service over one protocol: Bench of bench.proto over Triple, or BenchService over + * Dubbo. It takes the protocol, tri or dubbo, and the port. + */ +public class JavaServer { + + static class BenchImpl extends DubboBenchTriple.BenchImplBase { + @Override + public Payload echo(Payload request) { + return request; + } + } + + static class BenchServiceImpl implements BenchService { + @Override + public byte[] echo(byte[] data) { + return data; + } + } + + public static void main(String[] args) { + String protocol = args[0]; + ProtocolConfig serving = new ProtocolConfig(protocol, Integer.parseInt(args[1])); + serving.setHost("127.0.0.1"); + + ServiceConfig service = new ServiceConfig<>(); + if (protocol.equals("tri")) { + service.setInterface(Bench.class); + service.setRef(new BenchImpl()); + } else { + service.setInterface(BenchService.class); + service.setRef(new BenchServiceImpl()); + } + + ApplicationConfig application = new ApplicationConfig("bench-server"); + application.setQosEnable(false); + DubboBootstrap.getInstance() + .application(application) + .registry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)) + .protocol(serving) + .service(service) + .start(); + System.out.println("Serving " + protocol + " on port " + args[1]); + DubboBootstrap.getInstance().await(); + } +} diff --git a/benchmark/plot.py b/benchmark/plot.py new file mode 100644 index 00000000..b02f1647 --- /dev/null +++ b/benchmark/plot.py @@ -0,0 +1,366 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Chart the results of run.py as SVG and PNG files and one report.html, and tabulate them in summary.md. + +Each chart answers one question for one protocol and its serialization: + +- the peak throughput of each server on one core, the headline: a group of + bars per payload, one bar per implementation, the median of the rounds + with their range; +- the P99 latency of each server on one core at one number of calls in + flight; +- the peak throughput of each Dubbo server on several cores; +- the peak throughput of the Dubbo Python consumer on one core. + +With several runs, the charts show the first, and the table every run, the +first the baseline. + +Every implementation keeps its color and place in every chart. report.html +holds every chart, with the values of each mark on hover, the environment +and the table, and needs nothing else to open. +""" + +import argparse +import html +import json +import statistics +from collections import defaultdict +from pathlib import Path +from typing import Any + +import altair as alt +import vl_convert + +PROTOCOLS = {"tri": ("Triple + Protobuf", "triple-protobuf"), "dubbo": ("Dubbo + Hessian 2", "dubbo-hessian2")} +IMPLEMENTATIONS = { + "python": "Dubbo Python", + "java": "Dubbo Java", + "go": "Dubbo Go", + "grpcio": "grpcio", + "grpclib": "grpclib", +} +# The categorical palette in its fixed order: each implementation keeps its color, Dubbo Python the first. +COLORS = dict(zip(IMPLEMENTATIONS, ["#2a78d6", "#eb6834", "#1baf7a", "#eda100", "#e87ba4"], strict=True)) +INK, MUTED, GRID, AXIS = "#1f2329", "#5b6170", "#eceef2", "#c9ccd3" +# A load that used this share of the cores it may use may be what limits the throughput. +LOAD_LIMIT = 0.9 + + +@alt.theme.register("benchmark", enable=True) +def theme() -> alt.theme.ThemeConfig: + return { + "config": { + "font": "Inter, Helvetica, Arial, sans-serif", + "background": "#ffffff", + "view": {"stroke": None}, + "title": {"fontSize": 14, "fontWeight": 600, "anchor": "start", "color": INK, "offset": 10}, + "axis": { + "labelFontSize": 11, "titleFontSize": 11.5, "titleFontWeight": 400, "titleColor": MUTED, + "labelColor": MUTED, "gridColor": GRID, "domainColor": AXIS, "tickColor": AXIS, + }, + "axisX": {"grid": False}, + "legend": {"orient": "top", "labelFontSize": 11.5, "labelColor": INK, "title": None, "symbolType": "square"}, + "header": {"labelFontSize": 11.5, "labelColor": INK, "title": None}, + } + } # fmt: skip + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("runs", nargs="+", type=Path, help="directories of run.py, the first the baseline") + parser.add_argument("--concurrency", type=int, default=64, help="the calls in flight latency is compared at") + parser.add_argument("--out", type=Path, help="where to write the charts; the first run by default") + args = parser.parse_args() + out = args.out or args.runs[0] + out.mkdir(parents=True, exist_ok=True) + + runs = [run.name for run in args.runs] + points = aggregate( + {**json.loads(line), "run": run.name} + for run in args.runs + for line in (run / "results.jsonl").read_text().splitlines() + if line + ) + environment = json.loads((args.runs[0] / "env.json").read_text()) + charts = [] + for protocol, (name, slug) in PROTOCOLS.items(): + servers = [p for p in points if p["run"] == runs[0] and p["side"] == "server" and p["protocol"] == protocol] + one_core = [p for p in servers if p["cores"] == 1] + multi_core = [p for p in servers if (p["cores"] or 0) > 1] + consumer = [p for p in points if p["run"] == runs[0] and p["side"] == "client" and p["protocol"] == protocol] + if one_core: + charts.append((f"{slug}-throughput-one-core", peak_chart(one_core, f"Throughput, one core · {name}"))) + charts.append((f"{slug}-latency", latency_chart(one_core, name, args.concurrency))) + if multi_core: + cores = max(p["cores"] for p in multi_core) + title = f"Throughput, {cores} cores · {name}" + charts.append((f"{slug}-throughput-multi-core", peak_chart(multi_core, title))) + if consumer: + charts.append((f"{slug}-consumer", peak_chart(consumer, f"Consumer throughput, one core · {name}"))) + + for file, chart in charts: + spec = chart.to_dict() + (out / f"{file}.svg").write_text(vl_convert.vegalite_to_svg(spec)) + (out / f"{file}.png").write_bytes(vl_convert.vegalite_to_png(spec, scale=2)) + (out / "summary.md").write_text(table(points, runs)) + (out / "report.html").write_text(report(charts, environment, points, runs)) + print(f"Wrote {len(charts)} charts, report.html and summary.md to {out}") + + +def aggregate(rows) -> list[dict[str, Any]]: + """Return each point once, with the median of its rounds, and the range of their throughput.""" + rounds = defaultdict(list) + for row in rows: + key = tuple( + row.get(field) + for field in ( + "run", + "scenario", + "side", + "implementation", + "protocol", + "loop", + "size", + "concurrency", + "cores", + ) + ) + rounds[key].append(row) + points = [] + for each in rounds.values(): + first = each[0] + limited = any( + row.get("load_cores") is not None + and row.get("load_cores_available") + and row["load_cores"] >= LOAD_LIMIT * row["load_cores_available"] + for row in each + ) + cpu = "server_cpu_us" if first["side"] == "server" else "client_cpu_us" + points.append({ + **{field: first.get(field) for field in ("run", "scenario", "side", "implementation", "protocol", "loop", "size", "concurrency", "cores")}, + "rounds": len(each), + "rps": median([row["rps"] for row in each]), + "rps_min": min(row["rps"] for row in each), + "rps_max": max(row["rps"] for row in each), + "cpu_us": median([row.get(cpu) for row in each]), + "server_cores": median([row.get("server_cores") for row in each]), + "rss_mib": median([row.get("server_rss_mib") for row in each]), + "p50_ms": ms(median([row["latency_us"].get("p50") for row in each])), + "p99_ms": ms(median([row["latency_us"].get("p99") for row in each])), + "errors": sum(sum(row["errors"].values()) for row in each), + "pinned": all(row.get("pinned") for row in each), + "load": first.get("load") or first.get("peer"), + "load_limited": limited, + }) # fmt: skip + return points + + +def median(values: list[Any]) -> float | None: + values = [each for each in values if each is not None] + return statistics.median(values) if values else None + + +def ms(microseconds: float | None) -> float | None: + return None if microseconds is None else round(microseconds / 1000, 3) + + +def label(point: dict[str, Any]) -> str: + return IMPLEMENTATIONS[point["implementation"]] + + +def size(point: dict[str, Any]) -> str: + return f"{point['size']:,}" + + +def sizes(points) -> list[str]: + return [f"{each:,}" for each in sorted({point["size"] for point in points})] + + +def implementations(points) -> tuple[list[str], list[str]]: + """Return the names of the implementations among ``points``, in their fixed order, and their colors.""" + present = [each for each in IMPLEMENTATIONS if any(point["implementation"] == each for point in points)] + return [IMPLEMENTATIONS[each] for each in present], [COLORS[each] for each in present] + + +def bars(data, x_sort, names, colors, y, y_title, title, tooltip, low=None, high=None, mark_label="text"): + """Draw a group of bars per payload, one bar per implementation, labelled, with a range when given.""" + base = alt.Chart(alt.Data(values=data)).encode( + x=alt.X("payload:N", sort=x_sort, title="Payload (bytes)", axis=alt.Axis(labelAngle=0)), + xOffset=alt.XOffset("implementation:N", sort=names), + ) + layers = [ + base.mark_bar(cornerRadiusTopLeft=3, cornerRadiusTopRight=3).encode( + y=alt.Y(f"{y}:Q", title=y_title, axis=alt.Axis(format="~s")), + color=alt.Color("implementation:N", sort=names, scale=alt.Scale(domain=names, range=colors)), + tooltip=tooltip, + ) + ] + if low is not None: + layers.append(base.mark_rule(color=MUTED, strokeWidth=1).encode(y=f"{low}:Q", y2=f"{high}:Q")) + layers.append( + base.mark_text(dy=-6, fontSize=10, color=MUTED).encode(y=alt.Y(f"{high or y}:Q"), text=f"{mark_label}:N") + ) + # Each bar as wide in every chart: the step of the offset is that of one bar. + width = alt.Step(40) + return alt.layer(*layers).properties(width=width, height=280, title=title) + + +def peak_chart(points, title: str) -> alt.LayerChart: + best: dict[tuple[str, int], dict[str, Any]] = {} + for point in points: + key = (point["implementation"], point["size"]) + # A point where calls failed is the peak only when every point of its bar has failures. + if key not in best or (not point["errors"], point["rps"]) > (not best[key]["errors"], best[key]["rps"]): + best[key] = point + data = [ + { + "implementation": label(p), "payload": size(p), "rps": p["rps"], "low": p["rps_min"], "high": p["rps_max"], + "text": f"{p['rps'] / 1000:.3g}k" + (" †" if p["load_limited"] else ""), "concurrency": p["concurrency"], + "cpu": p["cpu_us"], "p99": p["p99_ms"], "cores": p["server_cores"], "errors": p["errors"], + "load": p["load"], "rounds": p["rounds"], + } + for p in best.values() + ] # fmt: skip + names, colors = implementations(points) + tooltip = [ + alt.Tooltip("implementation:N", title="Implementation"), alt.Tooltip("payload:N", title="Payload (bytes)"), + alt.Tooltip("rps:Q", title="Calls / s (median)", format=",.0f"), + alt.Tooltip("low:Q", title="Lowest round", format=",.0f"), alt.Tooltip("high:Q", title="Highest round", format=",.0f"), + alt.Tooltip("concurrency:Q", title="Calls in flight"), alt.Tooltip("cpu:Q", title="CPU of the side measured (µs / call)", format=".1f"), + alt.Tooltip("cores:Q", title="Server cores used", format=".2f"), alt.Tooltip("p99:Q", title="P99 (ms)", format=".2f"), + alt.Tooltip("errors:Q", title="Errors"), alt.Tooltip("load:N", title="Load"), + ] # fmt: skip + return bars( + data, sizes(points), names, colors, "rps", "Throughput (calls / s)", title, tooltip, low="low", high="high", + ) # fmt: skip + + +def latency_chart(points, protocol: str, concurrency: int) -> alt.LayerChart: + measured = sorted({p["concurrency"] for p in points}) + concurrency = min(measured, key=lambda each: abs(each - concurrency)) + chosen = [p for p in points if p["concurrency"] == concurrency and p["p99_ms"] is not None] + data = [ + { + "implementation": label(p), "payload": size(p), "p99": p["p99_ms"], "p50": p["p50_ms"], + "text": f"{p['p99_ms']:.3g}", "rps": p["rps"], "errors": p["errors"], "load": p["load"], + } + for p in chosen + ] # fmt: skip + names, colors = implementations(chosen) + tooltip = [ + alt.Tooltip("implementation:N", title="Implementation"), alt.Tooltip("payload:N", title="Payload (bytes)"), + alt.Tooltip("p99:Q", title="P99 (ms)", format=".3f"), alt.Tooltip("p50:Q", title="P50 (ms)", format=".3f"), + alt.Tooltip("rps:Q", title="Calls / s", format=",.0f"), alt.Tooltip("load:N", title="Load"), + ] # fmt: skip + return bars( + data, sizes(chosen), names, colors, "p99", "P99 latency (ms)", + f"P99 latency, one core, {concurrency} in flight · {protocol}", tooltip, + ) # fmt: skip + + +def table(points, runs: list[str]) -> str: + columns = ["Run"] if len(runs) > 1 else [] + columns += ["Scenario", "Side", "Protocol", "Implementation", "Payload (bytes)", "In flight", "Calls/s (median)"] + columns += [ + "Lowest", + "Highest", + "CPU µs/call", + "Server cores", + "Server RSS MiB", + "P50 ms", + "P99 ms", + "Errors", + "Load or peer", + ] + lines = ["| " + " | ".join(columns) + " |", "|" + "---|" * len(columns)] + order = list(IMPLEMENTATIONS) + + def key(p): + return ( + runs.index(p["run"]), + p["scenario"], + p["side"], + p["protocol"], + p["size"], + p["concurrency"], + order.index(p["implementation"]), + p["loop"] or "", + ) + + for p in sorted(points, key=key): + name = label(p) + (f" ({p['loop']})" if p["loop"] else "") + cells = [p["run"]] if len(runs) > 1 else [] + cells += [p["scenario"], p["side"], PROTOCOLS[p["protocol"]][0], name, size(p), p["concurrency"]] + cells += [f"{p['rps']:,.0f}", f"{p['rps_min']:,.0f}", f"{p['rps_max']:,.0f}", p["cpu_us"], p["server_cores"]] + cells += [ + p["rss_mib"], + p["p50_ms"], + p["p99_ms"], + p["errors"], + (p["load"] or "") + (" †" if p["load_limited"] else ""), + ] + lines.append("| " + " | ".join("" if cell is None else str(cell) for cell in cells) + " |") + return "\n".join(lines) + "\n" + + +def report(charts, environment: dict[str, Any], points, runs: list[str]) -> str: + """Return a page holding every chart, with the values of each mark on hover, the environment and the table.""" + specs = {f"chart-{index}": chart.to_dict() for index, (_, chart) in enumerate(charts)} + sections = "\n".join(f'
' for index in range(len(charts))) + rows = "\n".join( + f"{html.escape(str(key))}{html.escape(json.dumps(value) if isinstance(value, dict) else str(value))}" + for key, value in environment.items() + ) + summary = table(points, runs).splitlines() + head = "".join(f"{html.escape(cell.strip())}" for cell in summary[0].strip("|").split("|")) + body = "\n".join( + "" + "".join(f"{html.escape(cell.strip())}" for cell in line.strip("|").split("|")) + "" + for line in summary[2:] + ) + pinning = " by taskset" if environment.get("taskset") else ", by GOMAXPROCS and ActiveProcessorCount alone" + script = vl_convert.javascript_bundle() + embed = f"const specs = {json.dumps(specs)};\nfor (const [id, spec] of Object.entries(specs)) vegaEmbed('#' + id, spec, {{actions: false}});" + return f""" + +Dubbo Python benchmarks + +

Dubbo Python benchmarks

+
    +
  • A unary echo of bytes. Each bar is the median of the rounds; the thin line on it spans them.
  • +
  • One core: every server held to one core{pinning}; the Python ones run one event loop. +Multi-core: each Dubbo server held to several cores in the same way; a Python process serves on one.
  • +
  • Throughput is the best over the numbers of calls in flight; † marks a load that used most of its cores.
  • +
  • Hover a bar for all its numbers.
  • +
+{sections} +

Environment

{rows}
+

Every point

{head}{body}
+ + + +""" + + +if __name__ == "__main__": + main() diff --git a/benchmark/proto/bench.proto b/benchmark/proto/bench.proto new file mode 100644 index 00000000..af865485 --- /dev/null +++ b/benchmark/proto/bench.proto @@ -0,0 +1,33 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// The service that Triple carries in the benchmarks, for Python, Java, Go and ghz. +syntax = "proto3"; + +package org.apache.dubbo.benchmark; + +option go_package = "bench/benchpb;benchpb"; +option java_multiple_files = true; + +// The bytes of a request, which the response echoes. +message Payload { + bytes data = 1; +} + +service Bench { + rpc Echo(Payload) returns (Payload); +} diff --git a/benchmark/python/bench_pb2.py b/benchmark/python/bench_pb2.py new file mode 100644 index 00000000..6c164b19 --- /dev/null +++ b/benchmark/python/bench_pb2.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: bench.proto +# Protobuf Python Version: 7.35.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 7, + 35, + 1, + '', + 'bench.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0b\x62\x65nch.proto\x12\x1aorg.apache.dubbo.benchmark\"\x17\n\x07Payload\x12\x0c\n\x04\x64\x61ta\x18\x01 \x01(\x0c\x32Y\n\x05\x42\x65nch\x12P\n\x04\x45\x63ho\x12#.org.apache.dubbo.benchmark.Payload\x1a#.org.apache.dubbo.benchmark.PayloadB\x19P\x01Z\x15\x62\x65nch/benchpb;benchpbb\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'bench_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + _globals['DESCRIPTOR']._loaded_options = None + _globals['DESCRIPTOR']._serialized_options = b'P\001Z\025bench/benchpb;benchpb' + _globals['_PAYLOAD']._serialized_start=43 + _globals['_PAYLOAD']._serialized_end=66 + _globals['_BENCH']._serialized_start=68 + _globals['_BENCH']._serialized_end=157 +# @@protoc_insertion_point(module_scope) diff --git a/benchmark/python/bench_pb2.pyi b/benchmark/python/bench_pb2.pyi new file mode 100644 index 00000000..bf3bfb17 --- /dev/null +++ b/benchmark/python/bench_pb2.pyi @@ -0,0 +1,11 @@ +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from typing import ClassVar as _ClassVar, Optional as _Optional + +DESCRIPTOR: _descriptor.FileDescriptor + +class Payload(_message.Message): + __slots__ = ("data",) + DATA_FIELD_NUMBER: _ClassVar[int] + data: bytes + def __init__(self, data: _Optional[bytes] = ...) -> None: ... diff --git a/benchmark/python/client.py b/benchmark/python/client.py new file mode 100644 index 00000000..02182f2d --- /dev/null +++ b/benchmark/python/client.py @@ -0,0 +1,178 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""A closed-loop load of Python consumers: each of ``--concurrency`` tasks calls again as soon as its call returns. + +The tasks are spread over ``--processes`` processes, each with one event +loop, which start together once all have connected; it prints ``started`` +then. Calls during ``--warmup`` are not counted. It prints the result as +JSON: the calls and errors counted, the calls per second, the CPU seconds +the consumers spent meanwhile, and the latency percentiles in microseconds +with the histogram they come from. +""" + +import argparse +import asyncio +import collections +import json +import math +import os +import time +from multiprocessing import get_context +from multiprocessing.synchronize import Barrier +from queue import Queue + +from dubbo import Dubbo, RpcError +from dubbo.config import ApplicationConfig + +from bench_pb2 import Payload +from contract import Bench, BenchService, run + +# Latencies are counted in buckets about 1% wide: bucket b holds those of e ** (b / 100) to e ** ((b + 1) / 100) ns. +_BUCKETS_PER_E = 100 +PERCENTILES = (50, 90, 99, 99.9) + + +def bucket(nanoseconds: int) -> int: + return int(math.log(max(nanoseconds, 1)) * _BUCKETS_PER_E) + + +def percentiles(histogram: dict[int, int]) -> dict[str, float]: + """Return the latency percentiles, and the largest, in microseconds, each the middle of its bucket.""" + total = sum(histogram.values()) + result, seen = {}, 0 + wanted = list(PERCENTILES) + for each in sorted(histogram): + seen += histogram[each] + while wanted and seen >= total * wanted[0] / 100: + result[f"p{wanted.pop(0):g}"] = _microseconds(each) + if histogram: + result["max"] = _microseconds(max(histogram)) + return result + + +def _microseconds(bucket: int) -> float: + return round(math.exp((bucket + 0.5) / _BUCKETS_PER_E) / 1000, 1) + + +async def load( + args: argparse.Namespace, concurrency: int, start: Barrier +) -> tuple[dict[int, int], dict[str, int], float]: + app = Dubbo(application=ApplicationConfig(name="bench-client"), env_prefix=None) + payload = os.urandom(args.size) + if args.protocol == "tri": + bench = app.refer(Bench, url=args.url) + request = Payload(data=payload) + + def call(): + return bench.echo(request) + else: + service = app.refer(BenchService, url=args.url) + + def call(): + return service.echo(payload) + + histogram: collections.Counter[int] = collections.Counter() + errors: collections.Counter[str] = collections.Counter() + async with app: + await call() # Connects before the start. + await asyncio.to_thread(start.wait) + began = time.perf_counter() + counted, end = began + args.warmup, began + args.warmup + args.duration + + async def worker() -> None: + while (now := time.perf_counter()) < end: + sent = time.perf_counter_ns() + try: + await call() + except RpcError as error: + if now >= counted: + errors[error.status.name] += 1 + continue + if now >= counted: + histogram[bucket(time.perf_counter_ns() - sent)] += 1 + + async def measure_cpu() -> float: + await asyncio.sleep(counted - time.perf_counter()) + cpu = time.process_time() + await asyncio.sleep(end - time.perf_counter()) + return time.process_time() - cpu + + async with asyncio.TaskGroup() as tasks: + for _ in range(concurrency): + tasks.create_task(worker()) + cpu = tasks.create_task(measure_cpu()) + + return dict(histogram), dict(errors), cpu.result() + + +def run_process(args: argparse.Namespace, concurrency: int, start: Barrier, results: Queue) -> None: + results.put(run(load(args, concurrency, start), args.loop)) + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("--protocol", choices=["tri", "dubbo"], default="tri") + parser.add_argument("--url", help="the provider to call; 127.0.0.1:50051 over the protocol by default") + parser.add_argument("--size", type=int, default=128, help="bytes of each request and response") + parser.add_argument("--concurrency", type=int, default=16, help="calls in flight, over all processes") + parser.add_argument("--processes", type=int, default=1) + parser.add_argument("--duration", type=float, default=10.0, help="seconds counted") + parser.add_argument("--warmup", type=float, default=3.0, help="seconds before counting") + parser.add_argument("--loop", choices=["asyncio", "uvloop"], default="asyncio") + args = parser.parse_args() + args.url = args.url or f"{args.protocol}://127.0.0.1:50051" + + count = min(args.processes, args.concurrency) + shares = [args.concurrency // count + (i < args.concurrency % count) for i in range(count)] + context = get_context("spawn") + start, results = context.Barrier(count + 1), context.Queue() + processes = [context.Process(target=run_process, args=(args, share, start, results)) for share in shares] + for process in processes: + process.start() + # A process that fails to connect never reaches the start, which then breaks. + start.wait(timeout=60) + print("started", flush=True) + + histogram: collections.Counter[int] = collections.Counter() + errors: collections.Counter[str] = collections.Counter() + cpu = 0.0 + for _ in processes: + each_histogram, each_errors, each_cpu = results.get() + histogram.update(each_histogram) + errors.update(each_errors) + cpu += each_cpu + for process in processes: + process.join() + + calls = sum(histogram.values()) + print( + json.dumps( + { + "calls": calls, + "errors": dict(errors), + "rps": round(calls / args.duration, 1), + "client_cpu_us": round(cpu / calls * 1e6, 2) if calls else None, + "latency_us": percentiles(histogram), + "histogram": {str(each): count for each, count in sorted(histogram.items())}, + } + ) + ) + + +if __name__ == "__main__": + main() diff --git a/benchmark/python/contract.py b/benchmark/python/contract.py new file mode 100644 index 00000000..da95153e --- /dev/null +++ b/benchmark/python/contract.py @@ -0,0 +1,64 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The services the benchmarks call, the same in every language: an echo of bytes over each protocol. + +Also how the Python programs run on the event loop they are asked for. +""" + +import asyncio +import typing +from collections.abc import Coroutine +from typing import Any + +import dubbo + +from bench_pb2 import Payload + + +# Triple carries the protobuf messages of bench.proto, which ghz and the Go server read too. +@dubbo.service("org.apache.dubbo.benchmark.Bench") +class Bench(typing.Protocol): + @dubbo.method("Echo") + async def echo(self, request: Payload) -> Payload: ... + + +# The Dubbo protocol carries Java types in Hessian 2, as the Java interface BenchService declares them. +@dubbo.service("org.apache.dubbo.benchmark.BenchService") +class BenchService(typing.Protocol): + async def echo(self, data: bytes) -> bytes: ... + + +class BenchImpl(Bench): + async def echo(self, request: Payload) -> Payload: + return request + + +class BenchServiceImpl(BenchService): + async def echo(self, data: bytes) -> bytes: + return data + + +def run(main: Coroutine[Any, Any, Any], loop: str) -> Any: + """Run ``main`` on the event loop named ``loop``: ``asyncio`` or ``uvloop``.""" + loop_factory = None + if loop == "uvloop": + import uvloop + + loop_factory = uvloop.new_event_loop + with asyncio.Runner(loop_factory=loop_factory) as runner: + return runner.run(main) diff --git a/benchmark/python/dubbo_server.py b/benchmark/python/dubbo_server.py new file mode 100644 index 00000000..a9c8a2e3 --- /dev/null +++ b/benchmark/python/dubbo_server.py @@ -0,0 +1,49 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Dubbo Python serving the benchmark service over one protocol, on one event loop in one process.""" + +import argparse + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig + +from contract import BenchImpl, BenchServiceImpl, run + + +async def serve(protocol: str, port: int) -> None: + app = Dubbo( + application=ApplicationConfig(name="bench-server"), + protocols={protocol: ProtocolConfig(name=protocol, host="127.0.0.1", port=port)}, + env_prefix=None, + ) + app.export(BenchImpl() if protocol == "tri" else BenchServiceImpl()) + async with app: + await app.serve_forever() + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--protocol", choices=["tri", "dubbo"], default="tri") + parser.add_argument("--port", type=int, default=50051) + parser.add_argument("--loop", choices=["asyncio", "uvloop"], default="asyncio") + args = parser.parse_args() + run(serve(args.protocol, args.port), args.loop) + + +if __name__ == "__main__": + main() diff --git a/benchmark/python/grpcio_server.py b/benchmark/python/grpcio_server.py new file mode 100644 index 00000000..0b69d9b8 --- /dev/null +++ b/benchmark/python/grpcio_server.py @@ -0,0 +1,54 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""grpcio, the gRPC library of Google, serving the Bench service of bench.proto with grpc.aio, for comparison.""" + +import argparse + +import grpc + +from bench_pb2 import Payload +from contract import run + + +async def echo(request: Payload, context: grpc.aio.ServicerContext) -> Payload: + return request + + +async def serve(port: int) -> None: + server = grpc.aio.server() + method = grpc.unary_unary_rpc_method_handler( + echo, request_deserializer=Payload.FromString, response_serializer=Payload.SerializeToString + ) + server.add_generic_rpc_handlers( + (grpc.method_handlers_generic_handler("org.apache.dubbo.benchmark.Bench", {"Echo": method}),) + ) + server.add_insecure_port(f"127.0.0.1:{port}") + await server.start() + await server.wait_for_termination() + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--port", type=int, default=50051) + parser.add_argument("--loop", choices=["asyncio", "uvloop"], default="asyncio") + args = parser.parse_args() + run(serve(args.port), args.loop) + + +if __name__ == "__main__": + main() diff --git a/benchmark/python/grpclib_server.py b/benchmark/python/grpclib_server.py new file mode 100644 index 00000000..a3be290f --- /dev/null +++ b/benchmark/python/grpclib_server.py @@ -0,0 +1,53 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""grpclib, the gRPC library in pure Python, serving the Bench service of bench.proto, for comparison.""" + +import argparse + +from grpclib.const import Cardinality, Handler +from grpclib.server import Server, Stream + +from bench_pb2 import Payload +from contract import run + + +class Bench: + async def echo(self, stream: Stream[Payload, Payload]) -> None: + request = await stream.recv_message() + await stream.send_message(request) + + def __mapping__(self) -> dict[str, Handler]: + return {"/org.apache.dubbo.benchmark.Bench/Echo": Handler(self.echo, Cardinality.UNARY_UNARY, Payload, Payload)} + + +async def serve(port: int) -> None: + server = Server([Bench()]) + await server.start("127.0.0.1", port) + await server.wait_closed() + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--port", type=int, default=50051) + parser.add_argument("--loop", choices=["asyncio", "uvloop"], default="asyncio") + args = parser.parse_args() + run(serve(args.port), args.loop) + + +if __name__ == "__main__": + main() diff --git a/benchmark/ruff.toml b/benchmark/ruff.toml new file mode 100644 index 00000000..7f9024bb --- /dev/null +++ b/benchmark/ruff.toml @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The benchmarks import dubbo as an installed package, and the modules beside +# them as their own. +extend = "../pyproject.toml" + +[lint.isort] +default-section = "first-party" +known-third-party = ["dubbo", "grpc", "grpclib", "matplotlib", "uvloop"] diff --git a/benchmark/run.py b/benchmark/run.py new file mode 100644 index 00000000..062086f7 --- /dev/null +++ b/benchmark/run.py @@ -0,0 +1,468 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Measure the scenarios of scenarios.toml, writing each result as a line of results.jsonl beside env.json. + +Each point starts a server, loads it, and reads the CPU time and memory of +the server process at the start and at the end of the counted calls. A +point whose tools are missing is skipped, and env.json lists why. +""" + +import argparse +import base64 +import datetime +import importlib.metadata +import importlib.util +import itertools +import json +import os +import platform +import re +import shutil +import socket +import subprocess +import sys +import time +import tomllib +from pathlib import Path +from typing import Any + +import hessian2 + +HERE = Path(__file__).resolve().parent +PYTHON = HERE / "python" +# The protocols each implementation serves. +SERVES = { + "python": {"tri", "dubbo"}, + "java": {"tri", "dubbo"}, + "go": {"tri", "dubbo"}, + "grpcio": {"tri"}, + "grpclib": {"tri"}, +} +# ghz names the method by its full name, with a dot before it. +GHZ_CALL = "org.apache.dubbo.benchmark.Bench.Echo" +BENCH_SERVICE = "org.apache.dubbo.benchmark.BenchService" +# The event loop of the Python programs. +LOOP = "uvloop" if importlib.util.find_spec("uvloop") else "asyncio" + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("--scenarios", type=Path, default=HERE / "scenarios.toml") + parser.add_argument("--scenario", action="append", help="the name of a scenario to run; all by default") + parser.add_argument("--warmup", type=float, help="seconds before counting, over that of scenarios.toml") + parser.add_argument("--duration", type=float, help="seconds counted, over that of scenarios.toml") + parser.add_argument("--rounds", type=int, help="rounds of every point, over those of scenarios.toml") + parser.add_argument("--out", type=Path, help="the directory of the results; a new one in results/ by default") + args = parser.parse_args() + + settings = tomllib.loads(args.scenarios.read_text()) + warmup = args.warmup if args.warmup is not None else settings["warmup"] + duration = args.duration if args.duration is not None else settings["duration"] + rounds = args.rounds if args.rounds is not None else settings.get("rounds", 1) + scenarios = [each for each in settings["scenario"] if not args.scenario or each["name"] in args.scenario] + out = args.out or HERE / "results" / datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + (out / "logs").mkdir(parents=True, exist_ok=True) + + servers = {each for scenario in scenarios if scenario["side"] == "server" for each in scenario["implementations"]} + # Go builds the load of Dubbo servers; Go and Java are the servers the Python consumer calls. + peers = {"go", "java"} if any(scenario["side"] == "client" for scenario in scenarios) else set() + tools = Tools(out, servers | {"go"} | peers) + (out / "env.json").write_text(json.dumps(environment(tools, warmup, duration, rounds), indent=2) + "\n") + + points = [point for scenario in scenarios for point in scenario_points(scenario)] + with (out / "results.jsonl").open("a") as results: + # Each round measures every point, so that a drift of the machine spreads over all of them. + for round_, point in itertools.product(range(1, rounds + 1), points): + missing = tools.missing(point["implementation"]) + if missing: + if round_ == 1: + print(f"Skipping {point['implementation']} {point['protocol']}: {missing}", file=sys.stderr) + continue + result = measure(point, tools, settings, warmup, duration, out, round_) + results.write(json.dumps({**point, "round": round_, **result}) + "\n") + results.flush() + print(summary(point, round_, result), file=sys.stderr) + + print(f"Wrote {out}", file=sys.stderr) + + +def scenario_points(scenario: dict[str, Any]) -> list[dict[str, Any]]: + """Return the points of ``scenario``: each implementation, protocol it serves, size and calls in flight.""" + points = [] + for implementation, protocol, size, concurrency in itertools.product( + scenario["implementations"], scenario["protocols"], scenario["sizes"], scenario["concurrency"] + ): + if protocol not in SERVES[implementation]: + continue + points.append( + { + "scenario": scenario["name"], + "side": scenario["side"], + "implementation": implementation, + "protocol": protocol, + "loop": LOOP if python(implementation) else None, + "size": size, + "concurrency": concurrency, + "cores": scenario.get("cores"), + } + ) + return points + + +def python(implementation: str) -> bool: + return implementation in ("python", "grpcio", "grpclib") + + +class Tools: + """The programs the points need, found once: ghz, taskset, and the builds of Go and Java.""" + + def __init__(self, out: Path, implementations: set[str]) -> None: + self.out = out + self.ghz = shutil.which("ghz") + self.taskset = shutil.which("taskset") if sys.platform == "linux" else None + self.reasons: dict[str, str] = {} + self.go_server = self.go_load = self.java = self.java_classpath = None + if "go" in implementations: + if shutil.which("go"): + self.go_server, self.go_load = out / "go-server", out / "go-load" + for program, binary in (("./server", self.go_server), ("./load", self.go_load)): + subprocess.run(["go", "build", "-o", str(binary), program], cwd=HERE / "go", check=True) + else: + self.reasons["go"] = "go is not installed" + if "java" in implementations: + if shutil.which("mvn"): + classpath = out / "java-classpath.txt" + subprocess.run( + ["mvn", "-q", "compile", "dependency:build-classpath", f"-Dmdep.outputFile={classpath}"], + cwd=HERE / "java", + check=True, + ) + self.java_classpath = f"{HERE / 'java' / 'target' / 'classes'}{os.pathsep}{classpath.read_text()}" + self.java = find_java() + if self.java is None: + self.reasons["java"] = "Maven or a Java runtime is not installed" + for library in ("grpcio", "grpclib"): + if importlib.util.find_spec("grpc" if library == "grpcio" else library) is None: + self.reasons[library] = f"{library} is not installed; uv sync --inexact --group benchmark installs it" + + def missing(self, implementation: str) -> str | None: + return self.reasons.get(implementation) + + def cpu_sets(self, cores: int | None) -> tuple[str | None, str | None, int]: + """Return the CPUs of the side measured and of the other side for taskset, or none unpinned, and the count of the other's.""" + count = os.cpu_count() or 1 + if cores is None or self.taskset is None or cores >= count: + return None, None, count + return f"0-{cores - 1}", f"{cores}-{count - 1}", count - cores + + def request_body(self, size: int) -> Path: + """Return the file of the body of a request of the Dubbo echo, as Dubbo Python sends it, of ``size`` bytes.""" + path = self.out / f"request-{size}.bin" + if not path.exists(): + attachments = {"path": BENCH_SERVICE, "interface": BENCH_SERVICE, "version": "0.0.0", "timeout": "30000"} + values = ("2.0.2", BENCH_SERVICE, "0.0.0", "echo", "[B", os.urandom(size), attachments) + path.write_bytes(hessian2.dumps_many(values)) + return path + + +def find_java() -> str | None: + """Return the java of JAVA_HOME, else of PATH, else the one Maven runs on.""" + home = os.environ.get("JAVA_HOME") + candidates = [str(Path(home) / "bin" / "java")] if home else [] + candidates.append("java") + for candidate in candidates: + if subprocess.run([candidate, "-version"], capture_output=True).returncode == 0: + return candidate + version = subprocess.run(["mvn", "-v"], capture_output=True, text=True).stdout + found = re.search(r"runtime: (.+)", version) + return str(Path(found.group(1).strip()) / "bin" / "java") if found else None + + +def measure( + point: dict[str, Any], + tools: Tools, + settings: dict[str, Any], + warmup: float, + duration: float, + out: Path, + round_: int, +): + """Load the server of the point, or the server Python calls, and return what the counted calls cost.""" + port = free_port() + protocol, size, concurrency = point["protocol"], point["size"], point["concurrency"] + connections = min(settings.get("connections", 8), concurrency) + measured, others, other_cores = tools.cpu_sets(point["cores"]) + if point["side"] == "server": + command, env = server_command(point["implementation"], protocol, port, point["loop"], tools, point["cores"]) + command = pin(command, measured) + else: + peer = client_peer(protocol, tools) + command, env = server_command(peer, protocol, port, "asyncio", tools, None) + command = pin(command, others) + name = "-".join(str(value) for value in (*point.values(), round_) if value is not None) + + with serving(command, env, port, out / "logs" / f"{name}.log") as server: + if point["side"] == "client": + client = python_load(protocol, port, size, concurrency, 1, point["loop"], warmup, duration, measured) + result, before, after = run_load(client, PYTHON, server, warmup, duration) + result["peer"] = f"Dubbo {peer.capitalize()}" + elif protocol == "tri" and tools.ghz is not None: + run_ghz(tools.ghz, port, size, concurrency, connections, warmup, others) + before = process_stats(server.pid) + result = run_ghz(tools.ghz, port, size, concurrency, connections, duration, others) + after = process_stats(server.pid) + result["load"] = "ghz" + elif protocol != "tri" and tools.go_load is not None: + load = [ + *(str(tools.go_load), "--address", f"127.0.0.1:{port}", "--body", str(tools.request_body(size))), + *("--concurrency", str(concurrency), "--connections", str(connections)), + *("--warmup", str(warmup), "--duration", str(duration)), + ] + result, before, after = run_load(pin(load, others), HERE, server, warmup, duration) + result["load"] = "Go" + else: + processes = min(settings.get("load_processes", 4), concurrency) + client = python_load(protocol, port, size, concurrency, processes, LOOP, warmup, duration, others) + result, before, after = run_load(client, PYTHON, server, warmup, duration) + result["load"] = f"Dubbo Python x{processes}" + other_cores = min(other_cores, processes) + if point["side"] == "server": + if result.get("load_cores") is None and result["client_cpu_us"] is not None: + result["load_cores"] = round(result["client_cpu_us"] * result["calls"] / 1e6 / duration, 2) + # The cores the load may use: a load near them may be what limits the throughput. + result["load_cores_available"] = other_cores + + calls = result["calls"] + result["pinned"] = measured is not None + result["server_cpu_us"] = round((after["cpu"] - before["cpu"]) / calls * 1e6, 2) if calls else None + result["server_cores"] = round((after["cpu"] - before["cpu"]) / duration, 2) + result["server_rss_mib"] = round(after["rss"] / 2**20, 1) + return result + + +def pin(command: list[str], cpus: str | None) -> list[str]: + """Return ``command`` run on the CPUs ``cpus`` by taskset, or as it is for none.""" + return command if cpus is None else ["taskset", "-c", cpus, *command] + + +def client_peer(protocol: str, tools: Tools) -> str: + """Return the server the Python consumer calls: one that answers uncompressed unless configured otherwise. + + Dubbo Go compresses each Triple response its caller accepts compressed, and the consumer accepts gzip, so over + Triple the consumer calls Dubbo Java. + """ + if protocol == "tri" and tools.java is not None: + return "java" + return "go" if tools.go_server is not None else "python" + + +def server_command( + implementation: str, protocol: str, port: int, loop: str | None, tools: Tools, cores: int | None +) -> tuple[list[str], dict[str, str]]: + """Return the command of a server, and its environment, holding Go and Java to ``cores`` when given.""" + env = dict(os.environ) + if implementation == "go": + assert tools.go_server is not None + if cores is not None: + env["GOMAXPROCS"] = str(cores) + return [str(tools.go_server), "--protocol", protocol, "--port", str(port)], env + if implementation == "java": + assert tools.java is not None + assert tools.java_classpath is not None + processors = [f"-XX:ActiveProcessorCount={cores}"] if cores is not None else [] + command = [ + *(tools.java, *processors, "-Dorg.slf4j.simpleLogger.defaultLogLevel=warn", "-cp", tools.java_classpath), + *("org.apache.dubbo.benchmark.JavaServer", protocol, str(port)), + ] + return command, env + script = {"python": "dubbo_server.py", "grpcio": "grpcio_server.py", "grpclib": "grpclib_server.py"}[implementation] + options = ["--protocol", protocol] if implementation == "python" else [] + return [sys.executable, script, *options, "--port", str(port), "--loop", loop or "asyncio"], env + + +def python_load(protocol, port, size, concurrency, processes, loop, warmup, duration, cpus) -> list[str]: + command = [ + *(sys.executable, "client.py", "--protocol", protocol, "--url", f"{protocol}://127.0.0.1:{port}"), + *("--size", str(size), "--concurrency", str(concurrency), "--processes", str(processes), "--loop", loop), + *("--warmup", str(warmup), "--duration", str(duration)), + ] + return pin(command, cpus) + + +def run_load(command: list[str], cwd: Path, server, warmup: float, duration: float): + """Run a load that prints started, then its result, reading the stats of the server when it starts counting and when it stops.""" + with subprocess.Popen(command, cwd=cwd, stdout=subprocess.PIPE, text=True) as load: + assert load.stdout is not None + if load.stdout.readline().strip() != "started": + raise RuntimeError(f"{command[0]} did not start") + time.sleep(warmup) + before = process_stats(server.pid) + time.sleep(duration) + after = process_stats(server.pid) + result = json.loads(load.stdout.readline()) + if load.returncode: + raise RuntimeError(f"{command[0]} exited with {load.returncode}") + return result, before, after + + +def run_ghz(ghz, port, size, concurrency, connections, seconds, cpus) -> dict[str, Any]: + data = json.dumps({"data": base64.b64encode(os.urandom(size)).decode()}) + command = [ + *(ghz, "--insecure", "--proto", "bench.proto", "--call", GHZ_CALL, "--data", data), + *("--concurrency", str(concurrency), "--connections", str(connections)), + # Waiting for the calls in flight at the end, so that none fails as the connections close. + *("--duration", f"{seconds}s", "--duration-stop", "wait", "--format", "json"), + f"127.0.0.1:{port}", + ] + used = os.times() + output = subprocess.run(pin(command, cpus), cwd=HERE / "proto", capture_output=True, text=True, check=True).stdout + now = os.times() + report = json.loads(output) + codes = dict(report.get("statusCodeDistribution") or {}) + latencies = {f"p{each['percentage']:g}": round(each["latency"] / 1000, 1) for each in report["latencyDistribution"]} + cpu = now.children_user + now.children_system - used.children_user - used.children_system + return { + "calls": codes.get("OK", 0), + "errors": {code: count for code, count in codes.items() if code != "OK"}, + "rps": round(codes.get("OK", 0) / seconds, 1), + "client_cpu_us": None, + # Windows counts no CPU time of children. + "load_cores": None if sys.platform == "win32" else round(cpu / seconds, 2), + "latency_us": { + **{name: latencies[name] for name in ("p50", "p90", "p99") if name in latencies}, + "max": round(report["slowest"] / 1000, 1), + }, + } + + +class serving: + """Run a server until leaving, once its port accepts, logging its output.""" + + def __init__(self, command: list[str], env: dict[str, str], port: int, log: Path) -> None: + self.command, self.env, self.port, self.log = command, env, port, log + + def __enter__(self) -> subprocess.Popen[bytes]: + with self.log.open("wb") as log: + cwd = PYTHON if sys.executable in self.command else HERE + self.process = subprocess.Popen(self.command, cwd=cwd, env=self.env, stdout=log, stderr=subprocess.STDOUT) + deadline = time.monotonic() + 60 + while True: + if self.process.poll() is not None: + raise RuntimeError(f"the server exited with {self.process.returncode}; see {self.log}") + try: + socket.create_connection(("127.0.0.1", self.port), timeout=1).close() + return self.process + except OSError: + if time.monotonic() > deadline: + self.__exit__() + raise + time.sleep(0.1) + + def __exit__(self, *exc_info: object) -> None: + self.process.terminate() + try: + self.process.wait(timeout=30) + except subprocess.TimeoutExpired: + self.process.kill() + self.process.wait() + + +def process_stats(pid: int) -> dict[str, float]: + """Return the CPU seconds of a process, and its peak RSS on Linux or its RSS elsewhere in bytes.""" + if sys.platform == "linux": + # The fields after the name, which may hold spaces; utime and stime are the 14th and 15th of the line. + fields = Path(f"/proc/{pid}/stat").read_text().rpartition(")")[2].split() + cpu = (int(fields[11]) + int(fields[12])) / os.sysconf("SC_CLK_TCK") + status = Path(f"/proc/{pid}/status").read_text() + peak = re.search(r"^VmHWM:\s+(\d+) kB", status, re.MULTILINE) + return {"cpu": cpu, "rss": int(peak.group(1)) * 1024 if peak else 0} + output = subprocess.run(["ps", "-o", "time=,rss=", "-p", str(pid)], capture_output=True, text=True, check=True) + elapsed, rss = output.stdout.split() + seconds = 0.0 + for part in elapsed.split(":"): + seconds = seconds * 60 + float(part) + return {"cpu": seconds, "rss": int(rss) * 1024} + + +def free_port() -> int: + with socket.socket() as probe: + probe.bind(("127.0.0.1", 0)) + return probe.getsockname()[1] + + +def summary(point: dict[str, Any], round_: int, result: dict[str, Any]) -> str: + loop = f" ({point['loop']})" if point["loop"] else "" + return ( + f"{point['scenario']} round {round_}: {point['side']} {point['implementation']}{loop} {point['protocol']} " + f"{point['size']} B x{point['concurrency']}: {result['rps']:,.0f} calls/s, " + f"server {result['server_cpu_us']} us/call on {result['server_cores']} cores, " + f"p99 {result['latency_us'].get('p99')} us, errors {sum(result['errors'].values())}" + ) + + +def environment(tools: Tools, warmup: float, duration: float, rounds: int) -> dict[str, Any]: + def output(*command: str) -> str | None: + try: + done = subprocess.run(command, cwd=HERE, capture_output=True, text=True, check=True) + except (OSError, subprocess.CalledProcessError): + return None + lines = (done.stdout or done.stderr).strip().splitlines() + return lines[0] if lines else "" + + def version(package: str) -> str | None: + try: + return importlib.metadata.version(package) + except importlib.metadata.PackageNotFoundError: + return None + + if sys.platform == "linux": + names = re.findall(r"^model name\s*:\s*(.+)$", Path("/proc/cpuinfo").read_text(), re.MULTILINE) + cpu = names[0] if names else None + else: + cpu = output("sysctl", "-n", "machdep.cpu.brand_string") + go_module = (HERE / "go" / "go.mod").read_text() + pom = (HERE / "java" / "pom.xml").read_text() + return { + "time": datetime.datetime.now(datetime.UTC).isoformat(timespec="seconds"), + "commit": output("git", "rev-parse", "HEAD"), + "changed": bool(output("git", "status", "--porcelain", "--untracked-files=no")), + "platform": platform.platform(), + "cpu": cpu, + "cpus": os.cpu_count(), + "python": f"{platform.python_implementation()} {platform.python_version()}", + "versions": { + "apache-dubbo": version("apache-dubbo"), + "uvloop": version("uvloop"), + "grpcio": version("grpcio"), + "grpclib": version("grpclib"), + "dubbo-java": re.search(r"(.+)", pom).group(1), + "dubbo-go": re.search(r"^\s*dubbo\.apache\.org/\S+ (v\S+)", go_module, re.MULTILINE).group(1), + "java": output(tools.java, "-version") if tools.java else None, + "go": output("go", "version") if tools.go_server else None, + }, + "ghz": tools.ghz is not None, + "taskset": tools.taskset is not None, + "skipped": tools.reasons, + "warmup": warmup, + "duration": duration, + "rounds": rounds, + } + + +if __name__ == "__main__": + main() diff --git a/benchmark/scenarios.toml b/benchmark/scenarios.toml new file mode 100644 index 00000000..97a98f2c --- /dev/null +++ b/benchmark/scenarios.toml @@ -0,0 +1,66 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The scenarios run.py measures. Each measures every combination of its +# implementations, protocols, sizes and calls in flight, with a new server +# for each, in each of the rounds. The Python ones run on uvloop when it is +# installed. A scenario with cores holds the side it measures to that many +# cores, and the other side to the rest, on Linux with taskset. Times are in +# seconds. +warmup = 5.0 +duration = 15.0 +# Rounds of every point, run one after another over the whole list, so that a +# drift of the machine spreads over all points; the charts show the median. +rounds = 3 +# The connections each load opens, at most one for each call in flight. +connections = 8 +# The processes of Python consumers that load a Dubbo server where Go is not installed. +load_processes = 4 + +# Each server on one core, as the Python servers run one event loop: the +# headline. Its best throughput, and its P99 latency at 64 calls in flight. +[[scenario]] +name = "one-core" +side = "server" +cores = 1 +implementations = ["python", "java", "go", "grpcio", "grpclib"] +protocols = ["tri", "dubbo"] +sizes = [128, 16384] +concurrency = [64, 128] + +# Each Dubbo server on eight cores, which a Java or Go process uses and a Python one does not: +# its best throughput, with the load on the other cores. +[[scenario]] +name = "multi-core" +side = "server" +cores = 8 +implementations = ["python", "java", "go"] +protocols = ["tri", "dubbo"] +sizes = [128, 16384] +# Below 200, which Dubbo Python and Java serve at once by default and refuse beyond. +concurrency = [128, 192] + +# One Dubbo Python consumer on one core, calling, on the others, Dubbo Java over Triple and +# Dubbo Go over Dubbo. +[[scenario]] +name = "client" +side = "client" +cores = 1 +implementations = ["python"] +protocols = ["tri", "dubbo"] +sizes = [128, 16384] +concurrency = [64, 128] diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md deleted file mode 100755 index e5f24b01..00000000 --- a/docs/CONTRIBUTING.md +++ /dev/null @@ -1,122 +0,0 @@ -# CONTRIBUTING - -## Contributing to Dubbo Python - -Dubbo Python is released under the non-restrictive Apache 2.0 licenses and follows a very standard Github development process, using Github tracker for issues and merging pull requests into main. Contributions of all form to this repository is acceptable, as long as it follows the prescribed community guidelines enumerated below. - -### Sign the Contributor License Agreement - -Before we accept a non-trivial patch or pull request (PRs), we will need you to sign the Contributor License Agreement. Signing the contributors' agreement does not grant anyone commits rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. Active contributors may get invited to join the core team that will grant them privileges to merge existing PRs. - -### Contact - -### Mailing list - -The mailing list is the recommended way of pursuing a discussion on almost anything related to Dubbo. Please refer to this [guide](https://github.com/apache/dubbo/wiki/Mailing-list-subscription-guide) for detailed documentation on how to subscribe. - -- [dev@dubbo.apache.org](mailto:dev-subscribe@dubbo.apache.org): the developer mailing list where you can ask questions about an issue you may have encountered while working with Dubbo. -- [commits@dubbo.apache.org](mailto:commits-subscribe@dubbo.apache.org): the commit updates will get broadcasted on this mailing list. You can subscribe to it, should you be interested in following Dubbo's development. -- [notifications@dubbo.apache.org](mailto:notifications-subscribe@dubbo.apache.org): all the Github [issue](https://github.com/apache/dubbo/issues) updates and [pull request](https://github.com/apache/dubbo/pulls) updates will be sent to this mailing list. - -### Reporting issue - -Please follow the [template](https://github.com/apache/dubbo/issues/new?template=dubbo-issue-report-template.md) for reporting any issues. - -NOTE: Issues related to Dubbo Python should be submitted in the [Dubbo](https://github.com/apache/dubbo/issues) repository, and the **Apache Dubbo Component** option should be set to `Python SDK`. - -### Code Conventions - -Our code style almost fully adheres to the [**PEP 8 style guide**](https://peps.python.org/pep-0008/), with the following adjustments and new constraints: - -1. We have relaxed the **Maximum Line Length** limit from 79 to **120**. -2. For **Documentation Strings**, or **comment style**, we follow the `reStructuredText` format. -3. ... - -### Contribution flow - -A rough outline of an ideal contributors' workflow is as follows: - -- Fork the current repository -- Create a topic branch from where to base the contribution. Mostly, it's the main branch. -- Make commits of logical units. -- Make sure the commit messages are in the proper format (see below). -- Push changes in a topic branch to your forked repository. -- Follow the checklist in the [pull request template](https://github.com/apache/dubbo-python/blob/main/.github/PULL_REQUEST_TEMPLATE.md) -- Before sending out the pull request, please sync your forked repository with the remote repository to ensure that your PR is elegant, concise. Reference the guide below: - -``` -git remote add upstream git@github.com:apache/dubbo-python.git -git fetch upstream -git rebase upstream/master -git checkout -b your_awesome_patch -... add some work -git push origin your_awesome_patch - -``` - -- Submit a pull request to apache/dubbo-python and wait for the reply. - -Thanks for contributing! - - - -### Development & Testing - -Before you start working on development, please install the necessary dependencies for Dubbo-Python using the following command: - -```shell -pip install -r requirements-dev.txt -``` - -Our project uses a `src` layout, and packaging is required before running tests. We strongly recommend using the **editable installation mode** for packaging and testing: - -```shell -pip install -e . -``` - - - -### Code style - -We use **ruff** as the linter and code formatter for Dubbo-Python, and **Mypy** as the static type checker. - -Therefore, when developing, you should install both tools: - -- ruff: [https://github.com/astral-sh/ruff](https://github.com/astral-sh/ruff) -- Mypy: [https://github.com/python/mypy](https://github.com/python/mypy) - -We have already set up the configurations for ruff and Mypy in the `pyproject.toml` file. You only need to specify the configuration path (`pyproject.toml`) when using them. - -1. Code Formatting - - By default, ruff will look for the `pyproject.toml` file in the current directory and its parent directories and load its configuration. - - ```shell - # Default - ruff format - - # Specify configuration file - ruff format --config pyproject.toml - ``` - -2. Code Linting - - ```shell - # Just check - ruff check - - # Check and fix - ruff check --fix - ``` - -3. Static Type Checking - - Mypy will also automatically look for the `pyproject.toml` file and load its configuration. - - ```shell - # Default - mypy - - # Specify configuration file - mypy --config-file pyproject.toml - ``` \ No newline at end of file diff --git a/docs/img/Architecture.svg b/docs/img/Architecture.svg deleted file mode 100644 index dcb710a0..00000000 --- a/docs/img/Architecture.svg +++ /dev/null @@ -1,2 +0,0 @@ -ClientServerunarystreaming......ServiceDiscoveryLoadBalanceLogging......Triple (fully gRPC compatible)......BytesProtobufJsonCustomizableAsynciouvloopTCPHTTP2......Zookeeper......RandomCPU......logging(built-in)RegistryLoadBalanceLoggingAPIServiceGovernanceRPCProtocolSerializationtransport \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 7f9f425b..43aad937 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,173 +1,234 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. [build-system] -requires = ["hatchling", "hatch-fancy-pypi-readme"] +requires = ["hatchling>=1.26"] build-backend = "hatchling.build" [project] -name="apache-dubbo" -requires-python = ">=3.9" -authors = [ - {name = "Apache Dubbo Community", email = "dev@dubbo.apache.org"} -] -maintainers = [ - {name = "Apache Dubbo Community", email = "dev@dubbo.apache.org"} -] -description = "Python Implementation For Apache Dubbo." +name = "apache-dubbo" +version = "3.0.0b2" +description = "Python-native microservice RPC framework for Apache Dubbo" +readme = "README.md" +requires-python = ">=3.11" +authors = [{ name = "Apache Dubbo Community", email = "dev@dubbo.apache.org" }] license = "Apache-2.0" -license-files = ["LICEN[CS]E.*"] -keywords=["dubbo", "rpc","grpc", "dubbo-python", "http2", "network"] -classifiers=[ +license-files = ["LICENSE", "NOTICE"] +keywords = ["dubbo", "microservices", "rpc", "service-discovery"] +classifiers = [ "Development Status :: 4 - Beta", + "Framework :: AsyncIO", "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", - "Framework :: AsyncIO", - "Topic :: Internet", - "Topic :: Internet :: WWW/HTTP", - "Topic :: Internet :: WWW/HTTP :: HTTP Servers", + "Programming Language :: Python :: 3.14", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: System :: Networking", + "Typing :: Typed", ] - +# An upper bound only where the next major or minor release may break what is used. dependencies = [ - "h2>=4.1.0", - "uvloop>=0.19.0; platform_system!='Windows'", - "psutil>=6.0.0", + "anyio>=4.14,<5", + "attrs>=26.1", + "cattrs>=26.1", + "hessian2>=0.2,<0.3", + "multidict>=7.2", + "ngh2>=0.5,<0.6", + "protobuf>=7.36,<8", + "psutil>=7", ] -dynamic = ["version", "readme"] +[project.optional-dependencies] +# The rules that registries and configuration centers deliver are YAML. +zookeeper = ["kazoo>=2.11", "apache-dubbo[yaml]"] +nacos = ["nacos-sdk-python>=3.2,<4", "apache-dubbo[yaml]"] +yaml = ["PyYAML>=6"] +properties = ["dotproperties>=0.2,<0.3"] +uvloop = ["uvloop>=0.22,<1; sys_platform != 'win32'"] +protoc = ["grpcio-tools>=1.85"] [project.urls] -Homepage = "https://cn.dubbo.apache.org" -Documentation = "https://cn.dubbo.apache.org/en/overview/mannual/python-sdk/" +Homepage = "https://dubbo.apache.org/" +Documentation = "https://dubbo.apache.org/en/overview/mannual/python-sdk/" Repository = "https://github.com/apache/dubbo-python" Issues = "https://github.com/apache/dubbo/issues" -[project.optional-dependencies] -zookeeper = [ - "kazoo>=2.10.0", +[project.scripts] +protoc-gen-python-dubbo = "dubbo.protoc.plugin:main" + +[project.entry-points."apache_dubbo.config.parser"] +json = "dubbo.config.parsers.json:JsonParser" +yaml = "dubbo.config.parsers.yaml:YamlParser" +yml = "dubbo.config.parsers.yaml:YamlParser" +properties = "dubbo.config.parsers.properties:PropertiesParser" + +[project.entry-points."apache_dubbo.config_center"] +zookeeper = "dubbo.config_center.zookeeper:ZookeeperConfigCenter" +nacos = "dubbo.config_center.nacos:NacosConfigCenter" + +[project.entry-points."apache_dubbo.interface_registry"] +zookeeper = "dubbo.registry.zookeeper:ZookeeperInterfaceRegistry" +nacos = "dubbo.registry.nacos:NacosInterfaceRegistry" + +[project.entry-points."apache_dubbo.instance_registry"] +zookeeper = "dubbo.registry.zookeeper:ZookeeperInstanceRegistry" +nacos = "dubbo.registry.nacos:NacosInstanceRegistry" + +[project.entry-points."apache_dubbo.metadata_report"] +zookeeper = "dubbo.metadata.report.zookeeper:ZookeeperMetadataReport" +nacos = "dubbo.metadata.report.nacos:NacosMetadataReport" + +[project.entry-points."apache_dubbo.cluster"] +available = "dubbo.cluster.available:AvailableCluster" +broadcast = "dubbo.cluster.broadcast:BroadcastCluster" +failback = "dubbo.cluster.failback:FailbackCluster" +failfast = "dubbo.cluster.failfast:FailfastCluster" +failover = "dubbo.cluster.failover:FailoverCluster" +failsafe = "dubbo.cluster.failsafe:FailsafeCluster" +forking = "dubbo.cluster.forking:ForkingCluster" +zone-aware = "dubbo.cluster.zoneaware:ZoneAwareCluster" + +[project.entry-points."apache_dubbo.loadbalance"] +consistenthash = "dubbo.cluster.loadbalance.consistenthash:ConsistentHashLoadBalance" +leastactive = "dubbo.cluster.loadbalance.leastactive:LeastActiveLoadBalance" +random = "dubbo.cluster.loadbalance.random:RandomLoadBalance" +roundrobin = "dubbo.cluster.loadbalance.roundrobin:RoundRobinLoadBalance" + +[project.entry-points."apache_dubbo.router"] +condition = "dubbo.cluster.router.condition:ConditionRouter" +tag = "dubbo.cluster.router.tag:TagRouter" + +[project.entry-points."apache_dubbo.protocol"] +dubbo = "dubbo.protocol.dubbo:DubboProtocol" +tri = "dubbo.protocol.triple:TripleProtocol" + +[project.entry-points."apache_dubbo.serialization"] +hessian2 = "dubbo.serialization.hessian2:Hessian2Serialization" +protobuf = "dubbo.serialization.protobuf:ProtobufSerialization" + +[project.entry-points."apache_dubbo.compression"] +bzip2 = "dubbo.compression.bzip2:Bzip2Compressor" +deflate = "dubbo.compression.deflate:DeflateCompressor" +gzip = "dubbo.compression.gzip:GzipCompressor" + +[project.entry-points."apache_dubbo.transport.zookeeper"] +kazoo = "dubbo.transport.zookeeper.kazoo:KazooZookeeperClient" + +[project.entry-points."apache_dubbo.transport.nacos.naming"] +sdk = "dubbo.transport.nacos.sdk:SdkNacosNamingClient" + +[project.entry-points."apache_dubbo.transport.nacos.config"] +sdk = "dubbo.transport.nacos.sdk:SdkNacosConfigClient" + +[project.entry-points."apache_dubbo.transport.h2.client"] +aio = "dubbo.transport.h2.aio:AioH2Client" + +[project.entry-points."apache_dubbo.transport.h2.server"] +aio = "dubbo.transport.h2.aio:AioH2Server" + +[dependency-groups] +# The benchmarks of benchmark/: the gRPC libraries they compare with, and what plots the results. +benchmark = [{ include-group = "grpc" }, "altair>=6.3,<7", "grpclib>=0.4,<0.5", "vl-convert-python>=1.9,<2"] +dev = [ + { include-group = "lint" }, + { include-group = "test" }, + { include-group = "type" }, ] - -### Hatch settings ### -[tool.hatch.version] -path = "src/dubbo/__about__.py" +# grpcio, which the tests and the benchmarks call and serve gRPC with. +grpc = ["grpcio>=1.85,<2"] +lint = [ + "pre-commit>=4.6,<5", + "ruff>=0.17,<0.18", +] +# Pinned, so that regenerating the modules of src/dubbo/_proto changes nothing else. +proto = ["grpcio-tools==1.85.0"] +test = [{ include-group = "grpc" }, "pytest>=9.1,<10"] +type = ["ty==0.0.104", "types-protobuf>=7.35,<8"] [tool.hatch.build.targets.sdist] -include = [ - "/src", - "/tests", - "/README.md", -] +only-include = ["src/dubbo"] [tool.hatch.build.targets.wheel] packages = ["src/dubbo"] - -[tool.hatch.metadata.hooks.fancy-pypi-readme] -content-type = "text/markdown" - -[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]] -path = "README.md" - - - -### Ruff settings ### - -# Top-level [tool.ruff] -target-version = "py39" line-length = 120 -extend-exclude = ["samples/proto"] - -# Format -[tool.ruff.format] -docstring-code-format = true +# Modules generated by protoc. +extend-exclude = ["**/*_pb2.py", "**/*_pb2.pyi", "**/*_pb2_grpc.py", "**/*_dubbo.py"] +force-exclude = true -# Lint [tool.ruff.lint] select = [ - "E", # pycodestyle errors - "W", # pycodestyle warnings - "F", # pyflakes - "I", # Check for missing imports (auto-fixable) - "UP", # pyupgrade - "ASYNC", # flake8-async - "ISC", # Checks for implicit literal string concatenation (auto-fixable) - "LOG", # Checking the use of logging objects - "G", # Check for logging format issues (auto-fixable) -] -ignore = [ - "ISC001" # may casue conflict with ruff + # pycodestyle: import, statement, and syntax errors. + "E4", + "E7", + "E9", + # Pyflakes: undefined names, unused imports, and related errors. + "F", + # isort: import grouping and ordering. + "I", + # pyupgrade: syntax supported by the minimum Python version. + "UP", + # flake8-bugbear: likely bugs and fragile patterns. + "B", + # flake8-comprehensions: unnecessary or suboptimal comprehensions. + "C4", + # flake8-simplify: unnecessarily complex expressions and control flow. + "SIM", + # flake8-pie: unnecessary code and avoidable patterns. + "PIE", + # Perflint: common Python performance anti-patterns. + "PERF", + # flake8-pytest-style: common pytest API misuse. + "PT", + # Ruff: native correctness and suppression checks. + "RUF", ] +[tool.ty.src] +include = ["src"] -[tool.ruff.lint.isort] -combine-as-imports = true +[tool.ty.terminal] +error-on-warning = true -section-order = [ - "future", - "standard-library", - "third-party", - "first-party", - "local-folder" +[tool.pytest] +minversion = "9.1" +addopts = [ + "-ra", # Summarize every result except passed tests. + "--import-mode=importlib", # Import tests without changing sys.path. ] - -### Coverage settings ### -[tool.coverage.run] -branch = true -relative_files = true -include = ["src/dubbo/*"] - -[tool.coverage.report] -# Skip coverage report for 100% covered files -skip_covered = true -exclude_also = [ - "def __repr__", - "raise AssertionError", - "raise NotImplementedError", - "if __name__ == .__main__.:", - "@(abc\\.)?abstractmethod", - "@(typing(_extensions)?\\.)?overload", - "if (typing(_extensions)?\\.)?TYPE_CHECKING:" +strict_config = true +strict_markers = true +markers = [ + "zookeeper: needs the ZooKeeper whose host:port DUBBO_TEST_ZOOKEEPER holds", + "nacos: needs the Nacos whose host:port DUBBO_TEST_NACOS holds", + "samples: runs a sample of samples/ as its README says", + "real_clock: waits for a thread or a process, so it runs on the real clock instead of the virtual one", +] +strict_parametrization_ids = true +strict_xfail = true +filterwarnings = [ + "error", + "ignore::DeprecationWarning:v2.nacos", # The Nacos SDK declares pydantic models the deprecated way. + # The Nacos SDK leaves the files of its local cache open. + "ignore:Exception ignored (in.|while finalizing file) <_io.FileIO name='[^']*/nacos/cache/:pytest.PytestUnraisableExceptionWarning", ] - - -### Mypy settings ### -[tool.mypy] -ignore_missing_imports = true - -[[tool.mypy.overrides]] -module = "tests.*" -disallow_untyped_defs = false -check_untyped_defs = true - -### Pytest settings ### -[tool.pytest] -addopts = "-rxXs" -testpaths = ["tests"] -python_files = [ - "test_*.py" -] \ No newline at end of file diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index d43d7e5d..00000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,19 +0,0 @@ -# Here, we do not specify the dependencies required by the project in the requirements.txt file, -# as they have all been moved to the pyproject.toml file. -# In this file, we only specify the dependencies needed for the development environment, -# such as testing, packaging, linting, etc. - --e .[zoopkeeper] - - -# Packaging -hatch>=1.14.0 - - -# Formatting & Linting -ruff>=0.9.1 -mypy>=1.14.1 - -# Testing -pytest>=8.3.4 -coverage[toml]>=7.6.10 \ No newline at end of file diff --git a/samples/README.md b/samples/README.md index 0b212138..8c85b67a 100644 --- a/samples/README.md +++ b/samples/README.md @@ -1,10 +1,63 @@ -# Dubbo-python Samples +# Samples -## What It Contains +Small programs that each teach one thing about Apache Dubbo for Python, from a +first call to running beside other frameworks. Each sample has a README that +says what it shows, how to run it, and what you will see. -1. [**helloworld**](./helloworld): The simplest usage example for quick start. -2. [**serialization**](./serialization): Writing and using custom serialization functions, including protobuf, JSON, and more. -3. [**stream**](./stream): Using streaming calls, including `ClientStream`, `ServerStream`, and `BidirectionalStream`. -4. [**registry**](./registry): Using service registration and discovery features. -5. [**LLM Integration**](./llm): Easily integrating LLMs with Dubbo Python, providing RPC services using models like DeepSeek R1. +## Before you start +Install Apache Dubbo for Python: + +```console +$ pip install apache-dubbo +``` + +A sample that needs more, such as an extra, says so in its README. The +samples that use a registry or a configuration center need ZooKeeper or +Nacos; start both with Docker, from this directory: + +```console +$ docker compose -f compose.yaml up -d --wait +``` + +Run every sample from its own directory, the server first, then the client in +another terminal. + +## Basics + +Using the framework on its own, in order: + +| Sample | What it shows | +|---|---| +| [01_hello_world](basics/01_hello_world) | A contract, a provider and a consumer, with Python types over the Dubbo protocol | +| [02_protobuf](basics/02_protobuf) | Contracts generated from a `.proto` file, over the Triple protocol | +| [03_streaming](basics/03_streaming) | Server, client and bidirectional streaming | +| [04_registry](basics/04_registry) | Finding providers through ZooKeeper or Nacos; registering per service and per application; local and remote metadata | +| [05_configuration](basics/05_configuration) | Configuration files from defaults to one method, and environment variables | +| [06_logging](basics/06_logging) | Structured logs with the trace id of each call, written off the event loop | +| [07_graceful_shutdown](basics/07_graceful_shutdown) | Opening resources with the application, and stopping without losing calls | +| [08_errors_and_timeouts](basics/08_errors_and_timeouts) | Statuses, timeouts and retries | +| [09_context](basics/09_context) | Attachments along a chain of services | +| [10_group_version](basics/10_group_version) | Several versions of a service side by side | +| [11_load_balancing](basics/11_load_balancing) | Load balances and clusters: how calls spread, and what a failure leads to | +| [12_config_center](basics/12_config_center) | Configuration from a configuration center, and rules that change running calls | +| [13_routing](basics/13_routing) | Tag and condition routing, by configuration and by rules | +| [14_filters](basics/14_filters) | Code around every call: an API key check and timing | +| [15_extensions](basics/15_extensions) | An extension of your own, installed as a plugin | +| [16_tls](basics/16_tls) | Mutual TLS and compression | +| [17_generic](basics/17_generic) | Calls without the contract of the service | + +## Working with other languages + +| Sample | What it shows | +|---|---| +| [interop/java](interop/java) | Python and Java calling each other through Nacos, over Triple with Protobuf and over Dubbo with Hessian 2 | +| [interop/go](interop/go) | Python and Go calling each other through Nacos, over Triple with Protobuf | +| [interop/grpc](interop/grpc) | gRPC clients calling Dubbo, Dubbo calling gRPC servers, health and reflection | + +## Working with Python libraries + +| Sample | What it shows | +|---|---| +| [integrations/fastapi](integrations/fastapi) | A small shop: a FastAPI gateway, services that call each other through a registry, a trace id along the chain, and the statuses of failed calls as HTTP statuses | +| [integrations/pydantic_ai](integrations/pydantic_ai) | An AI agent that plans restocking with the services of a company as its tools, and drafts orders once a person agrees | diff --git a/samples/__init__.py b/samples/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/samples/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/samples/basics/01_hello_world/README.md b/samples/basics/01_hello_world/README.md new file mode 100644 index 00000000..b6449e75 --- /dev/null +++ b/samples/basics/01_hello_world/README.md @@ -0,0 +1,61 @@ +# Hello world + +Your first Dubbo service in Python: a contract, a server that implements it, +and a client that calls it, with no registry. + +## What you will learn + +- how a service contract is declared as a `typing.Protocol`; +- how a provider exports an implementation and serves it; +- how a consumer refers to a contract and calls it like a local object. + +## The files + +| File | Role | +|---|---| +| `greeter.py` | The contract that both sides import | +| `server.py` | The provider: implements `Greeter` and serves it on port 20880 | +| `client.py` | The consumer: calls the provider at `dubbo://127.0.0.1:20880` | + +## Run it + +From this directory, start the server: + +```console +$ python server.py +Serving on port 20880; press Ctrl+C to stop +``` + +In another terminal, run the client: + +```console +$ python client.py +Hello, Alice! +Hello, Bob! +``` + +The server prints each name it greets. Stop it with Ctrl+C. + +## How it works + +`@dubbo.service` gives the contract its service name, +`org.apache.dubbo.samples.Greeter`. The type hints of its methods say what +travels on the wire. + +The server creates a `Dubbo` application with one protocol, exports +`GreeterImpl`, and runs inside `async with app`. Leaving the block stops the +application gracefully. + +The client creates its own application and calls `app.refer(Greeter, url=...)`, +which returns an object with the methods of `Greeter`. Each call goes over +the network to the server. + +The Dubbo protocol carries Python values, such as `str`, `int`, `list` and +`dict`, in the Hessian 2 format, which Dubbo Java services read as well. + +## Next + +- [02_protobuf](../02_protobuf): define the contract in a `.proto` file and + use the Triple protocol, which gRPC also speaks. +- [04_registry](../04_registry): let the client find the server through a + registry instead of its address. diff --git a/samples/basics/01_hello_world/client.py b/samples/basics/01_hello_world/client.py new file mode 100644 index 00000000..83ef95ff --- /dev/null +++ b/samples/basics/01_hello_world/client.py @@ -0,0 +1,44 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: it calls the Greeter that server.py serves. + +import asyncio + +from dubbo import Dubbo + +from greeter import Greeter + + +async def main() -> None: + # A consumer that calls providers by their addresses needs no configuration. + app = Dubbo() + + # refer() returns an object that implements the contract by calling the + # provider. The URL names the protocol and address of the provider; the + # registry sample shows how to find providers without knowing them. + greeter = app.refer(Greeter, url="dubbo://127.0.0.1:20880") + + # Calls work while the application runs, that is inside `async with`. + async with app: + for name in ["Alice", "Bob"]: + reply = await greeter.greet(name) + print(reply) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/01_hello_world/greeter.py b/samples/basics/01_hello_world/greeter.py new file mode 100644 index 00000000..499f36f4 --- /dev/null +++ b/samples/basics/01_hello_world/greeter.py @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contract of the service: the server implements it, the client calls it. +# Both sides import this module, so they agree on the methods and their types. + +import typing + +import dubbo + + +# The name identifies the service on the wire and in registries. Java and Go +# services use the same kind of name, usually that of a Java interface. +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + # Every method is async. Its type hints say what travels on the wire: + # here a str goes in and a str comes back. + async def greet(self, name: str) -> str: ... diff --git a/samples/basics/01_hello_world/server.py b/samples/basics/01_hello_world/server.py new file mode 100644 index 00000000..8ea7f8ff --- /dev/null +++ b/samples/basics/01_hello_world/server.py @@ -0,0 +1,55 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The provider: it implements the Greeter contract and serves it until Ctrl+C. + +import asyncio + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig + +from greeter import Greeter + + +# The implementation subclasses the contract, so a type checker sees a +# method that is missing or has the wrong signature. +class GreeterImpl(Greeter): + async def greet(self, name: str) -> str: + print(f"Greeting {name}") + return f"Hello, {name}!" + + +async def main() -> None: + # The application has a name, and here one protocol: the Dubbo protocol on + # port 20880, which carries Python values such as str, int, list and dict + # in the Hessian 2 format that Java reads. + app = Dubbo( + application=ApplicationConfig(name="hello-world-server"), + protocols={"dubbo": ProtocolConfig(port=20880)}, + ) + app.export(GreeterImpl()) + + # The application starts when `async with` enters, and stops when it + # leaves. serve_forever() returns on Ctrl+C or SIGTERM, which then stops + # the application gracefully: running calls finish first. + async with app: + print("Serving on port 20880; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/02_protobuf/README.md b/samples/basics/02_protobuf/README.md new file mode 100644 index 00000000..6d0e5cb1 --- /dev/null +++ b/samples/basics/02_protobuf/README.md @@ -0,0 +1,79 @@ +# Protobuf and Triple + +Define the contract in a `.proto` file, generate Python code from it, and +serve it over Triple, the protocol of Dubbo that gRPC also speaks. + +## What you will learn + +- how to generate a Dubbo contract from a `.proto` file; +- how a provider implements the generated servicer; +- how a consumer calls the generated protocol over Triple. + +## Why Protobuf + +A `.proto` file is a contract that every language reads: Dubbo Java, Dubbo Go +and gRPC programs generate code from the same file. Use it when services in +several languages share a contract, or when gRPC clients call your service. +The [hello world](../01_hello_world) sample shows the other way, with +contracts written in Python. + +## The files + +| File | Role | +|---|---| +| `greeter.proto` | The contract | +| `greeter_pb2.py`, `greeter_pb2.pyi` | The messages, generated by protoc | +| `greeter_dubbo.py` | The Dubbo contracts, generated by `protoc-gen-python-dubbo` | +| `server.py` | The provider: implements `GreeterServicer` on port 50051 | +| `client.py` | The consumer: calls `Greeter` at `tri://127.0.0.1:50051` | + +## Generate the code + +The generated files are included, so you can skip this step. To generate +them again after changing `greeter.proto`, install the `protoc` extra and run +protoc from this directory, with the virtual environment activated so that +protoc finds the plugin: + +```console +$ pip install "apache-dubbo[protoc]" +$ python -m grpc_tools.protoc -I. --python_out=. --pyi_out=. --python-dubbo_out=. greeter.proto +``` + +`--python_out` and `--pyi_out` write the message classes, as for any Python +use of Protobuf. `--python-dubbo_out` runs `protoc-gen-python-dubbo`, which +writes `greeter_dubbo.py` with two classes for each service: + +- `Greeter`, a `typing.Protocol` that consumers refer to; +- `GreeterServicer`, an abstract class that providers subclass. + +## Run it + +From this directory, start the server: + +```console +$ python server.py +Serving on port 50051; press Ctrl+C to stop +``` + +In another terminal, run the client: + +```console +$ python client.py +Hello, Dubbo! +``` + +## How it works + +The server configures no protocol, so the application serves Triple on port +50051. Each `rpc` of the proto file becomes a method with a Python name: +`SayHello` becomes `say_hello`, and the service keeps its full name, +`org.apache.dubbo.samples.Greeter`, so that other languages find it. + +The client refers to `Greeter` with a `tri://` URL. Messages travel in the +Protobuf format, framed as gRPC frames them over HTTP/2. + +## Next + +- [03_streaming](../03_streaming): send and receive streams of messages. +- [interop/grpc](../../interop/grpc): call this kind of service from a gRPC + client. diff --git a/samples/basics/02_protobuf/client.py b/samples/basics/02_protobuf/client.py new file mode 100644 index 00000000..2880e7ba --- /dev/null +++ b/samples/basics/02_protobuf/client.py @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: it calls the Greeter that server.py serves. + +import asyncio + +from dubbo import Dubbo + +from greeter_dubbo import Greeter +from greeter_pb2 import HelloRequest + + +async def main() -> None: + app = Dubbo() + + # Callers refer to the generated Greeter protocol, not to the servicer. + greeter = app.refer(Greeter, url="tri://127.0.0.1:50051") + + async with app: + reply = await greeter.say_hello(HelloRequest(name="Dubbo")) + print(reply.message) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/02_protobuf/greeter.proto b/samples/basics/02_protobuf/greeter.proto new file mode 100644 index 00000000..e12cd1d1 --- /dev/null +++ b/samples/basics/02_protobuf/greeter.proto @@ -0,0 +1,33 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +syntax = "proto3"; + +package org.apache.dubbo.samples; + +// Greets people. +service Greeter { + rpc SayHello (HelloRequest) returns (HelloReply); +} + +message HelloRequest { + string name = 1; +} + +message HelloReply { + string message = 1; +} diff --git a/samples/basics/02_protobuf/greeter_dubbo.py b/samples/basics/02_protobuf/greeter_dubbo.py new file mode 100644 index 00000000..ea785534 --- /dev/null +++ b/samples/basics/02_protobuf/greeter_dubbo.py @@ -0,0 +1,29 @@ +# Generated by protoc-gen-python-dubbo. DO NOT EDIT! +# source: greeter.proto +"""Dubbo service contracts of greeter.proto.""" + +import abc +import typing + +import dubbo + +import greeter_pb2 + +__all__ = ["Greeter", "GreeterServicer"] + + +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + """Greets people.""" + + @dubbo.method("SayHello") + async def say_hello(self, request: greeter_pb2.HelloRequest) -> greeter_pb2.HelloReply: ... + + +@dubbo.service("org.apache.dubbo.samples.Greeter") +class GreeterServicer(abc.ABC): + """Greets people.""" + + @dubbo.method("SayHello") + @abc.abstractmethod + async def say_hello(self, request: greeter_pb2.HelloRequest) -> greeter_pb2.HelloReply: ... diff --git a/samples/basics/02_protobuf/greeter_pb2.py b/samples/basics/02_protobuf/greeter_pb2.py new file mode 100644 index 00000000..848d50f6 --- /dev/null +++ b/samples/basics/02_protobuf/greeter_pb2.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: greeter.proto +# Protobuf Python Version: 7.35.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 7, + 35, + 1, + '', + 'greeter.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rgreeter.proto\x12\x18org.apache.dubbo.samples\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t2c\n\x07Greeter\x12X\n\x08SayHello\x12&.org.apache.dubbo.samples.HelloRequest\x1a$.org.apache.dubbo.samples.HelloReplyb\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'greeter_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + DESCRIPTOR._loaded_options = None + _globals['_HELLOREQUEST']._serialized_start=43 + _globals['_HELLOREQUEST']._serialized_end=71 + _globals['_HELLOREPLY']._serialized_start=73 + _globals['_HELLOREPLY']._serialized_end=102 + _globals['_GREETER']._serialized_start=104 + _globals['_GREETER']._serialized_end=203 +# @@protoc_insertion_point(module_scope) diff --git a/samples/basics/02_protobuf/greeter_pb2.pyi b/samples/basics/02_protobuf/greeter_pb2.pyi new file mode 100644 index 00000000..bf0bd395 --- /dev/null +++ b/samples/basics/02_protobuf/greeter_pb2.pyi @@ -0,0 +1,17 @@ +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from typing import ClassVar as _ClassVar, Optional as _Optional + +DESCRIPTOR: _descriptor.FileDescriptor + +class HelloRequest(_message.Message): + __slots__ = ("name",) + NAME_FIELD_NUMBER: _ClassVar[int] + name: str + def __init__(self, name: _Optional[str] = ...) -> None: ... + +class HelloReply(_message.Message): + __slots__ = ("message",) + MESSAGE_FIELD_NUMBER: _ClassVar[int] + message: str + def __init__(self, message: _Optional[str] = ...) -> None: ... diff --git a/samples/basics/02_protobuf/server.py b/samples/basics/02_protobuf/server.py new file mode 100644 index 00000000..adda0f69 --- /dev/null +++ b/samples/basics/02_protobuf/server.py @@ -0,0 +1,50 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The provider: it implements the Greeter of greeter.proto and serves it over +# the Triple protocol until Ctrl+C. + +import asyncio + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig + +from greeter_dubbo import GreeterServicer +from greeter_pb2 import HelloReply, HelloRequest + + +# The generated GreeterServicer is an abstract class with one method per rpc +# of the proto file, named in Python style: SayHello becomes say_hello. +class GreeterImpl(GreeterServicer): + async def say_hello(self, request: HelloRequest) -> HelloReply: + print(f"Greeting {request.name}") + return HelloReply(message=f"Hello, {request.name}!") + + +async def main() -> None: + # With no protocol configured, an application serves Triple on port 50051. + # Triple runs over HTTP/2 and carries Protobuf messages as gRPC does. + app = Dubbo(application=ApplicationConfig(name="protobuf-server")) + app.export(GreeterImpl()) + + async with app: + print("Serving on port 50051; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/03_streaming/README.md b/samples/basics/03_streaming/README.md new file mode 100644 index 00000000..f1036636 --- /dev/null +++ b/samples/basics/03_streaming/README.md @@ -0,0 +1,71 @@ +# Streaming + +Besides a single request and reply, Triple carries streams of messages, in +either direction or both. This sample makes one call of each kind. + +## What you will learn + +- how a provider sends, receives, or does both on a stream; +- how a consumer holds a streaming call with `async with` and reads it with + `async for`; +- when to use each kind of streaming. + +## The three kinds + +| Kind | Requests | Replies | Typical use | +|---|---|---|---| +| Server streaming | one | many | results as they become ready, progress, live updates | +| Client streaming | many | one | uploads, batches, aggregation | +| Bidirectional | many | many | chat, interactive sessions | + +In `greeter.proto`, the keyword `stream` marks the streaming side of each +`rpc`. + +## Run it + +From this directory, start the server: + +```console +$ python server.py +Serving on port 50051; press Ctrl+C to stop +``` + +In another terminal, run the client: + +```console +$ python client.py +Server streaming: + Hello #1, Alice! + Hello #2, Alice! + Hello #3, Alice! +Client streaming: + Hello, Alice, Bob, Carol! +Bidirectional streaming: + Nice to meet you, Alice + Nice to meet you, Bob +``` + +The generated files are included; [02_protobuf](../02_protobuf) shows how to +generate them again. + +## How it works + +On the provider, each streaming handler gets a stream argument: + +- `greet_many_times` sends replies with `stream.send()`; the call ends when + the handler returns; +- `greet_everyone` reads requests with `async for` until the caller ends + them, then returns the reply; +- `chat` reads requests and sends replies on one stream. + +On the consumer, a streaming method returns a call to hold with +`async with`. Leaving the block ends the call, and cancels it if it still +runs. A call sends with `send()`, says it has sent everything with `end()`, +and receives with `receive()` or `async for`. + +A streaming call has no timeout of its own. Bound it with +`anyio.fail_after()`, whose deadline reaches the provider as well. + +## Next + +- [04_registry](../04_registry): find providers through a registry. diff --git a/samples/basics/03_streaming/client.py b/samples/basics/03_streaming/client.py new file mode 100644 index 00000000..b2810813 --- /dev/null +++ b/samples/basics/03_streaming/client.py @@ -0,0 +1,62 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: it makes one call of each streaming style. + +import asyncio + +from dubbo import Dubbo + +from greeter_dubbo import StreamGreeter +from greeter_pb2 import HelloRequest + + +async def main() -> None: + app = Dubbo() + greeter = app.refer(StreamGreeter, url="tri://127.0.0.1:50051") + + async with app: + # Server streaming: a streaming call is a context manager; leaving + # the block ends the call. `async for` reads the replies as they come. + print("Server streaming:") + async with greeter.greet_many_times(HelloRequest(name="Alice")) as replies: + async for reply in replies: + print(" ", reply.message) + + # Client streaming: send the requests, end them, then receive the reply. + print("Client streaming:") + async with greeter.greet_everyone() as stream: + for name in ["Alice", "Bob", "Carol"]: + await stream.send(HelloRequest(name=name)) + await stream.end() + reply = await stream.receive() + print(" ", reply.message) + + # Bidirectional streaming: here each request waits for its reply, but + # both sides may also send and receive independently, for example in + # two tasks. + print("Bidirectional streaming:") + async with greeter.chat() as stream: + for name in ["Alice", "Bob"]: + await stream.send(HelloRequest(name=name)) + reply = await stream.receive() + print(" ", reply.message) + await stream.end() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/03_streaming/greeter.proto b/samples/basics/03_streaming/greeter.proto new file mode 100644 index 00000000..b2b44bf1 --- /dev/null +++ b/samples/basics/03_streaming/greeter.proto @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +syntax = "proto3"; + +package org.apache.dubbo.samples; + +// Greets people in three streaming styles. +service StreamGreeter { + // Server streaming: one request, many replies. + rpc GreetManyTimes (HelloRequest) returns (stream HelloReply); + // Client streaming: many requests, one reply. + rpc GreetEveryone (stream HelloRequest) returns (HelloReply); + // Bidirectional streaming: requests and replies flow both ways. + rpc Chat (stream HelloRequest) returns (stream HelloReply); +} + +message HelloRequest { + string name = 1; +} + +message HelloReply { + string message = 1; +} diff --git a/samples/basics/03_streaming/greeter_dubbo.py b/samples/basics/03_streaming/greeter_dubbo.py new file mode 100644 index 00000000..4402bfeb --- /dev/null +++ b/samples/basics/03_streaming/greeter_dubbo.py @@ -0,0 +1,49 @@ +# Generated by protoc-gen-python-dubbo. DO NOT EDIT! +# source: greeter.proto +"""Dubbo service contracts of greeter.proto.""" + +import abc +import typing + +import dubbo + +import greeter_pb2 + +__all__ = ["StreamGreeter", "StreamGreeterServicer"] + + +@dubbo.service("org.apache.dubbo.samples.StreamGreeter") +class StreamGreeter(typing.Protocol): + """Greets people in three streaming styles.""" + + @dubbo.method("GreetManyTimes") + def greet_many_times(self, request: greeter_pb2.HelloRequest) -> dubbo.ServerStream[greeter_pb2.HelloReply]: + """Server streaming: one request, many replies.""" + + @dubbo.method("GreetEveryone") + def greet_everyone(self) -> dubbo.ClientStream[greeter_pb2.HelloRequest, greeter_pb2.HelloReply]: + """Client streaming: many requests, one reply.""" + + @dubbo.method("Chat") + def chat(self) -> dubbo.BidiStream[greeter_pb2.HelloRequest, greeter_pb2.HelloReply]: + """Bidirectional streaming: requests and replies flow both ways.""" + + +@dubbo.service("org.apache.dubbo.samples.StreamGreeter") +class StreamGreeterServicer(abc.ABC): + """Greets people in three streaming styles.""" + + @dubbo.method("GreetManyTimes") + @abc.abstractmethod + async def greet_many_times(self, request: greeter_pb2.HelloRequest, stream: dubbo.SendStream[greeter_pb2.HelloReply]) -> None: + """Server streaming: one request, many replies.""" + + @dubbo.method("GreetEveryone") + @abc.abstractmethod + async def greet_everyone(self, stream: dubbo.ReceiveStream[greeter_pb2.HelloRequest]) -> greeter_pb2.HelloReply: + """Client streaming: many requests, one reply.""" + + @dubbo.method("Chat") + @abc.abstractmethod + async def chat(self, stream: dubbo.Stream[greeter_pb2.HelloReply, greeter_pb2.HelloRequest]) -> None: + """Bidirectional streaming: requests and replies flow both ways.""" diff --git a/samples/basics/03_streaming/greeter_pb2.py b/samples/basics/03_streaming/greeter_pb2.py new file mode 100644 index 00000000..57dc9d6f --- /dev/null +++ b/samples/basics/03_streaming/greeter_pb2.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: greeter.proto +# Protobuf Python Version: 7.35.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 7, + 35, + 1, + '', + 'greeter.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rgreeter.proto\x12\x18org.apache.dubbo.samples\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t2\xac\x02\n\rStreamGreeter\x12`\n\x0eGreetManyTimes\x12&.org.apache.dubbo.samples.HelloRequest\x1a$.org.apache.dubbo.samples.HelloReply0\x01\x12_\n\rGreetEveryone\x12&.org.apache.dubbo.samples.HelloRequest\x1a$.org.apache.dubbo.samples.HelloReply(\x01\x12X\n\x04\x43hat\x12&.org.apache.dubbo.samples.HelloRequest\x1a$.org.apache.dubbo.samples.HelloReply(\x01\x30\x01\x62\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'greeter_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + DESCRIPTOR._loaded_options = None + _globals['_HELLOREQUEST']._serialized_start=43 + _globals['_HELLOREQUEST']._serialized_end=71 + _globals['_HELLOREPLY']._serialized_start=73 + _globals['_HELLOREPLY']._serialized_end=102 + _globals['_STREAMGREETER']._serialized_start=105 + _globals['_STREAMGREETER']._serialized_end=405 +# @@protoc_insertion_point(module_scope) diff --git a/samples/basics/03_streaming/greeter_pb2.pyi b/samples/basics/03_streaming/greeter_pb2.pyi new file mode 100644 index 00000000..bf0bd395 --- /dev/null +++ b/samples/basics/03_streaming/greeter_pb2.pyi @@ -0,0 +1,17 @@ +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from typing import ClassVar as _ClassVar, Optional as _Optional + +DESCRIPTOR: _descriptor.FileDescriptor + +class HelloRequest(_message.Message): + __slots__ = ("name",) + NAME_FIELD_NUMBER: _ClassVar[int] + name: str + def __init__(self, name: _Optional[str] = ...) -> None: ... + +class HelloReply(_message.Message): + __slots__ = ("message",) + MESSAGE_FIELD_NUMBER: _ClassVar[int] + message: str + def __init__(self, message: _Optional[str] = ...) -> None: ... diff --git a/samples/basics/03_streaming/server.py b/samples/basics/03_streaming/server.py new file mode 100644 index 00000000..08bcd642 --- /dev/null +++ b/samples/basics/03_streaming/server.py @@ -0,0 +1,61 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The provider: it implements the three streaming methods of greeter.proto. + +import asyncio + +import dubbo +from dubbo import Dubbo +from dubbo.config import ApplicationConfig + +from greeter_dubbo import StreamGreeterServicer +from greeter_pb2 import HelloReply, HelloRequest + + +class StreamGreeterImpl(StreamGreeterServicer): + # Server streaming: the handler gets a stream to send replies on. The + # call ends when the handler returns. + async def greet_many_times(self, request: HelloRequest, stream: dubbo.SendStream[HelloReply]) -> None: + for count in range(1, 4): + await stream.send(HelloReply(message=f"Hello #{count}, {request.name}!")) + await asyncio.sleep(0.2) + + # Client streaming: the handler reads the requests with `async for` until + # the caller ends them, then returns the one reply. + async def greet_everyone(self, stream: dubbo.ReceiveStream[HelloRequest]) -> HelloReply: + names = [request.name async for request in stream] + return HelloReply(message=f"Hello, {', '.join(names)}!") + + # Bidirectional streaming: the handler sends and receives on one stream, + # here a reply for each request as it arrives. + async def chat(self, stream: dubbo.Stream[HelloReply, HelloRequest]) -> None: + async for request in stream: + await stream.send(HelloReply(message=f"Nice to meet you, {request.name}")) + + +async def main() -> None: + app = Dubbo(application=ApplicationConfig(name="streaming-server")) + app.export(StreamGreeterImpl()) + + async with app: + print("Serving on port 50051; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/04_registry/README.md b/samples/basics/04_registry/README.md new file mode 100644 index 00000000..eb4efdd2 --- /dev/null +++ b/samples/basics/04_registry/README.md @@ -0,0 +1,142 @@ +# Registry + +In production, consumers do not know the addresses of providers: providers +register with a registry, and consumers discover them there, following them +as they start and stop. This sample uses ZooKeeper, then Nacos. + +## What you will learn + +- how a provider registers its services with a registry; +- how a consumer discovers providers without knowing their addresses; +- how calls spread across several providers; +- the two ways Dubbo registers, per service and per application; +- how to switch between ZooKeeper and Nacos. + +## Before you start + +Install the client of the registry you use: + +```console +$ pip install "apache-dubbo[zookeeper]" # or "apache-dubbo[nacos]" +``` + +and start the registries, from the `samples` directory: + +```console +$ docker compose -f compose.yaml up -d --wait +``` + +## Run it + +From this directory, start two servers on different ports. The second one +sets its port through an environment variable, which overrides the +configuration in the code; [05_configuration](../05_configuration) explains +how. + +```console +$ python server.py +Serving and registered; press Ctrl+C to stop +``` + +```console +$ DUBBO__PROTOCOLS__DUBBO__PORT=20881 python server.py +Serving and registered; press Ctrl+C to stop +``` + +Then run the client: + +```console +$ python client.py +Hello, Alice! (from server 85651) +Hello, Bob! (from server 85652) +Hello, Carol! (from server 85651) +Hello, Dave! (from server 85651) +``` + +The replies come from both servers; the numbers are their process IDs. Stop +one server and run the client again: all calls go to the other one. + +To use Nacos instead, set the registry address the same way for every +process: + +```console +$ export DUBBO__REGISTRIES__DEFAULT__ADDRESS=nacos://127.0.0.1:8848 +``` + +## How it works + +Both sides add a registry to their configuration. The scheme of its address, +`zookeeper://` or `nacos://`, selects the registry. + +When the server starts, it registers its address with the registry. When it +stops, it first removes the address, then keeps serving for 3 seconds, so +that consumers notice and send their calls elsewhere; that is why stopping +takes a moment. + +The client calls `app.refer(Greeter)` without a URL, so the application +looks the providers up in the registry and watches them. Starting waits up +to 3 seconds for a provider and fails if none is found. Each call then goes +to one provider, chosen at random by default. + +## Two ways to register + +Dubbo registers providers in two ways: + +- **per service**, or interface level, as Dubbo 2 does: one URL for each + service of each provider. Simple, but the registry holds as many entries + as services times instances; +- **per application**, or application level, as Dubbo 3 does: one entry for + each instance of an application, and a mapping from each service to the + applications that provide it. Consumers read the services of an instance + from its metadata. The registry stays small however many services there + are. + +By default a provider registers both ways, so that consumers of either +kind, in any language, find it, and a consumer calls the providers it finds +per application while there are any, else those it finds per service. The +`mode` of a registry selects one way: `"interface"`, `"instance"` or `"all"`. + +`show_registry.py` shows what the servers have registered in ZooKeeper. +Start a server in each mode and look: + +```console +$ DUBBO__REGISTRIES__DEFAULT__MODE=interface python server.py +``` + +```console +$ python show_registry.py +Providers of org.apache.dubbo.samples.Greeter, registered per service: + dubbo://127.0.0.1:20880/org.apache.dubbo.samples.Greeter +Instances of registry-server, registered per application: +Applications that provide org.apache.dubbo.samples.Greeter: registry-server +``` + +With `instance`, the providers list is empty and the instance +`127.0.0.1:20880` appears instead. The mapping stays after the servers +stop, since it says which applications provide a service rather than which +instances run. The client finds the server in every mode, since it +discovers both ways too. In code, the mode is a field: +`RegistryConfig(address=..., mode=RegistryMode.INSTANCE)`. + +### Where the metadata is + +Per application, a consumer learns which services an instance provides, and +on which protocols, from its metadata. By default an instance serves its own +metadata through a built-in `MetadataService`, which consumers call: +`metadata_type` `local`. With `remote`, the instance writes its metadata to +the registry, or to a separate metadata report, and consumers read it there: + +```console +$ DUBBO__APPLICATION__METADATA_TYPE=remote DUBBO__REGISTRIES__DEFAULT__MODE=instance python server.py +``` + +The metadata then appears under `/dubbo/metadata/registry-server`, one entry +per revision. `remote` spares consumers a call to each new instance, at the +cost of entries in the registry; `local` keeps the registry small. Dubbo +Java reads both; Dubbo Go 3.3.2 reads only `local`, since it looks for +remote metadata under another path in ZooKeeper. + +## Next + +- [05_configuration](../05_configuration): keep the configuration in a file + and override it from the environment. diff --git a/samples/basics/04_registry/client.py b/samples/basics/04_registry/client.py new file mode 100644 index 00000000..7402bb93 --- /dev/null +++ b/samples/basics/04_registry/client.py @@ -0,0 +1,48 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: it finds the providers of the Greeter in the registry and +# spreads its calls across them. + +import asyncio + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, RegistryConfig + +from greeter import Greeter + + +async def main() -> None: + # The same registry as the server, and no address of any provider. + app = Dubbo( + application=ApplicationConfig(name="registry-client"), + registries={"default": RegistryConfig(address="zookeeper://127.0.0.1:2181")}, + ) + + # Without a URL, refer() discovers the providers of the Greeter through + # the registry, and follows them as they come and go. + greeter = app.refer(Greeter) + + # Starting waits up to 3 seconds for a provider, and fails if none is + # found; each call then goes to one of them, chosen at random by default. + async with app: + for name in ["Alice", "Bob", "Carol", "Dave"]: + print(await greeter.greet(name)) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/04_registry/greeter.py b/samples/basics/04_registry/greeter.py new file mode 100644 index 00000000..499f36f4 --- /dev/null +++ b/samples/basics/04_registry/greeter.py @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contract of the service: the server implements it, the client calls it. +# Both sides import this module, so they agree on the methods and their types. + +import typing + +import dubbo + + +# The name identifies the service on the wire and in registries. Java and Go +# services use the same kind of name, usually that of a Java interface. +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + # Every method is async. Its type hints say what travels on the wire: + # here a str goes in and a str comes back. + async def greet(self, name: str) -> str: ... diff --git a/samples/basics/04_registry/server.py b/samples/basics/04_registry/server.py new file mode 100644 index 00000000..81db3e29 --- /dev/null +++ b/samples/basics/04_registry/server.py @@ -0,0 +1,53 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The provider: it registers the Greeter with a registry, so that consumers +# find it by its service name. Run several to see calls spread across them. + +import asyncio +import os + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig, RegistryConfig + +from greeter import Greeter + + +class GreeterImpl(Greeter): + async def greet(self, name: str) -> str: + # The process ID tells the replies of different servers apart. + return f"Hello, {name}! (from server {os.getpid()})" + + +async def main() -> None: + # The registry is one more part of the configuration. On start, the + # application registers its services there; on stop, it removes them. + # A registry needs the application name, which groups its instances. + app = Dubbo( + application=ApplicationConfig(name="registry-server"), + protocols={"dubbo": ProtocolConfig(port=20880)}, + registries={"default": RegistryConfig(address="zookeeper://127.0.0.1:2181")}, + ) + app.export(GreeterImpl()) + + async with app: + print("Serving and registered; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/04_registry/show_registry.py b/samples/basics/04_registry/show_registry.py new file mode 100644 index 00000000..a9dc6d34 --- /dev/null +++ b/samples/basics/04_registry/show_registry.py @@ -0,0 +1,58 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Shows what the servers have registered in ZooKeeper, in both ways Dubbo +# registers. It reads ZooKeeper directly with kazoo, which the zookeeper extra +# installs, and changes nothing. + +from urllib.parse import unquote + +from kazoo.client import KazooClient + +SERVICE = "org.apache.dubbo.samples.Greeter" +APPLICATION = "registry-server" + + +def children(zookeeper: KazooClient, path: str) -> list[str]: + return sorted(zookeeper.get_children(path)) if zookeeper.exists(path) else [] + + +def main() -> None: + zookeeper = KazooClient("127.0.0.1:2181") + zookeeper.start() + try: + # Interface level, as Dubbo 2 discovers: one URL per service and + # provider, under the name of the service. + print(f"Providers of {SERVICE}, registered per service:") + for url in children(zookeeper, f"/dubbo/{SERVICE}/providers"): + print(" ", unquote(url).split("?")[0]) + + # Application level, as Dubbo 3 discovers: one node per instance of + # the application, and a mapping from each service to the + # applications that provide it. + print(f"Instances of {APPLICATION}, registered per application:") + for instance in children(zookeeper, f"/services/{APPLICATION}"): + print(" ", instance) + mapping = f"/dubbo/mapping/{SERVICE}" + if zookeeper.exists(mapping): + print(f"Applications that provide {SERVICE}:", zookeeper.get(mapping)[0].decode()) + finally: + zookeeper.stop() + + +if __name__ == "__main__": + main() diff --git a/samples/basics/05_configuration/README.md b/samples/basics/05_configuration/README.md new file mode 100644 index 00000000..672bce0e --- /dev/null +++ b/samples/basics/05_configuration/README.md @@ -0,0 +1,135 @@ +# Configuration + +Keep the configuration out of the code: in files that describe each +application, with defaults for all its services, settings for one service or +one method, and environment variables that override them where the +application is deployed. + +## What you will learn + +- how an application reads its configuration from a YAML file; +- how the sections of the file map to the configuration classes; +- how settings go from defaults, to one service, to one method; +- how a provider's settings reach its consumers through the registry; +- how environment variables override a file; +- how to see what the framework logs. + +## Before you start + +YAML files need the `yaml` extra, and the registry the `zookeeper` extra: + +```console +$ pip install "apache-dubbo[yaml,zookeeper]" +``` + +Start ZooKeeper, from the `samples` directory: + +```console +$ docker compose -f compose.yaml up -d --wait +``` + +## Run it + +From this directory, start the server: + +```console +$ python server.py +INFO dubbo.accesslog: ... +configuration-server serving on port 20880 +``` + +In another terminal, run the client: + +```console +$ python client.py +Hello, Alice! +Hello... Bob! +``` + +The server logs each call: + +```console +INFO dubbo.accesslog: org.apache.dubbo.samples.Greeter greet OK 0.0ms +INFO dubbo.accesslog: org.apache.dubbo.samples.Greeter greet_slowly OK 2002.5ms +``` + +Now stop the server and start it with two environment variables: + +```console +$ DUBBO__APPLICATION__NAME=renamed DUBBO__PROTOCOLS__DUBBO__PORT=20881 python server.py +renamed serving on port 20881 +``` + +## How it works + +### The file + +`Dubbo(HERE / "server.yaml")` reads the file by the parser its suffix selects: +`.yaml` or `.yml`, `.json`, or `.properties` with the `properties` extra. +Each top-level section is a configuration class of `dubbo.config`, and each +key one of its fields: + +| Section | Class | Holds | +|---|---|---| +| `application` | `ApplicationConfig` | The identity of the application | +| `protocols` | `ProtocolConfig`, by name | What the application serves on | +| `registries` | `RegistryConfig`, by name | Where it registers and discovers | +| `provider` | `ProviderConfig` | Defaults for the services it provides | +| `consumer` | `ConsumerConfig` | Defaults for the services it calls | +| `shutdown` | `ShutdownConfig` | How it stops | + +The same file in code is +`Dubbo(application=ApplicationConfig(name="configuration-server", ...), ...)`. + +### From defaults to one method + +Settings narrow in three steps. `provider` holds the defaults of every +service; `provider.services` overrides them for one service, by its name; +and `methods` under it for one method. `consumer`, `consumer.references` +and their `methods` do the same on the calling side. + +A method is named as it is called on the wire, the name that Java and Go +use too: that of the Python method, unless `@dubbo.method` gives another, +and for a contract generated from a `.proto` file, the name in the file, +such as `ExportUsers` in [08_errors_and_timeouts](../08_errors_and_timeouts). + +Here the provider allows every call 1 second, but `greet_slowly` 5. The +client sets no timeout: a consumer takes the timeout the provider registered, +and calls `greet_slowly`, which takes 2 seconds, without failing. A timeout +the consumer sets itself would take precedence. The client does set +`retries: 0` for `greet_slowly`, since a slow call is not worth making again +on another provider. + +### Environment variables + +An environment variable that starts with `DUBBO__` sets one key: `__` +separates the levels, so `DUBBO__PROTOCOLS__DUBBO__PORT` sets +`protocols.dubbo.port`. A value in JSON, such as `["a", "b"]`, sets a list or +a mapping. Keys that hold dots, such as service names, cannot be written +this way; keep them in files. + +### Layers + +The configuration is read when the application starts, in layers from low +to high: + +1. the sources passed to `Dubbo`, in order: files or mappings; +2. the configuration center, when one is configured; +3. environment variables starting with `DUBBO__`; +4. the keyword arguments of `Dubbo`, and the `url` of `refer()`. + +A higher layer overrides only the keys it sets. `app.config` holds the +result once the application has started. + +### Logging + +The framework logs through the standard `logging` module, under loggers +named `dubbo.*`, and leaves the setup to the application. `server.py` calls +`logging.basicConfig()` to see them; `accesslog: true` logs each call at +INFO under `dubbo.accesslog`. [06_logging](../06_logging) shows how to +write them as structured lines. + +## Next + +- [06_logging](../06_logging): structured logs with the trace id of each + call, written off the event loop. diff --git a/samples/basics/05_configuration/client.py b/samples/basics/05_configuration/client.py new file mode 100644 index 00000000..68dcbc21 --- /dev/null +++ b/samples/basics/05_configuration/client.py @@ -0,0 +1,43 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: client.yaml says how to find the Greeter and how to call it, +# so the code only refers to the contract. + +import asyncio +from pathlib import Path + +from dubbo import Dubbo + +from greeter import Greeter + +HERE = Path(__file__).parent + + +async def main() -> None: + app = Dubbo(HERE / "client.yaml") + greeter = app.refer(Greeter) + + async with app: + print(await greeter.greet("Alice")) + # The provider allows this method 5 seconds, and the consumer takes + # that from the registry, so the 2 seconds it takes are fine. + print(await greeter.greet_slowly("Bob")) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/05_configuration/client.yaml b/samples/basics/05_configuration/client.yaml new file mode 100644 index 00000000..e838b43b --- /dev/null +++ b/samples/basics/05_configuration/client.yaml @@ -0,0 +1,39 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The configuration of client.py. + +application: + name: configuration-client + +registries: + zookeeper: + address: zookeeper://127.0.0.1:2181 + +# Defaults for every service this application calls. +consumer: + # Further attempts on other providers after a provider cannot take a call. + retries: 1 + # How a provider is chosen for each call. + loadbalance: roundrobin + # Settings of one reference, by the name of its service, over the defaults. + references: + org.apache.dubbo.samples.Greeter: + methods: + greet_slowly: + # A slow call is not worth repeating elsewhere. + retries: 0 diff --git a/samples/basics/05_configuration/greeter.py b/samples/basics/05_configuration/greeter.py new file mode 100644 index 00000000..92581462 --- /dev/null +++ b/samples/basics/05_configuration/greeter.py @@ -0,0 +1,30 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contract of the service, with a fast method and a slow one. + +import typing + +import dubbo + + +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + async def greet(self, name: str) -> str: ... + + # Takes 2 seconds, longer than the 1 second a call may take by default. + async def greet_slowly(self, name: str) -> str: ... diff --git a/samples/basics/05_configuration/server.py b/samples/basics/05_configuration/server.py new file mode 100644 index 00000000..2f33e506 --- /dev/null +++ b/samples/basics/05_configuration/server.py @@ -0,0 +1,60 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The provider: it reads its configuration from server.yaml, which the +# environment can override. + +import asyncio +import logging +from pathlib import Path + +from dubbo import Dubbo + +from greeter import Greeter + +HERE = Path(__file__).parent + + +class GreeterImpl(Greeter): + async def greet(self, name: str) -> str: + return f"Hello, {name}!" + + async def greet_slowly(self, name: str) -> str: + await asyncio.sleep(2) + return f"Hello... {name}!" + + +async def main() -> None: + # The framework logs through the standard logging module and leaves its + # setup to the application; INFO shows the calls that accesslog logs. + logging.basicConfig(level=logging.INFO, format="%(levelname)s %(name)s: %(message)s") + + # A file as a source is read by the parser its suffix selects. + # Environment variables starting with DUBBO__ override it. + app = Dubbo(HERE / "server.yaml") + app.export(GreeterImpl()) + + async with app: + # The configuration is read when the application starts; app.config + # then holds the result of all its layers. + config = app.config + print(f"{config.application.name} serving on port {config.protocols['dubbo'].port}") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/05_configuration/server.yaml b/samples/basics/05_configuration/server.yaml new file mode 100644 index 00000000..9bdeace5 --- /dev/null +++ b/samples/basics/05_configuration/server.yaml @@ -0,0 +1,55 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The configuration of server.py. Each section is a configuration class of +# dubbo.config, such as ApplicationConfig for `application`, and each key one +# of its fields. + +application: + name: configuration-server + version: 1.0.0 + # Shown to registries and governance tools. + owner: samples + environment: develop + +protocols: + dubbo: + port: 20880 + +registries: + zookeeper: + address: zookeeper://127.0.0.1:2181 + +# Defaults for every service this application provides. +provider: + # Seconds a call may take. Consumers take it from the registry when they + # set none themselves. + timeout: 1 + # Log each call at INFO. + accesslog: true + # Settings of one service, by its name, over the defaults above. + services: + org.apache.dubbo.samples.Greeter: + methods: + greet_slowly: + timeout: 5 + +shutdown: + # Seconds the services keep serving after they leave the registries. + unregister_wait: 1 + # Seconds stopping may take in all. + grace: 10 diff --git a/samples/basics/06_logging/README.md b/samples/basics/06_logging/README.md new file mode 100644 index 00000000..d677e906 --- /dev/null +++ b/samples/basics/06_logging/README.md @@ -0,0 +1,150 @@ +# Logging + +Turn the logs of Dubbo into the ones your application wants: one JSON line +per record, with the fields of each call and the trace id it carries, +written without holding up the event loop. + +## What you will learn + +- which loggers Dubbo logs to, and how to turn them up or down; +- the fields of each line of the access log; +- how to give each record the trace id of the call it was logged in; +- how to write logs from a thread instead of the event loop; +- how to render the same records with structlog or loguru. + +## Before you start + +```console +$ pip install apache-dubbo +``` + +Rendering with structlog also needs it: + +```console +$ pip install structlog +``` + +## Run it + +From this directory, start the server: + +```console +$ python server.py +{"time": "2026-11-20T03:44:25.665+00:00", "level": "INFO", "logger": "greeter", "message": "Serving on port 20880; press Ctrl+C to stop", "trace_id": null} +``` + +In another terminal, run the client: + +```console +$ python client.py +Hello, Alice! +Hello, Bob! +``` + +The server logs a line for each greeting and one for each call, each with +the trace id that the client attached: + +```console +{"time": "...", "level": "INFO", "logger": "greeter", "message": "Greeting Alice", "user": "Alice", "trace_id": "4bf92f35"} +{"time": "...", "level": "INFO", "logger": "dubbo.accesslog", "message": "org.apache.dubbo.samples.Greeter greet OK 0.1ms", "service": "org.apache.dubbo.samples.Greeter", "group": null, "version": null, "method": "greet", "status": "OK", "duration_ms": 0.10, "trace_id": "4bf92f35"} +``` + +Start the server with `--structlog` to render the same records with +structlog. + +## How it works + +### The loggers of Dubbo + +Dubbo logs through the standard `logging` module, to loggers under `dubbo`, +and leaves their handlers to the application: whatever the application sets +up for its own records applies to those of Dubbo. A level set on a logger +applies to those under it: + +```python +logging.getLogger("dubbo").setLevel(logging.WARNING) # only what goes wrong +logging.getLogger("dubbo.registry").setLevel(logging.DEBUG) # more of one part +``` + +`accesslog=True`, of `ProviderConfig` or of one service, logs each call +that a provider serves, at INFO to `dubbo.accesslog`. + +### Fields + +Each record of the access log holds the values of its call as fields, so +that a formatter writes them as they are rather than parsing the message: + +| Field | Value | +|---|---| +| `service` | The interface, such as `org.apache.dubbo.samples.Greeter` | +| `group`, `version` | Those of the service, `None` when it has none | +| `method` | The method called | +| `status` | The name of the status the call ended with: `OK`, `NOT_FOUND`, `CANCELLED`, ... | +| `duration_ms` | How long it took, in milliseconds | + +Your own records get fields the same way, with `extra=`: +`logger.info("Greeting %s", name, extra={"user": name})`. + +`JsonFormatter` in `logs.py` writes the attributes that every record has as +`time`, `level`, `logger` and `message`, and then every other attribute +of the record: those that `extra=` and filters gave it. + +### The trace id + +`TraceIdFilter` reads the attachments of the call being served with +`dubbo.incoming()`, and gives each record the `trace-id` the caller attached. +It runs on the handler, in the code that logs, and so inside the call; the +records of the access log are logged inside the call too. Outside a call, +the trace id is `None`. + +### Off the event loop + +A handler that writes to a terminal or a file writes as the code logs, and a +slow write holds up every call that the event loop runs. `logs.configure()` +puts a `QueueHandler` in front instead: it formats each record and puts it +on a queue, and a `QueueListener` writes the queue from a thread of its own. +Stop the listener at exit, so that it writes what the queue still holds. + +Formatting still happens in the code that logs, and the filter must run +there to see the call; keep both cheap. When the access log is too much at +full load, turn `dubbo.accesslog` down to WARNING, or give the handler a +filter that keeps one record in a hundred. + +### structlog + +`structlog_logs.py` renders the same records with structlog's +`ProcessorFormatter`, which formats the records of the logging module, those +of Dubbo among them, as it formats its own; `ExtraAdder` adds their fields. +It takes the place of `JsonFormatter`, behind the same queue and filter. + +### loguru + +loguru receives the records of the logging module through a handler that +passes each on, with its fields bound: + +```python +from loguru import logger + +import logs + + +class InterceptHandler(logging.Handler): + def emit(self, record: logging.LogRecord) -> None: + fields = {key: value for key, value in vars(record).items() if key not in logs._STANDARD} + logger.bind(**fields).opt(exception=record.exc_info).log(record.levelname, record.getMessage()) + + +handler = InterceptHandler() +handler.addFilter(logs.TraceIdFilter()) +logging.basicConfig(level=logging.INFO, handlers=[handler]) +logger.remove() +logger.add(sys.stderr, serialize=True, enqueue=True) +``` + +`serialize=True` writes JSON with the fields under `extra`, and +`enqueue=True` writes from a thread, as the queue above does. + +## Next + +- [07_graceful_shutdown](../07_graceful_shutdown): open resources with the + application, and stop without losing calls. diff --git a/samples/basics/06_logging/client.py b/samples/basics/06_logging/client.py new file mode 100644 index 00000000..3c089226 --- /dev/null +++ b/samples/basics/06_logging/client.py @@ -0,0 +1,39 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: it attaches a trace id to each call. + +import asyncio + +import dubbo +from dubbo import Dubbo + +from greeter import Greeter + + +async def main() -> None: + app = Dubbo() + greeter = app.refer(Greeter, url="dubbo://127.0.0.1:20880") + + async with app: + for trace_id, name in [("4bf92f35", "Alice"), ("a3ce929d", "Bob")]: + with dubbo.outgoing({"trace-id": trace_id}): + print(await greeter.greet(name)) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/06_logging/greeter.py b/samples/basics/06_logging/greeter.py new file mode 100644 index 00000000..c7176245 --- /dev/null +++ b/samples/basics/06_logging/greeter.py @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contract of the service: the server implements it, the client calls it. + +import typing + +import dubbo + + +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + async def greet(self, name: str) -> str: ... diff --git a/samples/basics/06_logging/logs.py b/samples/basics/06_logging/logs.py new file mode 100644 index 00000000..2be505a2 --- /dev/null +++ b/samples/basics/06_logging/logs.py @@ -0,0 +1,74 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Logging set up as the application wants it: a JSON line for each record, +# with the trace id of the call it was logged in, written by a thread so that +# writing never holds up the event loop. + +import datetime +import json +import logging +import logging.handlers +import queue + +import dubbo + +# The attributes that every record has; any other was given by extra= or by a +# filter, and is a field of the line. +_STANDARD = {*vars(logging.makeLogRecord({})), "message", "asctime"} + + +class JsonFormatter(logging.Formatter): + """Formats a record as one line of JSON, with each of its fields.""" + + def format(self, record: logging.LogRecord) -> str: + line = { + "time": datetime.datetime.fromtimestamp(record.created, datetime.UTC).isoformat(timespec="milliseconds"), + "level": record.levelname, + "logger": record.name, + "message": record.getMessage(), + } + line.update((key, value) for key, value in vars(record).items() if key not in _STANDARD) + if record.exc_info: + line["exception"] = self.formatException(record.exc_info) + return json.dumps(line, default=str) + + +class TraceIdFilter(logging.Filter): + """Gives each record the trace id that the caller attached, or None outside a call.""" + + def filter(self, record: logging.LogRecord) -> bool: + try: + record.trace_id = dubbo.incoming().attachments.get("trace-id") + except LookupError: + record.trace_id = None + return True + + +def configure(formatter: logging.Formatter) -> logging.handlers.QueueListener: + """Send every record to standard error through a queue, and return the listener to stop at exit.""" + # The queue handler runs in the thread that logs: its filter still sees + # the call there, and it formats the record, so that the thread of the + # listener only writes the line. + handler = logging.handlers.QueueHandler(queue.SimpleQueue()) + handler.addFilter(TraceIdFilter()) + handler.setFormatter(formatter) + logging.basicConfig(level=logging.INFO, handlers=[handler]) + + listener = logging.handlers.QueueListener(handler.queue, logging.StreamHandler()) + listener.start() + return listener diff --git a/samples/basics/06_logging/server.py b/samples/basics/06_logging/server.py new file mode 100644 index 00000000..0f892b0a --- /dev/null +++ b/samples/basics/06_logging/server.py @@ -0,0 +1,71 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The provider: it logs each greeting, and Dubbo logs each call it serves. + +import argparse +import asyncio +import logging + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig, ProviderConfig + +import logs +from greeter import Greeter + +logger = logging.getLogger("greeter") + + +class GreeterImpl(Greeter): + async def greet(self, name: str) -> str: + # extra= gives the record fields of its own, as Dubbo gives those of + # each call to the records of its access log. + logger.info("Greeting %s", name, extra={"user": name}) + return f"Hello, {name}!" + + +async def main() -> None: + app = Dubbo( + application=ApplicationConfig(name="logging-server"), + protocols={"dubbo": ProtocolConfig(port=20880)}, + # accesslog logs each call that the services serve, at INFO to the + # dubbo.accesslog logger. + provider=ProviderConfig(accesslog=True), + ) + app.export(GreeterImpl()) + + async with app: + logger.info("Serving on port 20880; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--structlog", action="store_true", help="render the lines with structlog") + if parser.parse_args().structlog: + import structlog_logs + + formatter = structlog_logs.formatter() + else: + formatter = logs.JsonFormatter() + + listener = logs.configure(formatter) + try: + asyncio.run(main()) + finally: + # Writes what the queue still holds. + listener.stop() diff --git a/samples/basics/06_logging/structlog_logs.py b/samples/basics/06_logging/structlog_logs.py new file mode 100644 index 00000000..c853910c --- /dev/null +++ b/samples/basics/06_logging/structlog_logs.py @@ -0,0 +1,41 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The same lines rendered by structlog, which formats records of the standard +# logging module as it formats its own. + +import logging + +import structlog + + +def formatter() -> logging.Formatter: + return structlog.stdlib.ProcessorFormatter( + # These run on each record logged through the logging module, such as + # those of Dubbo: ExtraAdder adds the fields of the record. + foreign_pre_chain=[ + structlog.processors.TimeStamper(fmt="iso", utc=True), + structlog.stdlib.add_log_level, + structlog.stdlib.add_logger_name, + structlog.stdlib.ExtraAdder(), + ], + processors=[ + structlog.stdlib.ProcessorFormatter.remove_processors_meta, + structlog.processors.format_exc_info, + structlog.processors.JSONRenderer(), + ], + ) diff --git a/samples/basics/07_graceful_shutdown/README.md b/samples/basics/07_graceful_shutdown/README.md new file mode 100644 index 00000000..90231f9a --- /dev/null +++ b/samples/basics/07_graceful_shutdown/README.md @@ -0,0 +1,76 @@ +# Graceful shutdown + +A provider usually holds resources for its services, such as a database +pool, and must stop without failing the calls it is serving. This sample +opens a resource with the application and stops while a call runs. + +## What you will learn + +- how `lifespan` opens and closes what the services use, such as a service + that is an async context manager itself; +- what the application does when it stops; +- how `shutdown.grace` bounds stopping. + +## Run it + +From this directory, start the server: + +```console +$ python server.py +Database opened +Serving on port 20880; press Ctrl+C to stop +``` + +In another terminal, run the client. Its call takes 5 seconds; press Ctrl+C +in the server window while it runs: + +```console +$ python client.py +Calling; press Ctrl+C in the server window now +Hello, Dr. Watson! +``` + +The server finishes the call before it closes the database: + +```console +Greeting Watson... +Stopping; running calls finish first +Greeted Watson +Database closed +Stopped +``` + +## How it works + +`Dubbo(..., lifespan=...)` takes a function that returns an async context +manager. The application enters it once it is ready and before the services +serve, and exits it after they have stopped serving, so services can rely on +what it opens for every call. + +Here the service itself is that context manager: `GreeterImpl` opens its +database in `__aenter__` and closes it in `__aexit__`, and `lifespan` returns +it. A function decorated with `contextlib.asynccontextmanager` works as well, +and suits a lifespan that opens several resources for several services. +While the lifespan enters, the references of the application can already +call other applications. + +Ctrl+C or SIGTERM ends `serve_forever()`. Leaving `async with app` then stops +the application in order: + +1. it leaves the registries, and keeps serving for `shutdown.unregister_wait` + seconds, 3 by default, so that consumers turn to other providers; without + registries, as here, there is nothing to wait for; +2. it takes no new calls and waits for the running ones; +3. it exits the lifespan and closes its connections. + +All of it takes at most `shutdown.grace` seconds, 10 by default and 15 here; +what still runs then is cancelled. A second Ctrl+C, or cancelling the task +that runs the application, stops at once. + +The client sets `consumer.timeout` to 10 seconds, because a call may take 1 +second by default and this one takes 5. + +## Next + +- [08_errors_and_timeouts](../08_errors_and_timeouts): handle failed calls, + timeouts and retries. diff --git a/samples/basics/07_graceful_shutdown/client.py b/samples/basics/07_graceful_shutdown/client.py new file mode 100644 index 00000000..2b438009 --- /dev/null +++ b/samples/basics/07_graceful_shutdown/client.py @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: it makes a call that takes 5 seconds. Stop the server while +# the call runs: the call still succeeds. + +import asyncio + +from dubbo import Dubbo +from dubbo.config import ConsumerConfig + +from greeter import Greeter + + +async def main() -> None: + # A call may take 10 seconds here, instead of 1 by default. + app = Dubbo(consumer=ConsumerConfig(timeout=10)) + greeter = app.refer(Greeter, url="dubbo://127.0.0.1:20880") + + async with app: + print("Calling; press Ctrl+C in the server window now") + print(await greeter.greet("Watson")) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/07_graceful_shutdown/greeter.py b/samples/basics/07_graceful_shutdown/greeter.py new file mode 100644 index 00000000..499f36f4 --- /dev/null +++ b/samples/basics/07_graceful_shutdown/greeter.py @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contract of the service: the server implements it, the client calls it. +# Both sides import this module, so they agree on the methods and their types. + +import typing + +import dubbo + + +# The name identifies the service on the wire and in registries. Java and Go +# services use the same kind of name, usually that of a Java interface. +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + # Every method is async. Its type hints say what travels on the wire: + # here a str goes in and a str comes back. + async def greet(self, name: str) -> str: ... diff --git a/samples/basics/07_graceful_shutdown/server.py b/samples/basics/07_graceful_shutdown/server.py new file mode 100644 index 00000000..e0ed62e9 --- /dev/null +++ b/samples/basics/07_graceful_shutdown/server.py @@ -0,0 +1,93 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The provider: its service opens a database when the application starts, +# and on Ctrl+C lets the running calls finish before it closes the database. + +import asyncio +from types import TracebackType +from typing import Self + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig, ShutdownConfig + +from greeter import Greeter + + +class Database: + """Stands for a resource that the service uses, such as a connection pool.""" + + @classmethod + async def connect(cls) -> "Database": + print("Database opened") + return cls() + + async def close(self) -> None: + print("Database closed") + + async def find_title(self, name: str) -> str: + await asyncio.sleep(5) # A slow query. + return "Dr." if name == "Watson" else "Mx." + + +class GreeterImpl(Greeter): + """A service that holds a database, opened and closed as an async context manager.""" + + async def __aenter__(self) -> Self: + self.database = await Database.connect() + return self + + async def __aexit__( + self, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None + ) -> None: + await self.database.close() + + async def greet(self, name: str) -> str: + print(f"Greeting {name}...") + title = await self.database.find_title(name) + print(f"Greeted {name}") + return f"Hello, {title} {name}!" + + +async def main() -> None: + greeter = GreeterImpl() + + # lifespan returns an async context manager, here the service itself. The + # application enters it once it is ready and before the services serve, + # and exits it after they have stopped serving, so the database is open + # for every call. + app = Dubbo( + application=ApplicationConfig(name="graceful-shutdown-server"), + protocols={"dubbo": ProtocolConfig(port=20880)}, + # Stopping may take 15 seconds in all; what still runs then is cancelled. + shutdown=ShutdownConfig(grace=15), + lifespan=lambda app: greeter, + ) + app.export(greeter) + + async with app: + print("Serving on port 20880; press Ctrl+C to stop") + await app.serve_forever() + # Ctrl+C or SIGTERM ends serve_forever(). Leaving the block then stops + # the application: it takes no new calls, waits for the running ones, + # and exits the lifespan. A second Ctrl+C stops at once. + print("Stopping; running calls finish first") + print("Stopped") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/08_errors_and_timeouts/README.md b/samples/basics/08_errors_and_timeouts/README.md new file mode 100644 index 00000000..0573d03e --- /dev/null +++ b/samples/basics/08_errors_and_timeouts/README.md @@ -0,0 +1,84 @@ +# Errors, timeouts and retries + +Calls fail: the request is wrong, the data is missing, the provider is busy +or slow. This sample fails calls in each of these ways and handles them. + +## What you will learn + +- how a provider fails a call with a status; +- how a consumer tells failures apart by their status; +- which failures are attempted again, and which are not; +- how to set timeouts per method, and bound a call further. + +## Run it + +From this directory, start the server: + +```console +$ python server.py +Serving on port 50051; press Ctrl+C to stop +``` + +In another terminal, run the client: + +```console +$ python client.py +User 1: Alice +User 2: Bob +No user 42 +Failed: INVALID_ARGUMENT: a user ID is not negative: -1 +Exported 2 users +Gave up exporting after 1 second +``` + +The server prints the attempts it rejected as too busy. + +## How it works + +### Failing a call + +A handler fails its call by raising `dubbo.RpcError` with a `Status`, the +codes gRPC defines, such as `NOT_FOUND` or `INVALID_ARGUMENT`, and a message. +The caller receives an `RpcError` of the same status and message, and checks +`error.status` to decide what to do. Any other exception that a handler +raises reaches the caller as `UNKNOWN`, and the provider logs it with its +traceback. + +### Retries + +Each call goes through a cluster, `failover` by default. When an attempt +fails with `UNAVAILABLE`, meaning that the provider could not take the call, +the cluster attempts it again, on another provider when there is one, up +to `retries` more times, 2 by default. Here the only provider rejects every +other attempt, and every call still succeeds. + +Other statuses are not attempted again: the provider did take the call, and +it may have done part of the work. `DEADLINE_EXCEEDED` is not attempted +again either. + +### Timeouts + +A unary call may take 1 second by default; past that it fails with +`DEADLINE_EXCEEDED`. The client gives `ExportUsers` 5 seconds with a +`MethodConfig` in the `ReferenceConfig` it gives `refer`, keyed by the name +of the method in the proto file. The +timeout also applies per service, per reference or to all references, in +code or in [configuration files](../05_configuration). + +`anyio.fail_after()` bounds the calls in its block further. Over Triple its +deadline travels with the call, so the provider stops working on a call +that its caller has given up on. + +### Statuses and other languages + +Over Triple, statuses are those of gRPC, and Java, Go and gRPC programs read +them as such. Over the Dubbo protocol, an `RpcError` travels as a Java +`org.apache.dubbo.rpc.RpcException`, which has codes for only some +statuses; the others arrive as `UNKNOWN`, with their message, in Python +consumers too. A service whose callers tell failures apart by their status +is served over Triple. + +## Next + +- [09_context](../09_context): send data along with calls, such as a trace + ID or a user. diff --git a/samples/basics/08_errors_and_timeouts/client.py b/samples/basics/08_errors_and_timeouts/client.py new file mode 100644 index 00000000..3c9c3326 --- /dev/null +++ b/samples/basics/08_errors_and_timeouts/client.py @@ -0,0 +1,75 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: it handles each way a call fails. + +import asyncio + +import anyio +from dubbo import Dubbo, RpcError, Status +from dubbo.config import MethodConfig, ReferenceConfig + +from users_dubbo import Users +from users_pb2 import ExportUsersRequest, GetUserRequest + + +async def main() -> None: + # A call may take 1 second by default. ExportUsers is known to be slow, + # so the reference gives it 5 seconds, by the name of the method in the + # proto file. + app = Dubbo() + users = app.refer( + Users, + url="tri://127.0.0.1:50051", + config=ReferenceConfig(methods={"ExportUsers": MethodConfig(timeout=5)}), + ) + + async with app: + # The provider rejects every other attempt as UNAVAILABLE, and the + # failover cluster attempts the call again, up to 2 more times by + # default, so these calls succeed. + for user_id in [1, 2]: + user = await users.get_user(GetUserRequest(id=user_id)) + print(f"User {user.id}: {user.name}") + + # Other statuses are not attempted again: they reach the caller as + # RpcError, whose status says what went wrong. + for user_id in [42, -1]: + try: + await users.get_user(GetUserRequest(id=user_id)) + except RpcError as error: + if error.status == Status.NOT_FOUND: + print(f"No user {user_id}") + else: + print(f"Failed: {error.status.name}: {error.message}") + + # Within its 5 seconds, the slow call succeeds. + reply = await users.export_users(ExportUsersRequest()) + print(f"Exported {reply.count} users") + + # anyio.fail_after() bounds the calls in its block further. Over Triple + # its deadline travels with the call, so the provider stops working on + # a call that its caller has given up on. + try: + with anyio.fail_after(1): + await users.export_users(ExportUsersRequest()) + except TimeoutError: + print("Gave up exporting after 1 second") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/08_errors_and_timeouts/server.py b/samples/basics/08_errors_and_timeouts/server.py new file mode 100644 index 00000000..ec861e19 --- /dev/null +++ b/samples/basics/08_errors_and_timeouts/server.py @@ -0,0 +1,66 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The provider: it fails calls on purpose, in the ways a real service does. + +import asyncio + +from dubbo import Dubbo, RpcError, Status +from dubbo.config import ApplicationConfig + +from users_dubbo import UsersServicer +from users_pb2 import ExportUsersReply, ExportUsersRequest, GetUserRequest, User + +USERS = {1: "Alice", 2: "Bob"} + + +class UsersImpl(UsersServicer): + def __init__(self) -> None: + self.calls = 0 + + async def get_user(self, request: GetUserRequest) -> User: + # Every other call finds the service too busy. UNAVAILABLE tells the + # caller that another attempt, maybe on another provider, may work. + self.calls += 1 + if self.calls % 2 == 1: + print(f"Rejecting call {self.calls}: too busy") + raise RpcError(Status.UNAVAILABLE, "too busy, try again") + + # Raising RpcError fails the call with that status and message; the + # caller receives an RpcError of the same status. + if request.id < 0: + raise RpcError(Status.INVALID_ARGUMENT, f"a user ID is not negative: {request.id}") + if request.id not in USERS: + raise RpcError(Status.NOT_FOUND, f"no user has ID {request.id}") + return User(id=request.id, name=USERS[request.id]) + + async def export_users(self, request: ExportUsersRequest) -> ExportUsersReply: + await asyncio.sleep(3) + return ExportUsersReply(count=len(USERS)) + + +async def main() -> None: + app = Dubbo(application=ApplicationConfig(name="errors-server")) + app.export(UsersImpl()) + + async with app: + print("Serving on port 50051; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/08_errors_and_timeouts/users.proto b/samples/basics/08_errors_and_timeouts/users.proto new file mode 100644 index 00000000..4fde3a7f --- /dev/null +++ b/samples/basics/08_errors_and_timeouts/users.proto @@ -0,0 +1,43 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +syntax = "proto3"; + +package org.apache.dubbo.samples; + +// Looks users up. +service Users { + // Fails with NOT_FOUND for an unknown ID, INVALID_ARGUMENT for a negative one. + rpc GetUser (GetUserRequest) returns (User); + // Takes 3 seconds. + rpc ExportUsers (ExportUsersRequest) returns (ExportUsersReply); +} + +message GetUserRequest { + int64 id = 1; +} + +message User { + int64 id = 1; + string name = 2; +} + +message ExportUsersRequest {} + +message ExportUsersReply { + int32 count = 1; +} diff --git a/samples/basics/08_errors_and_timeouts/users_dubbo.py b/samples/basics/08_errors_and_timeouts/users_dubbo.py new file mode 100644 index 00000000..48ea27b9 --- /dev/null +++ b/samples/basics/08_errors_and_timeouts/users_dubbo.py @@ -0,0 +1,40 @@ +# Generated by protoc-gen-python-dubbo. DO NOT EDIT! +# source: users.proto +"""Dubbo service contracts of users.proto.""" + +import abc +import typing + +import dubbo + +import users_pb2 + +__all__ = ["Users", "UsersServicer"] + + +@dubbo.service("org.apache.dubbo.samples.Users") +class Users(typing.Protocol): + """Looks users up.""" + + @dubbo.method("GetUser") + async def get_user(self, request: users_pb2.GetUserRequest) -> users_pb2.User: + """Fails with NOT_FOUND for an unknown ID, INVALID_ARGUMENT for a negative one.""" + + @dubbo.method("ExportUsers") + async def export_users(self, request: users_pb2.ExportUsersRequest) -> users_pb2.ExportUsersReply: + """Takes 3 seconds.""" + + +@dubbo.service("org.apache.dubbo.samples.Users") +class UsersServicer(abc.ABC): + """Looks users up.""" + + @dubbo.method("GetUser") + @abc.abstractmethod + async def get_user(self, request: users_pb2.GetUserRequest) -> users_pb2.User: + """Fails with NOT_FOUND for an unknown ID, INVALID_ARGUMENT for a negative one.""" + + @dubbo.method("ExportUsers") + @abc.abstractmethod + async def export_users(self, request: users_pb2.ExportUsersRequest) -> users_pb2.ExportUsersReply: + """Takes 3 seconds.""" diff --git a/samples/basics/08_errors_and_timeouts/users_pb2.py b/samples/basics/08_errors_and_timeouts/users_pb2.py new file mode 100644 index 00000000..d6121734 --- /dev/null +++ b/samples/basics/08_errors_and_timeouts/users_pb2.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: users.proto +# Protobuf Python Version: 7.35.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 7, + 35, + 1, + '', + 'users.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0busers.proto\x12\x18org.apache.dubbo.samples\"\x1c\n\x0eGetUserRequest\x12\n\n\x02id\x18\x01 \x01(\x03\" \n\x04User\x12\n\n\x02id\x18\x01 \x01(\x03\x12\x0c\n\x04name\x18\x02 \x01(\t\"\x14\n\x12\x45xportUsersRequest\"!\n\x10\x45xportUsersReply\x12\r\n\x05\x63ount\x18\x01 \x01(\x05\x32\xc5\x01\n\x05Users\x12S\n\x07GetUser\x12(.org.apache.dubbo.samples.GetUserRequest\x1a\x1e.org.apache.dubbo.samples.User\x12g\n\x0b\x45xportUsers\x12,.org.apache.dubbo.samples.ExportUsersRequest\x1a*.org.apache.dubbo.samples.ExportUsersReplyb\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'users_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + DESCRIPTOR._loaded_options = None + _globals['_GETUSERREQUEST']._serialized_start=41 + _globals['_GETUSERREQUEST']._serialized_end=69 + _globals['_USER']._serialized_start=71 + _globals['_USER']._serialized_end=103 + _globals['_EXPORTUSERSREQUEST']._serialized_start=105 + _globals['_EXPORTUSERSREQUEST']._serialized_end=125 + _globals['_EXPORTUSERSREPLY']._serialized_start=127 + _globals['_EXPORTUSERSREPLY']._serialized_end=160 + _globals['_USERS']._serialized_start=163 + _globals['_USERS']._serialized_end=360 +# @@protoc_insertion_point(module_scope) diff --git a/samples/basics/08_errors_and_timeouts/users_pb2.pyi b/samples/basics/08_errors_and_timeouts/users_pb2.pyi new file mode 100644 index 00000000..49c49b01 --- /dev/null +++ b/samples/basics/08_errors_and_timeouts/users_pb2.pyi @@ -0,0 +1,29 @@ +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from typing import ClassVar as _ClassVar, Optional as _Optional + +DESCRIPTOR: _descriptor.FileDescriptor + +class GetUserRequest(_message.Message): + __slots__ = ("id",) + ID_FIELD_NUMBER: _ClassVar[int] + id: int + def __init__(self, id: _Optional[int] = ...) -> None: ... + +class User(_message.Message): + __slots__ = ("id", "name") + ID_FIELD_NUMBER: _ClassVar[int] + NAME_FIELD_NUMBER: _ClassVar[int] + id: int + name: str + def __init__(self, id: _Optional[int] = ..., name: _Optional[str] = ...) -> None: ... + +class ExportUsersRequest(_message.Message): + __slots__ = () + def __init__(self) -> None: ... + +class ExportUsersReply(_message.Message): + __slots__ = ("count",) + COUNT_FIELD_NUMBER: _ClassVar[int] + count: int + def __init__(self, count: _Optional[int] = ...) -> None: ... diff --git a/samples/basics/09_context/README.md b/samples/basics/09_context/README.md new file mode 100644 index 00000000..28c4f6bf --- /dev/null +++ b/samples/basics/09_context/README.md @@ -0,0 +1,83 @@ +# Context + +Some data belongs to a whole request rather than to one method: a trace ID, +the user it acts for, a tenant. Attachments carry it beside the arguments, +as headers do in HTTP, along a chain of services. This sample sends a trace +ID and a user through two services. + +## What you will learn + +- how a consumer attaches data to its calls with `dubbo.outgoing()`; +- how a provider reads the call it serves with `dubbo.incoming()`; +- how attachments pass along a chain of calls on their own; +- how a provider attaches data to its reply. + +## The files + +| File | Role | +|---|---| +| `services.py` | The contracts of the two services | +| `inventory_server.py` | The inventory provider, on port 20881 | +| `order_server.py` | The order provider, on port 20880, which calls the inventory | +| `client.py` | The consumer, which places an order | + +## Run it + +From this directory, start the inventory server, then the order server, each +in its own terminal: + +```console +$ python inventory_server.py +Serving on port 20881; press Ctrl+C to stop +``` + +```console +$ python order_server.py +Serving on port 20880; press Ctrl+C to stop +``` + +Then run the client: + +```console +$ python client.py +Ordered 2 x book +Served by order-server +``` + +Both servers print the trace ID and the user, though only the client set +them: + +```console +[trace 4bf92f35] Order from alice at 127.0.0.1:49515 +``` + +```console +[trace 4bf92f35] Reserving 2 x book for alice +``` + +## How it works + +`with dubbo.outgoing({...}) as call:` adds attachments to every call made in +the block. Keys are text; values are printable ASCII text, or bytes under a +key that ends in `-bin`. After the block, `call.response_attachments` holds +what the provider of the last call attached to its reply. + +In a handler, `dubbo.incoming()` returns the call being served: +`attachments` holds what the caller sent, `peer` where it called from, and +`response_attachments` what goes back with the reply. + +While a handler serves a call, the calls it makes send on the attachments +it received, so the trace ID reaches the inventory service without the order +service passing it. Attachments that concern one call only are not passed +on: the identity of the service called, `timeout`, `token`, `dubbo.tag`, and +HTTP fields such as `authorization`. `dubbo.outgoing(..., inherit=False)` +starts a block from nothing. + +Attachments are part of the Dubbo protocols, so Java and Go services read and +send them too: they are what Dubbo Java calls the attachments of +`RpcContext`, and over Triple they travel as gRPC metadata. + +## Next + +- [10_group_version](../10_group_version): run several versions of a service + side by side. diff --git a/samples/basics/09_context/client.py b/samples/basics/09_context/client.py new file mode 100644 index 00000000..4c33c788 --- /dev/null +++ b/samples/basics/09_context/client.py @@ -0,0 +1,44 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: it attaches a trace ID and a user to its call, and reads what +# the order service attached to its reply. + +import asyncio + +import dubbo +from dubbo import Dubbo + +from services import Orders + + +async def main() -> None: + app = Dubbo() + orders = app.refer(Orders, url="dubbo://127.0.0.1:20880") + + async with app: + # Every call in the block sends these attachments: key-value pairs + # that travel beside the arguments, as headers do in HTTP. + with dubbo.outgoing({"trace-id": "4bf92f35", "user": "alice"}) as call: + print(await orders.place_order("book", 2)) + + # The last call of the block leaves the attachments of its reply. + print(f"Served by {call.response_attachments['served-by']}") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/09_context/inventory_server.py b/samples/basics/09_context/inventory_server.py new file mode 100644 index 00000000..c17f4628 --- /dev/null +++ b/samples/basics/09_context/inventory_server.py @@ -0,0 +1,51 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The inventory provider, at the end of the chain. + +import asyncio + +import dubbo +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig + +from services import Inventory + + +class InventoryImpl(Inventory): + async def reserve(self, item: str, quantity: int) -> bool: + # The attachments arrived from the order service, which did not set + # them: it passed on those it received from the client. + attachments = dubbo.incoming().attachments + print(f"[trace {attachments['trace-id']}] Reserving {quantity} x {item} for {attachments['user']}") + return True + + +async def main() -> None: + app = Dubbo( + application=ApplicationConfig(name="inventory-server"), + protocols={"dubbo": ProtocolConfig(port=20881)}, + ) + app.export(InventoryImpl()) + + async with app: + print("Serving on port 20881; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/09_context/order_server.py b/samples/basics/09_context/order_server.py new file mode 100644 index 00000000..8bf0c645 --- /dev/null +++ b/samples/basics/09_context/order_server.py @@ -0,0 +1,63 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The order provider: it serves the client and calls the inventory service. + +import asyncio + +import dubbo +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig + +from services import Inventory, Orders + + +class OrdersImpl(Orders): + def __init__(self, inventory: Inventory) -> None: + self.inventory = inventory + + async def place_order(self, item: str, quantity: int) -> str: + # dubbo.incoming() is the call this handler serves: the attachments + # the caller sent, where it calls from, and the attachments to send + # back. + call = dubbo.incoming() + print(f"[trace {call.attachments['trace-id']}] Order from {call.attachments['user']} at {call.peer}") + + # Calls made while serving a call send on the attachments it received, + # so the trace ID and the user reach the inventory service unasked. + if not await self.inventory.reserve(item, quantity): + return "Out of stock" + + call.response_attachments["served-by"] = "order-server" + return f"Ordered {quantity} x {item}" + + +async def main() -> None: + app = Dubbo( + application=ApplicationConfig(name="order-server"), + protocols={"dubbo": ProtocolConfig(port=20880)}, + ) + inventory = app.refer(Inventory, url="dubbo://127.0.0.1:20881") + app.export(OrdersImpl(inventory)) + + async with app: + print("Serving on port 20880; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/09_context/services.py b/samples/basics/09_context/services.py new file mode 100644 index 00000000..c9295322 --- /dev/null +++ b/samples/basics/09_context/services.py @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contracts of two services: an order service that calls an inventory +# service, so that context passes along a chain of calls. + +import typing + +import dubbo + + +@dubbo.service("org.apache.dubbo.samples.Orders") +class Orders(typing.Protocol): + async def place_order(self, item: str, quantity: int) -> str: ... + + +@dubbo.service("org.apache.dubbo.samples.Inventory") +class Inventory(typing.Protocol): + async def reserve(self, item: str, quantity: int) -> bool: ... diff --git a/samples/basics/10_group_version/README.md b/samples/basics/10_group_version/README.md new file mode 100644 index 00000000..eb5ea5d8 --- /dev/null +++ b/samples/basics/10_group_version/README.md @@ -0,0 +1,75 @@ +# Group and version + +One service may run in several forms at once: a new version beside the old +one while consumers move over, or one implementation per tenant or region. +The version and the group tell them apart. This sample runs two versions of +a service side by side. + +## What you will learn + +- how a provider registers a version of its services; +- how a consumer chooses the version it calls; +- what groups are for. + +## Before you start + +```console +$ pip install "apache-dubbo[zookeeper]" +$ docker compose -f ../../compose.yaml up -d --wait +``` + +## Run it + +From this directory, start both versions, each in its own terminal: + +```console +$ python server_v1.py +Serving version 1.0.0 on port 20880; press Ctrl+C to stop +``` + +```console +$ python server_v2.py +Serving version 2.0.0 on port 20881; press Ctrl+C to stop +``` + +Then call each version: + +```console +$ python client.py +Version 1.0.0: Hello, Alice! +$ python client.py 2.0.0 +Version 2.0.0: Good to see you, Alice! +``` + +A version that no provider registered fails at start: + +```console +$ python client.py 3.0.0 +dubbo.exceptions.RpcError: UNAVAILABLE: no provider of org.apache.dubbo.samples.Greeter is available; set check to false to start without one +``` + +## How it works + +A service is identified by its name, its group and its version together. +`ProviderConfig(version=...)` sets the version of every service of a +provider, and `ServiceConfig(version=...)`, given to `export`, that of one +service. A consumer sets the version it calls with +`ConsumerConfig(version=...)`, or `ReferenceConfig(version=...)`, given to +`refer`, for one service, and discovers only the providers of that version. + +So version 2.0.0 can be deployed while every consumer still calls 1.0.0, +then consumers move to it one by one, and version 1.0.0 stops once none +calls it. + +The group works the same way, with `group=` beside `version=`, and keeps +apart implementations of one contract that are not versions of each other, +such as one per region or per tenant, or one for tests. + +An application refers to a service once, so one application calls one +version of it. Over Triple, the group and the version travel with each call +in the `tri-service-group` and `tri-service-version` headers. + +## Next + +- [11_load_balancing](../11_load_balancing): choose how calls spread across + providers, and what happens when one fails. diff --git a/samples/basics/10_group_version/client.py b/samples/basics/10_group_version/client.py new file mode 100644 index 00000000..1793bb43 --- /dev/null +++ b/samples/basics/10_group_version/client.py @@ -0,0 +1,49 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: it calls the version of the Greeter named on its command +# line, 1.0.0 by default: +# +# python client.py +# python client.py 2.0.0 + +import asyncio +import sys + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ConsumerConfig, RegistryConfig + +from greeter import Greeter + + +async def main(version: str) -> None: + # ConsumerConfig(version=...) applies to every reference of the + # application; app.refer(Greeter, config=ReferenceConfig(version=...)) + # would choose it for one service only. + app = Dubbo( + application=ApplicationConfig(name="group-version-client"), + registries={"default": RegistryConfig(address="zookeeper://127.0.0.1:2181")}, + consumer=ConsumerConfig(version=version), + ) + greeter = app.refer(Greeter) + + async with app: + print(f"Version {version}:", await greeter.greet("Alice")) + + +if __name__ == "__main__": + asyncio.run(main(sys.argv[1] if len(sys.argv) > 1 else "1.0.0")) diff --git a/samples/basics/10_group_version/greeter.py b/samples/basics/10_group_version/greeter.py new file mode 100644 index 00000000..499f36f4 --- /dev/null +++ b/samples/basics/10_group_version/greeter.py @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contract of the service: the server implements it, the client calls it. +# Both sides import this module, so they agree on the methods and their types. + +import typing + +import dubbo + + +# The name identifies the service on the wire and in registries. Java and Go +# services use the same kind of name, usually that of a Java interface. +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + # Every method is async. Its type hints say what travels on the wire: + # here a str goes in and a str comes back. + async def greet(self, name: str) -> str: ... diff --git a/samples/basics/10_group_version/server_v1.py b/samples/basics/10_group_version/server_v1.py new file mode 100644 index 00000000..6b7a3543 --- /dev/null +++ b/samples/basics/10_group_version/server_v1.py @@ -0,0 +1,54 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Version 1.0.0 of the Greeter, which consumers have called so far. + +import asyncio + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig, ProviderConfig, RegistryConfig + +from greeter import Greeter + +VERSION = "1.0.0" +PORT = 20880 + + +class GreeterImpl(Greeter): + async def greet(self, name: str) -> str: + return f"Hello, {name}!" + + +async def main() -> None: + # The version, like the group, is part of the identity of the services + # the provider registers: consumers find a provider by name, group and + # version together. + app = Dubbo( + application=ApplicationConfig(name=f"greeter-v{VERSION}"), + protocols={"dubbo": ProtocolConfig(port=PORT)}, + registries={"default": RegistryConfig(address="zookeeper://127.0.0.1:2181")}, + provider=ProviderConfig(version=VERSION), + ) + app.export(GreeterImpl()) + + async with app: + print(f"Serving version {VERSION} on port {PORT}; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/10_group_version/server_v2.py b/samples/basics/10_group_version/server_v2.py new file mode 100644 index 00000000..e96bf966 --- /dev/null +++ b/samples/basics/10_group_version/server_v2.py @@ -0,0 +1,55 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Version 2.0.0 of the Greeter, which greets differently. It runs beside +# version 1.0.0, and only consumers that ask for it call it. + +import asyncio + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig, ProviderConfig, RegistryConfig + +from greeter import Greeter + +VERSION = "2.0.0" +PORT = 20881 + + +class GreeterImpl(Greeter): + async def greet(self, name: str) -> str: + return f"Good to see you, {name}!" + + +async def main() -> None: + # The version, like the group, is part of the identity of the services + # the provider registers: consumers find a provider by name, group and + # version together. + app = Dubbo( + application=ApplicationConfig(name=f"greeter-v{VERSION}"), + protocols={"dubbo": ProtocolConfig(port=PORT)}, + registries={"default": RegistryConfig(address="zookeeper://127.0.0.1:2181")}, + provider=ProviderConfig(version=VERSION), + ) + app.export(GreeterImpl()) + + async with app: + print(f"Serving version {VERSION} on port {PORT}; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/11_load_balancing/README.md b/samples/basics/11_load_balancing/README.md new file mode 100644 index 00000000..15d139ee --- /dev/null +++ b/samples/basics/11_load_balancing/README.md @@ -0,0 +1,81 @@ +# Load balancing and fault tolerance + +A service usually has several providers. For each call, a load balance +chooses one of them, and a cluster decides what a failed attempt leads to. +This sample calls three providers, a fast one, a slow one and an overloaded +one, with different choices of both. + +## What you will learn + +- how to choose the load balance of a reference; +- how `roundrobin` and `leastactive` spread calls; +- how the `failover` and `failfast` clusters handle a failing provider. + +## Run it + +From this directory, start the server, which runs the three providers: + +```console +$ python server.py +Serving on ports 20880, 20881 and 20882; press Ctrl+C to stop +``` + +In another terminal, run the client: + +```console +$ python client.py +roundrobin: fast 3, slow 3 +leastactive: fast 31, slow 9 +failover: fast 6 +failfast: UNAVAILABLE 3, fast 3 +``` + +The counts of `leastactive` vary from run to run. + +## How it works + +The client lists the providers of each reference in `ReferenceConfig(urls=...)`, +given to `refer`; +with a registry, they would come from it. `loadbalance` and `cluster` are +settings of the consumer, of one reference, or, for `loadbalance`, of one +method, in code or in [configuration files](../05_configuration). + +### Load balances + +| Name | Chooses | +|---|---| +| `random` (default) | At random, in proportion to the weights of the providers | +| `roundrobin` | Each provider in turn, in proportion to their weights | +| `leastactive` | The provider with the fewest calls under way, so slow providers get fewer | +| `consistenthash` | The same provider for the same first argument, as for a cache | + +Here `roundrobin` alternates between the fast and the slow provider, while +`leastactive`, with eight calls at a time, sends most calls to the fast one: +calls finish there sooner, so it has fewer under way. + +### Clusters + +| Name | On a failed attempt | +|---|---| +| `failover` (default) | Attempts the call again on another provider, up to `retries` times, when the attempt failed as `UNAVAILABLE` | +| `failfast` | Fails the call at once | +| `failsafe` | Returns `None` instead of failing, and logs the failure | +| `failback` | Returns `None`, and makes the call again in the background | +| `forking` | Calls several providers at once and takes the first answer | +| `broadcast` | Calls every provider in turn, and fails if any fails | +| `available` | Calls the first available provider, without a load balance | +| `zone-aware` | With several registries, calls through the preferred one, or that of the zone the call names | + +Here the overloaded provider rejects every call. With `failover`, each +rejected attempt is made again on the fast provider, and every call +succeeds. With `failfast`, the calls that went to the overloaded provider +fail, and the caller handles the error. + +`failover` is right for calls that can be repeated safely, such as reads. +For a call that must not happen twice, such as a payment, use `failfast`, or +set `retries` to 0. + +## Next + +- [12_config_center](../12_config_center): keep configuration in a + configuration center, and change it while applications run. diff --git a/samples/basics/11_load_balancing/client.py b/samples/basics/11_load_balancing/client.py new file mode 100644 index 00000000..2987a362 --- /dev/null +++ b/samples/basics/11_load_balancing/client.py @@ -0,0 +1,68 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: it calls the workers with different load balances and +# clusters, and counts where the calls went. + +import asyncio +from collections import Counter + +from dubbo import Dubbo, RpcError +from dubbo.config import ReferenceConfig + +from worker import Worker + +FAST, SLOW, OVERLOADED = "dubbo://127.0.0.1:20880", "dubbo://127.0.0.1:20881", "dubbo://127.0.0.1:20882" + + +async def call(urls: tuple[str, ...], calls: int, concurrency: int = 1, **settings: str) -> Counter[str]: + """Make `calls` calls, `concurrency` at a time, and count who answered them, or how they failed.""" + # The reference calls the providers its urls name. An application refers + # to a service once, so each setting gets an application of its own here. + app = Dubbo() + worker = app.refer(Worker, config=ReferenceConfig(urls=urls, **settings)) + results: Counter[str] = Counter() + + async def caller(count: int) -> None: + for _ in range(count): + try: + results[await worker.work("task")] += 1 + except RpcError as error: + results[error.status.name] += 1 + + async with app, asyncio.TaskGroup() as group: + for _ in range(concurrency): + group.create_task(caller(calls // concurrency)) + return results + + +def show(title: str, results: Counter[str]) -> None: + print(f"{title}: {', '.join(f'{name} {count}' for name, count in sorted(results.items()))}") + + +async def main() -> None: + # Load balancing chooses the provider of each call. + show("roundrobin", await call((FAST, SLOW), 6, loadbalance="roundrobin")) + show("leastactive", await call((FAST, SLOW), 40, concurrency=8, loadbalance="leastactive")) + + # The cluster decides what a failed attempt leads to. + show("failover", await call((FAST, OVERLOADED), 6, loadbalance="roundrobin")) + show("failfast", await call((FAST, OVERLOADED), 6, loadbalance="roundrobin", cluster="failfast")) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/11_load_balancing/server.py b/samples/basics/11_load_balancing/server.py new file mode 100644 index 00000000..3ca95dd3 --- /dev/null +++ b/samples/basics/11_load_balancing/server.py @@ -0,0 +1,67 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Three providers of the Worker, each with its own trait. They run in one +# process to keep the sample short; in production each is a process of its +# own, usually on a machine of its own. +# +# fast on port 20880: answers at once +# slow on port 20881: takes 0.2 seconds +# overloaded on port 20882: rejects every call as UNAVAILABLE + +import asyncio +from contextlib import AsyncExitStack + +from dubbo import Dubbo, RpcError, Status +from dubbo.config import ApplicationConfig, ProtocolConfig + +from worker import Worker + + +class FastWorker(Worker): + async def work(self, task: str) -> str: + return "fast" + + +class SlowWorker(Worker): + async def work(self, task: str) -> str: + await asyncio.sleep(0.2) + return "slow" + + +class OverloadedWorker(Worker): + async def work(self, task: str) -> str: + raise RpcError(Status.UNAVAILABLE, "overloaded") + + +async def main() -> None: + workers = {20880: FastWorker(), 20881: SlowWorker(), 20882: OverloadedWorker()} + async with AsyncExitStack() as stack: + for port, worker in workers.items(): + app = Dubbo( + application=ApplicationConfig(name=f"worker-{port}"), + protocols={"dubbo": ProtocolConfig(port=port)}, + ) + app.export(worker) + await stack.enter_async_context(app) + + print("Serving on ports 20880, 20881 and 20882; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/11_load_balancing/worker.py b/samples/basics/11_load_balancing/worker.py new file mode 100644 index 00000000..e759fc1c --- /dev/null +++ b/samples/basics/11_load_balancing/worker.py @@ -0,0 +1,28 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contract of the workers: each call returns the name of the provider +# that did the work, so the client sees where its calls went. + +import typing + +import dubbo + + +@dubbo.service("org.apache.dubbo.samples.Worker") +class Worker(typing.Protocol): + async def work(self, task: str) -> str: ... diff --git a/samples/basics/12_config_center/README.md b/samples/basics/12_config_center/README.md new file mode 100644 index 00000000..70d05054 --- /dev/null +++ b/samples/basics/12_config_center/README.md @@ -0,0 +1,99 @@ +# Configuration center + +A configuration center keeps configuration in one place for many +applications, and lets operators change how services are called while they +run. This sample reads an application's configuration from ZooKeeper, then +changes a timeout with a rule, without restarting anything. + +## What you will learn + +- how an application reads its configuration from a configuration center; +- how override rules change calls while applications run; +- where the configuration center keeps its entries. + +## Before you start + +```console +$ pip install "apache-dubbo[zookeeper]" +$ docker compose -f ../../compose.yaml up -d --wait +``` + +## Run it + +From this directory, publish the shared configuration: + +```console +$ python publish.py config +Published /dubbo/config/dubbo/dubbo.yaml +``` + +Start the server: + +```console +$ python server.py +Serving; registered with zookeeper from the configuration center +``` + +In another terminal, start the client. Its calls take 1.5 seconds, longer +than the 1 second a call may take, so they fail: + +```console +$ python client.py +DEADLINE_EXCEEDED: greet did not complete within 1.0 seconds +DEADLINE_EXCEEDED: greet did not complete within 1.0 seconds +``` + +While it runs, publish a rule that gives calls of the Greeter 3 seconds, in +a third terminal: + +```console +$ python publish.py rule +Published /dubbo/config/dubbo/org.apache.dubbo.samples.Greeter::.configurators +``` + +The next calls succeed, and the client stops after three: + +```console +Hello, Alice! +Hello, Alice! +Hello, Alice! +``` + +Remove the entries with `python publish.py clear`. + +## How it works + +### Configuration from the center + +The code of both applications names only their own name and the +configuration center, with `ConfigCenterConfig(address=...)`. At start, an +application reads the entry `dubbo.yaml` of the group `dubbo` from the +center, and takes the registry, the protocol and the provider settings from +it. The entry ranks above configuration files and below environment +variables and code, as [05_configuration](../05_configuration) shows. + +A registry can serve as the configuration center too: an application with +a ZooKeeper or Nacos registry and no `config_center` uses its registry, +unless `use_as_config_center` is false. + +### Rules + +Override rules change the settings of calls while applications run. Each is +a YAML entry in the center, under the key `{service}:{version}:{group}.configurators` +for one service, or `{application}.configurators` for every service of an +application. Applications watch these keys and apply a rule as soon as it +changes. The rule here sets the `timeout` of consumers of the Greeter to +3000 milliseconds; others change the weight of a provider, disable it, or +apply only to some addresses. + +The rules are in the format of Dubbo's override rules, so the same entry +applies to Java and Go applications, and consoles such as Dubbo Admin write +it. In ZooKeeper, the entries are under `/dubbo/config/{group}/{key}`; with +Nacos, they are configurations of the same group and data ID. + +`publish.py` writes the entries with kazoo directly, as an operator's tool +would; the framework only reads them. + +## Next + +- [13_routing](../13_routing): route calls to some providers by rules. diff --git a/samples/basics/12_config_center/client.py b/samples/basics/12_config_center/client.py new file mode 100644 index 00000000..32e8758d --- /dev/null +++ b/samples/basics/12_config_center/client.py @@ -0,0 +1,49 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: it calls the Greeter once a second until three calls have +# succeeded. Its calls time out until a rule in the configuration center gives +# them longer. + +import asyncio + +from dubbo import Dubbo, RpcError +from dubbo.config import ApplicationConfig, ConfigCenterConfig + +from greeter import Greeter + + +async def main() -> None: + app = Dubbo( + application=ApplicationConfig(name="config-center-client"), + config_center=ConfigCenterConfig(address="zookeeper://127.0.0.1:2181"), + ) + greeter = app.refer(Greeter) + + async with app: + succeeded = 0 + while succeeded < 3: + try: + print(await greeter.greet("Alice")) + succeeded += 1 + except RpcError as error: + print(f"{error.status.name}: {error.message}") + await asyncio.sleep(1) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/12_config_center/greeter.py b/samples/basics/12_config_center/greeter.py new file mode 100644 index 00000000..499f36f4 --- /dev/null +++ b/samples/basics/12_config_center/greeter.py @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contract of the service: the server implements it, the client calls it. +# Both sides import this module, so they agree on the methods and their types. + +import typing + +import dubbo + + +# The name identifies the service on the wire and in registries. Java and Go +# services use the same kind of name, usually that of a Java interface. +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + # Every method is async. Its type hints say what travels on the wire: + # here a str goes in and a str comes back. + async def greet(self, name: str) -> str: ... diff --git a/samples/basics/12_config_center/publish.py b/samples/basics/12_config_center/publish.py new file mode 100644 index 00000000..a2cca9af --- /dev/null +++ b/samples/basics/12_config_center/publish.py @@ -0,0 +1,86 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Writes to the configuration center what an operator, or a console such as +# Dubbo Admin, writes there. It uses kazoo, which the zookeeper extra +# installs, directly. +# +# python publish.py config the configuration that applications read at start +# python publish.py rule a rule that gives calls of the Greeter 3 seconds +# python publish.py clear removes both + +import sys + +from kazoo.client import KazooClient + +# The entries are under /dubbo/config/{group}/{key}; the group is "dubbo". +CONFIG = "/dubbo/config/dubbo/dubbo.yaml" +RULE = "/dubbo/config/dubbo/org.apache.dubbo.samples.Greeter::.configurators" + +SHARED_CONFIG = """\ +# Configuration shared by every application that reads this center. +registries: + zookeeper: + address: zookeeper://127.0.0.1:2181 +protocols: + dubbo: + port: 20880 +provider: + accesslog: true +""" + +# A rule in the format of Dubbo's override rules, which Dubbo Java and Go read +# too. The parameters are those of URLs, so the timeout is in milliseconds. +TIMEOUT_RULE = """\ +configVersion: v3.0 +scope: service +key: org.apache.dubbo.samples.Greeter +enabled: true +configs: + - side: consumer + parameters: + timeout: 3000 +""" + + +def main(command: str) -> None: + zookeeper = KazooClient("127.0.0.1:2181") + zookeeper.start() + try: + if command == "config": + write(zookeeper, CONFIG, SHARED_CONFIG) + elif command == "rule": + write(zookeeper, RULE, TIMEOUT_RULE) + elif command == "clear": + for path in (CONFIG, RULE): + if zookeeper.exists(path): + zookeeper.delete(path) + print("Cleared") + else: + raise SystemExit(f"unknown command {command!r}; use config, rule or clear") + finally: + zookeeper.stop() + + +def write(zookeeper: KazooClient, path: str, content: str) -> None: + zookeeper.ensure_path(path) + zookeeper.set(path, content.encode()) + print(f"Published {path}") + + +if __name__ == "__main__": + main(sys.argv[1] if len(sys.argv) > 1 else "") diff --git a/samples/basics/12_config_center/server.py b/samples/basics/12_config_center/server.py new file mode 100644 index 00000000..0c701cba --- /dev/null +++ b/samples/basics/12_config_center/server.py @@ -0,0 +1,53 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The provider: its code names the configuration center and nothing more of +# its environment; the registry comes from the center. + +import asyncio +import logging + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ConfigCenterConfig + +from greeter import Greeter + + +class GreeterImpl(Greeter): + async def greet(self, name: str) -> str: + # Takes longer than the 1 second a call may take by default. + await asyncio.sleep(1.5) + return f"Hello, {name}!" + + +async def main() -> None: + logging.basicConfig(level=logging.WARNING, format="%(levelname)s %(name)s: %(message)s") + logging.getLogger("dubbo.accesslog").setLevel(logging.INFO) + + app = Dubbo( + application=ApplicationConfig(name="config-center-server"), + config_center=ConfigCenterConfig(address="zookeeper://127.0.0.1:2181"), + ) + app.export(GreeterImpl()) + + async with app: + print(f"Serving; registered with {', '.join(app.config.registries)} from the configuration center") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/13_routing/README.md b/samples/basics/13_routing/README.md new file mode 100644 index 00000000..8a7ab6f7 --- /dev/null +++ b/samples/basics/13_routing/README.md @@ -0,0 +1,114 @@ +# Routing + +Routers narrow the providers a call may go to, before the load balance +chooses one: test traffic to a new release, the calls of some users to some +instances. This sample routes by tags, given by configuration and by a rule, +and by a condition rule, while the applications run. + +## What you will learn + +- how an instance gets a tag, from its configuration or from a rule, and how + a call asks for one; +- how a condition rule sends some calls to some providers; +- how routing rules are published in the configuration center, and apply at + once. + +## Before you start + +```console +$ pip install "apache-dubbo[zookeeper]" +$ docker compose -f ../../compose.yaml up -d --wait +``` + +## Run it + +From this directory, start the server, which runs three instances of one +application: `stable-1`, `stable-2`, and `gray`, a new release that its +configuration tags `gray`: + +```console +$ python server.py +Serving stable-1, stable-2 and gray; press Ctrl+C to stop +``` + +In another terminal, run the client, which prints the instances that +answered its calls: + +```console +$ python client.py +Bob: stable-1, stable-2 +Alice: stable-1, stable-2 +Bob, tagged gray: gray +Bob, tagged canary: stable-1, stable-2 +``` + +Publish a condition rule that sends the calls for Alice to `stable-1`, and +run the client again: + +```console +$ python publish.py condition +$ python client.py +Bob: stable-1, stable-2 +Alice: stable-1 +Bob, tagged gray: gray +Bob, tagged canary: stable-1, stable-2 +``` + +Publish a tag rule that tags `stable-2` `canary`, and run the client again: + +```console +$ python publish.py tag +$ python client.py +Bob: stable-1 +Alice: stable-1 +Bob, tagged gray: gray +Bob, tagged canary: stable-2 +``` + +Remove the rules with `python publish.py clear`. + +## How it works + +### Tags + +A call asks for a tag with the `dubbo.tag` attachment, as the client does +inside `dubbo.outgoing({"dubbo.tag": "gray"})`, or for all its calls with +`ReferenceConfig(tag=...)`. It goes to the instances of that tag, or, when +none has it, to the untagged ones; a call that asks for none goes to the +untagged only. So a new release runs beside the old one and receives only +the traffic marked for it. + +An instance gets a tag in two ways: + +- **from its configuration**: `ProviderConfig(tag="gray")`, or + `ServiceConfig` for one service, publishes the tag with its address. A + deployment usually sets it outside the code, as with + `DUBBO__PROVIDER__TAG=gray`, as Dubbo Java does with + `dubbo.provider.tag`; +- **from a rule**: `{provider application}.tag-router` in the configuration + center tags instances by address while they run, as `publish.py tag` does + for `stable-2`. An instance tagged by a rule no longer takes untagged + calls. + +### Conditions + +A condition rule reads `which calls => which providers`. The rule in +`publish.py` sends the calls whose first argument is `Alice` to the provider +on port 20880. The left side matches the call, by `method`, `arguments[i]` +or `attachments[key]`; the right side matches the URLs of providers, by +`host`, `port` or their parameters. `force: true` fails a call that no +provider matches, where `false` would ignore the rule for it. + +The rule of one service is under `{service}:{version}:{group}.condition-router`; +rules can also apply to all the services of an application. + +### Rules + +Consumers watch the rules and apply a change at once. The rules are in the +format of Dubbo's routing rules, so the same entries apply to Java and Go +consumers, and consoles such as Dubbo Admin write them; `publish.py` writes +them with kazoo directly. + +## Next + +- [14_filters](../14_filters): run code around every call. diff --git a/samples/basics/13_routing/client.py b/samples/basics/13_routing/client.py new file mode 100644 index 00000000..71cf3244 --- /dev/null +++ b/samples/basics/13_routing/client.py @@ -0,0 +1,55 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: it shows where calls go, with and without a tag. Run it before +# and after publishing each rule. + +import asyncio + +import dubbo +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, RegistryConfig + +from greeter import Greeter + + +async def main() -> None: + app = Dubbo( + application=ApplicationConfig(name="routing-client"), + registries={"default": RegistryConfig(address="zookeeper://127.0.0.1:2181")}, + ) + greeter = app.refer(Greeter) + + async def where(name: str) -> str: + # The instances that answered 20 calls for name. + instances = {(await greeter.greet(name)).split(" ")[0] for _ in range(20)} + return ", ".join(sorted(instances)) + + async with app: + # A call that asks for no tag goes to the untagged instances only. + print(f"Bob: {await where('Bob')}") + print(f"Alice: {await where('Alice')}") + + # A call that asks for a tag goes to the instances of that tag, such + # as test traffic to a new release, else to the untagged instances. + for tag in ["gray", "canary"]: + with dubbo.outgoing({"dubbo.tag": tag}): + print(f"Bob, tagged {tag}: {await where('Bob')}") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/13_routing/greeter.py b/samples/basics/13_routing/greeter.py new file mode 100644 index 00000000..499f36f4 --- /dev/null +++ b/samples/basics/13_routing/greeter.py @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contract of the service: the server implements it, the client calls it. +# Both sides import this module, so they agree on the methods and their types. + +import typing + +import dubbo + + +# The name identifies the service on the wire and in registries. Java and Go +# services use the same kind of name, usually that of a Java interface. +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + # Every method is async. Its type hints say what travels on the wire: + # here a str goes in and a str comes back. + async def greet(self, name: str) -> str: ... diff --git a/samples/basics/13_routing/publish.py b/samples/basics/13_routing/publish.py new file mode 100644 index 00000000..29ce8d52 --- /dev/null +++ b/samples/basics/13_routing/publish.py @@ -0,0 +1,84 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Writes or removes routing rules in the configuration center, as an operator, +# or a console such as Dubbo Admin, would. +# +# python publish.py tag tags the instance on port 20881 "canary" +# python publish.py condition sends the calls for Alice to stable-1 only +# python publish.py clear removes both rules + +import sys + +from kazoo.client import KazooClient + +# The tag rule of the provider application, under +# /dubbo/config/dubbo/{application}.tag-router. It tags instances by address, +# while they run, without changing their configuration. +TAG_RULE = "/dubbo/config/dubbo/routing-server.tag-router" +TAGS = """\ +configVersion: v3.0 +key: routing-server +enabled: true +force: false +tags: + - name: canary + addresses: ["127.0.0.1:20881"] +""" + +# The condition rule of one service, under +# /dubbo/config/dubbo/{service}:{version}:{group}.condition-router. Each +# condition reads "which calls => which providers". +CONDITION_RULE = "/dubbo/config/dubbo/org.apache.dubbo.samples.Greeter::.condition-router" +CONDITIONS = """\ +configVersion: v3.0 +scope: service +key: org.apache.dubbo.samples.Greeter +enabled: true +force: true +conditions: + - arguments[0] = Alice => port = 20880 +""" + + +def main(command: str) -> None: + zookeeper = KazooClient("127.0.0.1:2181") + zookeeper.start() + try: + if command == "tag": + write(zookeeper, TAG_RULE, TAGS) + elif command == "condition": + write(zookeeper, CONDITION_RULE, CONDITIONS) + elif command == "clear": + for path in (TAG_RULE, CONDITION_RULE): + if zookeeper.exists(path): + zookeeper.delete(path) + print("Cleared") + else: + raise SystemExit(f"unknown command {command!r}; use tag, condition or clear") + finally: + zookeeper.stop() + + +def write(zookeeper: KazooClient, path: str, content: str) -> None: + zookeeper.ensure_path(path) + zookeeper.set(path, content.encode()) + print(f"Published {path}") + + +if __name__ == "__main__": + main(sys.argv[1] if len(sys.argv) > 1 else "") diff --git a/samples/basics/13_routing/server.py b/samples/basics/13_routing/server.py new file mode 100644 index 00000000..2d454521 --- /dev/null +++ b/samples/basics/13_routing/server.py @@ -0,0 +1,67 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Three instances of one provider application, registered with ZooKeeper: +# +# stable-1 on port 20880 +# stable-2 on port 20881 +# gray on port 20882, tagged "gray" by its configuration: a new +# release that only test traffic should reach for now +# +# They run in one process to keep the sample short; in production each is a +# process of its own. + +import asyncio +from contextlib import AsyncExitStack + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig, ProviderConfig, RegistryConfig + +from greeter import Greeter + +INSTANCES = {"stable-1": (20880, None), "stable-2": (20881, None), "gray": (20882, "gray")} + + +class GreeterImpl(Greeter): + def __init__(self, instance: str) -> None: + self.instance = instance + + async def greet(self, name: str) -> str: + return f"{self.instance} greets {name}" + + +async def main() -> None: + async with AsyncExitStack() as stack: + for instance, (port, tag) in INSTANCES.items(): + app = Dubbo( + application=ApplicationConfig(name="routing-server"), + protocols={"dubbo": ProtocolConfig(port=port)}, + registries={"default": RegistryConfig(address="zookeeper://127.0.0.1:2181")}, + # The tag is published with the address of the instance. A + # deployment usually sets it outside the code, as with + # DUBBO__PROVIDER__TAG=gray. + provider=ProviderConfig(tag=tag), + ) + app.export(GreeterImpl(instance)) + await stack.enter_async_context(app) + + print("Serving stable-1, stable-2 and gray; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/14_filters/README.md b/samples/basics/14_filters/README.md new file mode 100644 index 00000000..aadb50d7 --- /dev/null +++ b/samples/basics/14_filters/README.md @@ -0,0 +1,81 @@ +# Filters + +A filter runs code around every call, on the consumer, the provider, or +both: authentication, metrics, logging, rate limits. This sample checks an +API key and times the calls a provider serves. + +## What you will learn + +- how to write a filter, and register it by name; +- how a service and a reference choose their filters, and in which order + they run; +- how a filter reads its settings, changes a call, and fails it. + +## Run it + +From this directory, start the server: + +```console +$ python server.py +Serving on port 20880; press Ctrl+C to stop +``` + +In another terminal, run the client: + +```console +$ python client.py +With the key: Hello, Alice! +Without: PERMISSION_DENIED: a valid API key is required +``` + +The server logs both calls, timed by its filter: + +```console +INFO filters: org.apache.dubbo.samples.Greeter.greet succeeded in 0.0 ms +INFO filters: org.apache.dubbo.samples.Greeter.greet failed in 0.0 ms +``` + +## How it works + +### Writing a filter + +A filter, in `filters.py`, is a class with two methods: + +- `__init__(url)`, called with the URL of the service or reference it runs + around. It reads its settings there once, such as the `api-key` parameter; +- `async invoke(call_next, invocation)`, called for each call. It may change + the invocation, such as its attachments, then call `call_next` to go on, + and change the result it returns. To fail the call, it returns + `Result(error=RpcError(...))` without going on. + +A filter keeps no state across calls of its own, since it may be created +again when rules change the URL. + +`extensions.register(Filter, "timing", TimingFilter)` gives the filter a +name, which configuration then uses; the sample does it in +`filters.register()`, which the client and the server call before they +configure the filters. A filter meant for many applications is +installed as a package instead; [15_extensions](../15_extensions) shows how. + +### Choosing filters + +| Where | Setting | Runs around | +|---|---|---| +| Provider | `ProviderConfig(filters=...)`, or `ServiceConfig` for one service | Each call it serves, where `dubbo.incoming()` works | +| Consumer | `ConsumerConfig(filters=...)`, or `ReferenceConfig` for one service | Each call, once whatever the retries | +| Consumer | `attempt_filters` of the same | Each attempt, on the provider it goes to | + +The first filter of a list is the outermost, so `("timing", "api-key-check")` +times the check as well. `parameters` reach the URL the filters are created +with. + +### Built in + +The framework has filters of its own, which settings turn on: `token` for a +shared secret like the one here, `accesslog`, `executes` and `tps` for +limits on a provider, and `actives` on a consumer. Use those when they fit. + +## Next + +- [15_extensions](../15_extensions): add an extension of your own as an + installable plugin. diff --git a/samples/basics/14_filters/client.py b/samples/basics/14_filters/client.py new file mode 100644 index 00000000..469421d0 --- /dev/null +++ b/samples/basics/14_filters/client.py @@ -0,0 +1,47 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: one application attaches the API key with a filter, and one +# does not. + +import asyncio + +from dubbo import Dubbo, RpcError +from dubbo.config import ConsumerConfig + +import filters +from greeter import Greeter + + +async def greet(consumer: ConsumerConfig) -> str: + app = Dubbo(consumer=consumer) + greeter = app.refer(Greeter, url="dubbo://127.0.0.1:20880") + async with app: + try: + return await greeter.greet("Alice") + except RpcError as error: + return f"{error.status.name}: {error.message}" + + +async def main() -> None: + filters.register() + print("With the key:", await greet(ConsumerConfig(filters=("api-key",), parameters={"api-key": "s3cret"}))) + print("Without:", await greet(ConsumerConfig())) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/14_filters/filters.py b/samples/basics/14_filters/filters.py new file mode 100644 index 00000000..8c917b69 --- /dev/null +++ b/samples/basics/14_filters/filters.py @@ -0,0 +1,81 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Three filters: one that attaches an API key to the calls of a consumer, one +# that checks it on the provider, and one that times the calls a provider +# serves. register() gives them their names. + +import logging +import time + +from dubbo import Invocation, Invoke, Result, RpcError, Status +from dubbo.extension import extensions +from dubbo.filter import Filter +from dubbo.url import URL + +_logger = logging.getLogger(__name__) + +API_KEY = "api-key" + + +class ApiKeyFilter(Filter): + """Attaches the API key of the reference to each of its calls.""" + + # A filter is created with the URL of what it runs around, and reads its + # settings from it once: here the api-key parameter of the reference. + def __init__(self, url: URL) -> None: + self.key = url.parameters[API_KEY] + + async def invoke(self, call_next: Invoke, invocation: Invocation) -> Result: + invocation.attachments[API_KEY] = self.key + return await call_next(invocation) + + +class ApiKeyCheckFilter(Filter): + """Refuses the calls that do not attach the API key of the service.""" + + def __init__(self, url: URL) -> None: + self.key = url.parameters[API_KEY] + + async def invoke(self, call_next: Invoke, invocation: Invocation) -> Result: + if invocation.attachments.get(API_KEY) != self.key: + # A filter fails a call by returning an error, without calling on. + error = RpcError(Status.PERMISSION_DENIED, "a valid API key is required") + return Result(error=error) + return await call_next(invocation) + + +class TimingFilter(Filter): + """Logs how long each call takes, and how it ended.""" + + def __init__(self, url: URL) -> None: + self.service = url.path + + async def invoke(self, call_next: Invoke, invocation: Invocation) -> Result: + start = time.perf_counter() + result = await call_next(invocation) + outcome = "failed" if result.error else "succeeded" + elapsed = (time.perf_counter() - start) * 1000 + _logger.info("%s.%s %s in %.1f ms", self.service, invocation.method, outcome, elapsed) + return result + + +def register() -> None: + """Give the filters the names that configuration selects them by.""" + extensions.register(Filter, "api-key", ApiKeyFilter) + extensions.register(Filter, "api-key-check", ApiKeyCheckFilter) + extensions.register(Filter, "timing", TimingFilter) diff --git a/samples/basics/14_filters/greeter.py b/samples/basics/14_filters/greeter.py new file mode 100644 index 00000000..499f36f4 --- /dev/null +++ b/samples/basics/14_filters/greeter.py @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contract of the service: the server implements it, the client calls it. +# Both sides import this module, so they agree on the methods and their types. + +import typing + +import dubbo + + +# The name identifies the service on the wire and in registries. Java and Go +# services use the same kind of name, usually that of a Java interface. +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + # Every method is async. Its type hints say what travels on the wire: + # here a str goes in and a str comes back. + async def greet(self, name: str) -> str: ... diff --git a/samples/basics/14_filters/server.py b/samples/basics/14_filters/server.py new file mode 100644 index 00000000..4ac91f49 --- /dev/null +++ b/samples/basics/14_filters/server.py @@ -0,0 +1,59 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The provider: every call it serves goes through the timing filter, then the +# API key check, before it reaches the Greeter. + +import asyncio +import logging + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig, ProviderConfig + +import filters +from greeter import Greeter + + +class GreeterImpl(Greeter): + async def greet(self, name: str) -> str: + return f"Hello, {name}!" + + +async def main() -> None: + logging.basicConfig(level=logging.INFO, format="%(levelname)s %(name)s: %(message)s") + filters.register() + + app = Dubbo( + application=ApplicationConfig(name="filters-server"), + protocols={"dubbo": ProtocolConfig(port=20880)}, + provider=ProviderConfig( + # The first filter is the outermost: timing measures the check too. + filters=("timing", "api-key-check"), + # Parameters reach the URL the filters are created with. Keep real + # keys out of the code, in the environment or a secret store. + parameters={"api-key": "s3cret"}, + ), + ) + app.export(GreeterImpl()) + + async with app: + print("Serving on port 20880; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/15_extensions/README.md b/samples/basics/15_extensions/README.md new file mode 100644 index 00000000..1852bfc2 --- /dev/null +++ b/samples/basics/15_extensions/README.md @@ -0,0 +1,88 @@ +# Extensions + +Every protocol, registry, load balance, router, filter and configuration +format of the framework is an extension, found by name among the installed +packages. A package of your own can add one. This sample adds a format, +TOML, as a plugin that any application can install. + +## What you will learn + +- how the framework finds extensions through entry points; +- how to package an extension so that installing it is enough; +- which extension points there are. + +## The files + +| File | Role | +|---|---| +| `dubbo-toml/dubbo_toml.py` | The extension: a configuration parser for TOML | +| `dubbo-toml/pyproject.toml` | The package, which declares the extension as an entry point | +| `server.toml` | The configuration of the server, in TOML | +| `server.py`, `client.py`, `greeter.py` | The provider, which reads `server.toml`, its consumer, and their contract | + +## Run it + +Before the plugin is installed, the server cannot read its configuration: + +```console +$ python server.py +dubbo.config.exceptions.ConfigReadError: cannot load configuration parser 'toml' for '.../server.toml' +``` + +From this directory, install the plugin, then start the server: + +```console +$ pip install -e ./dubbo-toml +$ python server.py +extensions-server serving on port 20880; press Ctrl+C to stop +``` + +In another terminal, run the client: + +```console +$ python client.py +Hello, Alice! +Hello, Bob! +``` + +## How it works + +An extension point is a contract of the framework, such as `ConfigParser`, +with an entry point group, such as `apache_dubbo.config.parser`. An +extension is a class that implements the contract, installed under that +group with a name: + +```toml +[project.entry-points."apache_dubbo.config.parser"] +toml = "dubbo_toml:TomlParser" +``` + +When the configuration needs the parser for a `.toml` file, the framework +looks up the name `toml` in the group, imports `dubbo_toml`, and creates a +`TomlParser`. Nothing else names the plugin: installing the package is +enough, and the plugin is imported only when it is first needed. + +The other extension points work the same way: + +| Group | Contract | Selected by | +|---|---|---| +| `apache_dubbo.filter` | `dubbo.filter.Filter` | `filters` of a provider, service, consumer or reference | +| `apache_dubbo.loadbalance` | `dubbo.cluster.LoadBalance` | `loadbalance` | +| `apache_dubbo.cluster` | `dubbo.cluster.Cluster` | `cluster` | +| `apache_dubbo.router` | `dubbo.cluster.Router` | `routers` of a consumer or reference | +| `apache_dubbo.interface_registry`, `apache_dubbo.instance_registry` | `dubbo.registry` contracts | the scheme of a registry address | +| `apache_dubbo.config_center` | `dubbo.config_center.ConfigCenter` | the scheme of a configuration center address | +| `apache_dubbo.metadata_report` | `dubbo.metadata` contract | the scheme of a metadata report address | +| `apache_dubbo.protocol` | `dubbo.protocol.Protocol` | the name of a protocol | +| `apache_dubbo.serialization` | `dubbo.serialization.Serialization` | `serialization` | +| `apache_dubbo.compression` | `dubbo.compression.Compressor` | the compressor of Triple | +| `apache_dubbo.config.parser` | `dubbo.config.ConfigParser` | the suffix of a configuration file | +| `apache_dubbo.transport.*` | The clients of ZooKeeper, Nacos and HTTP/2 under the extensions above | a parameter of their URL, else the default | + +The docstring of each contract says what an implementation does. For one +application, `dubbo.extension.extensions.register()` registers an extension +in code instead, as [14_filters](../14_filters) does. + +## Next + +- [16_tls](../16_tls): secure calls with TLS, and compress them. diff --git a/samples/basics/15_extensions/client.py b/samples/basics/15_extensions/client.py new file mode 100644 index 00000000..83ef95ff --- /dev/null +++ b/samples/basics/15_extensions/client.py @@ -0,0 +1,44 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: it calls the Greeter that server.py serves. + +import asyncio + +from dubbo import Dubbo + +from greeter import Greeter + + +async def main() -> None: + # A consumer that calls providers by their addresses needs no configuration. + app = Dubbo() + + # refer() returns an object that implements the contract by calling the + # provider. The URL names the protocol and address of the provider; the + # registry sample shows how to find providers without knowing them. + greeter = app.refer(Greeter, url="dubbo://127.0.0.1:20880") + + # Calls work while the application runs, that is inside `async with`. + async with app: + for name in ["Alice", "Bob"]: + reply = await greeter.greet(name) + print(reply) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/15_extensions/dubbo-toml/dubbo_toml.py b/samples/basics/15_extensions/dubbo-toml/dubbo_toml.py new file mode 100644 index 00000000..5c2d542a --- /dev/null +++ b/samples/basics/15_extensions/dubbo-toml/dubbo_toml.py @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""A configuration parser for TOML files, with tomllib from the standard library.""" + +import tomllib + +from dubbo.config import ConfigData, ConfigParseError, ConfigParser + + +class TomlParser(ConfigParser): + """Reads a TOML document; its tables are the sections of the configuration.""" + + def loads(self, text: str, /) -> ConfigData: + try: + return tomllib.loads(text) + except tomllib.TOMLDecodeError as error: + raise ConfigParseError("invalid TOML configuration") from error diff --git a/samples/basics/15_extensions/dubbo-toml/pyproject.toml b/samples/basics/15_extensions/dubbo-toml/pyproject.toml new file mode 100644 index 00000000..afb973ac --- /dev/null +++ b/samples/basics/15_extensions/dubbo-toml/pyproject.toml @@ -0,0 +1,35 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# A plugin that teaches Apache Dubbo for Python to read TOML configuration +# files. Installing it is enough: the entry point below names the parser, and +# the framework finds it by the suffix of a file, .toml. + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "dubbo-toml" +version = "0.1.0" +description = "TOML configuration files for Apache Dubbo for Python" +requires-python = ">=3.11" +dependencies = ["apache-dubbo"] + +# The group is the extension point, and the name the extension. +[project.entry-points."apache_dubbo.config.parser"] +toml = "dubbo_toml:TomlParser" diff --git a/samples/basics/15_extensions/greeter.py b/samples/basics/15_extensions/greeter.py new file mode 100644 index 00000000..499f36f4 --- /dev/null +++ b/samples/basics/15_extensions/greeter.py @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contract of the service: the server implements it, the client calls it. +# Both sides import this module, so they agree on the methods and their types. + +import typing + +import dubbo + + +# The name identifies the service on the wire and in registries. Java and Go +# services use the same kind of name, usually that of a Java interface. +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + # Every method is async. Its type hints say what travels on the wire: + # here a str goes in and a str comes back. + async def greet(self, name: str) -> str: ... diff --git a/samples/basics/15_extensions/server.py b/samples/basics/15_extensions/server.py new file mode 100644 index 00000000..8c69f18a --- /dev/null +++ b/samples/basics/15_extensions/server.py @@ -0,0 +1,46 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The provider: it reads its configuration from server.toml, which only the +# installed dubbo-toml plugin can read. + +import asyncio +from pathlib import Path + +from dubbo import Dubbo + +from greeter import Greeter + +HERE = Path(__file__).parent + + +class GreeterImpl(Greeter): + async def greet(self, name: str) -> str: + return f"Hello, {name}!" + + +async def main() -> None: + app = Dubbo(HERE / "server.toml") + app.export(GreeterImpl()) + + async with app: + print(f"{app.config.application.name} serving on port 20880; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/15_extensions/server.toml b/samples/basics/15_extensions/server.toml new file mode 100644 index 00000000..7fd73629 --- /dev/null +++ b/samples/basics/15_extensions/server.toml @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The configuration of server.py, in TOML, which the dubbo-toml plugin reads. + +[application] +name = "extensions-server" + +[protocols.dubbo] +port = 20880 diff --git a/samples/basics/16_tls/.gitignore b/samples/basics/16_tls/.gitignore new file mode 100644 index 00000000..2569b105 --- /dev/null +++ b/samples/basics/16_tls/.gitignore @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Generated by make_certificates.py. +certs/ diff --git a/samples/basics/16_tls/README.md b/samples/basics/16_tls/README.md new file mode 100644 index 00000000..3b2454bf --- /dev/null +++ b/samples/basics/16_tls/README.md @@ -0,0 +1,77 @@ +# TLS and compression + +Calls between services often cross networks that others share. TLS encrypts +them and proves who is at each end; mutual TLS lets the server check the +client too. This sample serves over mutual TLS, and compresses the messages. + +## What you will learn + +- how a provider serves over TLS, and requires client certificates; +- how a consumer trusts a server, and presents its certificate; +- how to compress the messages of Triple. + +## Before you start + +The sample makes its own certificate authority with +[trustme](https://github.com/python-trio/trustme), which is meant for tests: + +```console +$ pip install trustme +$ python make_certificates.py +Wrote ca.pem, server.pem and client.pem to .../certs +``` + +## Run it + +From this directory, start the server: + +```console +$ python server.py +Serving over TLS on port 50051; press Ctrl+C to stop +``` + +In another terminal, run the client: + +```console +$ python client.py +With a client certificate: Hello, Alice, over TLS! +Without: UNAVAILABLE: the HTTP/2 connection is closed +``` + +## How it works + +### TLS + +`TLSConfig` secures every connection an application serves and opens, over +both protocols: + +| Field | On a server | On a client | +|---|---|---| +| `certfile` | The certificate to present, required | The certificate to present when the server asks | +| `keyfile` | Its private key, unless `certfile` holds it | The same | +| `cafile` | The authorities whose clients it accepts; setting it requires client certificates | The authorities it trusts, instead of those of the system | +| `server_hostname` | — | The name the server certificate must carry, else the host it connects to | + +The server certificate here names `localhost`, so the client connects to +`tri://localhost:50051`. A client without a certificate completes the +handshake, and the server then closes the connection, so the call fails as +`UNAVAILABLE`. For full control, `server_context` and `client_context` take +an `ssl.SSLContext` built in code. + +In production, certificates come from your own authority, or from a service +mesh, and their files from the environment, such as +`DUBBO__TLS__CERTFILE`. + +### Compression + +`TripleConfig(compressor="gzip")` compresses the messages one side sends: +on the server, under its protocol; on the client, under the consumer or one +reference. A server compresses only for the callers that accept it, as gRPC +does. `deflate` and `bzip2` are built in too. + +Compression saves bandwidth on large messages at the cost of CPU, and +rarely pays off on small ones. + +## Next + +- [17_generic](../17_generic): call a service without its contract. diff --git a/samples/basics/16_tls/client.py b/samples/basics/16_tls/client.py new file mode 100644 index 00000000..586a107c --- /dev/null +++ b/samples/basics/16_tls/client.py @@ -0,0 +1,60 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The consumer: it calls the Greeter over TLS, once with its certificate, and +# once without. + +import asyncio +from pathlib import Path + +from dubbo import Dubbo, RpcError +from dubbo.config import ConsumerConfig, TLSConfig, TripleConfig + +from greeter_dubbo import Greeter +from greeter_pb2 import HelloRequest + +CERTS = Path(__file__).parent / "certs" + + +async def greet(tls: TLSConfig) -> str: + app = Dubbo( + tls=tls, + # Requests are compressed with gzip too. + consumer=ConsumerConfig(triple=TripleConfig(compressor="gzip"), check=False), + ) + # With TLS configured, every connection of the application uses it. + greeter = app.refer(Greeter, url="tri://localhost:50051") + async with app: + try: + reply = await greeter.say_hello(HelloRequest(name="Alice")) + except RpcError as error: + return f"{error.status.name}: {error.message}" + return reply.message + + +async def main() -> None: + # The client trusts the sample's authority, which signed the server + # certificate, and presents its own certificate when the server asks. + with_certificate = TLSConfig(cafile=CERTS / "ca.pem", certfile=CERTS / "client.pem") + print("With a client certificate:", await greet(with_certificate)) + + # Without its certificate, the server refuses the connection. + print("Without:", await greet(TLSConfig(cafile=CERTS / "ca.pem"))) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/16_tls/greeter.proto b/samples/basics/16_tls/greeter.proto new file mode 100644 index 00000000..e12cd1d1 --- /dev/null +++ b/samples/basics/16_tls/greeter.proto @@ -0,0 +1,33 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +syntax = "proto3"; + +package org.apache.dubbo.samples; + +// Greets people. +service Greeter { + rpc SayHello (HelloRequest) returns (HelloReply); +} + +message HelloRequest { + string name = 1; +} + +message HelloReply { + string message = 1; +} diff --git a/samples/basics/16_tls/greeter_dubbo.py b/samples/basics/16_tls/greeter_dubbo.py new file mode 100644 index 00000000..ea785534 --- /dev/null +++ b/samples/basics/16_tls/greeter_dubbo.py @@ -0,0 +1,29 @@ +# Generated by protoc-gen-python-dubbo. DO NOT EDIT! +# source: greeter.proto +"""Dubbo service contracts of greeter.proto.""" + +import abc +import typing + +import dubbo + +import greeter_pb2 + +__all__ = ["Greeter", "GreeterServicer"] + + +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + """Greets people.""" + + @dubbo.method("SayHello") + async def say_hello(self, request: greeter_pb2.HelloRequest) -> greeter_pb2.HelloReply: ... + + +@dubbo.service("org.apache.dubbo.samples.Greeter") +class GreeterServicer(abc.ABC): + """Greets people.""" + + @dubbo.method("SayHello") + @abc.abstractmethod + async def say_hello(self, request: greeter_pb2.HelloRequest) -> greeter_pb2.HelloReply: ... diff --git a/samples/basics/16_tls/greeter_pb2.py b/samples/basics/16_tls/greeter_pb2.py new file mode 100644 index 00000000..848d50f6 --- /dev/null +++ b/samples/basics/16_tls/greeter_pb2.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: greeter.proto +# Protobuf Python Version: 7.35.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 7, + 35, + 1, + '', + 'greeter.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rgreeter.proto\x12\x18org.apache.dubbo.samples\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t2c\n\x07Greeter\x12X\n\x08SayHello\x12&.org.apache.dubbo.samples.HelloRequest\x1a$.org.apache.dubbo.samples.HelloReplyb\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'greeter_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + DESCRIPTOR._loaded_options = None + _globals['_HELLOREQUEST']._serialized_start=43 + _globals['_HELLOREQUEST']._serialized_end=71 + _globals['_HELLOREPLY']._serialized_start=73 + _globals['_HELLOREPLY']._serialized_end=102 + _globals['_GREETER']._serialized_start=104 + _globals['_GREETER']._serialized_end=203 +# @@protoc_insertion_point(module_scope) diff --git a/samples/basics/16_tls/greeter_pb2.pyi b/samples/basics/16_tls/greeter_pb2.pyi new file mode 100644 index 00000000..bf0bd395 --- /dev/null +++ b/samples/basics/16_tls/greeter_pb2.pyi @@ -0,0 +1,17 @@ +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from typing import ClassVar as _ClassVar, Optional as _Optional + +DESCRIPTOR: _descriptor.FileDescriptor + +class HelloRequest(_message.Message): + __slots__ = ("name",) + NAME_FIELD_NUMBER: _ClassVar[int] + name: str + def __init__(self, name: _Optional[str] = ...) -> None: ... + +class HelloReply(_message.Message): + __slots__ = ("message",) + MESSAGE_FIELD_NUMBER: _ClassVar[int] + message: str + def __init__(self, message: _Optional[str] = ...) -> None: ... diff --git a/samples/basics/16_tls/make_certificates.py b/samples/basics/16_tls/make_certificates.py new file mode 100644 index 00000000..1f2c0742 --- /dev/null +++ b/samples/basics/16_tls/make_certificates.py @@ -0,0 +1,46 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Makes a certificate authority for testing, and certificates it signs for the +# server and the client, in certs/. Real deployments get them from their own +# authority instead. Needs trustme: pip install trustme + +from pathlib import Path + +import trustme + +CERTS = Path(__file__).parent / "certs" + + +def main() -> None: + CERTS.mkdir(exist_ok=True) + authority = trustme.CA() + authority.cert_pem.write_to_path(CERTS / "ca.pem") + + # The server certificate names the host clients connect to. + server = authority.issue_cert("localhost", "127.0.0.1") + server.private_key_and_cert_chain_pem.write_to_path(CERTS / "server.pem") + + # The client certificate identifies the client to servers that ask. + client = authority.issue_cert("greeter-client") + client.private_key_and_cert_chain_pem.write_to_path(CERTS / "client.pem") + + print(f"Wrote ca.pem, server.pem and client.pem to {CERTS}") + + +if __name__ == "__main__": + main() diff --git a/samples/basics/16_tls/server.py b/samples/basics/16_tls/server.py new file mode 100644 index 00000000..7a3fa393 --- /dev/null +++ b/samples/basics/16_tls/server.py @@ -0,0 +1,59 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The provider: it serves the Greeter over TLS, and accepts only clients with +# a certificate that the sample's authority signed. + +import asyncio +from pathlib import Path + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig, TLSConfig, TripleConfig + +from greeter_dubbo import GreeterServicer +from greeter_pb2 import HelloReply, HelloRequest + +CERTS = Path(__file__).parent / "certs" + + +class GreeterImpl(GreeterServicer): + async def say_hello(self, request: HelloRequest) -> HelloReply: + return HelloReply(message=f"Hello, {request.name}, over TLS!") + + +async def main() -> None: + app = Dubbo( + application=ApplicationConfig(name="tls-server"), + # Replies are compressed with gzip for the callers that accept it. + protocols={"tri": ProtocolConfig(port=50051, triple=TripleConfig(compressor="gzip"))}, + tls=TLSConfig( + # The certificate the server presents, with its private key. + certfile=CERTS / "server.pem", + # Setting the authority on a server requires every client to + # present a certificate it signed: mutual TLS. + cafile=CERTS / "ca.pem", + ), + ) + app.export(GreeterImpl()) + + async with app: + print("Serving over TLS on port 50051; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/17_generic/README.md b/samples/basics/17_generic/README.md new file mode 100644 index 00000000..3d1150f3 --- /dev/null +++ b/samples/basics/17_generic/README.md @@ -0,0 +1,70 @@ +# Generic calls + +A generic call names a service and a method as text, and passes plain data, +without the contract of the service. Gateways, consoles and test tools use +it to call any service, including services written later or in other +languages. This sample calls a user service that way. + +## What you will learn + +- how to refer to a service by its name, without its contract; +- how to call its methods by name with plain data; +- how generic calls reach Java providers. + +## Run it + +From this directory, start the server: + +```console +$ python server.py +Serving on port 20880; press Ctrl+C to stop +``` + +In another terminal, run the client: + +```console +$ python client.py +{'id': 1, 'name': 'Alice', 'email': 'alice@example.com'} +['Alice'] +UNKNOWN: no user has ID 42 +``` + +## How it works + +`app.refer_generic("org.apache.dubbo.samples.Users", url=...)` returns a +`GenericService` for the service of that name. Its `call(method, *arguments)` +calls a unary method by its name on the wire, with the arguments in order, +and returns the result. Arguments and results are plain data: strings, +numbers, lists, and dicts for objects. + +The provider needs nothing special: it serves generic calls of any of its +services. Settings, such as timeouts or a registry, apply as to a reference +of a contract. + +The failure arrives as `UNKNOWN` rather than `NOT_FOUND`, since the Dubbo +protocol carries failures as Java's `RpcException`, which has no code for +it; [08_errors_and_timeouts](../08_errors_and_timeouts) explains why. + +### Calling Java providers + +A generic call is how Dubbo calls services across languages without shared +code. For a Java provider, an object is a dict that names its Java class +under `"class"`, and `types` names the Java type of each parameter, which a +Java provider needs to tell apart methods of one name: + +```python +user = await users.call( + "updateUser", + {"class": "com.example.User", "id": 1, "name": "Alice"}, + types=["com.example.User"], +) +``` + +`refer_generic(..., generic=...)` chooses other forms of arguments and +results, such as `"protobuf-json"` for services defined in proto files, or +`"gson"` for JSON. + +## Next + +- [interop/java](../../interop/java): call Java services from Python, and + Python services from Java. diff --git a/samples/basics/17_generic/client.py b/samples/basics/17_generic/client.py new file mode 100644 index 00000000..6174aafd --- /dev/null +++ b/samples/basics/17_generic/client.py @@ -0,0 +1,47 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# A consumer without the contract of the service it calls: it names the +# service and its methods as text, and passes and receives plain data. Such +# calls suit tools that call any service, such as gateways, consoles and +# tests. + +import asyncio + +from dubbo import Dubbo, RpcError + + +async def main() -> None: + app = Dubbo() + + # refer_generic() takes the name of a service instead of its contract. + users = app.refer_generic("org.apache.dubbo.samples.Users", url="dubbo://127.0.0.1:20880") + + async with app: + # call() takes the name of a method and its arguments in order. + print(await users.call("get_user", 1)) + print(await users.call("find_names", "A")) + + # Failures arrive as they do for any call. + try: + await users.call("get_user", 42) + except RpcError as error: + print(f"{error.status.name}: {error.message}") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/basics/17_generic/server.py b/samples/basics/17_generic/server.py new file mode 100644 index 00000000..036523c0 --- /dev/null +++ b/samples/basics/17_generic/server.py @@ -0,0 +1,61 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# A provider of a user service, with a contract like any other. The consumer +# in client.py does not import it. + +import asyncio +import typing + +import dubbo +from dubbo import Dubbo, RpcError, Status +from dubbo.config import ApplicationConfig, ProtocolConfig + +USERS = { + 1: {"id": 1, "name": "Alice", "email": "alice@example.com"}, + 2: {"id": 2, "name": "Bob", "email": "bob@example.com"}, +} + + +@dubbo.service("org.apache.dubbo.samples.Users") +class Users(typing.Protocol): + async def get_user(self, user_id: int) -> dict[str, typing.Any]: ... + + async def find_names(self, prefix: str) -> list[str]: ... + + +class UsersImpl(Users): + async def get_user(self, user_id: int) -> dict[str, typing.Any]: + if user_id not in USERS: + raise RpcError(Status.NOT_FOUND, f"no user has ID {user_id}") + return USERS[user_id] + + async def find_names(self, prefix: str) -> list[str]: + return [user["name"] for user in USERS.values() if user["name"].startswith(prefix)] + + +async def main() -> None: + app = Dubbo(application=ApplicationConfig(name="generic-server"), protocols={"dubbo": ProtocolConfig(port=20880)}) + app.export(UsersImpl()) + + async with app: + print("Serving on port 20880; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/compose.yaml b/samples/compose.yaml new file mode 100644 index 00000000..d58db0c8 --- /dev/null +++ b/samples/compose.yaml @@ -0,0 +1,50 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The registries the samples use: +# +# docker compose -f samples/compose.yaml up -d --wait +# docker compose -f samples/compose.yaml down +# +# ZooKeeper listens on 127.0.0.1:2181 and Nacos on 127.0.0.1:8848. A Nacos +# client also reaches Nacos over gRPC on port 9848. + +name: dubbo-samples + +services: + zookeeper: + image: zookeeper:3.9.5 + ports: + - 127.0.0.1:2181:2181 + healthcheck: + test: [CMD, zkServer.sh, status] + interval: 2s + timeout: 5s + retries: 30 + + nacos: + image: nacos/nacos-server:v2.4.3 + environment: + MODE: standalone + ports: + - 127.0.0.1:8848:8848 + - 127.0.0.1:9848:9848 + healthcheck: + test: [CMD-SHELL, curl -fs http://localhost:8848/nacos/v1/console/health/readiness && nc -z localhost 9848] + interval: 2s + timeout: 5s + retries: 60 diff --git a/samples/helloworld/__init__.py b/samples/helloworld/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/samples/helloworld/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/samples/helloworld/client.py b/samples/helloworld/client.py deleted file mode 100644 index 88815477..00000000 --- a/samples/helloworld/client.py +++ /dev/null @@ -1,36 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import dubbo -from dubbo.configs import ReferenceConfig - - -class UnaryServiceStub: - def __init__(self, client: dubbo.Client): - self.unary = client.unary(method_name="unary") - - def say_hello(self, message: bytes) -> bytes: - return self.unary(message) - - -if __name__ == "__main__": - # Create a client - reference_config = ReferenceConfig.from_url("tri://127.0.0.1:50051/org.apache.dubbo.samples.HelloWorld") - dubbo_client = dubbo.Client(reference_config) - unary_service_stub = UnaryServiceStub(dubbo_client) - - # Call the remote method - result = unary_service_stub.say_hello(b"Hello from client") - print(result) diff --git a/samples/helloworld/server.py b/samples/helloworld/server.py deleted file mode 100644 index 6ace94c7..00000000 --- a/samples/helloworld/server.py +++ /dev/null @@ -1,45 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import dubbo -from dubbo.configs import ServiceConfig -from dubbo.proxy.handlers import RpcMethodHandler, RpcServiceHandler - - -class UnaryServiceServicer: - def say_hello(self, message: bytes) -> bytes: - print(f"Received message from client: {message}") - return b"Hello from server" - - -def build_service_handler(): - # build a method handler - method_handler = RpcMethodHandler.unary(method=UnaryServiceServicer().say_hello, method_name="unary") - # build a service handler - service_handler = RpcServiceHandler( - service_name="org.apache.dubbo.samples.HelloWorld", - method_handlers=[method_handler], - ) - return service_handler - - -if __name__ == "__main__": - # build service config - service_handler = build_service_handler() - service_config = ServiceConfig(service_handler=service_handler, host="127.0.0.1", port=50051) - # start the server - server = dubbo.Server(service_config).start() - - input("Press Enter to stop the server...\n") diff --git a/samples/integrations/fastapi/README.md b/samples/integrations/fastapi/README.md new file mode 100644 index 00000000..aa6e507f --- /dev/null +++ b/samples/integrations/fastapi/README.md @@ -0,0 +1,174 @@ +# FastAPI + +A web application often fronts services: it takes HTTP requests and calls +the services behind it, which call others in turn. This sample is a small +shop: a [FastAPI](https://fastapi.tiangolo.com/) gateway takes orders over +HTTP, an orders service checks each with the users and the inventory +services, and each failure along the way becomes the HTTP status that fits it. + +``` + HTTP Triple Triple + client ─────────▶ app.py ─────────────▶ orders.py ──────────▶ backend.py + gateway Orders ├──────▶ Users + └──────▶ Inventory +``` + +## What you will learn + +- how to run a Dubbo application for as long as a FastAPI application runs; +- how services find each other through a registry; +- how to pass Python dataclasses and several parameters over Triple; +- how one service calls two others at once; +- how a trace id travels from an HTTP request through every service; +- how timeouts at each step and the statuses of failed calls become HTTP + statuses; +- why a call that changes something is not attempted again. + +## Before you start + +```console +$ pip install "apache-dubbo[zookeeper]" fastapi uvicorn +$ docker compose -f ../../compose.yaml up -d --wait +``` + +## The files + +| File | Role | +|---|---| +| `shop.py` | The contracts of the three services, their types, and the settings every process shares | +| `backend.py` | The Users and Inventory services, in one application, on port 50051 | +| `orders.py` | The Orders service, on port 50052: it calls Users and Inventory | +| `app.py` | The gateway: a FastAPI application that calls Users and Orders | + +## Run it + +From this directory, start each in its own terminal, in this order: + +```console +$ python backend.py +Serving users and inventory on port 50051; press Ctrl+C to stop +``` + +```console +$ python orders.py +Serving orders on port 50052; press Ctrl+C to stop +``` + +```console +$ uvicorn app:app +INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) +``` + +Then place an order: + +```console +$ curl -i -X POST localhost:8000/orders -H 'content-type: application/json' \ + -d '{"user_id": 1, "item": "book", "quantity": 2}' +HTTP/1.1 200 OK +x-trace-id: 82b25943 + +{"id":1,"user":"Alice","item":"book","quantity":2,"total":25.0} +``` + +Each service prints the calls it serves under the trace id of the request: + +```console +[82b25943] place_order(1, 'book', 2) +``` + +```console +[82b25943] get_user(1) +[82b25943] get_item('book') +``` + +Orders that fail answer with the status that says why: + +| Request | Answer | +|---|---| +| `{"user_id": 9, "item": "book", "quantity": 1}` | `404 Not Found`: `no user has ID 9` | +| `{"user_id": 1, "item": "sofa", "quantity": 1}` | `404 Not Found`: `the shop sells no sofa` | +| `{"user_id": 1, "item": "lamp", "quantity": 5}` | `409 Conflict`: `only 2 lamp left` | +| `{"user_id": 1, "item": "book", "quantity": 0}` | `400 Bad Request`: `an order is of one item or more` | +| `{"user_id": 2, "item": "piano", "quantity": 1}` | `504 Gateway Timeout`: `get_item did not complete within 1.0 seconds` | + +Stop `backend.py` and place an order again: it fails with `503 Service +Unavailable`, and `orders.py` prints it once. + +`GET /users/1` calls the Users service from the gateway directly. + +## How it works + +### The gateway and its lifespan + +A Dubbo application runs while `async with` holds it, and must be entered and +left in the same task. FastAPI's `lifespan` does exactly that: it is entered +when the server starts and left when it stops, in one task, and requests are +served in between. So `lifespan` holds the Dubbo application with +`async with dubbo_app`, and routes call the references created next to it. +When uvicorn stops on Ctrl+C, it exits the lifespan, which stops the Dubbo +application gracefully, as in +[07_graceful_shutdown](../../basics/07_graceful_shutdown). + +### Finding each other + +Every application registers what it serves in ZooKeeper and finds what it +calls there, so no process names the address of another: `refer(Users)` +names only the service. Start a second backend on another port, with +`DUBBO__PROTOCOLS__TRI__PORT=50061 python backend.py`, and the orders service +spreads its calls over both. + +### Python types over Triple + +The contracts in `shop.py` are Python classes whose methods take several +parameters and return dataclasses. Protobuf, the default serialization of +Triple, carries one message per call; Hessian 2 carries any of these. The +providers set `serialization="hessian2"`, and publish it in the registry, +where their consumers take it. + +Hessian 2 sends an object under a Java class name, which +`@hessian2.java_class` gives each dataclass; Python services only need to +agree on it, and Java or Go services read the object as that class. + +Triple rather than the Dubbo protocol, because over Triple the status of a +failed call reaches its caller as it was raised, and its deadline travels +with it. Over the Dubbo protocol, statuses that Java does not know arrive as +`UNKNOWN`, as [08_errors_and_timeouts](../../basics/08_errors_and_timeouts) +tells. + +### Two calls at once + +`place_order` needs the user and the item, which do not depend on each other, +so it awaits both with `asyncio.gather`. The first to fail fails the order: +its `RpcError`, raised in the handler, reaches the gateway with its status. + +### The trace id + +A middleware of the gateway takes the `x-trace-id` header of the request, or +makes one, and wraps the request in `dubbo.outgoing({"trace-id": ...})`, so +every Dubbo call made for it attaches the trace id. The orders service reads +it with `dubbo.incoming()`, and the calls it makes while serving pass it on +by themselves, as in [09_context](../../basics/09_context). +[06_logging](../../basics/06_logging) puts it into every log record. + +### Timeouts and statuses + +Each step has its budget: a request may take 2 seconds at the gateway, and +each call of the orders service 1 second. Counting a piano takes 3, so the +orders service gives up on it, and the gateway answers `504`. Over Triple, +the inventory service learns that its caller gave up, and stops counting. + +An exception handler of the gateway turns the status of a failed call into +an HTTP status: `NOT_FOUND` into 404, `FAILED_PRECONDITION` into 409, +`INVALID_ARGUMENT` into 400, `UNAVAILABLE` into 503 and `DEADLINE_EXCEEDED` +into 504; any other into 502. + +### Not twice + +When a call fails as `UNAVAILABLE`, the default `failover` cluster attempts +it again, as [11_load_balancing](../../basics/11_load_balancing) shows. That +is right for reads such as `get_user`, but an order attempted again may be +placed twice, so the gateway refers to Orders with `retries=0`. + +## Next + +- [Samples](../..): the other samples. diff --git a/samples/integrations/fastapi/app.py b/samples/integrations/fastapi/app.py new file mode 100644 index 00000000..96d4a70e --- /dev/null +++ b/samples/integrations/fastapi/app.py @@ -0,0 +1,100 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The gateway of the shop: a FastAPI application that answers each HTTP +# request with calls to the services of the shop. +# Run it with: uvicorn app:app + +import uuid +from collections.abc import AsyncIterator, Awaitable, Callable +from contextlib import asynccontextmanager + +import dubbo +from dubbo import Dubbo, RpcError, Status +from dubbo.config import ApplicationConfig, ConsumerConfig, ReferenceConfig +from fastapi import FastAPI, Request, Response +from fastapi.responses import JSONResponse +from pydantic import BaseModel + +from shop import REGISTRIES, Order, Orders, User, Users + +# The Dubbo application and its references are created once, at import, and +# shared by every request. A request may take 2 seconds in all. +dubbo_app = Dubbo( + application=ApplicationConfig(name="shop-gateway"), + registries=REGISTRIES, + consumer=ConsumerConfig(timeout=2), +) +users = dubbo_app.refer(Users) +# A call that failed as UNAVAILABLE is attempted again by default; an order +# must not be placed twice, so its calls are not. +orders = dubbo_app.refer(Orders, config=ReferenceConfig(retries=0)) + + +# FastAPI enters the lifespan when the server starts and exits it when the +# server stops, in one task, as a Dubbo application must be entered and +# exited. Requests are served in between, while the Dubbo application runs. +@asynccontextmanager +async def lifespan(app: FastAPI) -> AsyncIterator[None]: + async with dubbo_app: + yield + + +app = FastAPI(lifespan=lifespan) + + +# Every Dubbo call made for a request carries its trace id, which the +# services print, and the response tells it to the client. +@app.middleware("http") +async def trace(request: Request, call_next: Callable[[Request], Awaitable[Response]]) -> Response: + trace_id = request.headers.get("x-trace-id") or uuid.uuid4().hex[:8] + with dubbo.outgoing({"trace-id": trace_id}): + response = await call_next(request) + response.headers["x-trace-id"] = trace_id + return response + + +# A failed call answers with the HTTP status that matches its own; any +# other failure of a service is one of the gateway. +HTTP_STATUSES = { + Status.INVALID_ARGUMENT: 400, + Status.NOT_FOUND: 404, + Status.FAILED_PRECONDITION: 409, + Status.UNAVAILABLE: 503, + Status.DEADLINE_EXCEEDED: 504, +} + + +@app.exception_handler(RpcError) +async def rpc_error(request: Request, error: RpcError) -> JSONResponse: + return JSONResponse({"detail": error.message}, status_code=HTTP_STATUSES.get(error.status, 502)) + + +class OrderRequest(BaseModel): + user_id: int + item: str + quantity: int + + +@app.get("/users/{user_id}") +async def get_user(user_id: int) -> User: + return await users.get_user(user_id) + + +@app.post("/orders") +async def place_order(request: OrderRequest) -> Order: + return await orders.place_order(request.user_id, request.item, request.quantity) diff --git a/samples/integrations/fastapi/backend.py b/samples/integrations/fastapi/backend.py new file mode 100644 index 00000000..4ff4948b --- /dev/null +++ b/samples/integrations/fastapi/backend.py @@ -0,0 +1,77 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The users and the inventory of the shop, served by one application. + +import asyncio + +import dubbo +from dubbo import Dubbo, RpcError, Status +from dubbo.config import ApplicationConfig, ProtocolConfig, ProviderConfig + +from shop import REGISTRIES, SERIALIZATION, Inventory, Item, User, Users + +USERS = {1: User(id=1, name="Alice"), 2: User(id=2, name="Bob")} +ITEMS = { + "book": Item(name="book", price=12.5, stock=10), + "lamp": Item(name="lamp", price=30.0, stock=2), + "piano": Item(name="piano", price=2000.0, stock=1), +} + + +def trace_id() -> str: + # The gateway attaches a trace id to each request, and the orders service + # passes it on with the calls it makes. + return dubbo.incoming().attachments.get("trace-id", "-") + + +class UsersImpl(Users): + async def get_user(self, user_id: int) -> User: + print(f"[{trace_id()}] get_user({user_id})") + if user_id not in USERS: + raise RpcError(Status.NOT_FOUND, f"no user has ID {user_id}") + return USERS[user_id] + + +class InventoryImpl(Inventory): + async def get_item(self, name: str) -> Item: + print(f"[{trace_id()}] get_item({name!r})") + if name == "piano": + # The stock of a piano is counted by hand. + await asyncio.sleep(3) + if name not in ITEMS: + raise RpcError(Status.NOT_FOUND, f"the shop sells no {name}") + return ITEMS[name] + + +async def main() -> None: + app = Dubbo( + application=ApplicationConfig(name="shop-backend"), + protocols={"tri": ProtocolConfig(port=50051)}, + registries=REGISTRIES, + provider=ProviderConfig(serialization=SERIALIZATION), + ) + app.export(UsersImpl()) + app.export(InventoryImpl()) + + async with app: + print("Serving users and inventory on port 50051; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/integrations/fastapi/orders.py b/samples/integrations/fastapi/orders.py new file mode 100644 index 00000000..c4bc0d77 --- /dev/null +++ b/samples/integrations/fastapi/orders.py @@ -0,0 +1,70 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The orders service: it calls the users and the inventory services for each +# order. + +import asyncio +import itertools + +import dubbo +from dubbo import Dubbo, RpcError, Status +from dubbo.config import ApplicationConfig, ConsumerConfig, ProtocolConfig, ProviderConfig + +from shop import REGISTRIES, SERIALIZATION, Inventory, Order, Orders, Users + + +class OrdersImpl(Orders): + def __init__(self, users: Users, inventory: Inventory) -> None: + self.users = users + self.inventory = inventory + self.ids = itertools.count(1) + + async def place_order(self, user_id: int, item: str, quantity: int) -> Order: + trace_id = dubbo.incoming().attachments.get("trace-id", "-") + print(f"[{trace_id}] place_order({user_id}, {item!r}, {quantity})") + if quantity < 1: + raise RpcError(Status.INVALID_ARGUMENT, "an order is of one item or more") + + # The two calls run at once. The first to fail fails the order: its + # RpcError, raised here, reaches the caller with its status. + user, stock = await asyncio.gather(self.users.get_user(user_id), self.inventory.get_item(item)) + if stock.stock < quantity: + raise RpcError(Status.FAILED_PRECONDITION, f"only {stock.stock} {item} left") + return Order(id=next(self.ids), user=user.name, item=item, quantity=quantity, total=stock.price * quantity) + + +async def main() -> None: + app = Dubbo( + application=ApplicationConfig(name="shop-orders"), + protocols={"tri": ProtocolConfig(port=50052)}, + registries=REGISTRIES, + provider=ProviderConfig(serialization=SERIALIZATION), + # Each call to the users and the inventory may take 1 second. + consumer=ConsumerConfig(timeout=1), + ) + users = app.refer(Users) + inventory = app.refer(Inventory) + app.export(OrdersImpl(users, inventory)) + + async with app: + print("Serving orders on port 50052; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/integrations/fastapi/shop.py b/samples/integrations/fastapi/shop.py new file mode 100644 index 00000000..0a909709 --- /dev/null +++ b/samples/integrations/fastapi/shop.py @@ -0,0 +1,77 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contracts of the services of the shop, and the settings they share. +# Every process imports this module, so they agree on the types and the +# registry. + +import dataclasses +import typing + +import dubbo +import hessian2 +from dubbo.config import RegistryConfig + +# Each application registers its services in ZooKeeper, and finds those it +# calls there. +REGISTRIES = {"zookeeper": RegistryConfig(address="zookeeper://127.0.0.1:2181")} +# Over Triple, Hessian 2 carries Python types and several parameters, where +# protobuf carries one message. Providers name it, and their consumers take +# it from the registry. +SERIALIZATION = "hessian2" + + +# Hessian 2 carries an object under a Java class name, field by field, so +# that Java and Go read it too; the name is any that the services agree on. +@hessian2.java_class("org.apache.dubbo.samples.shop.User") +@dataclasses.dataclass +class User: + id: int + name: str + + +@hessian2.java_class("org.apache.dubbo.samples.shop.Item") +@dataclasses.dataclass +class Item: + name: str + price: float + stock: int + + +@hessian2.java_class("org.apache.dubbo.samples.shop.Order") +@dataclasses.dataclass +class Order: + id: int + user: str + item: str + quantity: int + total: float + + +@dubbo.service("org.apache.dubbo.samples.shop.Users") +class Users(typing.Protocol): + async def get_user(self, user_id: int) -> User: ... + + +@dubbo.service("org.apache.dubbo.samples.shop.Inventory") +class Inventory(typing.Protocol): + async def get_item(self, name: str) -> Item: ... + + +@dubbo.service("org.apache.dubbo.samples.shop.Orders") +class Orders(typing.Protocol): + async def place_order(self, user_id: int, item: str, quantity: int) -> Order: ... diff --git a/samples/integrations/pydantic_ai/README.md b/samples/integrations/pydantic_ai/README.md new file mode 100644 index 00000000..224768fe --- /dev/null +++ b/samples/integrations/pydantic_ai/README.md @@ -0,0 +1,136 @@ +# Pydantic AI + +An AI agent works by calling tools, and in a company the tools it needs are +the services the company already runs. This sample is an agent, built with +[Pydantic AI](https://ai.pydantic.dev/), that plans the restocking of a +warehouse before a sale. Its tools are the supply services of the company, +called over Dubbo: the methods of a reference are given to the agent as they +are, with no code between them. + +``` + tools Dubbo + planner.py ───────────────────▶ Inventory.low_stock ┐ + Pydantic AI agent ▶ Forecast.predict ├─▶ services.py + + a model ▶ Suppliers.quotes ┘ + │ + ▼ the plan, once a person agrees + Purchasing.draft ─────────────────────────────────────▶ services.py +``` + +## What you will learn + +- how the methods of a reference become the tools of an agent, with their + names, parameters and descriptions taken from the contract; +- how to write a contract whose docstrings tell a model what each method does; +- why the agent only reads, and a person decides what is written; +- how to run it with any model that speaks the API of OpenAI, or with none. + +## Before you start + +```console +$ pip install apache-dubbo "pydantic-ai-slim[openai]" +``` + +You also need a model: any service compatible with the Chat Completions API +of OpenAI, which most providers and self-hosted servers such as vLLM and +Ollama offer, or another that Pydantic AI supports. + +## The files + +| File | Role | +|---|---| +| `supply.py` | The contracts of the four supply services and their types | +| `services.py` | The services, in one application, on port 20880, with the stock, sales and suppliers of a few SKUs | +| `planner.py` | The agent: it plans with three services as its tools, then drafts the orders once you agree | + +## Run it + +From this directory, start the services: + +```console +$ python services.py +Serving inventory, forecast, suppliers and purchasing on port 20880; press Ctrl+C to stop +``` + +Then, in another terminal, say which model to use, and ask the agent for a +plan: + +```console +$ export OPENAI_BASE_URL=https://... OPENAI_API_KEY=... MODEL=openai-chat: +$ python planner.py +``` + +`OPENAI_BASE_URL` is the address of the service, ending as its documentation +says, often in `/v1`; `` is a name it lists. The model must support +tool calls. + +Without arguments, it asks for the sale this sample is set up for: "The sale +starts in 7 days and lasts 3. Restock the EAST warehouse for it, within a +budget of 20,000." Give your own request as the arguments instead. + +`services.py` prints each call the agent makes, as the model chooses them: + +```console +low_stock('EAST') +predict('TEA-OOLONG-250G', 10) +quotes('TEA-OOLONG-250G') +... +``` + +`planner.py` prints the plan, with the reason for each line, and asks before +it drafts the orders. The stock, sales and suppliers are set so that one plan +is right: 320 oolong tea from Fujian Hills, as Hangzhou Leaf is cheaper but +too slow for the sale; 285 flasks from Yongkang Steel; no mugs, as those in +transit cover the sale; 19,705.00 in all. Lower the budget, and the agent has +to choose what to leave out. + +### Another model, or none + +`MODEL` names the model as [Pydantic AI](https://ai.pydantic.dev/models/) +names them, so any model it supports may be given, with the settings its +page names. Set it to `test` to run without a model: the test model of +Pydantic AI calls each tool once, with arguments it makes up, which shows the +calls going through without an API key. + +## How it works + +### The agent loop + +An agent runs a loop: it sends the request and the descriptions of its tools +to the model; the model answers with the tools to call; the agent calls them +and sends back what they return; and so on, until the model answers with the +result. `agent.run` is that loop, and each call of a tool is here a Dubbo +call. The result is a `Plan`, which Pydantic checks: when the model answers +with something else, the agent asks it again. + +### Contracts as tools + +A model chooses a tool by its name, its parameters and its description. +Pydantic AI takes them from the function it is given: its name, signature, +type annotations and docstring. Each method of a reference has those of the +method of the contract it calls, so `inventory.low_stock` is described as +`low_stock(warehouse: str)`, with the docstring of `Inventory.low_stock`, and +the parameters described under its `Args:`. The docstrings of `supply.py` are +therefore written for the model as much as for people. The same methods can +be given to other frameworks that describe tools by their functions, such as +LangChain, the OpenAI Agents SDK or an MCP server. + +### Reading and writing + +The tools of the agent only read. Drafting a purchase order is not one of +them: the agent plans, the plan is printed, and the orders are drafted by +`planner.py` itself once you answer `y`. A model may choose wrongly; what +changes the business stays with a person. + +### The services behind the tools + +The services serve over the Dubbo protocol, with Hessian 2 and Java class +names, as most Java services do, so in a company they may as well be Java +services, as [interop/java](../../interop/java) shows. Here the planner calls +them at their address; with a registry, it would find them by name, as in +[FastAPI](../fastapi). + +## Next + +- [FastAPI](../fastapi): services behind a web application. +- [Samples](../..): the other samples. diff --git a/samples/integrations/pydantic_ai/planner.py b/samples/integrations/pydantic_ai/planner.py new file mode 100644 index 00000000..8e2d1635 --- /dev/null +++ b/samples/integrations/pydantic_ai/planner.py @@ -0,0 +1,101 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# An agent that plans the restocking of a warehouse before a sale, with the +# supply services as its tools. It only reads; the purchase orders it plans +# are drafted once a person agrees. + +import asyncio +import os +import sys + +from dubbo import Dubbo +from pydantic import BaseModel +from pydantic_ai import Agent + +from supply import ADDRESS, Forecast, Inventory, Purchasing, Suppliers + +# A model as Pydantic AI names it, such as openai-chat: for any service +# compatible with the Chat Completions API of OpenAI, or test for none. +MODEL = os.environ.get("MODEL") +REQUEST = "The sale starts in 7 days and lasts 3. Restock the EAST warehouse for it, within a budget of 20,000." + + +class Line(BaseModel): + sku: str + supplier: str + quantity: int + unit_price: float + reason: str + + +class Plan(BaseModel): + lines: list[Line] + total: float + notes: str + + +INSTRUCTIONS = """\ +You plan the restocking of a warehouse before a sale. For each SKU running +low, forecast its sales until the sale ends, and order what its stock and the +goods in transit do not cover. Choose a supplier whose goods arrive before +the sale starts, the cheapest of those, and order at least its minimum. Keep +the total within the budget; when it does not fit, leave out what is least +needed. Say in each line why you chose it, and in the notes what you left out. +""" + + +async def main(request: str) -> None: + app = Dubbo() + inventory = app.refer(Inventory, url=ADDRESS) + forecast = app.refer(Forecast, url=ADDRESS) + suppliers = app.refer(Suppliers, url=ADDRESS) + purchasing = app.refer(Purchasing, url=ADDRESS) + + # The methods of the references are the tools: their names, parameters + # and docstrings are those of the contracts. + agent = Agent( + MODEL, + instructions=INSTRUCTIONS, + tools=[inventory.low_stock, forecast.predict, suppliers.quotes], + output_type=Plan, + ) + + async with app: + plan = (await agent.run(request)).output + + for line in plan.lines: + print( + f"{line.sku:<20} {line.quantity:>6} from {line.supplier:<16} at {line.unit_price:>7.2f} {line.reason}" + ) + print(f"Total {plan.total:,.2f}. {plan.notes}") + + # Writing is left to a person, not to the model. + answer = await asyncio.to_thread(input, "Draft these purchase orders? [y/N] ") + if answer.strip().lower() != "y": + print("Nothing drafted") + return + + for line in plan.lines: + draft = await purchasing.draft(line.supplier, line.sku, line.quantity) + print(f"Drafted {draft.id}: {draft.quantity} {draft.sku} from {draft.supplier}, {draft.total:,.2f}") + + +if __name__ == "__main__": + if MODEL is None: + sys.exit("Set MODEL to the model to plan with, such as openai-chat:, or to test") + asyncio.run(main(" ".join(sys.argv[1:]) or REQUEST)) diff --git a/samples/integrations/pydantic_ai/services.py b/samples/integrations/pydantic_ai/services.py new file mode 100644 index 00000000..5675a270 --- /dev/null +++ b/samples/integrations/pydantic_ai/services.py @@ -0,0 +1,99 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The supply services of a company, in one application: in a real company, +# each is a service of its own, often in Java. + +import asyncio +import itertools + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig + +from supply import Draft, Forecast, Inventory, Purchasing, Quote, Stock, Suppliers + +STOCK = { + "EAST": [ + Stock(sku="TEA-OOLONG-250G", name="Oolong tea, 250 g", on_hand=120, in_transit=0), + Stock(sku="MUG-CERAMIC-WHITE", name="White ceramic mug", on_hand=40, in_transit=200), + Stock(sku="FLASK-500ML", name="Vacuum flask, 500 ml", on_hand=15, in_transit=0), + ] +} +# Units a day before the sale, and how many times more during it. +DAILY = {"TEA-OOLONG-250G": (20, 5), "MUG-CERAMIC-WHITE": (8, 3), "FLASK-500ML": (12, 6)} +SALE_STARTS, SALE_DAYS = 7, 3 +QUOTES = { + "TEA-OOLONG-250G": [ + Quote(supplier="Hangzhou Leaf", sku="TEA-OOLONG-250G", unit_price=18.0, lead_days=10, min_order=100), + Quote(supplier="Fujian Hills", sku="TEA-OOLONG-250G", unit_price=21.5, lead_days=4, min_order=50), + ], + "MUG-CERAMIC-WHITE": [ + Quote(supplier="Jingdezhen Kiln", sku="MUG-CERAMIC-WHITE", unit_price=9.0, lead_days=5, min_order=200), + ], + "FLASK-500ML": [ + Quote(supplier="Yongkang Steel", sku="FLASK-500ML", unit_price=45.0, lead_days=6, min_order=100), + Quote(supplier="Ningbo Home", sku="FLASK-500ML", unit_price=52.0, lead_days=3, min_order=20), + ], +} +PRICES = {(quote.supplier, quote.sku): quote.unit_price for quotes in QUOTES.values() for quote in quotes} + + +class InventoryImpl(Inventory): + async def low_stock(self, warehouse: str) -> list[Stock]: + print(f"low_stock({warehouse!r})") + return STOCK.get(warehouse, []) + + +class ForecastImpl(Forecast): + async def predict(self, sku: str, days: int) -> int: + print(f"predict({sku!r}, {days})") + daily, uplift = DAILY.get(sku, (0, 1)) + sale = max(0, min(days, SALE_STARTS + SALE_DAYS) - SALE_STARTS) + return daily * (days - sale) + daily * uplift * sale + + +class SuppliersImpl(Suppliers): + async def quotes(self, sku: str) -> list[Quote]: + print(f"quotes({sku!r})") + return QUOTES.get(sku, []) + + +class PurchasingImpl(Purchasing): + def __init__(self) -> None: + self._ids = itertools.count(1) + + async def draft(self, supplier: str, sku: str, quantity: int) -> Draft: + print(f"draft({supplier!r}, {sku!r}, {quantity})") + total = PRICES.get((supplier, sku), 0.0) * quantity + return Draft(id=f"PO-{next(self._ids):04d}", supplier=supplier, sku=sku, quantity=quantity, total=total) + + +async def main() -> None: + app = Dubbo( + application=ApplicationConfig(name="supply-services"), + protocols={"dubbo": ProtocolConfig(port=20880)}, + ) + for service in (InventoryImpl(), ForecastImpl(), SuppliersImpl(), PurchasingImpl()): + app.export(service) + + async with app: + print("Serving inventory, forecast, suppliers and purchasing on port 20880; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/integrations/pydantic_ai/supply.py b/samples/integrations/pydantic_ai/supply.py new file mode 100644 index 00000000..49641f34 --- /dev/null +++ b/samples/integrations/pydantic_ai/supply.py @@ -0,0 +1,105 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contracts of the supply services, which the services and the planner +# both import. The docstrings are what the agent reads to choose its tools. + +import dataclasses +import typing + +import dubbo +import hessian2 + +# The services serve over the Dubbo protocol, which carries these types with +# Hessian 2, as most Java services do. +ADDRESS = "dubbo://127.0.0.1:20880" + + +@hessian2.java_class("org.apache.dubbo.samples.supply.Stock") +@dataclasses.dataclass +class Stock: + sku: str + name: str + on_hand: int + in_transit: int + + +@hessian2.java_class("org.apache.dubbo.samples.supply.Quote") +@dataclasses.dataclass +class Quote: + supplier: str + sku: str + unit_price: float + lead_days: int + min_order: int + + +@hessian2.java_class("org.apache.dubbo.samples.supply.Draft") +@dataclasses.dataclass +class Draft: + id: str + supplier: str + sku: str + quantity: int + total: float + + +@dubbo.service("org.apache.dubbo.samples.supply.Inventory") +class Inventory(typing.Protocol): + async def low_stock(self, warehouse: str) -> list[Stock]: + """Return the SKUs of a warehouse whose stock is running low. + + Args: + warehouse: Code of the warehouse, such as EAST. + """ + ... + + +@dubbo.service("org.apache.dubbo.samples.supply.Forecast") +class Forecast(typing.Protocol): + async def predict(self, sku: str, days: int) -> int: + """Return how many units of a SKU will sell in the coming days, the sale included. + + Args: + sku: The SKU. + days: Number of days from today. + """ + ... + + +@dubbo.service("org.apache.dubbo.samples.supply.Suppliers") +class Suppliers(typing.Protocol): + async def quotes(self, sku: str) -> list[Quote]: + """Return what each supplier of a SKU asks for it, how many days its goods take to arrive, and its minimum order. + + Args: + sku: The SKU. + """ + ... + + +@dubbo.service("org.apache.dubbo.samples.supply.Purchasing") +class Purchasing(typing.Protocol): + async def draft(self, supplier: str, sku: str, quantity: int) -> Draft: + """Draft a purchase order, for a buyer to send. + + Args: + supplier: The supplier. + sku: The SKU. + quantity: Number of units. + """ + ... diff --git a/samples/interop/go/README.md b/samples/interop/go/README.md new file mode 100644 index 00000000..257f3219 --- /dev/null +++ b/samples/interop/go/README.md @@ -0,0 +1,156 @@ +# Go + +Dubbo Go serves Triple with Protobuf, as Dubbo for Python does. A Python +service and a Go service share a `.proto` file and find each other in the +same registry. This sample runs a provider and a consumer in each language, +which find each other in Nacos. + +## What you will learn + +- how Python and Go share a contract in a `.proto` file, and generate their + code from it; +- how statuses and attachments, such as a trace id, cross between the + languages; +- how each side finds the other through a registry, with no addresses in + the code. + +## Before you start + +You need Go 1.25 or later, and Nacos, as in +[04_registry](../../basics/04_registry): + +```console +$ pip install "apache-dubbo[nacos]" +$ docker compose -f ../../compose.yaml up -d --wait +``` + +## The files + +| File | Role | +|---|---| +| `proto/greeter.proto` | The contract of `Greeter`, which both languages generate code from | +| `greeter_pb2.py`, `greeter_pb2.pyi`, `greeter_dubbo.py` | The Python code generated from it, as in [02_protobuf](../../basics/02_protobuf) | +| `python_server.py`, `python_client.py` | The Python provider and consumer | +| `go/greeter/` | The Go code generated from it | +| `go/server/`, `go/client/` | The Go provider and consumer, in a Go module | + +## Run it + +### Python calls Go + +From this directory, start the Go server: + +```console +$ go -C go run ./server +Serving Greeter on port 50052; press Ctrl+C to stop +``` + +The first run downloads the dependencies, which takes a while. In another +terminal, run the Python client: + +```console +$ python python_client.py +Hello, Alice, from Go! +Hello #1, Bob, from Go! +Hello #2, Bob, from Go! +Hello #3, Bob, from Go! +INVALID_ARGUMENT: a name is required +``` + +The Go server prints each call it serves, with the trace id that the Python +client attached: + +```console +[py-4bf9] SayHello(Alice) +[py-4bf9] SayHello() +``` + +### Go calls Python + +Stop the Go server with Ctrl+C, and start the Python server: + +```console +$ python python_server.py +Serving Greeter on port 50051; press Ctrl+C to stop +``` + +In another terminal, run the Go client: + +```console +$ go -C go run ./client +Hello, Alice, from Python! +Hello #1, Bob, from Python! +Hello #2, Bob, from Python! +Hello #3, Bob, from Python! +``` + +The Python server prints the trace id that the Go client attached: + +```console +[go-1c9d] say_hello(Alice) +``` + +## How it works + +### Finding each other + +A consumer looks a service up by its name, and reads from the metadata of +each instance which protocol and port to call it on; neither side knows the +language of the other. + +By default, Dubbo Go registers and finds providers per application only. +Python registers both per application and per service, and finds providers +per application while there are any, as +[04_registry](../../basics/04_registry) explains, so the two meet per +application with their defaults. + +### One contract + +`Greeter` is defined once, in `proto/greeter.proto`, and its name is the +package and service of the file: `org.apache.dubbo.samples.Greeter`. +`option go_package` only says where the Go code goes. Each language calls +and serves it as its own code: a `Recv()` loop in Go, `async for` in +Python. + +The generated code of both languages is included. To generate the Go code +again, install the two plugins of protoc for Go, and run protoc from the Go +module, since `protoc-gen-go-triple` writes its file into the module of the +current directory: + +```console +$ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest +$ go install github.com/dubbogo/protoc-gen-go-triple/v3@v3.0.3 +$ cd go +$ protoc -I../proto --go_out=. --go_opt=module=interop --go-triple_out=. ../proto/greeter.proto +``` + +`python -m grpc_tools.protoc` from the `protoc` extra can stand for +`protoc`. + +### Statuses + +A Go handler fails with a status by returning +`triple_protocol.NewError(triple_protocol.CodeInvalidArgument, err)`, which +reaches Python as an `RpcError` of `INVALID_ARGUMENT`. An `RpcError` of a +Python handler reaches Go as an error with the same code. + +Dubbo Go retries a failed call, by default twice, whatever its status; +Python retries only calls that fail as `UNAVAILABLE`. + +### Attachments + +Over Triple, attachments travel as headers of the call, so each language +reads what the other attached: + +| | Attach to calls | Read in a handler | +|---|---|---| +| Python | `with dubbo.outgoing({"trace-id": ...}):` | `dubbo.incoming().attachments` | +| Go | `triple_protocol.AppendToOutgoingContext(ctx, "trace-id", ...)` | `triple_protocol.FromIncomingContext(ctx)` | + +Both attach to every call made in their block or with their context. Header +names are case-insensitive, so keys in lower case read the same in both. + +## Next + +- [interop/grpc](../grpc): call Dubbo services from gRPC, and gRPC services + from Dubbo. diff --git a/samples/interop/go/go/client/main.go b/samples/interop/go/go/client/main.go new file mode 100644 index 00000000..523fc578 --- /dev/null +++ b/samples/interop/go/go/client/main.go @@ -0,0 +1,70 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// The Go consumer: it finds the Python service in Nacos and calls it. +package main + +import ( + "context" + "fmt" + + "dubbo.apache.org/dubbo-go/v3" + _ "dubbo.apache.org/dubbo-go/v3/imports" + "dubbo.apache.org/dubbo-go/v3/logger" + "dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol" + "dubbo.apache.org/dubbo-go/v3/registry" + + "interop/greeter" +) + +func main() { + instance, err := dubbo.NewInstance( + dubbo.WithName("go-client"), + dubbo.WithRegistry(registry.WithNacos(), registry.WithAddress("127.0.0.1:8848")), + dubbo.WithLogger(logger.WithLevel("warn")), + ) + if err != nil { + panic(err) + } + client, err := instance.NewClient() + if err != nil { + panic(err) + } + service, err := greeter.NewGreeter(client) + if err != nil { + panic(err) + } + // Every call made with this context attaches the trace id. + ctx := triple_protocol.AppendToOutgoingContext(context.Background(), "trace-id", "go-1c9d") + + reply, err := service.SayHello(ctx, &greeter.HelloRequest{Name: "Alice"}) + if err != nil { + panic(err) + } + fmt.Println(reply.Message) + + stream, err := service.SayHelloStream(ctx, &greeter.HelloRequest{Name: "Bob"}) + if err != nil { + panic(err) + } + for stream.Recv() { + fmt.Println(stream.Msg().Message) + } + if err := stream.Err(); err != nil { + panic(err) + } +} diff --git a/samples/interop/go/go/go.mod b/samples/interop/go/go/go.mod new file mode 100644 index 00000000..00f42cd9 --- /dev/null +++ b/samples/interop/go/go/go.mod @@ -0,0 +1,158 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +module interop + +go 1.25.0 + +require ( + dubbo.apache.org/dubbo-go/v3 v3.3.2 + google.golang.org/protobuf v1.34.2 +) + +require ( + github.com/RoaringBitmap/roaring v1.2.3 // indirect + github.com/Workiva/go-datastructures v1.0.52 // indirect + github.com/alibaba/sentinel-golang v1.0.4 // indirect + github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect + github.com/alibabacloud-go/tea v1.1.17 // indirect + github.com/alibabacloud-go/tea-utils v1.4.4 // indirect + github.com/aliyun/alibaba-cloud-sdk-go v1.61.1800 // indirect + github.com/aliyun/alibabacloud-dkms-gcs-go-sdk v0.2.2 // indirect + github.com/aliyun/alibabacloud-dkms-transfer-go-sdk v0.1.7 // indirect + github.com/apache/dubbo-getty v1.4.10 // indirect + github.com/apache/dubbo-go-hessian2 v1.12.5 // indirect + github.com/apolloconfig/agollo/v4 v4.4.0 // indirect + github.com/beorn7/perks v1.0.1 // indirect + github.com/bits-and-blooms/bitset v1.2.0 // indirect + github.com/buger/jsonparser v1.2.0 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/coreos/go-semver v0.3.0 // indirect + github.com/coreos/go-systemd/v22 v22.3.2 // indirect + github.com/creasty/defaults v1.5.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dlclark/regexp2 v1.7.0 // indirect + github.com/dop251/goja v0.0.0-20240220182346-e401ed450204 // indirect + github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5 // indirect + github.com/dubbogo/gost v1.14.3 // indirect + github.com/dubbogo/grpc-go v1.42.10 // indirect + github.com/dubbogo/triple v1.2.2-rc4 // indirect + github.com/dustin/go-humanize v1.0.1 // indirect + github.com/emicklei/go-restful/v3 v3.10.1 // indirect + github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/go-logr/logr v1.4.3 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.12.0 // indirect + github.com/go-resty/resty/v2 v2.7.0 // indirect + github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/mock v1.6.0 // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/golang/snappy v0.0.4 // indirect + github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/gorilla/websocket v1.4.2 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/hashicorp/golang-lru v0.5.4 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/hashicorp/vault/sdk v0.7.0 // indirect + github.com/influxdata/tdigest v0.0.1 // indirect + github.com/jmespath/go-jmespath v0.4.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/k0kubun/pp v3.0.1+incompatible // indirect + github.com/knadh/koanf v1.5.0 // indirect + github.com/leodido/go-urn v1.2.2 // indirect + github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect + github.com/magiconair/properties v1.8.5 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.16 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/mschoch/smat v0.2.0 // indirect + github.com/nacos-group/nacos-sdk-go/v2 v2.2.5 // indirect + github.com/natefinch/lumberjack v2.0.0+incompatible // indirect + github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 // indirect + github.com/opentracing/opentracing-go v1.2.0 // indirect + github.com/openzipkin/zipkin-go v0.4.2 // indirect + github.com/pelletier/go-toml v1.9.3 // indirect + github.com/pierrec/lz4 v2.6.1+incompatible // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/polarismesh/polaris-go v1.3.0 // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect + github.com/prometheus/client_golang v1.19.1 // indirect + github.com/prometheus/client_model v0.5.0 // indirect + github.com/prometheus/common v0.48.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect + github.com/quic-go/qpack v0.6.0 // indirect + github.com/quic-go/quic-go v0.59.1 // indirect + github.com/shirou/gopsutil/v3 v3.22.2 // indirect + github.com/sirupsen/logrus v1.9.4 // indirect + github.com/spaolacci/murmur3 v1.1.0 // indirect + github.com/spf13/afero v1.6.0 // indirect + github.com/spf13/cast v1.3.1 // indirect + github.com/spf13/jwalterweatherman v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/spf13/viper v1.8.1 // indirect + github.com/subosito/gotenv v1.2.0 // indirect + github.com/tklauser/go-sysconf v0.3.10 // indirect + github.com/tklauser/numcpus v0.4.0 // indirect + github.com/uber/jaeger-client-go v2.29.1+incompatible // indirect + github.com/uber/jaeger-lib v2.4.1+incompatible // indirect + github.com/ugorji/go/codec v1.2.6 // indirect + github.com/yusufpapurcu/wmi v1.2.2 // indirect + go.etcd.io/etcd/api/v3 v3.5.7 // indirect + go.etcd.io/etcd/client/pkg/v3 v3.5.7 // indirect + go.etcd.io/etcd/client/v3 v3.5.7 // indirect + go.opentelemetry.io/contrib/propagators/b3 v1.10.0 // indirect + go.opentelemetry.io/otel v1.21.0 // indirect + go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0 // indirect + go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.21.0 // indirect + go.opentelemetry.io/otel/exporters/zipkin v1.21.0 // indirect + go.opentelemetry.io/otel/metric v1.21.0 // indirect + go.opentelemetry.io/otel/sdk v1.21.0 // indirect + go.opentelemetry.io/otel/trace v1.21.0 // indirect + go.opentelemetry.io/proto/otlp v1.0.0 // indirect + go.uber.org/atomic v1.10.0 // indirect + go.uber.org/multierr v1.8.0 // indirect + go.uber.org/zap v1.21.0 // indirect + golang.org/x/crypto v0.53.0 // indirect + golang.org/x/net v0.56.0 // indirect + golang.org/x/sync v0.21.0 // indirect + golang.org/x/sys v0.46.0 // indirect + golang.org/x/text v0.39.0 // indirect + golang.org/x/time v0.15.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect + google.golang.org/grpc v1.64.1 // indirect + gopkg.in/ini.v1 v1.66.2 // indirect + gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/samples/interop/go/go/go.sum b/samples/interop/go/go/go.sum new file mode 100644 index 00000000..a7eef428 --- /dev/null +++ b/samples/interop/go/go/go.sum @@ -0,0 +1,1422 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI= +cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk= +cloud.google.com/go v0.78.0/go.mod h1:QjdrLG0uq+YwhjoVOLsS1t7TW8fs36kLs4XO5R5ECHg= +cloud.google.com/go v0.79.0/go.mod h1:3bzgcEeQlzbuEAYu4mrWhKqWjmpprinYgKJLgKHnbb8= +cloud.google.com/go v0.81.0/go.mod h1:mk/AM35KwGk/Nm2YSeZbxXdrNK3KZOYHmLkOqC2V6E0= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +dubbo.apache.org/dubbo-go/v3 v3.3.2 h1:EGvql7w2vUtYFTqRbI+jcbaDg4JY7vUfKmc7Z+d8RoI= +dubbo.apache.org/dubbo-go/v3 v3.3.2/go.mod h1:TZIR3cVt1Gi1XX/wqU6YJ24Av8fqidlbNxgC18wdS8M= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/HdrHistogram/hdrhistogram-go v1.1.2 h1:5IcZpTvzydCQeHzK4Ef/D5rrSqwxob0t8PQPMybUNFM= +github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= +github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/RoaringBitmap/roaring v1.2.3 h1:yqreLINqIrX22ErkKI0vY47/ivtJr6n+kMhVOVmhWBY= +github.com/RoaringBitmap/roaring v1.2.3/go.mod h1:plvDsJQpxOC5bw8LRteu/MLWHsHez/3y6cubLI4/1yE= +github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= +github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= +github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= +github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= +github.com/Workiva/go-datastructures v1.0.52 h1:PLSK6pwn8mYdaoaCZEMsXBpBotr4HHn9abU0yMQt0NI= +github.com/Workiva/go-datastructures v1.0.52/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA= +github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= +github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= +github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= +github.com/agiledragon/gomonkey/v2 v2.11.0 h1:5oxSgA+tC1xuGsrIorR+sYiziYltmJyEZ9qA25b6l5U= +github.com/agiledragon/gomonkey/v2 v2.11.0/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY= +github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= +github.com/alibaba/sentinel-golang v1.0.4 h1:i0wtMvNVdy7vM4DdzYrlC4r/Mpk1OKUUBurKKkWhEo8= +github.com/alibaba/sentinel-golang v1.0.4/go.mod h1:Lag5rIYyJiPOylK8Kku2P+a23gdKMMqzQS7wTnjWEpk= +github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 h1:NqugFkGxx1TXSh/pBcU00Y6bljgDPaFdh5MUSeJ7e50= +github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68/go.mod h1:6pb/Qy8c+lqua8cFpEy7g39NRRqOWc3rOwAy8m5Y2BY= +github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg= +github.com/alibabacloud-go/tea v1.1.17 h1:05R5DnaJXe9sCNIe8KUgWHC/z6w/VZIwczgUwzRnul8= +github.com/alibabacloud-go/tea v1.1.17/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A= +github.com/alibabacloud-go/tea-utils v1.4.4 h1:lxCDvNCdTo9FaXKKq45+4vGETQUKNOW/qKTcX9Sk53o= +github.com/alibabacloud-go/tea-utils v1.4.4/go.mod h1:KNcT0oXlZZxOXINnZBs6YvgOd5aYp9U67G+E3R8fcQw= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.18/go.mod h1:v8ESoHo4SyHmuB4b1tJqDHxfTGEciD+yhvOU/5s1Rfk= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704/go.mod h1:RcDobYh8k5VP6TNybz9m++gL3ijVI5wueVr0EM10VsU= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.1800 h1:ie/8RxBOfKZWcrbYSJi2Z8uX8TcOlSMwPlEJh83OeOw= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.1800/go.mod h1:RcDobYh8k5VP6TNybz9m++gL3ijVI5wueVr0EM10VsU= +github.com/aliyun/alibabacloud-dkms-gcs-go-sdk v0.2.2 h1:rWkH6D2XlXb/Y+tNAQROxBzp3a0p92ni+pXcaHBe/WI= +github.com/aliyun/alibabacloud-dkms-gcs-go-sdk v0.2.2/go.mod h1:GDtq+Kw+v0fO+j5BrrWiUHbBq7L+hfpzpPfXKOZMFE0= +github.com/aliyun/alibabacloud-dkms-transfer-go-sdk v0.1.7 h1:olLiPI2iM8Hqq6vKnSxpM3awCrm9/BeOgHpzQkOYnI4= +github.com/aliyun/alibabacloud-dkms-transfer-go-sdk v0.1.7/go.mod h1:oDg1j4kFxnhgftaiLJABkGeSvuEvSF5Lo6UmRAMruX4= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/apache/dubbo-getty v1.4.10 h1:ZmkpHJa/qgS0evX2tTNqNCz6rClI/9Wwp7ctyMml82w= +github.com/apache/dubbo-getty v1.4.10/go.mod h1:V64WqLIxksEgNu5aBJBOxNIvpOZyfUJ7J/DXBlKSUoA= +github.com/apache/dubbo-go-hessian2 v1.9.1/go.mod h1:xQUjE7F8PX49nm80kChFvepA/AvqAZ0oh/UaB6+6pBE= +github.com/apache/dubbo-go-hessian2 v1.9.3/go.mod h1:xQUjE7F8PX49nm80kChFvepA/AvqAZ0oh/UaB6+6pBE= +github.com/apache/dubbo-go-hessian2 v1.12.5 h1:19lJz2Md0EYF2bOtEvFqXEQRYvLz04GfsoocsBWlLWQ= +github.com/apache/dubbo-go-hessian2 v1.12.5/go.mod h1:QP9Tc0w/B/mDopjusebo/c7GgEfl6Lz8jeuFg8JA6yw= +github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= +github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= +github.com/apolloconfig/agollo/v4 v4.4.0 h1:bIIRTEN4f7HgLx97/cNpduEvP9qQ7BkCyDOI2j800VM= +github.com/apolloconfig/agollo/v4 v4.4.0/go.mod h1:6WjI68IzqMk/Y6ghMtrj5AX6Uewo20ZnncvRhTceQqg= +github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A= +github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= +github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= +github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= +github.com/aws/aws-sdk-go-v2 v1.9.2/go.mod h1:cK/D0BBs0b/oWPIcX/Z/obahJK1TT7IPVjy53i/mX/4= +github.com/aws/aws-sdk-go-v2/config v1.8.3/go.mod h1:4AEiLtAb8kLs7vgw2ZV3p2VZ1+hBavOc84hqxVNpCyw= +github.com/aws/aws-sdk-go-v2/credentials v1.4.3/go.mod h1:FNNC6nQZQUuyhq5aE5c7ata8o9e4ECGmS4lAXC7o1mQ= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.6.0/go.mod h1:gqlclDEZp4aqJOancXK6TN24aKhT0W0Ae9MHk3wzTMM= +github.com/aws/aws-sdk-go-v2/internal/ini v1.2.4/go.mod h1:ZcBrrI3zBKlhGFNYWvju0I3TR93I7YIgAfy82Fh4lcQ= +github.com/aws/aws-sdk-go-v2/service/appconfig v1.4.2/go.mod h1:FZ3HkCe+b10uFZZkFdvf98LHW21k49W8o8J366lqVKY= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.3.2/go.mod h1:72HRZDLMtmVQiLG2tLfQcaWLCssELvGl+Zf2WVxMmR8= +github.com/aws/aws-sdk-go-v2/service/sso v1.4.2/go.mod h1:NBvT9R1MEF+Ud6ApJKM0G+IkPchKS7p7c2YPKwHmBOk= +github.com/aws/aws-sdk-go-v2/service/sts v1.7.2/go.mod h1:8EzeIqfWt2wWT4rJVu3f21TfrhJ8AEMzVybRNSb/b4g= +github.com/aws/smithy-go v1.8.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= +github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bits-and-blooms/bitset v1.2.0 h1:Kn4yilvwNtMACtf1eYDlG8H77R07mZSPbMjLyS07ChA= +github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= +github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= +github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= +github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= +github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= +github.com/buger/jsonparser v1.2.0 h1:4EFcvK1kD4jyj6YqNK6skK6w+y7FHHBR+XBCtxwu/6g= +github.com/buger/jsonparser v1.2.0/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= +github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= +github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= +github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= +github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo= +github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA= +github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= +github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= +github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI= +github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/creasty/defaults v1.5.2 h1:/VfB6uxpyp6h0fr7SPp7n8WJBoV8jfxQXPCnkVSjyls= +github.com/creasty/defaults v1.5.2/go.mod h1:FPZ+Y0WNrbqOVw+c6av63eyHUAl6pMHZwqLPvXUZGfY= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= +github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo= +github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= +github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= +github.com/dop251/goja v0.0.0-20240220182346-e401ed450204 h1:O7I1iuzEA7SG+dK8ocOBSlYAA9jBUmCYl/Qa7ey7JAM= +github.com/dop251/goja v0.0.0-20240220182346-e401ed450204/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4= +github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y= +github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d h1:W1n4DvpzZGOISgp7wWNtraLcHtnmnTwBlJidqtMIuwQ= +github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM= +github.com/dubbogo/go-zookeeper v1.0.3/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c= +github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5 h1:XoR8SSVziXe698dt4uZYDfsmHpKLemqAgFyndQsq5Kw= +github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c= +github.com/dubbogo/gost v1.9.0/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8= +github.com/dubbogo/gost v1.11.18/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI= +github.com/dubbogo/gost v1.13.1/go.mod h1:9HMXBv+WBMRWhF3SklpqDjkS/01AKWm2SrVdz/A0xJI= +github.com/dubbogo/gost v1.14.3 h1:bInkIjdImMo9ENTDdCcs4YlQ/vz5rP/rjcnLakK5x24= +github.com/dubbogo/gost v1.14.3/go.mod h1:WydBuEOkwKEm9mcWLlOnmsVe1ELFgrNPmC5SzXdPv4A= +github.com/dubbogo/grpc-go v1.42.9/go.mod h1:F1T9hnUvYGW4JLK1QNriavpOkhusU677ovPzLkk6zHM= +github.com/dubbogo/grpc-go v1.42.10 h1:CoyCdtqKJEar/3rPa6peZbDqYZ/mVsCqAxB6TfTSkhQ= +github.com/dubbogo/grpc-go v1.42.10/go.mod h1:JMkPt1mIHL96GAFeYsMoMjew6f1ROKycikGzZQH1s5U= +github.com/dubbogo/jsonparser v1.0.1/go.mod h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU= +github.com/dubbogo/net v0.0.4/go.mod h1:1CGOnM7X3he+qgGNqjeADuE5vKZQx/eMSeUkpU3ujIc= +github.com/dubbogo/triple v1.0.9/go.mod h1:1t9me4j4CTvNDcsMZy6/OGarbRyAUSY0tFXGXHCp7Iw= +github.com/dubbogo/triple v1.2.2-rc4 h1:zL15Fb6W/yNAFQve5eqpTOEWWD9dpTFq78mdeSKc2pk= +github.com/dubbogo/triple v1.2.2-rc4/go.mod h1:9pgEahtmsY/avYJp3dzUQE8CMMVe1NtGBmUhfICKLJk= +github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= +github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= +github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= +github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= +github.com/emicklei/go-restful/v3 v3.10.1 h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ= +github.com/emicklei/go-restful/v3 v3.10.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= +github.com/envoyproxy/go-control-plane v0.10.0/go.mod h1:AY7fTTXNdv/aJ2O5jwpxAPOWUZ7hQAEvzN5Pf27BkQQ= +github.com/envoyproxy/go-control-plane v0.10.1/go.mod h1:AY7fTTXNdv/aJ2O5jwpxAPOWUZ7hQAEvzN5Pf27BkQQ= +github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239/go.mod h1:Gdwt2ce0yfBxPvZrHkprdPPTTS3N5rwmLE8T22KBXlw= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= +github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= +github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= +github.com/form3tech-oss/jwt-go v3.2.2+incompatible h1:TcekIExNqud5crz4xD2pavyTgWiPvpYe4Xau31I0PRk= +github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= +github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= +github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= +github.com/frankban/quicktest v1.10.0 h1:Gfh+GAJZOAoKZsIZeZbdn2JF10kN1XHNvjsvQK8gVkE= +github.com/frankban/quicktest v1.10.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= +github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o= +github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= +github.com/go-ldap/ldap v3.0.2+incompatible/go.mod h1:qfd9rJvER9Q0/D/Sqn1DfHRoBp40uXYvFoEVrNEPqRc= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= +github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM= +github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.12.0 h1:E4gtWgxWxp8YSxExrQFv5BpCahla0PVF2oTTEYaWQGI= +github.com/go-playground/validator/v10 v10.12.0/go.mod h1:hCAPuzYvKdP33pxWa+2+6AIKXEKqjIUyqsNCtbsSJrA= +github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY= +github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I= +github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU= +github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= +github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-test/deep v1.0.2-0.20181118220953-042da051cf31/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= +github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68= +github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= +github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac/go.mod h1:P32wAyui1PQ58Oce/KYkOqQv8cVw1zAapXOl+dRFGbc= +github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82/go.mod h1:PxC8OnwL11+aosOB5+iEPoV3picfs8tUpkVd0pDo+Kg= +github.com/gonum/integrate v0.0.0-20181209220457-a422b5c0fdf2/go.mod h1:pDgmNM6seYpwvPos3q+zxlXMsbve6mOIPucUnUOrI7Y= +github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhSyOzRwuXkOgAvijx4o+4YMUJJo9OvPYMkks= +github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9/go.mod h1:XA3DeT6rxh2EAE789SSiSJNqxPaC0aE9J8NTOI0Jo/A= +github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9/go.mod h1:0EXg4mc1CNP0HCqCz+K4ts155PXIlUywf0wqN+GfPZw= +github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b/go.mod h1:Z4GIJBJO3Wa4gD4vbwQxXXZ+WHmW6E9ixmNrwvs0iZs= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20230207041349-798e818bf904 h1:4/hN5RUoecvl+RmJRE2YxKWtnnQls6rQjjW5oV7qg2U= +github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gopherjs/gopherjs v0.0.0-20190910122728-9d188e94fb99 h1:twflg0XRTjwKpxb/jFExr4HGq6on2dEOmnL6FV+fgPw= +github.com/gopherjs/gopherjs v0.0.0-20190910122728-9d188e94fb99/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= +github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 h1:FlFbCRLd5Jr4iYXZufAvgWN6Ao0JrI5chLINnUXDDr0= +github.com/grpc-ecosystem/go-grpc-middleware v1.2.2/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw= +github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= +github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= +github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= +github.com/hashicorp/consul/api v1.13.0/go.mod h1:ZlVrynguJKcYr54zGaDbaL3fOvKC9m72FhPvA8T35KQ= +github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= +github.com/hashicorp/go-hclog v0.8.0/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= +github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY= +github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= +github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= +github.com/hashicorp/go-rootcerts v1.0.1/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= +github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A= +github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= +github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= +github.com/hashicorp/mdns v1.0.4/go.mod h1:mtBihi+LeNXGtG8L9dX59gAEa12BDtBQSp4v/YAJqrc= +github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= +github.com/hashicorp/memberlist v0.3.0/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= +github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= +github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= +github.com/hashicorp/vault/api v1.0.4/go.mod h1:gDcqh3WGcR1cpF5AJz/B1UFheUEneMoIospckxBxk6Q= +github.com/hashicorp/vault/sdk v0.1.13/go.mod h1:B+hVj7TpuQY1Y/GPbCpffmgd+tSEwvhkWnjtSYCaS2M= +github.com/hashicorp/vault/sdk v0.7.0 h1:2pQRO40R1etpKkia5fb4kjrdYMx3BHklPxl1pxpxDHg= +github.com/hashicorp/vault/sdk v0.7.0/go.mod h1:KyfArJkhooyba7gYCKSq8v66QdqJmnbAxtV/OX1+JTs= +github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= +github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= +github.com/hjson/hjson-go/v4 v4.0.0 h1:wlm6IYYqHjOdXH1gHev4VoXCaW20HdQAGCxdOEEg2cs= +github.com/hjson/hjson-go/v4 v4.0.0/go.mod h1:KaYt3bTw3zhBjYqnXkYywcYctk0A2nxeEFTse3rH13E= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= +github.com/influxdata/tdigest v0.0.1 h1:XpFptwYmnEKUqmkcDjrzffswZ3nvNeevbUSLPP/ZzIY= +github.com/influxdata/tdigest v0.0.1/go.mod h1:Z0kXnxzbTC2qrx4NaIzYkE1k66+6oEDQTvL95hQFh5Y= +github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ= +github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= +github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM= +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= +github.com/k0kubun/pp v3.0.1+incompatible h1:3tqvf7QgUnZ5tXO6pNAZlrvHgl6DvifjDrd9g2S9Z40= +github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/knadh/koanf v1.5.0 h1:q2TSd/3Pyc/5yP9ldIrSdIz26MCcyNQzW0pEAugLPNs= +github.com/knadh/koanf v1.5.0/go.mod h1:Hgyjp4y8v44hpZtPzs7JZfRAW5AhN7KfZcwv1RYggDs= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-urn v1.2.2 h1:7z68G0FCGvDk646jz1AelTYNYWrTNm0bEcFAo147wt4= +github.com/leodido/go-urn v1.2.2/go.mod h1:kUaIbLZWttglzwNuG0pgsh5vuV6u2YcGBYz1hIPjtOQ= +github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570/go.mod h1:BLt8L9ld7wVsvEWQbuLrUZnCMnUmLZ+CGDzKtclrTlE= +github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f/go.mod h1:UGmTpUd3rjbtfIpwAPrcfmGf/Z1HS95TATB+m57TPB8= +github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042/go.mod h1:TPpsiPUEh0zFL1Snz4crhMlBe60PYxRHr5oFF3rRYg0= +github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= +github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= +github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls= +github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= +github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= +github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= +github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= +github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= +github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= +github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= +github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM= +github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/nacos-group/nacos-sdk-go v1.0.8/go.mod h1:hlAPn3UdzlxIlSILAyOXKxjFSvDJ9oLzTJ9hLAK1KzA= +github.com/nacos-group/nacos-sdk-go/v2 v2.1.2/go.mod h1:ys/1adWeKXXzbNWfRNbaFlX/t6HVLWdpsNDvmoWTw0g= +github.com/nacos-group/nacos-sdk-go/v2 v2.2.5 h1:r0wwT7PayEjvEHzWXwr1ROi/JSqzujM4w+1L5ikThzQ= +github.com/nacos-group/nacos-sdk-go/v2 v2.2.5/go.mod h1:OObBon0prVJVPoIbSZxpEkFiBfL0d1LcBtuAMiNn+8c= +github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM= +github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk= +github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= +github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= +github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= +github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= +github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= +github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= +github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/npillmayer/nestext v0.1.3/go.mod h1:h2lrijH8jpicr25dFY+oAJLyzlya6jhnuG+zWp9L0Uk= +github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= +github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= +github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 h1:Yl0tPBa8QPjGmesFh1D0rDy+q1Twx6FyU7VWHi8wZbI= +github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852/go.mod h1:eqOVx5Vwu4gd2mmMZvVZsgIqNSaW3xxRThUJ0k/TPk4= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= +github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= +github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= +github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= +github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= +github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA= +github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= +github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= +github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= +github.com/openzipkin/zipkin-go v0.4.2 h1:zjqfqHjUpPmB3c1GlCvvgsM1G4LkvqQbBDueDOCg/jA= +github.com/openzipkin/zipkin-go v0.4.2/go.mod h1:ZeVkFjuuBiSy13y8vpSDCjMi9GoI3hPpCJSBx/EYFhY= +github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= +github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ= +github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= +github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= +github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= +github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= +github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= +github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/polarismesh/polaris-go v1.3.0 h1:KZKX//ow4OPPoS5+s7h07ptprg+2AcNVGrN6WakC9QM= +github.com/polarismesh/polaris-go v1.3.0/go.mod h1:HsN0ierETIujHpmnnYJ3qkwQw4QGAECuHvBZTDaw1tI= +github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= +github.com/prometheus/client_golang v1.5.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= +github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= +github.com/prometheus/client_golang v1.9.0/go.mod h1:FqZLKOZnGdFAhOK4nqGHa7D66IdsO+O441Eve7ptJDU= +github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= +github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= +github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= +github.com/prometheus/client_golang v1.12.2/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= +github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= +github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= +github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= +github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= +github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= +github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= +github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= +github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= +github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= +github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= +github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8= +github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII= +github.com/quic-go/quic-go v0.59.1 h1:0Gmua0HW1Tv7ANR7hUYwRyD0MG5OJfgvYSZasGZzBic= +github.com/quic-go/quic-go v0.59.1/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU= +github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/rhnvrm/simples3 v0.6.1/go.mod h1:Y+3vYm2V7Y4VijFoJHHTrja6OgPrJ2cBti8dPGkC3sA= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/rwtodd/Go.Sed v0.0.0-20210816025313-55464686f9ef/go.mod h1:8AEUvGVi2uQ5b24BIhcr0GCcpd/RNAFWaN2CJFrWIIQ= +github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= +github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/shirou/gopsutil v3.20.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/shirou/gopsutil/v3 v3.21.6/go.mod h1:JfVbDpIBLVzT8oKbvMg9P3wEIMDDpVn+LwHTKj0ST88= +github.com/shirou/gopsutil/v3 v3.22.2 h1:wCrArWFkHYIdDxx/FSfF5RB4dpJYW6t7rcp3+zL8uks= +github.com/shirou/gopsutil/v3 v3.22.2/go.mod h1:WapW1AOOPlHyXr+yOyw3uYx36enocrtSoSBy0L5vUHY= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= +github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/soheilhy/cmux v0.1.5-0.20210205191134-5ec6847320e5 h1:GJTW+uNMIV1RKwox+T4aN0/sQlYRg78uHZf2H0aBcDw= +github.com/soheilhy/cmux v0.1.5-0.20210205191134-5ec6847320e5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= +github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY= +github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= +github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= +github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= +github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= +github.com/spf13/viper v1.8.1 h1:Kq1fyeebqsBfbjZj4EL7gj2IO0mMaiyjYUWcUsl2O44= +github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns= +github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= +github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= +github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tebeka/strftime v0.1.3/go.mod h1:7wJm3dZlpr4l/oVK0t1HYIc4rMzQ2XJlOMIUJUJH6XQ= +github.com/tevid/gohamcrest v1.1.1 h1:ou+xSqlIw1xfGTg1uq1nif/htZ2S3EzRqLm2BP+tYU0= +github.com/tevid/gohamcrest v1.1.1/go.mod h1:3UvtWlqm8j5JbwYZh80D/PVBt0mJ1eJiYgZMibh0H/k= +github.com/tklauser/go-sysconf v0.3.6/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= +github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs= +github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw= +github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= +github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM= +github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8= +github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o= +github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= +github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 h1:uruHq4dN7GR16kFc5fp3d1RIYzJW5onx8Ybykw2YQFA= +github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3/go.mod h1:QDlpd3qS71vYtakd2hmdpqhJ9nwv6mD6A30bQ1BPBFE= +github.com/uber/jaeger-client-go v2.29.1+incompatible h1:R9ec3zO3sGpzs0abd43Y+fBZRJ9uiH6lXyR/+u6brW4= +github.com/uber/jaeger-client-go v2.29.1+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= +github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg= +github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= +github.com/ugorji/go v1.2.6/go.mod h1:anCg0y61KIhDlPZmnH+so+RQbysYVyDko0IMgJv0Nn0= +github.com/ugorji/go/codec v1.2.6 h1:7kbGefxLoDBuYXOms4yD7223OpNMMPNPZxXk5TvFcyQ= +github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxWFFpvxTw= +github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= +github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0= +go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= +go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738 h1:VcrIfasaLFkyjk6KNlXQSzO+B0fZcnECiDrKJsfxka0= +go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= +go.etcd.io/etcd/api/v3 v3.5.0-alpha.0/go.mod h1:mPcW6aZJukV6Aa81LSKpBjQXTWlXB5r74ymPoSWa3Sw= +go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= +go.etcd.io/etcd/api/v3 v3.5.4/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A= +go.etcd.io/etcd/api/v3 v3.5.7 h1:sbcmosSVesNrWOJ58ZQFitHMdncusIifYcrBfwrlJSY= +go.etcd.io/etcd/api/v3 v3.5.7/go.mod h1:9qew1gCdDDLu+VwmeG+iFpL+QlpHTo7iubavdVDgCAA= +go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= +go.etcd.io/etcd/client/pkg/v3 v3.5.4/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= +go.etcd.io/etcd/client/pkg/v3 v3.5.7 h1:y3kf5Gbp4e4q7egZdn5T7W9TSHUvkClN6u+Rq9mEOmg= +go.etcd.io/etcd/client/pkg/v3 v3.5.7/go.mod h1:o0Abi1MK86iad3YrWhgUsbGx1pmTS+hrORWc2CamuhY= +go.etcd.io/etcd/client/v2 v2.305.0-alpha.0/go.mod h1:kdV+xzCJ3luEBSIeQyB/OEKkWKd8Zkux4sbDeANrosU= +go.etcd.io/etcd/client/v2 v2.305.0 h1:ftQ0nOOHMcbMS3KIaDQ0g5Qcd6bhaBrQT6b89DfwLTs= +go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= +go.etcd.io/etcd/client/v3 v3.5.0-alpha.0/go.mod h1:wKt7jgDgf/OfKiYmCq5WFGxOFAkVMLxiiXgLDFhECr8= +go.etcd.io/etcd/client/v3 v3.5.4/go.mod h1:ZaRkVgBZC+L+dLCjTcF1hRXpgZXQPOvnA/Ak/gq3kiY= +go.etcd.io/etcd/client/v3 v3.5.7 h1:u/OhpiuCgYY8awOHlhIhmGIGpxfBU/GZBUP3m/3/Iz4= +go.etcd.io/etcd/client/v3 v3.5.7/go.mod h1:sOWmj9DZUMyAngS7QQwCyAXXAL6WhgTOPLNS/NabQgw= +go.etcd.io/etcd/pkg/v3 v3.5.0-alpha.0 h1:3yLUEC0nFCxw/RArImOyRUI4OAFbg4PFpBbAhSNzKNY= +go.etcd.io/etcd/pkg/v3 v3.5.0-alpha.0/go.mod h1:tV31atvwzcybuqejDoY3oaNRTtlD2l/Ot78Pc9w7DMY= +go.etcd.io/etcd/raft/v3 v3.5.0-alpha.0 h1:DvYJotxV9q1Lkn7pknzAbFO/CLtCVidCr2K9qRLJ8pA= +go.etcd.io/etcd/raft/v3 v3.5.0-alpha.0/go.mod h1:FAwse6Zlm5v4tEWZaTjmNhe17Int4Oxbu7+2r0DiD3w= +go.etcd.io/etcd/server/v3 v3.5.0-alpha.0 h1:fYv7CmmdyuIu27UmKQjS9K/1GtcCa+XnPKqiKBbQkrk= +go.etcd.io/etcd/server/v3 v3.5.0-alpha.0/go.mod h1:tsKetYpt980ZTpzl/gb+UOJj9RkIyCb1u4wjzMg90BQ= +go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= +go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= +go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= +go.opentelemetry.io/contrib/propagators/b3 v1.10.0 h1:6AD2VV8edRdEYNaD8cNckpzgdMLU2kbV9OYyxt2kvCg= +go.opentelemetry.io/contrib/propagators/b3 v1.10.0/go.mod h1:oxvamQ/mTDFQVugml/uFS59+aEUnFLhmd1wsG+n5MOE= +go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc= +go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo= +go.opentelemetry.io/otel/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4= +go.opentelemetry.io/otel/exporters/jaeger v1.17.0/go.mod h1:nPCqOnEH9rNLKqH/+rrUjiMzHJdV1BlpKcTwRTyKkKI= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 h1:cl5P5/GIfFh4t6xyruOgJP5QiA1pw4fYYdv6nc6CBWw= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0/go.mod h1:zgBdWWAu7oEEMC06MMKc5NLbA/1YDXV1sMpSqEeLQLg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 h1:tIqheXEFWAZ7O8A7m+J0aPTmpJN3YQ7qetUAdkkkKpk= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0/go.mod h1:nUeKExfxAQVbiVFn32YXpXZZHZ61Cc3s3Rn1pDBGAb0= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0 h1:digkEZCJWobwBqMwC0cwCq8/wkkRy/OowZg5OArWZrM= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0/go.mod h1:/OpE/y70qVkndM0TrxT4KBoN3RsFZP0QaofcfYrj76I= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.21.0 h1:VhlEQAPp9R1ktYfrPk5SOryw1e9LDDTZCbIPFrho0ec= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.21.0/go.mod h1:kB3ufRbfU+CQ4MlUcqtW8Z7YEOBeK2DJ6CmR5rYYF3E= +go.opentelemetry.io/otel/exporters/zipkin v1.21.0 h1:D+Gv6lSfrFBWmQYyxKjDd0Zuld9SRXpIrEsKZvE4DO4= +go.opentelemetry.io/otel/exporters/zipkin v1.21.0/go.mod h1:83oMKR6DzmHisFOW3I+yIMGZUTjxiWaiBI8M8+TU5zE= +go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4= +go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM= +go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= +go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= +go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc= +go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= +go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= +go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= +go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/mock v0.5.2 h1:LbtPTcP8A5k9WPXj54PPPbjcI4Y6lhyOZXn+VS7wNko= +go.uber.org/mock v0.5.2/go.mod h1:wLlUxC2vVTPTaE3UD51E0BGOAElKrILxhVSDYQLld5o= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= +go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= +go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= +go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= +go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= +go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8= +go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto= +golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio= +golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5 h1:FR+oGxGfbQu1d+jglI3rCkjAjUnhRSZcUxr+DqlDLNo= +golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= +golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211105192438-b53810dc28af/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o= +golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM= +golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201223074533-0d417f636930/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211106132015-ebca88c72f68/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw= +golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.39.0 h1:UbZz4pLOvn600D6Oh6GGEI6VAmndrEBLv8/6BEXzyus= +golang.org/x/text v0.39.0/go.mod h1:3UwRclnC2g0TU9x8PZiyfOajCd1zaUNHF9cvqcQZ+ZM= +golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= +golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= +golang.org/x/tools v0.0.0-20201014170642-d1624618ad65/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= +golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= +gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= +gonum.org/v1/gonum v0.8.2 h1:CCXrcPKiGGotvnN6jfUsKk4rRqm7q09/YbKb5xCEvtM= +gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0= +gonum.org/v1/netlib v0.0.0-20181029234149-ec6d1f5cefe6/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= +gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= +gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc= +google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= +google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE= +google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= +google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= +google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= +google.golang.org/api v0.44.0/go.mod h1:EBOGZqzyhtvMDoxwS97ctnh0zUmYY6CxqXsc1AvkYD8= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200806141610-86f49bd18e98/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210106152847-07624b53cd92/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210222152913-aa3ee6e6a81c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210303154014-9728d6b83eeb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= +google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20211104193956-4c6863e31247/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20220504150022-98cd25cafc72/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= +google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d h1:VBu5YqKPv6XiJ199exd8Br+Aetz+o08F+PLMnwJQHAY= +google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d/go.mod h1:yZTlhN0tQnXo3h00fuXNCxJdLdIdnVFVBaRJ5LWBbw4= +google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 h1:RFiFrvy37/mpSpdySBDrUdipW/dHwsRwh3J3+A9VgT4= +google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237/go.mod h1:Z5Iiy3jtmioajWHDGFk7CeugTyHtPvMHA4UTmUkyalE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= +google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= +google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= +google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= +google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= +google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= +gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI= +gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= +gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= +gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= +honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= +sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= +sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= +sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= diff --git a/samples/interop/go/go/greeter/greeter.pb.go b/samples/interop/go/go/greeter/greeter.pb.go new file mode 100644 index 00000000..179f09e5 --- /dev/null +++ b/samples/interop/go/go/greeter/greeter.pb.go @@ -0,0 +1,194 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.12 +// protoc v7.35.1 +// source: greeter.proto + +package greeter + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type HelloRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *HelloRequest) Reset() { + *x = HelloRequest{} + mi := &file_greeter_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *HelloRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HelloRequest) ProtoMessage() {} + +func (x *HelloRequest) ProtoReflect() protoreflect.Message { + mi := &file_greeter_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HelloRequest.ProtoReflect.Descriptor instead. +func (*HelloRequest) Descriptor() ([]byte, []int) { + return file_greeter_proto_rawDescGZIP(), []int{0} +} + +func (x *HelloRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +type HelloReply struct { + state protoimpl.MessageState `protogen:"open.v1"` + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *HelloReply) Reset() { + *x = HelloReply{} + mi := &file_greeter_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *HelloReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HelloReply) ProtoMessage() {} + +func (x *HelloReply) ProtoReflect() protoreflect.Message { + mi := &file_greeter_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HelloReply.ProtoReflect.Descriptor instead. +func (*HelloReply) Descriptor() ([]byte, []int) { + return file_greeter_proto_rawDescGZIP(), []int{1} +} + +func (x *HelloReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_greeter_proto protoreflect.FileDescriptor + +const file_greeter_proto_rawDesc = "" + + "\n" + + "\rgreeter.proto\x12\x18org.apache.dubbo.samples\"\"\n" + + "\fHelloRequest\x12\x12\n" + + "\x04name\x18\x01 \x01(\tR\x04name\"&\n" + + "\n" + + "HelloReply\x12\x18\n" + + "\amessage\x18\x01 \x01(\tR\amessage2\xc5\x01\n" + + "\aGreeter\x12X\n" + + "\bSayHello\x12&.org.apache.dubbo.samples.HelloRequest\x1a$.org.apache.dubbo.samples.HelloReply\x12`\n" + + "\x0eSayHelloStream\x12&.org.apache.dubbo.samples.HelloRequest\x1a$.org.apache.dubbo.samples.HelloReply0\x01B\x19Z\x17interop/greeter;greeterb\x06proto3" + +var ( + file_greeter_proto_rawDescOnce sync.Once + file_greeter_proto_rawDescData []byte +) + +func file_greeter_proto_rawDescGZIP() []byte { + file_greeter_proto_rawDescOnce.Do(func() { + file_greeter_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_greeter_proto_rawDesc), len(file_greeter_proto_rawDesc))) + }) + return file_greeter_proto_rawDescData +} + +var file_greeter_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_greeter_proto_goTypes = []any{ + (*HelloRequest)(nil), // 0: org.apache.dubbo.samples.HelloRequest + (*HelloReply)(nil), // 1: org.apache.dubbo.samples.HelloReply +} +var file_greeter_proto_depIdxs = []int32{ + 0, // 0: org.apache.dubbo.samples.Greeter.SayHello:input_type -> org.apache.dubbo.samples.HelloRequest + 0, // 1: org.apache.dubbo.samples.Greeter.SayHelloStream:input_type -> org.apache.dubbo.samples.HelloRequest + 1, // 2: org.apache.dubbo.samples.Greeter.SayHello:output_type -> org.apache.dubbo.samples.HelloReply + 1, // 3: org.apache.dubbo.samples.Greeter.SayHelloStream:output_type -> org.apache.dubbo.samples.HelloReply + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_greeter_proto_init() } +func file_greeter_proto_init() { + if File_greeter_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_greeter_proto_rawDesc), len(file_greeter_proto_rawDesc)), + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_greeter_proto_goTypes, + DependencyIndexes: file_greeter_proto_depIdxs, + MessageInfos: file_greeter_proto_msgTypes, + }.Build() + File_greeter_proto = out.File + file_greeter_proto_goTypes = nil + file_greeter_proto_depIdxs = nil +} diff --git a/samples/interop/go/go/greeter/greeter.triple.go b/samples/interop/go/go/greeter/greeter.triple.go new file mode 100644 index 00000000..6fa8a38d --- /dev/null +++ b/samples/interop/go/go/greeter/greeter.triple.go @@ -0,0 +1,204 @@ +// Code generated by protoc-gen-triple. DO NOT EDIT. +// +// Source: greeter.proto +package greeter + +import ( + "context" + "net/http" +) + +import ( + "dubbo.apache.org/dubbo-go/v3" + "dubbo.apache.org/dubbo-go/v3/client" + "dubbo.apache.org/dubbo-go/v3/common" + "dubbo.apache.org/dubbo-go/v3/common/constant" + "dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol" + "dubbo.apache.org/dubbo-go/v3/server" +) + +// This is a compile-time assertion to ensure that this generated file and the Triple package +// are compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of Triple newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of Triple or updating the Triple +// version compiled into your binary. +const _ = triple_protocol.IsAtLeastVersion0_1_0 + +const ( + // GreeterName is the fully-qualified name of the Greeter service. + GreeterName = "org.apache.dubbo.samples.Greeter" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // GreeterSayHelloProcedure is the fully-qualified name of the Greeter's SayHello RPC. + GreeterSayHelloProcedure = "/org.apache.dubbo.samples.Greeter/SayHello" + // GreeterSayHelloStreamProcedure is the fully-qualified name of the Greeter's SayHelloStream RPC. + GreeterSayHelloStreamProcedure = "/org.apache.dubbo.samples.Greeter/SayHelloStream" +) + +var ( + _ Greeter = (*GreeterImpl)(nil) + + _ Greeter_SayHelloStreamClient = (*GreeterSayHelloStreamClient)(nil) + + _ Greeter_SayHelloStreamServer = (*GreeterSayHelloStreamServer)(nil) +) + +// Greeter is a client for the org.apache.dubbo.samples.Greeter service. +type Greeter interface { + SayHello(ctx context.Context, req *HelloRequest, opts ...client.CallOption) (*HelloReply, error) + SayHelloStream(ctx context.Context, req *HelloRequest, opts ...client.CallOption) (Greeter_SayHelloStreamClient, error) +} + +// NewGreeter constructs a client for the greeter.Greeter service. +func NewGreeter(cli *client.Client, opts ...client.ReferenceOption) (Greeter, error) { + conn, err := cli.DialWithInfo("org.apache.dubbo.samples.Greeter", &Greeter_ClientInfo, opts...) + if err != nil { + return nil, err + } + return &GreeterImpl{ + conn: conn, + }, nil +} + +func SetConsumerGreeter(srv common.RPCService) { + dubbo.SetConsumerServiceWithInfo(srv, &Greeter_ClientInfo) +} + +// GreeterImpl implements Greeter. +type GreeterImpl struct { + conn *client.Connection +} + +func (c *GreeterImpl) SayHello(ctx context.Context, req *HelloRequest, opts ...client.CallOption) (*HelloReply, error) { + resp := new(HelloReply) + if err := c.conn.CallUnary(ctx, []interface{}{req}, resp, "SayHello", opts...); err != nil { + return nil, err + } + return resp, nil +} + +func (c *GreeterImpl) SayHelloStream(ctx context.Context, req *HelloRequest, opts ...client.CallOption) (Greeter_SayHelloStreamClient, error) { + stream, err := c.conn.CallServerStream(ctx, req, "SayHelloStream", opts...) + if err != nil { + return nil, err + } + rawStream := stream.(*triple_protocol.ServerStreamForClient) + return &GreeterSayHelloStreamClient{rawStream}, nil +} + +type Greeter_SayHelloStreamClient interface { + Recv() bool + ResponseHeader() http.Header + ResponseTrailer() http.Header + Msg() *HelloReply + Err() error + Conn() (triple_protocol.StreamingClientConn, error) + Close() error +} + +type GreeterSayHelloStreamClient struct { + *triple_protocol.ServerStreamForClient +} + +func (cli *GreeterSayHelloStreamClient) Recv() bool { + msg := new(HelloReply) + return cli.ServerStreamForClient.Receive(msg) +} + +func (cli *GreeterSayHelloStreamClient) Msg() *HelloReply { + msg := cli.ServerStreamForClient.Msg() + if msg == nil { + return new(HelloReply) + } + return msg.(*HelloReply) +} + +func (cli *GreeterSayHelloStreamClient) Conn() (triple_protocol.StreamingClientConn, error) { + return cli.ServerStreamForClient.Conn() +} + +var Greeter_ClientInfo = client.ClientInfo{ + InterfaceName: "org.apache.dubbo.samples.Greeter", + MethodNames: []string{"SayHello", "SayHelloStream"}, + ConnectionInjectFunc: func(dubboCliRaw interface{}, conn *client.Connection) { + dubboCli := dubboCliRaw.(*GreeterImpl) + dubboCli.conn = conn + }, +} + +// GreeterHandler is an implementation of the org.apache.dubbo.samples.Greeter service. +type GreeterHandler interface { + SayHello(context.Context, *HelloRequest) (*HelloReply, error) + SayHelloStream(context.Context, *HelloRequest, Greeter_SayHelloStreamServer) error +} + +func RegisterGreeterHandler(srv *server.Server, hdlr GreeterHandler, opts ...server.ServiceOption) error { + return srv.Register(hdlr, &Greeter_ServiceInfo, opts...) +} + +func SetProviderGreeter(srv common.RPCService) { + dubbo.SetProviderServiceWithInfo(srv, &Greeter_ServiceInfo) +} + +type Greeter_SayHelloStreamServer interface { + Send(*HelloReply) error + ResponseHeader() http.Header + ResponseTrailer() http.Header + Conn() triple_protocol.StreamingHandlerConn +} + +type GreeterSayHelloStreamServer struct { + *triple_protocol.ServerStream +} + +func (g *GreeterSayHelloStreamServer) Send(msg *HelloReply) error { + return g.ServerStream.Send(msg) +} + +var Greeter_ServiceInfo = server.ServiceInfo{ + InterfaceName: "org.apache.dubbo.samples.Greeter", + ServiceType: (*GreeterHandler)(nil), + Methods: []server.MethodInfo{ + { + Name: "SayHello", + Type: constant.CallUnary, + ReqInitFunc: func() interface{} { + return new(HelloRequest) + }, + MethodFunc: func(ctx context.Context, args []interface{}, handler interface{}) (interface{}, error) { + req := args[0].(*HelloRequest) + res, err := handler.(GreeterHandler).SayHello(ctx, req) + if err != nil { + return nil, err + } + return triple_protocol.NewResponse(res), nil + }, + }, + { + Name: "SayHelloStream", + Type: constant.CallServerStream, + ReqInitFunc: func() interface{} { + return new(HelloRequest) + }, + StreamInitFunc: func(baseStream interface{}) interface{} { + return &GreeterSayHelloStreamServer{baseStream.(*triple_protocol.ServerStream)} + }, + MethodFunc: func(ctx context.Context, args []interface{}, handler interface{}) (interface{}, error) { + req := args[0].(*HelloRequest) + stream := args[1].(Greeter_SayHelloStreamServer) + if err := handler.(GreeterHandler).SayHelloStream(ctx, req, stream); err != nil { + return nil, err + } + return nil, nil + }, + }, + }, +} diff --git a/samples/interop/go/go/server/main.go b/samples/interop/go/go/server/main.go new file mode 100644 index 00000000..16575d7a --- /dev/null +++ b/samples/interop/go/go/server/main.go @@ -0,0 +1,82 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// The Go provider: Greeter over Triple, registered in Nacos. +package main + +import ( + "context" + "errors" + "fmt" + + "dubbo.apache.org/dubbo-go/v3" + _ "dubbo.apache.org/dubbo-go/v3/imports" + "dubbo.apache.org/dubbo-go/v3/logger" + "dubbo.apache.org/dubbo-go/v3/protocol" + "dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol" + "dubbo.apache.org/dubbo-go/v3/registry" + + "interop/greeter" +) + +type GreeterImpl struct{} + +func (GreeterImpl) SayHello(ctx context.Context, request *greeter.HelloRequest) (*greeter.HelloReply, error) { + // The attachments that the caller sent arrive as the headers of the call. + header, _ := triple_protocol.FromIncomingContext(ctx) + fmt.Printf("[%s] SayHello(%s)\n", header.Get("trace-id"), request.Name) + if request.Name == "" { + return nil, triple_protocol.NewError(triple_protocol.CodeInvalidArgument, errors.New("a name is required")) + } + return &greeter.HelloReply{Message: fmt.Sprintf("Hello, %s, from Go!", request.Name)}, nil +} + +func (GreeterImpl) SayHelloStream( + _ context.Context, request *greeter.HelloRequest, stream greeter.Greeter_SayHelloStreamServer, +) error { + for count := 1; count <= 3; count++ { + reply := &greeter.HelloReply{Message: fmt.Sprintf("Hello #%d, %s, from Go!", count, request.Name)} + if err := stream.Send(reply); err != nil { + return err + } + } + return nil +} + +func main() { + instance, err := dubbo.NewInstance( + dubbo.WithName("go-server"), + dubbo.WithRegistry(registry.WithNacos(), registry.WithAddress("127.0.0.1:8848")), + dubbo.WithProtocol(protocol.WithTriple(), protocol.WithPort(50052)), + dubbo.WithLogger(logger.WithLevel("warn")), + ) + if err != nil { + panic(err) + } + server, err := instance.NewServer() + if err != nil { + panic(err) + } + if err := greeter.RegisterGreeterHandler(server, GreeterImpl{}); err != nil { + panic(err) + } + + fmt.Println("Serving Greeter on port 50052; press Ctrl+C to stop") + if err := server.Serve(); err != nil { + panic(err) + } +} diff --git a/samples/interop/go/greeter_dubbo.py b/samples/interop/go/greeter_dubbo.py new file mode 100644 index 00000000..70ab25c1 --- /dev/null +++ b/samples/interop/go/greeter_dubbo.py @@ -0,0 +1,40 @@ +# Generated by protoc-gen-python-dubbo. DO NOT EDIT! +# source: greeter.proto +"""Dubbo service contracts of greeter.proto.""" + +import abc +import typing + +import dubbo + +import greeter_pb2 + +__all__ = ["Greeter", "GreeterServicer"] + + +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + """Greets people, in Python and in Go.""" + + @dubbo.method("SayHello") + async def say_hello(self, request: greeter_pb2.HelloRequest) -> greeter_pb2.HelloReply: + """One greeting.""" + + @dubbo.method("SayHelloStream") + def say_hello_stream(self, request: greeter_pb2.HelloRequest) -> dubbo.ServerStream[greeter_pb2.HelloReply]: + """Three greetings, streamed one by one.""" + + +@dubbo.service("org.apache.dubbo.samples.Greeter") +class GreeterServicer(abc.ABC): + """Greets people, in Python and in Go.""" + + @dubbo.method("SayHello") + @abc.abstractmethod + async def say_hello(self, request: greeter_pb2.HelloRequest) -> greeter_pb2.HelloReply: + """One greeting.""" + + @dubbo.method("SayHelloStream") + @abc.abstractmethod + async def say_hello_stream(self, request: greeter_pb2.HelloRequest, stream: dubbo.SendStream[greeter_pb2.HelloReply]) -> None: + """Three greetings, streamed one by one.""" diff --git a/samples/interop/go/greeter_pb2.py b/samples/interop/go/greeter_pb2.py new file mode 100644 index 00000000..af6ef2db --- /dev/null +++ b/samples/interop/go/greeter_pb2.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: greeter.proto +# Protobuf Python Version: 7.35.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 7, + 35, + 1, + '', + 'greeter.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rgreeter.proto\x12\x18org.apache.dubbo.samples\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t2\xc5\x01\n\x07Greeter\x12X\n\x08SayHello\x12&.org.apache.dubbo.samples.HelloRequest\x1a$.org.apache.dubbo.samples.HelloReply\x12`\n\x0eSayHelloStream\x12&.org.apache.dubbo.samples.HelloRequest\x1a$.org.apache.dubbo.samples.HelloReply0\x01\x42\x19Z\x17interop/greeter;greeterb\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'greeter_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + _globals['DESCRIPTOR']._loaded_options = None + _globals['DESCRIPTOR']._serialized_options = b'Z\027interop/greeter;greeter' + _globals['_HELLOREQUEST']._serialized_start=43 + _globals['_HELLOREQUEST']._serialized_end=71 + _globals['_HELLOREPLY']._serialized_start=73 + _globals['_HELLOREPLY']._serialized_end=102 + _globals['_GREETER']._serialized_start=105 + _globals['_GREETER']._serialized_end=302 +# @@protoc_insertion_point(module_scope) diff --git a/samples/interop/go/greeter_pb2.pyi b/samples/interop/go/greeter_pb2.pyi new file mode 100644 index 00000000..bf0bd395 --- /dev/null +++ b/samples/interop/go/greeter_pb2.pyi @@ -0,0 +1,17 @@ +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from typing import ClassVar as _ClassVar, Optional as _Optional + +DESCRIPTOR: _descriptor.FileDescriptor + +class HelloRequest(_message.Message): + __slots__ = ("name",) + NAME_FIELD_NUMBER: _ClassVar[int] + name: str + def __init__(self, name: _Optional[str] = ...) -> None: ... + +class HelloReply(_message.Message): + __slots__ = ("message",) + MESSAGE_FIELD_NUMBER: _ClassVar[int] + message: str + def __init__(self, message: _Optional[str] = ...) -> None: ... diff --git a/samples/interop/go/proto/greeter.proto b/samples/interop/go/proto/greeter.proto new file mode 100644 index 00000000..f703feeb --- /dev/null +++ b/samples/interop/go/proto/greeter.proto @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +syntax = "proto3"; + +package org.apache.dubbo.samples; + +option go_package = "interop/greeter;greeter"; + +// Greets people, in Python and in Go. +service Greeter { + // One greeting. + rpc SayHello (HelloRequest) returns (HelloReply); + // Three greetings, streamed one by one. + rpc SayHelloStream (HelloRequest) returns (stream HelloReply); +} + +message HelloRequest { + string name = 1; +} + +message HelloReply { + string message = 1; +} diff --git a/samples/interop/go/python_client.py b/samples/interop/go/python_client.py new file mode 100644 index 00000000..8266d953 --- /dev/null +++ b/samples/interop/go/python_client.py @@ -0,0 +1,55 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The Python consumer: it finds the Go service in Nacos and calls it. + +import asyncio + +import dubbo +from dubbo import Dubbo, RpcError +from dubbo.config import ApplicationConfig, RegistryConfig + +from greeter_dubbo import Greeter +from greeter_pb2 import HelloRequest + + +async def main() -> None: + app = Dubbo( + application=ApplicationConfig(name="python-client"), + registries={"default": RegistryConfig(address="nacos://127.0.0.1:8848")}, + ) + # No URL: the providers come from the registry, in whatever language. + greeter = app.refer(Greeter) + + async with app: + # Every call in the block attaches the trace id. + with dubbo.outgoing({"trace-id": "py-4bf9"}): + reply = await greeter.say_hello(HelloRequest(name="Alice")) + print(reply.message) + async with greeter.say_hello_stream(HelloRequest(name="Bob")) as replies: + async for reply in replies: + print(reply.message) + + # A failure arrives as an RpcError with the status of the provider. + try: + await greeter.say_hello(HelloRequest()) + except RpcError as error: + print(error) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/interop/go/python_server.py b/samples/interop/go/python_server.py new file mode 100644 index 00000000..c12dc167 --- /dev/null +++ b/samples/interop/go/python_server.py @@ -0,0 +1,60 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The Python provider: Greeter over Triple, registered in Nacos, where Go +# consumers find it. + +import asyncio + +import dubbo +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig, RegistryConfig + +from greeter_dubbo import GreeterServicer +from greeter_pb2 import HelloReply, HelloRequest + + +def trace_id() -> str | bytes | None: + # The attachments that the caller sent with the call being served. + return dubbo.incoming().attachments.get("trace-id") + + +class GreeterImpl(GreeterServicer): + async def say_hello(self, request: HelloRequest) -> HelloReply: + print(f"[{trace_id()}] say_hello({request.name})") + return HelloReply(message=f"Hello, {request.name}, from Python!") + + async def say_hello_stream(self, request: HelloRequest, stream: dubbo.SendStream[HelloReply]) -> None: + for count in range(1, 4): + await stream.send(HelloReply(message=f"Hello #{count}, {request.name}, from Python!")) + + +async def main() -> None: + app = Dubbo( + application=ApplicationConfig(name="python-server"), + registries={"default": RegistryConfig(address="nacos://127.0.0.1:8848")}, + protocols={"tri": ProtocolConfig(port=50051)}, + ) + app.export(GreeterImpl()) + + async with app: + print("Serving Greeter on port 50051; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/interop/grpc/README.md b/samples/interop/grpc/README.md new file mode 100644 index 00000000..0c9a700c --- /dev/null +++ b/samples/interop/grpc/README.md @@ -0,0 +1,96 @@ +# gRPC + +Triple speaks the gRPC protocol over HTTP/2, so gRPC programs in any language +call Dubbo services, and Dubbo calls gRPC services, with nothing in between. +This sample does both in Python, with `grpcio` on the gRPC side. + +## What you will learn + +- how a plain gRPC client calls a Dubbo provider; +- how a Dubbo consumer calls a plain gRPC server; +- how to turn on the gRPC health and reflection services, for tools such as + `grpcurl` and for health probes. + +## Before you start + +```console +$ pip install grpcio +``` + +## The files + +| File | Role | +|---|---| +| `greeter.proto` | The contract both sides generate code from | +| `greeter_pb2.py`, `greeter_pb2.pyi` | The messages, generated by protoc | +| `greeter_pb2_grpc.py` | The gRPC stub and servicer, generated by `--grpc_python_out` | +| `greeter_dubbo.py` | The Dubbo contracts, generated by `--python-dubbo_out` | +| `dubbo_server.py`, `grpc_client.py` | A Dubbo provider and a gRPC client of it | +| `grpc_server.py`, `dubbo_client.py` | A gRPC server and a Dubbo consumer of it | + +The generated files are included. To generate them again, with the `protoc` +extra installed: + +```console +$ python -m grpc_tools.protoc -I. --python_out=. --pyi_out=. --grpc_python_out=. --python-dubbo_out=. greeter.proto +``` + +## Run it + +### A gRPC client calls Dubbo + +From this directory: + +```console +$ python dubbo_server.py +Serving on port 50051; press Ctrl+C to stop +``` + +```console +$ python grpc_client.py +Hello, gRPC, from Dubbo! +``` + +### Dubbo calls a gRPC server + +```console +$ python grpc_server.py +Serving on port 50052; press Ctrl+C to stop +``` + +```console +$ python dubbo_client.py +Hello, Dubbo, from gRPC! +``` + +### Health and reflection + +With `dubbo_server.py` running, [grpcurl](https://github.com/fullstorydev/grpcurl) +lists the services through reflection, calls the Greeter without any proto +file, and checks health: + +```console +$ grpcurl -plaintext 127.0.0.1:50051 list +$ grpcurl -plaintext -d '{"name": "grpcurl"}' 127.0.0.1:50051 org.apache.dubbo.samples.Greeter/SayHello +$ grpcurl -plaintext 127.0.0.1:50051 grpc.health.v1.Health/Check +``` + +## How it works + +Both sides generate code from the same `greeter.proto`. The service keeps the +full name of the proto, `org.apache.dubbo.samples.Greeter`, and its methods +their proto names, `SayHello`, on the wire, whatever their Python names. + +The Dubbo provider serves Triple, which a gRPC client reads as gRPC. The Dubbo +consumer refers to the gRPC server with a `tri://` URL, as to any Triple +provider. + +`health_enabled` and `reflection_enabled` under `triple` add the standard +`grpc.health.v1.Health` and `grpc.reflection.v1.ServerReflection` services. +Health reports each exported service as serving until the application +stops. Neither is registered with a registry. + +## Next + +- [integrations/fastapi](../../integrations/fastapi): call Dubbo services + from a web application. diff --git a/samples/interop/grpc/dubbo_client.py b/samples/interop/grpc/dubbo_client.py new file mode 100644 index 00000000..4782542e --- /dev/null +++ b/samples/interop/grpc/dubbo_client.py @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# A Dubbo consumer that calls the plain gRPC server of grpc_server.py. + +import asyncio + +from dubbo import Dubbo + +from greeter_dubbo import Greeter +from greeter_pb2 import HelloRequest + + +async def main() -> None: + app = Dubbo() + + # A gRPC server is a Triple provider: the tri:// URL is all it takes. + greeter = app.refer(Greeter, url="tri://127.0.0.1:50052") + + async with app: + reply = await greeter.say_hello(HelloRequest(name="Dubbo")) + print(reply.message) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/interop/grpc/dubbo_server.py b/samples/interop/grpc/dubbo_server.py new file mode 100644 index 00000000..6b895bb1 --- /dev/null +++ b/samples/interop/grpc/dubbo_server.py @@ -0,0 +1,51 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# A Dubbo provider that gRPC clients call: it serves the Greeter of +# greeter.proto over Triple, with the gRPC health and reflection services. + +import asyncio + +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig, TripleConfig + +from greeter_dubbo import GreeterServicer +from greeter_pb2 import HelloReply, HelloRequest + + +class GreeterImpl(GreeterServicer): + async def say_hello(self, request: HelloRequest) -> HelloReply: + return HelloReply(message=f"Hello, {request.name}, from Dubbo!") + + +async def main() -> None: + # Health and reflection are off by default; tools such as grpcurl, and load + # balancers that probe gRPC health, use them. + triple = TripleConfig(health_enabled=True, reflection_enabled=True) + app = Dubbo( + application=ApplicationConfig(name="grpc-interop-server"), + protocols={"tri": ProtocolConfig(port=50051, triple=triple)}, + ) + app.export(GreeterImpl()) + + async with app: + print("Serving on port 50051; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/interop/grpc/greeter.proto b/samples/interop/grpc/greeter.proto new file mode 100644 index 00000000..e12cd1d1 --- /dev/null +++ b/samples/interop/grpc/greeter.proto @@ -0,0 +1,33 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +syntax = "proto3"; + +package org.apache.dubbo.samples; + +// Greets people. +service Greeter { + rpc SayHello (HelloRequest) returns (HelloReply); +} + +message HelloRequest { + string name = 1; +} + +message HelloReply { + string message = 1; +} diff --git a/samples/interop/grpc/greeter_dubbo.py b/samples/interop/grpc/greeter_dubbo.py new file mode 100644 index 00000000..ea785534 --- /dev/null +++ b/samples/interop/grpc/greeter_dubbo.py @@ -0,0 +1,29 @@ +# Generated by protoc-gen-python-dubbo. DO NOT EDIT! +# source: greeter.proto +"""Dubbo service contracts of greeter.proto.""" + +import abc +import typing + +import dubbo + +import greeter_pb2 + +__all__ = ["Greeter", "GreeterServicer"] + + +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + """Greets people.""" + + @dubbo.method("SayHello") + async def say_hello(self, request: greeter_pb2.HelloRequest) -> greeter_pb2.HelloReply: ... + + +@dubbo.service("org.apache.dubbo.samples.Greeter") +class GreeterServicer(abc.ABC): + """Greets people.""" + + @dubbo.method("SayHello") + @abc.abstractmethod + async def say_hello(self, request: greeter_pb2.HelloRequest) -> greeter_pb2.HelloReply: ... diff --git a/samples/interop/grpc/greeter_pb2.py b/samples/interop/grpc/greeter_pb2.py new file mode 100644 index 00000000..848d50f6 --- /dev/null +++ b/samples/interop/grpc/greeter_pb2.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: greeter.proto +# Protobuf Python Version: 7.35.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 7, + 35, + 1, + '', + 'greeter.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rgreeter.proto\x12\x18org.apache.dubbo.samples\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t2c\n\x07Greeter\x12X\n\x08SayHello\x12&.org.apache.dubbo.samples.HelloRequest\x1a$.org.apache.dubbo.samples.HelloReplyb\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'greeter_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + DESCRIPTOR._loaded_options = None + _globals['_HELLOREQUEST']._serialized_start=43 + _globals['_HELLOREQUEST']._serialized_end=71 + _globals['_HELLOREPLY']._serialized_start=73 + _globals['_HELLOREPLY']._serialized_end=102 + _globals['_GREETER']._serialized_start=104 + _globals['_GREETER']._serialized_end=203 +# @@protoc_insertion_point(module_scope) diff --git a/samples/interop/grpc/greeter_pb2.pyi b/samples/interop/grpc/greeter_pb2.pyi new file mode 100644 index 00000000..bf0bd395 --- /dev/null +++ b/samples/interop/grpc/greeter_pb2.pyi @@ -0,0 +1,17 @@ +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from typing import ClassVar as _ClassVar, Optional as _Optional + +DESCRIPTOR: _descriptor.FileDescriptor + +class HelloRequest(_message.Message): + __slots__ = ("name",) + NAME_FIELD_NUMBER: _ClassVar[int] + name: str + def __init__(self, name: _Optional[str] = ...) -> None: ... + +class HelloReply(_message.Message): + __slots__ = ("message",) + MESSAGE_FIELD_NUMBER: _ClassVar[int] + message: str + def __init__(self, message: _Optional[str] = ...) -> None: ... diff --git a/samples/interop/grpc/greeter_pb2_grpc.py b/samples/interop/grpc/greeter_pb2_grpc.py new file mode 100644 index 00000000..9df881fe --- /dev/null +++ b/samples/interop/grpc/greeter_pb2_grpc.py @@ -0,0 +1,100 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc +import warnings + +import greeter_pb2 as greeter__pb2 + +GRPC_GENERATED_VERSION = '1.85.1' +GRPC_VERSION = grpc.__version__ +_version_not_supported = False + +try: + from grpc._utilities import first_version_is_lower + _version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION) +except ImportError: + _version_not_supported = True + +if _version_not_supported: + raise RuntimeError( + f'The grpc package installed is at version {GRPC_VERSION},' + + ' but the generated code in greeter_pb2_grpc.py depends on' + + f' grpcio>={GRPC_GENERATED_VERSION}.' + + f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}' + + f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.' + ) + + +class GreeterStub: + """Greets people. + """ + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.SayHello = channel.unary_unary( + '/org.apache.dubbo.samples.Greeter/SayHello', + request_serializer=greeter__pb2.HelloRequest.SerializeToString, + response_deserializer=greeter__pb2.HelloReply.FromString, + _registered_method=True) + + +class GreeterServicer: + """Greets people. + """ + + def SayHello(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_GreeterServicer_to_server(servicer, server): + rpc_method_handlers = { + 'SayHello': grpc.unary_unary_rpc_method_handler( + servicer.SayHello, + request_deserializer=greeter__pb2.HelloRequest.FromString, + response_serializer=greeter__pb2.HelloReply.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'org.apache.dubbo.samples.Greeter', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + server.add_registered_method_handlers('org.apache.dubbo.samples.Greeter', rpc_method_handlers) + + + # This class is part of an EXPERIMENTAL API. +class Greeter: + """Greets people. + """ + + @staticmethod + def SayHello(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary( + request, + target, + '/org.apache.dubbo.samples.Greeter/SayHello', + greeter__pb2.HelloRequest.SerializeToString, + greeter__pb2.HelloReply.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + _registered_method=True) diff --git a/samples/interop/grpc/grpc_client.py b/samples/interop/grpc/grpc_client.py new file mode 100644 index 00000000..9a28c0d1 --- /dev/null +++ b/samples/interop/grpc/grpc_client.py @@ -0,0 +1,36 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# A plain gRPC client, with no Dubbo in it, that calls dubbo_server.py. + +import asyncio + +import grpc + +from greeter_pb2 import HelloRequest +from greeter_pb2_grpc import GreeterStub + + +async def main() -> None: + async with grpc.aio.insecure_channel("127.0.0.1:50051") as channel: + stub = GreeterStub(channel) + reply = await stub.SayHello(HelloRequest(name="gRPC")) + print(reply.message) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/interop/grpc/grpc_server.py b/samples/interop/grpc/grpc_server.py new file mode 100644 index 00000000..555f3e01 --- /dev/null +++ b/samples/interop/grpc/grpc_server.py @@ -0,0 +1,49 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# A plain gRPC server, with no Dubbo in it, that dubbo_client.py calls. + +import asyncio +import contextlib + +import grpc + +from greeter_pb2 import HelloReply, HelloRequest +from greeter_pb2_grpc import GreeterServicer, add_GreeterServicer_to_server + + +class GreeterImpl(GreeterServicer): + async def SayHello(self, request: HelloRequest, context: grpc.aio.ServicerContext) -> HelloReply: + return HelloReply(message=f"Hello, {request.name}, from gRPC!") + + +async def main() -> None: + server = grpc.aio.server() + add_GreeterServicer_to_server(GreeterImpl(), server) + server.add_insecure_port("127.0.0.1:50052") + await server.start() + print("Serving on port 50052; press Ctrl+C to stop") + try: + await server.wait_for_termination() + finally: + await server.stop(grace=5) + + +if __name__ == "__main__": + # asyncio.run() raises KeyboardInterrupt once Ctrl+C has stopped the server. + with contextlib.suppress(KeyboardInterrupt): + asyncio.run(main()) diff --git a/samples/interop/java/README.md b/samples/interop/java/README.md new file mode 100644 index 00000000..99920af2 --- /dev/null +++ b/samples/interop/java/README.md @@ -0,0 +1,175 @@ +# Java + +Most Dubbo services are written in Java. A Python service joins them in the +same registry: Java consumers call it as they call a Java service, and it +calls Java services, over both protocols. This sample runs a provider and a +consumer in each language, which find each other in Nacos. + +## What you will learn + +- how Python and Java share a contract: a `.proto` file over Triple, and a + Java interface with its classes over Dubbo; +- how a Python class stands for a Java class in Hessian 2, and a Python int + for a Java `long`; +- how exceptions cross between the languages; +- how attachments, such as a trace id, cross between them; +- how each side finds the other through a registry, with no addresses in + the code. + +## Before you start + +You need a JDK 17 or later and Maven, and Nacos, as in +[04_registry](../../basics/04_registry): + +```console +$ pip install "apache-dubbo[nacos]" +$ docker compose -f ../../compose.yaml up -d --wait +``` + +## The files + +| File | Role | +|---|---| +| `proto/greeter.proto` | The contract of `Greeter`, which both languages generate code from | +| `greeter_pb2.py`, `greeter_pb2.pyi`, `greeter_dubbo.py` | The Python code generated from it, as in [02_protobuf](../../basics/02_protobuf) | +| `users.py` | The contract of `UserService` in Python, with the `User` class | +| `python_server.py`, `python_client.py` | The Python provider and consumer | +| `java/` | A Maven project: `UserService` and `User` in Java, the Java provider and consumer; Maven generates the Java code of `greeter.proto` | + +## Run it + +### Python calls Java + +From this directory, start the Java server: + +```console +$ mvn -q -f java/pom.xml compile exec:java -Dexec.mainClass=org.apache.dubbo.samples.JavaServer +Serving Greeter on port 50052 and UserService on port 20881; press Ctrl+C to stop +``` + +The first run downloads the dependencies, which takes a while. In another +terminal, run the Python client: + +```console +$ python python_client.py +Hello, Alice, from Java! +Hello #1, Bob, from Java! +Hello #2, Bob, from Java! +Hello #3, Bob, from Java! +User(id=1, name='Alice', email='alice@example.com') +java.lang.IllegalArgumentException: no user has ID 42 +``` + +The Java server prints each call it serves, with the trace id that the +Python client attached: + +```console +[py-4bf9] sayHello(Alice) +[py-4bf9] getUser(1) +[py-4bf9] getUser(42) +``` + +Stop the Java server with Ctrl+C. Its Nacos client may log interrupted +threads as it stops; they do no harm. + +### Java calls Python + +Start the Python server: + +```console +$ python python_server.py +Serving Greeter on port 50051 and UserService on port 20880; press Ctrl+C to stop +``` + +In another terminal, run the Java client: + +```console +$ mvn -q -f java/pom.xml compile exec:java -Dexec.mainClass=org.apache.dubbo.samples.JavaClient +Hello, Alice, from Python! +Hello #1, Bob, from Python! +Hello #2, Bob, from Python! +Hello #3, Bob, from Python! +User(id=1, name=Alice, email=alice@example.com) +java.lang.IllegalArgumentException: no user has ID 42 +``` + +The Python server prints the trace id that the Java client attached: + +```console +[java-7f3a] say_hello(Alice) +[java-7f3a] get_user(1) +[None] get_user(42) +``` + +With both servers running, each client finds the services of both and +spreads its calls over them, whatever their language. + +## How it works + +### Finding each other + +Both sides use Nacos and their defaults: a provider registers per +application and per service, and a consumer finds providers per application +while there are any, as [04_registry](../../basics/04_registry) explains. +Neither knows the language of the other: a consumer looks a service up by +its name, and reads from the metadata of each instance which protocol and +port to call it on. + +So a service must have the same name on both sides, and so must its +methods. + +### Triple and Protobuf + +`Greeter` is defined once, in `proto/greeter.proto`. protoc generates the +Python code, and the `dubbo-maven-plugin` of the Maven project the Java code, +from the same file. Each language calls and serves it as its own code: +`StreamObserver` in Java, `async for` in Python. + +Its name is the package and service of the `.proto` file, +`org.apache.dubbo.samples.Greeter`. Dubbo Java registers a service under the +name of its Java interface, though, which `option java_package` would +change. So the file sets no `java_package`, and the Java interface has the +same name as the service. + +### Dubbo and Hessian 2 + +`UserService` is a Java interface, the most common kind of Dubbo service. +Python declares the same contract in `users.py`, with the Java names: + +- `@dubbo.service("org.apache.dubbo.samples.UserService")` names the + interface, and `@dubbo.method("getUser")` the method; +- `@hessian2.java_class("org.apache.dubbo.samples.User")` makes the + dataclass `User` travel as the Java class `User`, field by field; a field + such as `user_id` would travel as `userId`, as Java names it; +- `hessian2.Long` marks an int that Java declares `long`. Java tells methods + apart by the types of their parameters as well as by name, so the types + must match. + +### Exceptions + +An exception a Java provider throws reaches Python as a `dubbo.RemoteError`, +an `RpcError` that names the Java class. A Python provider throws a Java +exception the same way, with +`RemoteError("java.lang.IllegalArgumentException", message)`, which Java +catches as an `IllegalArgumentException`. An `RpcError` of a Python +provider reaches Java as an `RpcException`, as a failure of the call rather +than of the service. + +### Attachments + +Attachments travel with a call in both protocols, as headers over Triple +and as a map over Dubbo, so each language reads what another attached: + +| | Attach to calls | Read in a handler | +|---|---|---| +| Python | `with dubbo.outgoing({"trace-id": ...}):` | `dubbo.incoming().attachments` | +| Java | `RpcContext.getClientAttachment().setAttachment("trace-id", ...)` | `RpcContext.getServerAttachment().getAttachment("trace-id")` | + +Python attaches to every call in the block. Java attaches to the next call +only: the Java client attaches the trace id before `sayHello` and +`getUser(1)`, and `getUser(42)` arrives without one. + +## Next + +- [interop/go](../go): call Go services from Python, and Python services + from Go. diff --git a/samples/interop/java/greeter_dubbo.py b/samples/interop/java/greeter_dubbo.py new file mode 100644 index 00000000..090c62cd --- /dev/null +++ b/samples/interop/java/greeter_dubbo.py @@ -0,0 +1,40 @@ +# Generated by protoc-gen-python-dubbo. DO NOT EDIT! +# source: greeter.proto +"""Dubbo service contracts of greeter.proto.""" + +import abc +import typing + +import dubbo + +import greeter_pb2 + +__all__ = ["Greeter", "GreeterServicer"] + + +@dubbo.service("org.apache.dubbo.samples.Greeter") +class Greeter(typing.Protocol): + """Greets people, in Python and in Java.""" + + @dubbo.method("SayHello") + async def say_hello(self, request: greeter_pb2.HelloRequest) -> greeter_pb2.HelloReply: + """One greeting.""" + + @dubbo.method("SayHelloStream") + def say_hello_stream(self, request: greeter_pb2.HelloRequest) -> dubbo.ServerStream[greeter_pb2.HelloReply]: + """Three greetings, streamed one by one.""" + + +@dubbo.service("org.apache.dubbo.samples.Greeter") +class GreeterServicer(abc.ABC): + """Greets people, in Python and in Java.""" + + @dubbo.method("SayHello") + @abc.abstractmethod + async def say_hello(self, request: greeter_pb2.HelloRequest) -> greeter_pb2.HelloReply: + """One greeting.""" + + @dubbo.method("SayHelloStream") + @abc.abstractmethod + async def say_hello_stream(self, request: greeter_pb2.HelloRequest, stream: dubbo.SendStream[greeter_pb2.HelloReply]) -> None: + """Three greetings, streamed one by one.""" diff --git a/samples/interop/java/greeter_pb2.py b/samples/interop/java/greeter_pb2.py new file mode 100644 index 00000000..5383d98e --- /dev/null +++ b/samples/interop/java/greeter_pb2.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: greeter.proto +# Protobuf Python Version: 7.35.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 7, + 35, + 1, + '', + 'greeter.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rgreeter.proto\x12\x18org.apache.dubbo.samples\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t2\xc5\x01\n\x07Greeter\x12X\n\x08SayHello\x12&.org.apache.dubbo.samples.HelloRequest\x1a$.org.apache.dubbo.samples.HelloReply\x12`\n\x0eSayHelloStream\x12&.org.apache.dubbo.samples.HelloRequest\x1a$.org.apache.dubbo.samples.HelloReply0\x01\x42\x02P\x01\x62\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'greeter_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + _globals['DESCRIPTOR']._loaded_options = None + _globals['DESCRIPTOR']._serialized_options = b'P\001' + _globals['_HELLOREQUEST']._serialized_start=43 + _globals['_HELLOREQUEST']._serialized_end=71 + _globals['_HELLOREPLY']._serialized_start=73 + _globals['_HELLOREPLY']._serialized_end=102 + _globals['_GREETER']._serialized_start=105 + _globals['_GREETER']._serialized_end=302 +# @@protoc_insertion_point(module_scope) diff --git a/samples/interop/java/greeter_pb2.pyi b/samples/interop/java/greeter_pb2.pyi new file mode 100644 index 00000000..bf0bd395 --- /dev/null +++ b/samples/interop/java/greeter_pb2.pyi @@ -0,0 +1,17 @@ +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from typing import ClassVar as _ClassVar, Optional as _Optional + +DESCRIPTOR: _descriptor.FileDescriptor + +class HelloRequest(_message.Message): + __slots__ = ("name",) + NAME_FIELD_NUMBER: _ClassVar[int] + name: str + def __init__(self, name: _Optional[str] = ...) -> None: ... + +class HelloReply(_message.Message): + __slots__ = ("message",) + MESSAGE_FIELD_NUMBER: _ClassVar[int] + message: str + def __init__(self, message: _Optional[str] = ...) -> None: ... diff --git a/samples/interop/java/java/.gitignore b/samples/interop/java/java/.gitignore new file mode 100644 index 00000000..f288ec5a --- /dev/null +++ b/samples/interop/java/java/.gitignore @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Maven builds into target. +target/ diff --git a/samples/interop/java/java/pom.xml b/samples/interop/java/java/pom.xml new file mode 100644 index 00000000..32b0515e --- /dev/null +++ b/samples/interop/java/java/pom.xml @@ -0,0 +1,93 @@ + + + + 4.0.0 + + org.apache.dubbo.samples + interop-java + 1.0.0 + + + 17 + UTF-8 + 3.3.7 + + + + + + org.apache.dubbo + dubbo-dependencies-bom + ${dubbo.version} + pom + import + + + + + + + org.apache.dubbo + dubbo + ${dubbo.version} + + + com.alibaba.nacos + nacos-client + + + com.google.protobuf + protobuf-java + + + org.slf4j + slf4j-simple + 1.7.36 + + + + + + + + org.apache.dubbo + dubbo-maven-plugin + ${dubbo.version} + + ${project.basedir}/../proto + + + + + compile + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.5.1 + + + + diff --git a/samples/interop/java/java/src/main/java/org/apache/dubbo/samples/JavaClient.java b/samples/interop/java/java/src/main/java/org/apache/dubbo/samples/JavaClient.java new file mode 100644 index 00000000..b372893c --- /dev/null +++ b/samples/interop/java/java/src/main/java/org/apache/dubbo/samples/JavaClient.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.dubbo.samples; + +import java.util.concurrent.CompletableFuture; + +import org.apache.dubbo.common.stream.StreamObserver; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ReferenceConfig; +import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.config.bootstrap.DubboBootstrap; +import org.apache.dubbo.rpc.RpcContext; + +/** The Java consumer: it finds the Python services in Nacos and calls them. */ +public class JavaClient { + + public static void main(String[] args) throws Exception { + ReferenceConfig greeterReference = new ReferenceConfig<>(); + greeterReference.setInterface(Greeter.class); + ReferenceConfig usersReference = new ReferenceConfig<>(); + usersReference.setInterface(UserService.class); + + DubboBootstrap.getInstance() + .application(new ApplicationConfig("java-client")) + .registry(new RegistryConfig("nacos://127.0.0.1:8848")) + .reference(greeterReference) + .reference(usersReference) + .start(); + Greeter greeter = greeterReference.get(); + UserService users = usersReference.get(); + + // An attachment set here goes with the next call only. + RpcContext.getClientAttachment().setAttachment("trace-id", "java-7f3a"); + System.out.println(greeter.sayHello(HelloRequest.newBuilder().setName("Alice").build()).getMessage()); + CompletableFuture done = new CompletableFuture<>(); + greeter.sayHelloStream(HelloRequest.newBuilder().setName("Bob").build(), new StreamObserver<>() { + @Override + public void onNext(HelloReply reply) { + System.out.println(reply.getMessage()); + } + + @Override + public void onError(Throwable error) { + done.completeExceptionally(error); + } + + @Override + public void onCompleted() { + done.complete(null); + } + }); + done.get(); + + RpcContext.getClientAttachment().setAttachment("trace-id", "java-7f3a"); + System.out.println(users.getUser(1)); + try { + users.getUser(42); + } catch (IllegalArgumentException error) { + System.out.println(error); + } + // Exiting stops Dubbo through its shutdown hook. + System.exit(0); + } +} diff --git a/samples/interop/java/java/src/main/java/org/apache/dubbo/samples/JavaServer.java b/samples/interop/java/java/src/main/java/org/apache/dubbo/samples/JavaServer.java new file mode 100644 index 00000000..be63e9b3 --- /dev/null +++ b/samples/interop/java/java/src/main/java/org/apache/dubbo/samples/JavaServer.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.dubbo.samples; + +import java.util.List; + +import org.apache.dubbo.common.stream.StreamObserver; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ProtocolConfig; +import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.config.ServiceConfig; +import org.apache.dubbo.config.bootstrap.DubboBootstrap; +import org.apache.dubbo.rpc.RpcContext; + +/** The Java provider: Greeter over Triple and UserService over Dubbo, registered in Nacos. */ +public class JavaServer { + + static class GreeterImpl extends DubboGreeterTriple.GreeterImplBase { + @Override + public HelloReply sayHello(HelloRequest request) { + System.out.println("[" + traceId() + "] sayHello(" + request.getName() + ")"); + return reply("Hello, " + request.getName() + ", from Java!"); + } + + @Override + public void sayHelloStream(HelloRequest request, StreamObserver replies) { + for (int count = 1; count <= 3; count++) { + replies.onNext(reply("Hello #" + count + ", " + request.getName() + ", from Java!")); + } + replies.onCompleted(); + } + + private static HelloReply reply(String message) { + return HelloReply.newBuilder().setMessage(message).build(); + } + } + + static class UserServiceImpl implements UserService { + @Override + public User getUser(long id) { + System.out.println("[" + traceId() + "] getUser(" + id + ")"); + if (id != 1) { + throw new IllegalArgumentException("no user has ID " + id); + } + return new User(1, "Alice", "alice@example.com"); + } + } + + /** The trace id among the attachments that the caller sent with the call being served. */ + static String traceId() { + return RpcContext.getServerAttachment().getAttachment("trace-id"); + } + + public static void main(String[] args) { + ProtocolConfig triple = new ProtocolConfig("tri", 50052); + ProtocolConfig dubbo = new ProtocolConfig("dubbo", 20881); + + ServiceConfig greeter = new ServiceConfig<>(); + greeter.setInterface(Greeter.class); + greeter.setRef(new GreeterImpl()); + // Each service on one protocol: Protobuf messages over Triple, Java objects over Dubbo. + greeter.setProtocol(triple); + + ServiceConfig users = new ServiceConfig<>(); + users.setInterface(UserService.class); + users.setRef(new UserServiceImpl()); + users.setProtocol(dubbo); + + DubboBootstrap.getInstance() + .application(new ApplicationConfig("java-server")) + .registry(new RegistryConfig("nacos://127.0.0.1:8848")) + .protocols(List.of(triple, dubbo)) + .service(greeter) + .service(users) + .start(); + System.out.println("Serving Greeter on port 50052 and UserService on port 20881; press Ctrl+C to stop"); + DubboBootstrap.getInstance().await(); + } +} diff --git a/samples/interop/java/java/src/main/java/org/apache/dubbo/samples/User.java b/samples/interop/java/java/src/main/java/org/apache/dubbo/samples/User.java new file mode 100644 index 00000000..66f93efa --- /dev/null +++ b/samples/interop/java/java/src/main/java/org/apache/dubbo/samples/User.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.dubbo.samples; + +import java.io.Serializable; + +/** A user, which Hessian 2 carries field by field; the Python class declares the same name and fields. */ +public class User implements Serializable { + + private long id; + private String name; + private String email; + + public User() {} + + public User(long id, String name, String email) { + this.id = id; + this.name = name; + this.email = email; + } + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + public String getEmail() { + return email; + } + + @Override + public String toString() { + return "User(id=" + id + ", name=" + name + ", email=" + email + ")"; + } +} diff --git a/samples/interop/java/java/src/main/java/org/apache/dubbo/samples/UserService.java b/samples/interop/java/java/src/main/java/org/apache/dubbo/samples/UserService.java new file mode 100644 index 00000000..17c9194a --- /dev/null +++ b/samples/interop/java/java/src/main/java/org/apache/dubbo/samples/UserService.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.dubbo.samples; + +/** Finds users; served over the Dubbo protocol, in Hessian 2. */ +public interface UserService { + + /** Returns the user of the ID, or fails if there is none. */ + User getUser(long id); +} diff --git a/samples/interop/java/proto/greeter.proto b/samples/interop/java/proto/greeter.proto new file mode 100644 index 00000000..a6f3b84f --- /dev/null +++ b/samples/interop/java/proto/greeter.proto @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +syntax = "proto3"; + +package org.apache.dubbo.samples; + +option java_multiple_files = true; + +// Greets people, in Python and in Java. +service Greeter { + // One greeting. + rpc SayHello (HelloRequest) returns (HelloReply); + // Three greetings, streamed one by one. + rpc SayHelloStream (HelloRequest) returns (stream HelloReply); +} + +message HelloRequest { + string name = 1; +} + +message HelloReply { + string message = 1; +} diff --git a/samples/interop/java/python_client.py b/samples/interop/java/python_client.py new file mode 100644 index 00000000..93cf6785 --- /dev/null +++ b/samples/interop/java/python_client.py @@ -0,0 +1,57 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The Python consumer: it finds the Java services in Nacos and calls them. + +import asyncio + +import dubbo +from dubbo import Dubbo, RpcError +from dubbo.config import ApplicationConfig, RegistryConfig + +from greeter_dubbo import Greeter +from greeter_pb2 import HelloRequest +from users import UserService + + +async def main() -> None: + app = Dubbo( + application=ApplicationConfig(name="python-client"), + registries={"default": RegistryConfig(address="nacos://127.0.0.1:8848")}, + ) + # No URL: the providers come from the registry, in whatever language. + greeter = app.refer(Greeter) + users = app.refer(UserService) + + async with app: + # Every call in the block attaches the trace id. + with dubbo.outgoing({"trace-id": "py-4bf9"}): + reply = await greeter.say_hello(HelloRequest(name="Alice")) + print(reply.message) + async with greeter.say_hello_stream(HelloRequest(name="Bob")) as replies: + async for reply in replies: + print(reply.message) + + print(await users.get_user(1)) + try: + await users.get_user(42) + except RpcError as error: + print(error) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/interop/java/python_server.py b/samples/interop/java/python_server.py new file mode 100644 index 00000000..a1708c7a --- /dev/null +++ b/samples/interop/java/python_server.py @@ -0,0 +1,73 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The Python provider: Greeter over Triple and UserService over Dubbo, +# registered in Nacos, where Java consumers find them. + +import asyncio + +import dubbo +from dubbo import Dubbo, RemoteError +from dubbo.config import ApplicationConfig, ProtocolConfig, RegistryConfig, ServiceConfig + +from greeter_dubbo import GreeterServicer +from greeter_pb2 import HelloReply, HelloRequest +from users import User, UserService + + +def trace_id() -> str | bytes | None: + # The attachments that the caller sent with the call being served. + return dubbo.incoming().attachments.get("trace-id") + + +class GreeterImpl(GreeterServicer): + async def say_hello(self, request: HelloRequest) -> HelloReply: + print(f"[{trace_id()}] say_hello({request.name})") + return HelloReply(message=f"Hello, {request.name}, from Python!") + + async def say_hello_stream(self, request: HelloRequest, stream: dubbo.SendStream[HelloReply]) -> None: + for count in range(1, 4): + await stream.send(HelloReply(message=f"Hello #{count}, {request.name}, from Python!")) + + +class UserServiceImpl(UserService): + async def get_user(self, id: int) -> User: + print(f"[{trace_id()}] get_user({id})") + if id != 1: + # A Java exception, by its class name, as the Java server throws. + raise RemoteError("java.lang.IllegalArgumentException", f"no user has ID {id}") + return User(id=1, name="Alice", email="alice@example.com") + + +async def main() -> None: + app = Dubbo( + application=ApplicationConfig(name="python-server"), + registries={"default": RegistryConfig(address="nacos://127.0.0.1:8848")}, + protocols={"tri": ProtocolConfig(port=50051), "dubbo": ProtocolConfig(port=20880)}, + ) + # Each service on one protocol, as the Java side does: Protobuf messages + # over Triple, Java objects over Dubbo. + app.export(GreeterImpl(), config=ServiceConfig(protocols=("tri",))) + app.export(UserServiceImpl(), config=ServiceConfig(protocols=("dubbo",))) + + async with app: + print("Serving Greeter on port 50051 and UserService on port 20880; press Ctrl+C to stop") + await app.serve_forever() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/samples/interop/java/users.py b/samples/interop/java/users.py new file mode 100644 index 00000000..67d1ca3e --- /dev/null +++ b/samples/interop/java/users.py @@ -0,0 +1,44 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The contract of the Java UserService, in Python: the names it has in Java, +# and Java types where Python ones would differ. + +import dataclasses +import typing + +import dubbo +import hessian2 + + +# Hessian 2 carries an object under its Java class name, field by field; Java +# sees this class as org.apache.dubbo.samples.User. hessian2.Long is a Python +# int sent as a Java long, where an int would be sent as a Java int. +@hessian2.java_class("org.apache.dubbo.samples.User") +@dataclasses.dataclass +class User: + id: hessian2.Long + name: str + email: str + + +@dubbo.service("org.apache.dubbo.samples.UserService") +class UserService(typing.Protocol): + # The Java name of the method; Java also tells methods of one name apart + # by the types of their parameters, here a long. + @dubbo.method("getUser") + async def get_user(self, id: hessian2.Long) -> User: ... diff --git a/samples/llm/README.md b/samples/llm/README.md deleted file mode 100644 index 36326b27..00000000 --- a/samples/llm/README.md +++ /dev/null @@ -1,127 +0,0 @@ -## Integrating LLM - -Dubbo Python can easily integrate with LLMs and provide RPC services. - -- **Model**: DeepSeek-R1-Distill-Qwen-7B -- **Model Deployment Framework**: LMDeploy -- **GPU**: NVIDIA Corporation GA102GL [A10] (rev a1) - -**Description**: This example demonstrates the use of [DeepSeek R1](https://github.com/deepseek-ai/DeepSeek-R1) and [LMDeploy](https://github.com/InternLM/lmdeploy) for deployment, but the overall process is applicable to other models and inference frameworks. If you wish to deploy using Docker or other containerization methods, refer to the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/index.html) documentation for relevant configuration steps. - -### Basic Environment - -```sh ----------- -Operating System: Ubuntu 22.04.5 -Python Version: 3.11.10 -PyTorch Version: 2.5.1 ----------- -``` - -### Model Download - -Use the `snapshot_download` function provided by modelscope to download the model. The first parameter is the model name, and the `cache_dir` parameter specifies the download path for the model. - -```python -from modelscope import snapshot_download - -model_dir = snapshot_download('deepseek-ai/DeepSeek-R1-Distill-Qwen-7B', cache_dir='/home/dubbo/model', revision='master') -``` - -### Core code - -```python -from time import sleep - -from lmdeploy import GenerationConfig, TurbomindEngineConfig, pipeline - -from dubbo import Dubbo -from dubbo.configs import RegistryConfig, ServiceConfig -from dubbo.proxy.handlers import RpcMethodHandler, RpcServiceHandler -import chat_pb2 - -# the path of a model. It could be one of the following options: -# 1. A local directory path of a turbomind model -# 2. The model_id of a lmdeploy-quantized model -# 3. The model_id of a model hosted inside a model repository -model = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B" - -backend_config = TurbomindEngineConfig(cache_max_entry_count=0.2, max_context_token_num=20544, session_len=20544) - -gen_config = GenerationConfig( - top_p=0.95, - temperature=0.6, - max_new_tokens=8192, - stop_token_ids=[151329, 151336, 151338], - do_sample=True, # enable sampling -) - - -class DeepSeekAiServicer: - def __init__(self, model: str, backend_config: TurbomindEngineConfig, gen_config: GenerationConfig): - self.llm = pipeline(model, backend_config=backend_config) - self.gen_config = gen_config - - def chat(self, stream): - # read request from stream - request = stream.read() - print(f"Received request: {request}") - # prepare prompts - prompts = [{"role": request.role, "content": request.content + "\n"}] - - is_think = False - - # perform streaming inference - for item in self.llm.stream_infer(prompts, gen_config=gen_config): - # update think status - if item.text == "": - is_think = True - continue - elif item.text == "": - is_think = False - continue - # According to the state of thought, decide the content of the reply. - if is_think: - # send thought - stream.write(chat_pb2.ChatReply(think=item.text, answer="")) - else: - # send answer - stream.write(chat_pb2.ChatReply(think="", answer=item.text)) - - stream.done_writing() - - -def build_server_handler(): - # build a method handler - deepseek_ai_servicer = DeepSeekAiServicer(model, backend_config, gen_config) - method_handler = RpcMethodHandler.server_stream( - deepseek_ai_servicer.chat, - method_name="chat", - request_deserializer=chat_pb2.ChatRequest.FromString, - response_serializer=chat_pb2.ChatReply.SerializeToString, - ) - # build a service handler - service_handler = RpcServiceHandler( - service_name="org.apache.dubbo.samples.llm.api.DeepSeekAiService", - method_handlers=[method_handler], - ) - return service_handler - - -if __name__ == "__main__": - # build a service handler - service_handler = build_server_handler() - service_config = ServiceConfig(service_handler=service_handler) - - # Configure the Zookeeper registry - registry_config = RegistryConfig.from_url("zookeeper://zookeeper:2181") - bootstrap = Dubbo(registry_config=registry_config) - - # Create and start the server - bootstrap.create_server(service_config).start() - - # 30days - sleep(30 * 24 * 60 * 60) - -``` - diff --git a/samples/llm/__init__.py b/samples/llm/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/samples/llm/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/samples/llm/chat.proto b/samples/llm/chat.proto deleted file mode 100644 index e0416360..00000000 --- a/samples/llm/chat.proto +++ /dev/null @@ -1,21 +0,0 @@ -syntax = "proto3"; - -option java_multiple_files = true; -option java_outer_classname = "ChatProto"; - -package org.apache.dubbo.samples.llm.api; - -message ChatRequest { - string role = 1; - string content = 2; -} - -message ChatReply { - string think = 1; - string answer = 2; -} - -service DeepSeekAiService { - // chat - rpc chat(ChatRequest) returns (stream ChatReply); -} diff --git a/samples/llm/chat_pb2.py b/samples/llm/chat_pb2.py deleted file mode 100644 index de9488e5..00000000 --- a/samples/llm/chat_pb2.py +++ /dev/null @@ -1,32 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: chat.proto -# Protobuf Python Version: 4.25.3 -"""Generated protocol buffer code.""" - -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( - b'\n\nchat.proto\x12 org.apache.dubbo.samples.llm.api",\n\x0b\x43hatRequest\x12\x0c\n\x04role\x18\x01 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x02 \x01(\t"*\n\tChatReply\x12\r\n\x05think\x18\x01 \x01(\t\x12\x0e\n\x06\x61nswer\x18\x02 \x01(\t2y\n\x11\x44\x65\x65pSeekAiService\x12\x64\n\x04\x63hat\x12-.org.apache.dubbo.samples.llm.api.ChatRequest\x1a+.org.apache.dubbo.samples.llm.api.ChatReply0\x01\x42\rB\tChatProtoP\x01\x62\x06proto3' -) - -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, "chat_pb2", _globals) -if _descriptor._USE_C_DESCRIPTORS == False: - _globals["DESCRIPTOR"]._options = None - _globals["DESCRIPTOR"]._serialized_options = b"B\tChatProtoP\001" - _globals["_CHATREQUEST"]._serialized_start = 48 - _globals["_CHATREQUEST"]._serialized_end = 92 - _globals["_CHATREPLY"]._serialized_start = 94 - _globals["_CHATREPLY"]._serialized_end = 136 - _globals["_DEEPSEEKAISERVICE"]._serialized_start = 138 - _globals["_DEEPSEEKAISERVICE"]._serialized_end = 259 -# @@protoc_insertion_point(module_scope) diff --git a/samples/llm/main.py b/samples/llm/main.py deleted file mode 100644 index e3157162..00000000 --- a/samples/llm/main.py +++ /dev/null @@ -1,106 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from time import sleep - -from lmdeploy import GenerationConfig, TurbomindEngineConfig, pipeline - -from dubbo import Dubbo -from dubbo.configs import RegistryConfig, ServiceConfig -from dubbo.proxy.handlers import RpcMethodHandler, RpcServiceHandler -import chat_pb2 - -# the path of a model. It could be one of the following options: -# 1. A local directory path of a turbomind model -# 2. The model_id of a lmdeploy-quantized model -# 3. The model_id of a model hosted inside a model repository -model = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B" - -backend_config = TurbomindEngineConfig(cache_max_entry_count=0.2, max_context_token_num=20544, session_len=20544) - -gen_config = GenerationConfig( - top_p=0.95, - temperature=0.6, - max_new_tokens=8192, - stop_token_ids=[151329, 151336, 151338], - do_sample=True, # enable sampling -) - - -class DeepSeekAiServicer: - def __init__(self, model: str, backend_config: TurbomindEngineConfig, gen_config: GenerationConfig): - self.llm = pipeline(model, backend_config=backend_config) - self.gen_config = gen_config - - def chat(self, stream): - # read request from stream - request = stream.read() - print(f"Received request: {request}") - # prepare prompts - prompts = [{"role": request.role, "content": request.content + "\n"}] - - is_think = False - - # perform streaming inference - for item in self.llm.stream_infer(prompts, gen_config=gen_config): - # update think status - if item.text == "": - is_think = True - continue - elif item.text == "": - is_think = False - continue - # According to the state of thought, decide the content of the reply. - if is_think: - # send thought - stream.write(chat_pb2.ChatReply(think=item.text, answer="")) - else: - # send answer - stream.write(chat_pb2.ChatReply(think="", answer=item.text)) - - stream.done_writing() - - -def build_server_handler(): - # build a method handler - deepseek_ai_servicer = DeepSeekAiServicer(model, backend_config, gen_config) - method_handler = RpcMethodHandler.server_stream( - deepseek_ai_servicer.chat, - method_name="chat", - request_deserializer=chat_pb2.ChatRequest.FromString, - response_serializer=chat_pb2.ChatReply.SerializeToString, - ) - # build a service handler - service_handler = RpcServiceHandler( - service_name="org.apache.dubbo.samples.llm.api.DeepSeekAiService", - method_handlers=[method_handler], - ) - return service_handler - - -if __name__ == "__main__": - # build a service handler - service_handler = build_server_handler() - service_config = ServiceConfig(service_handler=service_handler) - - # Configure the Zookeeper registry - registry_config = RegistryConfig.from_url("zookeeper://zookeeper:2181") - bootstrap = Dubbo(registry_config=registry_config) - - # Create and start the server - bootstrap.create_server(service_config).start() - - # 30days - sleep(30 * 24 * 60 * 60) diff --git a/samples/proto/__init__.py b/samples/proto/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/samples/proto/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/samples/proto/greeter.proto b/samples/proto/greeter.proto deleted file mode 100644 index 491520a3..00000000 --- a/samples/proto/greeter.proto +++ /dev/null @@ -1,28 +0,0 @@ -syntax = "proto3"; - -package org.apache.dubbo.samples.proto; - -message GreeterRequest { - string name = 1; -} - -message GreeterReply { - string message = 1; -} - -service Greeter{ - - // unary - rpc sayHello(GreeterRequest) returns (GreeterReply); - - // client stream - rpc clientStream(stream GreeterRequest) returns (GreeterReply); - - // server stream - rpc serverStream(GreeterRequest) returns (stream GreeterReply); - - // bi-directional stream - rpc biStream(stream GreeterRequest) returns (stream GreeterReply); - - -} diff --git a/samples/proto/greeter_pb2.py b/samples/proto/greeter_pb2.py deleted file mode 100644 index b8f5020b..00000000 --- a/samples/proto/greeter_pb2.py +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# NO CHECKED-IN PROTOBUF GENCODE -# source: greeter.proto -# Protobuf Python Version: 5.27.0 -"""Generated protocol buffer code.""" -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import runtime_version as _runtime_version -from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder -_runtime_version.ValidateProtobufRuntimeVersion( - _runtime_version.Domain.PUBLIC, - 5, - 27, - 0, - '', - 'greeter.proto' -) -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rgreeter.proto\x12\x1eorg.apache.dubbo.samples.proto\"\x1e\n\x0eGreeterRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1f\n\x0cGreeterReply\x12\x0f\n\x07message\x18\x01 \x01(\t2\xc1\x03\n\x07Greeter\x12h\n\x08sayHello\x12..org.apache.dubbo.samples.proto.GreeterRequest\x1a,.org.apache.dubbo.samples.proto.GreeterReply\x12n\n\x0c\x63lientStream\x12..org.apache.dubbo.samples.proto.GreeterRequest\x1a,.org.apache.dubbo.samples.proto.GreeterReply(\x01\x12n\n\x0cserverStream\x12..org.apache.dubbo.samples.proto.GreeterRequest\x1a,.org.apache.dubbo.samples.proto.GreeterReply0\x01\x12l\n\x08\x62iStream\x12..org.apache.dubbo.samples.proto.GreeterRequest\x1a,.org.apache.dubbo.samples.proto.GreeterReply(\x01\x30\x01\x62\x06proto3') - -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'greeter_pb2', _globals) -if not _descriptor._USE_C_DESCRIPTORS: - DESCRIPTOR._loaded_options = None - _globals['_GREETERREQUEST']._serialized_start=49 - _globals['_GREETERREQUEST']._serialized_end=79 - _globals['_GREETERREPLY']._serialized_start=81 - _globals['_GREETERREPLY']._serialized_end=112 - _globals['_GREETER']._serialized_start=115 - _globals['_GREETER']._serialized_end=564 -# @@protoc_insertion_point(module_scope) diff --git a/samples/registry/README.md b/samples/registry/README.md deleted file mode 100644 index dc8a0684..00000000 --- a/samples/registry/README.md +++ /dev/null @@ -1,26 +0,0 @@ -## Service Registration and Discovery - -Using service registration and discovery is very simple. In fact, it only requires two additional lines of code compared to point-to-point calls. Before using this feature, we need to install the relevant registry client. Currently, Dubbo-python only supports `Zookeeper`, so the following demonstration will use `Zookeeper`. - -Similar to before, we need to clone the Dubbo-python source code and install it. However, in this case, we also need to install the `Zookeeper` client. The commands are: - -```shell -git clone https://github.com/apache/dubbo-python.git -cd dubbo-python && pip install .[zookeeper] -``` - -After that, simply start `Zookeeper` and insert the following code into your existing example: - -```python -# Configure the Zookeeper registry -registry_config = RegistryConfig.from_url("zookeeper://127.0.0.1:2181") -bootstrap = Dubbo(registry_config=registry_config) - -# Create the client -client = bootstrap.create_client(reference_config) - -# Create and start the server -bootstrap.create_server(service_config).start() -``` - -This enables service registration and discovery within your Dubbo-python project. diff --git a/samples/registry/__init__.py b/samples/registry/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/samples/registry/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/samples/registry/zookeeper/__init__.py b/samples/registry/zookeeper/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/samples/registry/zookeeper/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/samples/registry/zookeeper/client.py b/samples/registry/zookeeper/client.py deleted file mode 100644 index b9035d65..00000000 --- a/samples/registry/zookeeper/client.py +++ /dev/null @@ -1,45 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import dubbo -from dubbo.configs import ReferenceConfig, RegistryConfig -from samples.proto import greeter_pb2 - - -class GreeterServiceStub: - def __init__(self, client: dubbo.Client): - self.unary = client.unary( - method_name="sayHello", - request_serializer=greeter_pb2.GreeterRequest.SerializeToString, - response_deserializer=greeter_pb2.GreeterReply.FromString, - ) - - def say_hello(self, request): - return self.unary(request) - - -if __name__ == "__main__": - registry_config = RegistryConfig.from_url("zookeeper://127.0.0.1:2181") - bootstrap = dubbo.Dubbo(registry_config=registry_config) - - reference_config = ReferenceConfig(protocol="tri", service="org.apache.dubbo.samples.data.Greeter") - dubbo_client = bootstrap.create_client(reference_config) - - stub = GreeterServiceStub(dubbo_client) - - result = stub.say_hello(greeter_pb2.GreeterRequest(name="dubbo-python")) - - print(result.message) diff --git a/samples/registry/zookeeper/server.py b/samples/registry/zookeeper/server.py deleted file mode 100644 index 8e9b463f..00000000 --- a/samples/registry/zookeeper/server.py +++ /dev/null @@ -1,55 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import dubbo -from dubbo.configs import RegistryConfig, ServiceConfig -from dubbo.proxy.handlers import RpcMethodHandler, RpcServiceHandler -from samples.proto import greeter_pb2 - - -class GreeterServiceServicer: - def say_hello(self, request): - print(f"Received request: {request.name}") - return greeter_pb2.GreeterReply(message=f"Hello, {request.name}!") - - -def build_server_handler(): - # build a method handler - method_handler = RpcMethodHandler.unary( - GreeterServiceServicer().say_hello, - method_name="sayHello", - request_deserializer=greeter_pb2.GreeterRequest.FromString, - response_serializer=greeter_pb2.GreeterReply.SerializeToString, - ) - # build a service handler - service_handler = RpcServiceHandler( - service_name="org.apache.dubbo.samples.data.Greeter", - method_handlers=[method_handler], - ) - return service_handler - - -if __name__ == "__main__": - registry_config = RegistryConfig.from_url("zookeeper://127.0.0.1:2181") - bootstrap = dubbo.Dubbo(registry_config=registry_config) - - # build a service config - service_handler = build_server_handler() - service_config = ServiceConfig(service_handler) - - # start the server - server = bootstrap.create_server(service_config).start() - - input("Press Enter to stop the server...\n") diff --git a/samples/ruff.toml b/samples/ruff.toml new file mode 100644 index 00000000..fee5d4a4 --- /dev/null +++ b/samples/ruff.toml @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The samples import dubbo as an installed package, and the modules beside each +# sample as their own. +extend = "../pyproject.toml" + +[lint.isort] +default-section = "first-party" +known-third-party = ["anyio", "dubbo", "fastapi", "grpc", "hessian2", "kazoo", "pydantic", "pydantic_ai", "structlog"] diff --git a/samples/serialization/README.md b/samples/serialization/README.md deleted file mode 100644 index d711d4f6..00000000 --- a/samples/serialization/README.md +++ /dev/null @@ -1,190 +0,0 @@ -## Custom Serialization - -Python is a dynamic language, and its flexibility makes it challenging to design a universal serialization layer for other languages. Therefore, we removed the framework-level serialization layer and instead exposed interfaces, allowing users to implement their own (as they know best the data format they will be passing). - -Serialization typically involves two parts: serialization and deserialization. We have defined the types for these functions, and custom serialization/deserialization functions must follow these "formats." - -For serialization functions, we specify: - -```python -# A function that takes any number of arguments and returns data of type bytes -SerializingFunction = Callable[..., bytes] -``` - -For deserialization functions, we specify: - -```python -# A function that takes an argument of type bytes and returns data of any type -DeserializingFunction = Callable[[bytes], Any] -``` - -Below, I'll demonstrate how to use `protobuf` and `json` for serialization. - -### [protobuf](./protobuf) - -1. For defining and compiling `protobuf` files, please refer to the [protobuf tutorial](https://protobuf.dev/getting-started/pythontutorial/) for detailed instructions. - -2. Set `xxx_serializer` and `xxx_deserializer` in the client and server. - - client - - ```python - class GreeterServiceStub: - def __init__(self, client: dubbo.Client): - self.unary = client.unary( - method_name="sayHello", - request_serializer=greeter_pb2.GreeterRequest.SerializeToString, - response_deserializer=greeter_pb2.GreeterReply.FromString, - ) - - def say_hello(self, request): - return self.unary(request) - - - if __name__ == "__main__": - reference_config = ReferenceConfig.from_url( - "tri://127.0.0.1:50051/org.apache.dubbo.samples.data.Greeter" - ) - dubbo_client = dubbo.Client(reference_config) - - stub = GreeterServiceStub(dubbo_client) - result = stub.say_hello(greeter_pb2.GreeterRequest(name="Dubbo-python")) - print(f"Received reply: {result.message}") - ``` - - server - - ```python - class GreeterServiceServicer: - def say_hello(self, request): - print(f"Received request: {request}") - return greeter_pb2.GreeterReply(message=f"Hello, {request.name}") - - - def build_service_handler(): - # build a method handler - method_handler = RpcMethodHandler.unary( - GreeterServiceServicer().say_hello, - method_name="sayHello", - request_deserializer=greeter_pb2.GreeterRequest.FromString, - response_serializer=greeter_pb2.GreeterReply.SerializeToString, - ) - # build a service handler - service_handler = RpcServiceHandler( - service_name="org.apache.dubbo.samples.data.Greeter", - method_handlers=[method_handler], - ) - return service_handler - - - if __name__ == "__main__": - # build a service handler - service_handler = build_service_handler() - service_config = ServiceConfig( - service_handler=service_handler, host="127.0.0.1", port=50051 - ) - - # start the server - server = dubbo.Server(service_config).start() - - input("Press Enter to stop the server...\n") - ``` - - - -### [Json](./json) - -We have already implemented single-parameter serialization and deserialization using `protobuf`. Now, I will demonstrate how to write a multi-parameter `Json` serialization and deserialization function to enable remote calls for methods with multiple parameters. - -1. Install `orjson`: - - ```shell - pip install orjson - ``` - -2. Define serialization and deserialization functions: - - client - - ```python - def request_serializer(name: str, age: int) -> bytes: - return orjson.dumps({"name": name, "age": age}) - - - def response_deserializer(data: bytes) -> str: - json_dict = orjson.loads(data) - return json_dict["message"] - - - class GreeterServiceStub: - def __init__(self, client: dubbo.Client): - self.unary = client.unary( - method_name="unary", - request_serializer=request_serializer, - response_deserializer=response_deserializer, - ) - - def say_hello(self, name: str, age: int): - return self.unary(name, age) - - - if __name__ == "__main__": - reference_config = ReferenceConfig.from_url( - "tri://127.0.0.1:50051/org.apache.dubbo.samples.serialization.json" - ) - dubbo_client = dubbo.Client(reference_config) - - stub = GreeterServiceStub(dubbo_client) - result = stub.say_hello("dubbo-python", 18) - print(result) - ``` - - server - - ```python - def request_deserializer(data: bytes) -> Tuple[str, int]: - json_dict = orjson.loads(data) - return json_dict["name"], json_dict["age"] - - - def response_serializer(message: str) -> bytes: - return orjson.dumps({"message": message}) - - - class GreeterServiceServicer: - def say_hello(self, request): - name, age = request - print(f"Received request: {name}, {age}") - return f"Hello, {name}, you are {age} years old." - - - def build_service_handler(): - # build a method handler - method_handler = RpcMethodHandler.unary( - GreeterServiceServicer().say_hello, - method_name="unary", - request_deserializer=request_deserializer, - response_serializer=response_serializer, - ) - # build a service handler - service_handler = RpcServiceHandler( - service_name="org.apache.dubbo.samples.serialization.json", - method_handlers=[method_handler], - ) - return service_handler - - - if __name__ == "__main__": - # build server config - service_handler = build_service_handler() - service_config = ServiceConfig( - service_handler=service_handler, host="127.0.0.1", port=50051 - ) - - # start the server - server = dubbo.Server(service_config).start() - - input("Press Enter to stop the server...\n") - ``` - - \ No newline at end of file diff --git a/samples/serialization/__init__.py b/samples/serialization/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/samples/serialization/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/samples/serialization/json/__init__.py b/samples/serialization/json/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/samples/serialization/json/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/samples/serialization/json/client.py b/samples/serialization/json/client.py deleted file mode 100644 index 9cd13c82..00000000 --- a/samples/serialization/json/client.py +++ /dev/null @@ -1,50 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import orjson - -import dubbo -from dubbo.configs import ReferenceConfig - - -def request_serializer(name: str, age: int) -> bytes: - return orjson.dumps({"name": name, "age": age}) - - -def response_deserializer(data: bytes) -> str: - json_dict = orjson.loads(data) - return json_dict["message"] - - -class GreeterServiceStub: - def __init__(self, client: dubbo.Client): - self.unary = client.unary( - method_name="unary", - request_serializer=request_serializer, - response_deserializer=response_deserializer, - ) - - def say_hello(self, name: str, age: int): - return self.unary(name, age) - - -if __name__ == "__main__": - reference_config = ReferenceConfig.from_url("tri://127.0.0.1:50051/org.apache.dubbo.samples.serialization.json") - dubbo_client = dubbo.Client(reference_config) - - stub = GreeterServiceStub(dubbo_client) - result = stub.say_hello("dubbo-python", 18) - print(result) diff --git a/samples/serialization/json/server.py b/samples/serialization/json/server.py deleted file mode 100644 index f2b71602..00000000 --- a/samples/serialization/json/server.py +++ /dev/null @@ -1,64 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import orjson - -import dubbo -from dubbo.configs import ServiceConfig -from dubbo.proxy.handlers import RpcMethodHandler, RpcServiceHandler - - -def request_deserializer(data: bytes) -> tuple[str, int]: - json_dict = orjson.loads(data) - return json_dict["name"], json_dict["age"] - - -def response_serializer(message: str) -> bytes: - return orjson.dumps({"message": message}) - - -class GreeterServiceServicer: - def say_hello(self, request): - name, age = request - print(f"Received request: {name}, {age}") - return f"Hello, {name}, you are {age} years old." - - -def build_service_handler(): - # build a method handler - method_handler = RpcMethodHandler.unary( - GreeterServiceServicer().say_hello, - method_name="unary", - request_deserializer=request_deserializer, - response_serializer=response_serializer, - ) - # build a service handler - service_handler = RpcServiceHandler( - service_name="org.apache.dubbo.samples.serialization.json", - method_handlers=[method_handler], - ) - return service_handler - - -if __name__ == "__main__": - # build server config - service_handler = build_service_handler() - service_config = ServiceConfig(service_handler=service_handler, host="127.0.0.1", port=50051) - - # start the server - server = dubbo.Server(service_config).start() - - input("Press Enter to stop the server...\n") diff --git a/samples/serialization/protobuf/__init__.py b/samples/serialization/protobuf/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/samples/serialization/protobuf/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/samples/serialization/protobuf/client.py b/samples/serialization/protobuf/client.py deleted file mode 100644 index 0f331376..00000000 --- a/samples/serialization/protobuf/client.py +++ /dev/null @@ -1,39 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import dubbo -from dubbo.configs import ReferenceConfig -from samples.proto import greeter_pb2 - - -class GreeterServiceStub: - def __init__(self, client: dubbo.Client): - self.unary = client.unary( - method_name="sayHello", - request_serializer=greeter_pb2.GreeterRequest.SerializeToString, - response_deserializer=greeter_pb2.GreeterReply.FromString, - ) - - def say_hello(self, request): - return self.unary(request) - - -if __name__ == "__main__": - reference_config = ReferenceConfig.from_url("tri://127.0.0.1:50051/org.apache.dubbo.samples.data.Greeter") - dubbo_client = dubbo.Client(reference_config) - - stub = GreeterServiceStub(dubbo_client) - result = stub.say_hello(greeter_pb2.GreeterRequest(name="Dubbo-python")) - print(f"Received reply: {result.message}") diff --git a/samples/serialization/protobuf/server.py b/samples/serialization/protobuf/server.py deleted file mode 100644 index 73811790..00000000 --- a/samples/serialization/protobuf/server.py +++ /dev/null @@ -1,52 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import dubbo -from dubbo.configs import ServiceConfig -from dubbo.proxy.handlers import RpcMethodHandler, RpcServiceHandler -from samples.proto import greeter_pb2 - - -class GreeterServiceServicer: - def say_hello(self, request): - print(f"Received request: {request}") - return greeter_pb2.GreeterReply(message=f"Hello, {request.name}") - - -def build_service_handler(): - # build a method handler - method_handler = RpcMethodHandler.unary( - GreeterServiceServicer().say_hello, - method_name="sayHello", - request_deserializer=greeter_pb2.GreeterRequest.FromString, - response_serializer=greeter_pb2.GreeterReply.SerializeToString, - ) - # build a service handler - service_handler = RpcServiceHandler( - service_name="org.apache.dubbo.samples.data.Greeter", - method_handlers=[method_handler], - ) - return service_handler - - -if __name__ == "__main__": - # build a service handler - service_handler = build_service_handler() - service_config = ServiceConfig(service_handler=service_handler, host="127.0.0.1", port=50051) - - # start the server - server = dubbo.Server(service_config).start() - - input("Press Enter to stop the server...\n") diff --git a/samples/stream/README.md b/samples/stream/README.md deleted file mode 100644 index 51100e03..00000000 --- a/samples/stream/README.md +++ /dev/null @@ -1,94 +0,0 @@ -## Streaming Calls - -Dubbo-Python supports streaming calls, including `ClientStream`, `ServerStream`, and `BidirectionalStream` modes. - -Streaming calls can be divided into write-streams and read-streams. For `ClientStream`, it’s multiple writes with a single read; for `ServerStream`, a single write with multiple reads; and `BidirectionalStream` allows multiple writes and reads. - -### Write-Stream - -Write operations in streaming calls can be divided into single write (`ServerStream`) and multiple writes (`ClientStream` and `BidirectionalStream`). - -#### Single Write - -Single write calls are similar to unary mode. For example: - -```python -stub.server_stream(greeter_pb2.GreeterRequest(name="hello world from dubbo-python")) -``` - -#### Multiple Writes - -For multiple writes, users can write data using either an iterator or `writeStream` (only one of these options should be used). - -1. **Iterator-based Write**: Writing via iterator is similar to unary mode, with the main difference being the use of an iterator for multiple writes. For example: - - ```python - # Use an iterator to send multiple requests - def request_generator(): - for i in ["hello", "world", "from", "dubbo-python"]: - yield greeter_pb2.GreeterRequest(name=str(i)) - - # Call the remote method and return a read_stream - stream = stub.client_stream(request_generator()) - ``` - -2. **Using `writeStream`**: This method requires an empty argument, after which data is written incrementally using `write`, and `done_writing` is called to end the write-stream. For example: - - ```python - stream = stub.bi_stream() - # Use the write method to send messages - stream.write(greeter_pb2.GreeterRequest(name="jock")) - stream.write(greeter_pb2.GreeterRequest(name="jane")) - stream.write(greeter_pb2.GreeterRequest(name="alice")) - stream.write(greeter_pb2.GreeterRequest(name="dave")) - # Call done_writing to notify the server that the client has finished writing - stream.done_writing() - ``` - -### Read-Stream - -Read operations for streaming calls can be single read (`ClientStream`) or multiple reads (`ServerStream` and `BidirectionalStream`). A `ReadStream` is returned in all cases, and data can be read using the `read` method or an iterator. When using `read`, please note: - -1. The `read` method supports a `timeout` parameter (in seconds). -2. The `read` method can return one of three values: the expected data, `None` (timeout exceeded), or `EOF` (end of the read-stream). - -#### Single Read - -A single call to the `read` method will retrieve the data, for example: - -```python -result = stream.read() -print(f"Received response: {result.message}") -``` - -#### Multiple Reads - -Multiple reads can be done by repeatedly calling `read`, with handling for `None` and `EOF` values. Since `ReadStream` implements `__iter__` and `__next__`, an iterator-based approach can also be used, which automatically handles these values but doesn’t support a timeout. - -1. **Using Iterator (Recommended)**: - - ```python - def client_stream(self, request_iterator): - response = "" - for request in request_iterator: - print(f"Received request: {request.name}") - response += f"{request.name} " - return greeter_pb2.GreeterReply(message=response) - ``` - -2. **Multiple Calls to `read` Method**: - - ```python - # Use read method to receive messages - # If no message arrives within the specified time, returns None - # If the server has finished sending messages, returns EOF - while True: - i = stream.read(timeout=0.5) - if i is dubbo.classes.EOF: - break - elif i is None: - print("No message received") - continue - print(f"Received response: {i.message}") - ``` - diff --git a/samples/stream/__init__.py b/samples/stream/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/samples/stream/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/samples/stream/bidi_stream/__init__.py b/samples/stream/bidi_stream/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/samples/stream/bidi_stream/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/samples/stream/bidi_stream/client.py b/samples/stream/bidi_stream/client.py deleted file mode 100644 index 4c387dc8..00000000 --- a/samples/stream/bidi_stream/client.py +++ /dev/null @@ -1,65 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import dubbo -from dubbo.classes import EOF -from dubbo.configs import ReferenceConfig -from samples.proto import greeter_pb2 - - -class GreeterServiceStub: - def __init__(self, client: dubbo.Client): - self.bidi_stream = client.bi_stream( - method_name="biStream", - request_serializer=greeter_pb2.GreeterRequest.SerializeToString, - response_deserializer=greeter_pb2.GreeterReply.FromString, - ) - - def bi_stream(self, *args): - return self.bidi_stream(args) - - -if __name__ == "__main__": - # Create a reference config - reference_config = ReferenceConfig.from_url("tri://127.0.0.1:50051/org.apache.dubbo.samples.data.Greeter") - dubbo_client = dubbo.Client(reference_config) - stub = GreeterServiceStub(dubbo_client) - - stream = stub.bi_stream() - # use write method to send message - stream.write(greeter_pb2.GreeterRequest(name="jock")) - - # use read method to receive message - print(f"Received response: {stream.read().message}") - - # continue to send message - stream.write(greeter_pb2.GreeterRequest(name="jane")) - stream.write(greeter_pb2.GreeterRequest(name="alice")) - stream.write(greeter_pb2.GreeterRequest(name="dave")) - # done_writing method must be called to notify the server that the client has finished writing - stream.done_writing() - - # use read method to receive message - # If no message arrives within the specified time, returns None - # If the server has finished sending messages and the client has received all messages, returns EOF - while True: - i = stream.read(timeout=0.5) - if i is EOF: - break - elif i is None: - print("No message received") - continue - print(f"Received response: {i.message}") diff --git a/samples/stream/bidi_stream/server.py b/samples/stream/bidi_stream/server.py deleted file mode 100644 index a01246a4..00000000 --- a/samples/stream/bidi_stream/server.py +++ /dev/null @@ -1,61 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import time - -import dubbo -from dubbo.configs import ServiceConfig -from dubbo.proxy.handlers import RpcMethodHandler, RpcServiceHandler -from samples.proto import greeter_pb2 - - -class GreeterServiceServicer: - def bi_stream(self, stream): - counter = 0 - for request in stream: - print(f"Received request: {request.name}") - # simulate a long time to process - if counter == 1: - time.sleep(1) - counter += 1 - - stream.write(greeter_pb2.GreeterReply(message=f"Hello, {request.name}!")) - - stream.done_writing() - - -def build_server_handler(): - method_handler = RpcMethodHandler.bi_stream( - GreeterServiceServicer().bi_stream, - method_name="biStream", - request_deserializer=greeter_pb2.GreeterRequest.FromString, - response_serializer=greeter_pb2.GreeterReply.SerializeToString, - ) - service_handler = RpcServiceHandler( - service_name="org.apache.dubbo.samples.data.Greeter", - method_handlers=[method_handler], - ) - return service_handler - - -if __name__ == "__main__": - # build a service config - service_handler = build_server_handler() - service_config = ServiceConfig(service_handler, host="127.0.0.1", port=50051) - - # start the server - server = dubbo.Server(service_config).start() - - input("Press Enter to stop the server...\n") diff --git a/samples/stream/client_stream/__init__.py b/samples/stream/client_stream/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/samples/stream/client_stream/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/samples/stream/client_stream/client.py b/samples/stream/client_stream/client.py deleted file mode 100644 index b9c1bbe3..00000000 --- a/samples/stream/client_stream/client.py +++ /dev/null @@ -1,46 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import dubbo -from dubbo.configs import ReferenceConfig -from samples.proto import greeter_pb2 - - -class GreeterServiceStub: - def __init__(self, client: dubbo.Client): - self.unary_stream = client.client_stream( - method_name="clientStream", - request_serializer=greeter_pb2.GreeterRequest.SerializeToString, - response_deserializer=greeter_pb2.GreeterReply.FromString, - ) - - def client_stream(self, request_iterator): - return self.unary_stream(request_iterator) - - -if __name__ == "__main__": - reference_config = ReferenceConfig.from_url("tri://127.0.0.1:50051/org.apache.dubbo.samples.data.Greeter") - dubbo_client = dubbo.Client(reference_config) - stub = GreeterServiceStub(dubbo_client) - - # use iterator to send multiple requests - def request_generator(): - for i in ["hello", "world", "from", "dubbo-python"]: - yield greeter_pb2.GreeterRequest(name=str(i)) - - # call the remote method and return a read_stream - stream = stub.client_stream(request_generator()) - # use read method to get the response - print(stream.read()) diff --git a/samples/stream/client_stream/server.py b/samples/stream/client_stream/server.py deleted file mode 100644 index 2ab0a28d..00000000 --- a/samples/stream/client_stream/server.py +++ /dev/null @@ -1,54 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import dubbo -from dubbo.configs import ServiceConfig -from dubbo.proxy.handlers import RpcMethodHandler, RpcServiceHandler -from samples.proto import greeter_pb2 - - -class GreeterServiceServicer: - def client_stream(self, request_iterator): - response = "" - for request in request_iterator: - print(f"Received request: {request.name}") - response += f"{request.name} " - return greeter_pb2.GreeterReply(message=response) - - -def build_service_handler(): - # build a method handler - method_handler = RpcMethodHandler.client_stream( - GreeterServiceServicer().client_stream, - method_name="clientStream", - request_deserializer=greeter_pb2.GreeterRequest.FromString, - response_serializer=greeter_pb2.GreeterReply.SerializeToString, - ) - # build a service handler - service_handler = RpcServiceHandler( - service_name="org.apache.dubbo.samples.data.Greeter", - method_handlers=[method_handler], - ) - return service_handler - - -if __name__ == "__main__": - # build server config - service_handler = build_service_handler() - service_config = ServiceConfig(service_handler=service_handler, host="127.0.0.1", port=50051) - # start the server - server = dubbo.Server(service_config).start() - - input("Press Enter to stop the server...\n") diff --git a/samples/stream/server_stream/__init__.py b/samples/stream/server_stream/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/samples/stream/server_stream/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/samples/stream/server_stream/client.py b/samples/stream/server_stream/client.py deleted file mode 100644 index 383b226a..00000000 --- a/samples/stream/server_stream/client.py +++ /dev/null @@ -1,41 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import dubbo -from dubbo.configs import ReferenceConfig -from samples.proto import greeter_pb2 - - -class GreeterServiceStub: - def __init__(self, client: dubbo.Client): - self.stream_unary = client.server_stream( - method_name="serverStream", - request_serializer=greeter_pb2.GreeterRequest.SerializeToString, - response_deserializer=greeter_pb2.GreeterReply.FromString, - ) - - def server_stream(self, values): - return self.stream_unary(values) - - -if __name__ == "__main__": - reference_config = ReferenceConfig.from_url("tri://127.0.0.1:50051/org.apache.dubbo.samples.data.Greeter") - dubbo_client = dubbo.Client(reference_config) - stub = GreeterServiceStub(dubbo_client) - - stream = stub.server_stream(greeter_pb2.GreeterRequest(name="hello world from dubbo-python")) - - for i in stream: - print(f"Received response: {i.message}") diff --git a/samples/stream/server_stream/server.py b/samples/stream/server_stream/server.py deleted file mode 100644 index bce6aca1..00000000 --- a/samples/stream/server_stream/server.py +++ /dev/null @@ -1,55 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import dubbo -from dubbo.configs import ServiceConfig -from dubbo.proxy.handlers import RpcMethodHandler, RpcServiceHandler -from samples.proto import greeter_pb2 - - -class GreeterServiceServicer: - def server_stream(self, stream): - request = stream.read() - print(f"Received request: {request.name}") - response = request.name.split(" ") - for i in response: - yield greeter_pb2.GreeterReply(message=i) - - -def build_server_handler(): - # build a method handler - method_handler = RpcMethodHandler.server_stream( - GreeterServiceServicer().server_stream, - method_name="serverStream", - request_deserializer=greeter_pb2.GreeterRequest.FromString, - response_serializer=greeter_pb2.GreeterReply.SerializeToString, - ) - # build a service handler - service_handler = RpcServiceHandler( - service_name="org.apache.dubbo.samples.data.Greeter", - method_handlers=[method_handler], - ) - return service_handler - - -if __name__ == "__main__": - # build a service config - service_handler = build_server_handler() - service_config = ServiceConfig(service_handler, host="127.0.0.1", port=50051) - - # start the server - server = dubbo.Server(service_config).start() - - input("Press Enter to stop the server...\n") diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100755 index 51d538dc..00000000 --- a/scripts/build.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -echo "Building the project..." - -hatch build - -echo "Finished building the project." \ No newline at end of file diff --git a/scripts/check.sh b/scripts/check.sh deleted file mode 100755 index 015db373..00000000 --- a/scripts/check.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -export SOURCE_FILES="src/dubbo tests" - -# check code style -echo "Checking code style..." -ruff format $SOURCE_FILES --diff -ruff check --output-format=github $SOURCE_FILES --config=pyproject.toml - -# TODO:Temporarily disable mypy check, because it's too strict for now -# mypy $SOURCE_FILES - - -echo "Finished code style check." diff --git a/scripts/check_install.py b/scripts/check_install.py new file mode 100644 index 00000000..00f8e10a --- /dev/null +++ b/scripts/check_install.py @@ -0,0 +1,78 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Check that an application serves and calls with only the default dependencies, as a fresh install has them. + +Run with ``python scripts/check_install.py`` in an environment that holds the +default dependencies alone: it makes one call over each built-in protocol. +""" + +import asyncio +import typing + +import dubbo +from dubbo import Dubbo +from dubbo.config import ConsumerConfig, ProtocolConfig, ReferenceConfig + +_APP = {"application": {"name": "check-install"}} + + +async def _call(protocol: str, port: int, echo: type, impl: object, value: object) -> None: + provider = Dubbo( + _APP, protocols={protocol: ProtocolConfig(name=protocol, host="127.0.0.1", port=port)}, env_prefix=None + ) + provider.export(impl) + reference = ReferenceConfig(urls=(f"{protocol}://127.0.0.1:{port}/check.Echo",)) + consumer = Dubbo(_APP, consumer=ConsumerConfig(references={"check.Echo": reference}), env_prefix=None) + caller = consumer.refer(echo) + + async with provider, consumer: + assert await caller.echo(value) == value + + +async def _tri() -> None: + from google.protobuf.wrappers_pb2 import StringValue + + @dubbo.service("check.Echo") + class Echo(typing.Protocol): + async def echo(self, text: StringValue) -> StringValue: ... + + class EchoImpl(Echo): + async def echo(self, text: StringValue) -> StringValue: + return text + + await _call("tri", 50071, Echo, EchoImpl(), StringValue(value="hi")) + + +async def _hessian2() -> None: + @dubbo.service("check.Echo") + class Echo(typing.Protocol): + async def echo(self, text: str) -> str: ... + + class EchoImpl(Echo): + async def echo(self, text: str) -> str: + return text + + await _call("dubbo", 50072, Echo, EchoImpl(), "hi") + + +async def _main() -> None: + await _tri() + await _hessian2() + + +if __name__ == "__main__": + asyncio.run(_main()) diff --git a/scripts/generate_protos.py b/scripts/generate_protos.py new file mode 100644 index 00000000..b7d6451a --- /dev/null +++ b/scripts/generate_protos.py @@ -0,0 +1,93 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Generate the modules of the protos in ``src/dubbo/_proto``, each beside its proto. + +Run with ``uv run --group proto python scripts/generate_protos.py``. The +``_pb2`` modules register their types in the pool of ``dubbo._proto.pool`` +instead of protobuf's default pool, and ``protoc-gen-python-dubbo`` writes +the ``_dubbo`` modules of the service contracts. +""" + +import pathlib +import re +import subprocess +import sys + +ROOT = pathlib.Path(__file__).resolve().parent.parent +PACKAGE = "dubbo._proto" +PROTOS = ROOT / "src" / "dubbo" / "_proto" + + +def main() -> None: + protos = sorted(path.relative_to(PROTOS).as_posix() for path in PROTOS.rglob("*.proto")) + subprocess.run( + [ + sys.executable, + "-m", + "grpc_tools.protoc", + f"--proto_path={PROTOS}", + f"--python_out={PROTOS}", + f"--pyi_out={PROTOS}", + f"--plugin=protoc-gen-python-dubbo={pathlib.Path(sys.executable).with_name('protoc-gen-python-dubbo')}", + f"--python-dubbo_out={PROTOS}", + *protos, + ], + check=True, + ) + + modules = [proto.removesuffix(".proto").replace("/", ".") + "_pb2" for proto in protos] + for proto in protos: + module = PROTOS / (proto.removesuffix(".proto") + "_pb2.py") + module.write_text(_in_package(module.read_text(), proto)) + contracts = PROTOS / (proto.removesuffix(".proto") + "_dubbo.py") + if contracts.exists(): + contracts.write_text(_imports_in_package(contracts.read_text(), modules)) + + +def _in_package(code: str, proto: str) -> str: + """Register the types in the private pool and name the module where it lives.""" + name = proto.removesuffix(".proto").replace("/", ".") + "_pb2" + replacements = { + "from google.protobuf import descriptor_pool as _descriptor_pool\n": f"from {PACKAGE}.pool import pool as _pool\n", + "_descriptor_pool.Default()": "_pool", + repr(name): repr(f"{PACKAGE}.{name}"), + } + for old, new in replacements.items(): + if code.count(old) != 1: + raise SystemExit(f"{proto}: the generated code does not contain {old!r} once") + code = code.replace(old, new) + + return code + + +def _imports_in_package(code: str, modules: list[str]) -> str: + """Import the ``_pb2`` modules of contracts from where they live.""" + for name in modules: + package, _, module = name.rpartition(".") + statement = rf"from {re.escape(package)} import" if package else "import" + code = re.sub( + rf"^{statement} {module}\b", + f"from {PACKAGE}.{package} import {module}" if package else f"from {PACKAGE} import {module}", + code, + flags=re.MULTILINE, + ) + + return code + + +if __name__ == "__main__": + main() diff --git a/scripts/install-dev.sh b/scripts/install-dev.sh deleted file mode 100755 index 9bc23777..00000000 --- a/scripts/install-dev.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Install dependencies for development -REQUIREMENTS_DEV="requirements-dev.txt" - -# Upgrade pip -pip install -U pip - -# Install dependencies -pip install -r $REQUIREMENTS_DEV - diff --git a/scripts/rat.sh b/scripts/rat.sh deleted file mode 100755 index d76d6920..00000000 --- a/scripts/rat.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/sh - -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -### Apache RAT license check script ### -# This script downloads Apache RAT and runs it to check the license headers of the source files. - -set -e - -ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" -TMP_DIR="$(mktemp -d)" - -RAT_VERSION="0.16.1" -RAT_JAR="${TMP_DIR}/apache-rat-${RAT_VERSION}.jar" - - -cd "${ROOT_DIR}" - -# Set Java command -if [ -x "${JAVA_HOME}/bin/java" ]; then - java_cmd="${JAVA_HOME}/bin/java" -else - java_cmd="java" -fi - - -# Download Apache RAT jar -echo "Downloading Apache RAT ${RAT_VERSION}..." - -RAT_URL="https://repo1.maven.org/maven2/org/apache/rat/apache-rat/${RAT_VERSION}/apache-rat-${RAT_VERSION}.jar" -JAR_PART="${RAT_JAR}.part" - -if command -v curl &> /dev/null; then - curl -L --silent "${RAT_URL}" -o "${JAR_PART}" && mv "${JAR_PART}" "${RAT_JAR}" -elif command -v wget &> /dev/null; then - wget --quiet "${RAT_URL}" -O "${JAR_PART}" && mv "${JAR_PART}" "${RAT_JAR}" -else - echo "Neither curl nor wget found." - exit 1 -fi - -unzip -tq "${RAT_JAR}" > /dev/null -if [ $? -ne 0 ]; then - echo "Downloaded Apache RAT jar is invalid" - exit 1 -fi - -echo "Downloaded Apache RAT ${RAT_VERSION} successfully." - - -# Run Apache RAT -echo "Running Apache license check, this may take a while..." -${java_cmd} -jar ${RAT_JAR} -d ${ROOT_DIR} -E "${ROOT_DIR}/.license-ignore" > "${TMP_DIR}/rat-report.txt" - - -# Check the result -if [ $? -ne 0 ]; then - echo "RAT exited abnormally" - exit 1 -elif grep -q "??" "${TMP_DIR}/rat-report.txt"; then - echo >&2 "Could not find Apache license headers in the following files:" - grep "??" "${TMP_DIR}/rat-report.txt" >&2 - exit 1 -else - echo "Apache license check passed." -fi diff --git a/scripts/test.sh b/scripts/test.sh deleted file mode 100755 index bded3cf4..00000000 --- a/scripts/test.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -# Run tests -coverage run -m pytest - -# Generate coverage report -# TODO: shut down the coverage report for now, because the current code coverage is too low -# coverage report --show-missing --skip-covered --fail-under=100 \ No newline at end of file diff --git a/src/dubbo/__about__.py b/src/dubbo/__about__.py deleted file mode 100644 index 73028396..00000000 --- a/src/dubbo/__about__.py +++ /dev/null @@ -1,17 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -__version__ = "3.0.0b1" diff --git a/src/dubbo/__init__.py b/src/dubbo/__init__.py index ded7e253..67c2ec8a 100644 --- a/src/dubbo/__init__.py +++ b/src/dubbo/__init__.py @@ -1,21 +1,81 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Python-native Apache Dubbo: declare a service contract with `service`, then serve and call services with `Dubbo`. + +``protoc-gen-python-dubbo`` generates contracts from proto files; see `dubbo.protoc`. +""" -from .bootstrap import Dubbo -from .client import Client -from .server import Server +from .application import Dubbo +from .exceptions import DubboError, EndOfStream, RemoteError, RpcError, Status +from .rpc import ( + BidiStream, + ClientStream, + GenericService, + IncomingCall, + Invocation, + Invoke, + Invoker, + Method, + OutgoingCall, + Parameter, + ReceiveStream, + Result, + RpcType, + SendStream, + ServerStream, + Service, + Stream, + get_definition, + incoming, + method, + outgoing, + service, +) +from .url import URL -__all__ = ["Dubbo", "Client", "Server"] +__all__ = [ + "URL", + "BidiStream", + "ClientStream", + "Dubbo", + "DubboError", + "EndOfStream", + "GenericService", + "IncomingCall", + "Invocation", + "Invoke", + "Invoker", + "Method", + "OutgoingCall", + "Parameter", + "ReceiveStream", + "RemoteError", + "Result", + "RpcError", + "RpcType", + "SendStream", + "ServerStream", + "Service", + "Status", + "Stream", + "get_definition", + "incoming", + "method", + "outgoing", + "service", +] diff --git a/src/dubbo/_proto/__init__.py b/src/dubbo/_proto/__init__.py new file mode 100644 index 00000000..da8c64bc --- /dev/null +++ b/src/dubbo/_proto/__init__.py @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + diff --git a/src/dubbo/_proto/google/__init__.py b/src/dubbo/_proto/google/__init__.py new file mode 100644 index 00000000..6c032d66 --- /dev/null +++ b/src/dubbo/_proto/google/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/src/dubbo/_proto/google/rpc/__init__.py b/src/dubbo/_proto/google/rpc/__init__.py new file mode 100644 index 00000000..6c032d66 --- /dev/null +++ b/src/dubbo/_proto/google/rpc/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/src/dubbo/_proto/google/rpc/status.proto b/src/dubbo/_proto/google/rpc/status.proto new file mode 100644 index 00000000..97f50b9d --- /dev/null +++ b/src/dubbo/_proto/google/rpc/status.proto @@ -0,0 +1,48 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.rpc; + +import "google/protobuf/any.proto"; + +option go_package = "google.golang.org/genproto/googleapis/rpc/status;status"; +option java_multiple_files = true; +option java_outer_classname = "StatusProto"; +option java_package = "com.google.rpc"; +option objc_class_prefix = "RPC"; + +// The `Status` type defines a logical error model that is suitable for +// different programming environments, including REST APIs and RPC APIs. It is +// used by [gRPC](https://github.com/grpc). Each `Status` message contains +// three pieces of data: error code, error message, and error details. +// +// You can find out more about this error model and how to work with it in the +// [API Design Guide](https://cloud.google.com/apis/design/errors). +message Status { + // The status code, which should be an enum value of + // [google.rpc.Code][google.rpc.Code]. + int32 code = 1; + + // A developer-facing error message, which should be in English. Any + // user-facing error message should be localized and sent in the + // [google.rpc.Status.details][google.rpc.Status.details] field, or localized + // by the client. + string message = 2; + + // A list of messages that carry the error details. There is a common set of + // message types for APIs to use. + repeated google.protobuf.Any details = 3; +} diff --git a/src/dubbo/_proto/google/rpc/status_pb2.py b/src/dubbo/_proto/google/rpc/status_pb2.py new file mode 100644 index 00000000..2966a8b4 --- /dev/null +++ b/src/dubbo/_proto/google/rpc/status_pb2.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: google/rpc/status.proto +# Protobuf Python Version: 7.35.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from dubbo._proto.pool import pool as _pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 7, + 35, + 1, + '', + 'google/rpc/status.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.protobuf import any_pb2 as google_dot_protobuf_dot_any__pb2 + + +DESCRIPTOR = _pool.AddSerializedFile(b'\n\x17google/rpc/status.proto\x12\ngoogle.rpc\x1a\x19google/protobuf/any.proto\"N\n\x06Status\x12\x0c\n\x04\x63ode\x18\x01 \x01(\x05\x12\x0f\n\x07message\x18\x02 \x01(\t\x12%\n\x07\x64\x65tails\x18\x03 \x03(\x0b\x32\x14.google.protobuf.AnyB^\n\x0e\x63om.google.rpcB\x0bStatusProtoP\x01Z7google.golang.org/genproto/googleapis/rpc/status;status\xa2\x02\x03RPCb\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'dubbo._proto.google.rpc.status_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + _globals['DESCRIPTOR']._loaded_options = None + _globals['DESCRIPTOR']._serialized_options = b'\n\016com.google.rpcB\013StatusProtoP\001Z7google.golang.org/genproto/googleapis/rpc/status;status\242\002\003RPC' + _globals['_STATUS']._serialized_start=66 + _globals['_STATUS']._serialized_end=144 +# @@protoc_insertion_point(module_scope) diff --git a/src/dubbo/_proto/google/rpc/status_pb2.pyi b/src/dubbo/_proto/google/rpc/status_pb2.pyi new file mode 100644 index 00000000..f40c561a --- /dev/null +++ b/src/dubbo/_proto/google/rpc/status_pb2.pyi @@ -0,0 +1,18 @@ +from google.protobuf import any_pb2 as _any_pb2 +from google.protobuf.internal import containers as _containers +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from collections.abc import Iterable as _Iterable, Mapping as _Mapping +from typing import ClassVar as _ClassVar, Optional as _Optional, Union as _Union + +DESCRIPTOR: _descriptor.FileDescriptor + +class Status(_message.Message): + __slots__ = ("code", "message", "details") + CODE_FIELD_NUMBER: _ClassVar[int] + MESSAGE_FIELD_NUMBER: _ClassVar[int] + DETAILS_FIELD_NUMBER: _ClassVar[int] + code: int + message: str + details: _containers.RepeatedCompositeFieldContainer[_any_pb2.Any] + def __init__(self, code: _Optional[int] = ..., message: _Optional[str] = ..., details: _Optional[_Iterable[_Union[_any_pb2.Any, _Mapping]]] = ...) -> None: ... diff --git a/src/dubbo/_proto/grpc/__init__.py b/src/dubbo/_proto/grpc/__init__.py new file mode 100644 index 00000000..6c032d66 --- /dev/null +++ b/src/dubbo/_proto/grpc/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/src/dubbo/_proto/grpc/health/__init__.py b/src/dubbo/_proto/grpc/health/__init__.py new file mode 100644 index 00000000..6c032d66 --- /dev/null +++ b/src/dubbo/_proto/grpc/health/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/src/dubbo/_proto/grpc/health/v1/__init__.py b/src/dubbo/_proto/grpc/health/v1/__init__.py new file mode 100644 index 00000000..6c032d66 --- /dev/null +++ b/src/dubbo/_proto/grpc/health/v1/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/src/dubbo/_proto/grpc/health/v1/health.proto b/src/dubbo/_proto/grpc/health/v1/health.proto new file mode 100644 index 00000000..288ce7c9 --- /dev/null +++ b/src/dubbo/_proto/grpc/health/v1/health.proto @@ -0,0 +1,92 @@ +// Copyright 2015 The gRPC Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// The canonical version of this proto can be found at +// https://github.com/grpc/grpc-proto/blob/master/grpc/health/v1/health.proto + +syntax = "proto3"; + +package grpc.health.v1; + +option csharp_namespace = "Grpc.Health.V1"; +option go_package = "google.golang.org/grpc/health/grpc_health_v1"; +option java_multiple_files = true; +option java_outer_classname = "HealthProto"; +option java_package = "io.grpc.health.v1"; +option objc_class_prefix = "GrpcHealthV1"; + +message HealthCheckRequest { + string service = 1; +} + +message HealthCheckResponse { + enum ServingStatus { + UNKNOWN = 0; + SERVING = 1; + NOT_SERVING = 2; + SERVICE_UNKNOWN = 3; // Used only by the Watch method. + } + ServingStatus status = 1; +} + +message HealthListRequest {} + +message HealthListResponse { + // statuses contains all the services and their respective status. + map statuses = 1; +} + +// Health is gRPC's mechanism for checking whether a server is able to handle +// RPCs. Its semantics are documented in +// https://github.com/grpc/grpc/blob/master/doc/health-checking.md. +service Health { + // Check gets the health of the specified service. If the requested service + // is unknown, the call will fail with status NOT_FOUND. If the caller does + // not specify a service name, the server should respond with its overall + // health status. + // + // Clients should set a deadline when calling Check, and can declare the + // server unhealthy if they do not receive a timely response. + rpc Check(HealthCheckRequest) returns (HealthCheckResponse); + + // List provides a non-atomic snapshot of the health of all the available + // services. + // + // The server may respond with a RESOURCE_EXHAUSTED error if too many services + // exist. + // + // Clients should set a deadline when calling List, and can declare the server + // unhealthy if they do not receive a timely response. + // + // Clients should keep in mind that the list of health services exposed by an + // application can change over the lifetime of the process. + rpc List(HealthListRequest) returns (HealthListResponse); + + // Performs a watch for the serving status of the requested service. + // The server will immediately send back a message indicating the current + // serving status. It will then subsequently send a new message whenever + // the service's serving status changes. + // + // If the requested service is unknown when the call is received, the + // server will send a message setting the serving status to + // SERVICE_UNKNOWN but will *not* terminate the call. If at some + // future point, the serving status of the service becomes known, the + // server will send a new message with the service's serving status. + // + // If the call terminates with status UNIMPLEMENTED, then clients + // should assume this method is not supported and should not retry the + // call. If the call terminates with any other status (including OK), + // clients should retry the call with appropriate exponential backoff. + rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse); +} diff --git a/src/dubbo/_proto/grpc/health/v1/health_dubbo.py b/src/dubbo/_proto/grpc/health/v1/health_dubbo.py new file mode 100644 index 00000000..c4717f40 --- /dev/null +++ b/src/dubbo/_proto/grpc/health/v1/health_dubbo.py @@ -0,0 +1,121 @@ +# Generated by protoc-gen-python-dubbo. DO NOT EDIT! +# source: grpc/health/v1/health.proto +"""Dubbo service contracts of grpc/health/v1/health.proto.""" + +import abc +import typing + +import dubbo + +from dubbo._proto.grpc.health.v1 import health_pb2 + +__all__ = ["Health", "HealthServicer"] + + +@dubbo.service("grpc.health.v1.Health") +class Health(typing.Protocol): + """Health is gRPC's mechanism for checking whether a server is able to handle + RPCs. Its semantics are documented in + https://github.com/grpc/grpc/blob/master/doc/health-checking.md. + """ + + @dubbo.method("Check") + async def check(self, request: health_pb2.HealthCheckRequest) -> health_pb2.HealthCheckResponse: + """Check gets the health of the specified service. If the requested service + is unknown, the call will fail with status NOT_FOUND. If the caller does + not specify a service name, the server should respond with its overall + health status. + + Clients should set a deadline when calling Check, and can declare the + server unhealthy if they do not receive a timely response. + """ + + @dubbo.method("List") + async def list(self, request: health_pb2.HealthListRequest) -> health_pb2.HealthListResponse: + """List provides a non-atomic snapshot of the health of all the available + services. + + The server may respond with a RESOURCE_EXHAUSTED error if too many services + exist. + + Clients should set a deadline when calling List, and can declare the server + unhealthy if they do not receive a timely response. + + Clients should keep in mind that the list of health services exposed by an + application can change over the lifetime of the process. + """ + + @dubbo.method("Watch") + def watch(self, request: health_pb2.HealthCheckRequest) -> dubbo.ServerStream[health_pb2.HealthCheckResponse]: + """Performs a watch for the serving status of the requested service. + The server will immediately send back a message indicating the current + serving status. It will then subsequently send a new message whenever + the service's serving status changes. + + If the requested service is unknown when the call is received, the + server will send a message setting the serving status to + SERVICE_UNKNOWN but will *not* terminate the call. If at some + future point, the serving status of the service becomes known, the + server will send a new message with the service's serving status. + + If the call terminates with status UNIMPLEMENTED, then clients + should assume this method is not supported and should not retry the + call. If the call terminates with any other status (including OK), + clients should retry the call with appropriate exponential backoff. + """ + + +@dubbo.service("grpc.health.v1.Health") +class HealthServicer(abc.ABC): + """Health is gRPC's mechanism for checking whether a server is able to handle + RPCs. Its semantics are documented in + https://github.com/grpc/grpc/blob/master/doc/health-checking.md. + """ + + @dubbo.method("Check") + @abc.abstractmethod + async def check(self, request: health_pb2.HealthCheckRequest) -> health_pb2.HealthCheckResponse: + """Check gets the health of the specified service. If the requested service + is unknown, the call will fail with status NOT_FOUND. If the caller does + not specify a service name, the server should respond with its overall + health status. + + Clients should set a deadline when calling Check, and can declare the + server unhealthy if they do not receive a timely response. + """ + + @dubbo.method("List") + @abc.abstractmethod + async def list(self, request: health_pb2.HealthListRequest) -> health_pb2.HealthListResponse: + """List provides a non-atomic snapshot of the health of all the available + services. + + The server may respond with a RESOURCE_EXHAUSTED error if too many services + exist. + + Clients should set a deadline when calling List, and can declare the server + unhealthy if they do not receive a timely response. + + Clients should keep in mind that the list of health services exposed by an + application can change over the lifetime of the process. + """ + + @dubbo.method("Watch") + @abc.abstractmethod + async def watch(self, request: health_pb2.HealthCheckRequest, stream: dubbo.SendStream[health_pb2.HealthCheckResponse]) -> None: + """Performs a watch for the serving status of the requested service. + The server will immediately send back a message indicating the current + serving status. It will then subsequently send a new message whenever + the service's serving status changes. + + If the requested service is unknown when the call is received, the + server will send a message setting the serving status to + SERVICE_UNKNOWN but will *not* terminate the call. If at some + future point, the serving status of the service becomes known, the + server will send a new message with the service's serving status. + + If the call terminates with status UNIMPLEMENTED, then clients + should assume this method is not supported and should not retry the + call. If the call terminates with any other status (including OK), + clients should retry the call with appropriate exponential backoff. + """ diff --git a/src/dubbo/_proto/grpc/health/v1/health_pb2.py b/src/dubbo/_proto/grpc/health/v1/health_pb2.py new file mode 100644 index 00000000..e23e8d83 --- /dev/null +++ b/src/dubbo/_proto/grpc/health/v1/health_pb2.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: grpc/health/v1/health.proto +# Protobuf Python Version: 7.35.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from dubbo._proto.pool import pool as _pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 7, + 35, + 1, + '', + 'grpc/health/v1/health.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _pool.AddSerializedFile(b'\n\x1bgrpc/health/v1/health.proto\x12\x0egrpc.health.v1\"%\n\x12HealthCheckRequest\x12\x0f\n\x07service\x18\x01 \x01(\t\"\xa9\x01\n\x13HealthCheckResponse\x12\x41\n\x06status\x18\x01 \x01(\x0e\x32\x31.grpc.health.v1.HealthCheckResponse.ServingStatus\"O\n\rServingStatus\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x0b\n\x07SERVING\x10\x01\x12\x0f\n\x0bNOT_SERVING\x10\x02\x12\x13\n\x0fSERVICE_UNKNOWN\x10\x03\"\x13\n\x11HealthListRequest\"\xae\x01\n\x12HealthListResponse\x12\x42\n\x08statuses\x18\x01 \x03(\x0b\x32\x30.grpc.health.v1.HealthListResponse.StatusesEntry\x1aT\n\rStatusesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x32\n\x05value\x18\x02 \x01(\x0b\x32#.grpc.health.v1.HealthCheckResponse:\x02\x38\x01\x32\xfd\x01\n\x06Health\x12P\n\x05\x43heck\x12\".grpc.health.v1.HealthCheckRequest\x1a#.grpc.health.v1.HealthCheckResponse\x12M\n\x04List\x12!.grpc.health.v1.HealthListRequest\x1a\".grpc.health.v1.HealthListResponse\x12R\n\x05Watch\x12\".grpc.health.v1.HealthCheckRequest\x1a#.grpc.health.v1.HealthCheckResponse0\x01\x42p\n\x11io.grpc.health.v1B\x0bHealthProtoP\x01Z,google.golang.org/grpc/health/grpc_health_v1\xa2\x02\x0cGrpcHealthV1\xaa\x02\x0eGrpc.Health.V1b\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'dubbo._proto.grpc.health.v1.health_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + _globals['DESCRIPTOR']._loaded_options = None + _globals['DESCRIPTOR']._serialized_options = b'\n\021io.grpc.health.v1B\013HealthProtoP\001Z,google.golang.org/grpc/health/grpc_health_v1\242\002\014GrpcHealthV1\252\002\016Grpc.Health.V1' + _globals['_HEALTHLISTRESPONSE_STATUSESENTRY']._loaded_options = None + _globals['_HEALTHLISTRESPONSE_STATUSESENTRY']._serialized_options = b'8\001' + _globals['_HEALTHCHECKREQUEST']._serialized_start=47 + _globals['_HEALTHCHECKREQUEST']._serialized_end=84 + _globals['_HEALTHCHECKRESPONSE']._serialized_start=87 + _globals['_HEALTHCHECKRESPONSE']._serialized_end=256 + _globals['_HEALTHCHECKRESPONSE_SERVINGSTATUS']._serialized_start=177 + _globals['_HEALTHCHECKRESPONSE_SERVINGSTATUS']._serialized_end=256 + _globals['_HEALTHLISTREQUEST']._serialized_start=258 + _globals['_HEALTHLISTREQUEST']._serialized_end=277 + _globals['_HEALTHLISTRESPONSE']._serialized_start=280 + _globals['_HEALTHLISTRESPONSE']._serialized_end=454 + _globals['_HEALTHLISTRESPONSE_STATUSESENTRY']._serialized_start=370 + _globals['_HEALTHLISTRESPONSE_STATUSESENTRY']._serialized_end=454 + _globals['_HEALTH']._serialized_start=457 + _globals['_HEALTH']._serialized_end=710 +# @@protoc_insertion_point(module_scope) diff --git a/src/dubbo/_proto/grpc/health/v1/health_pb2.pyi b/src/dubbo/_proto/grpc/health/v1/health_pb2.pyi new file mode 100644 index 00000000..f0fe8f0e --- /dev/null +++ b/src/dubbo/_proto/grpc/health/v1/health_pb2.pyi @@ -0,0 +1,47 @@ +from google.protobuf.internal import containers as _containers +from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from collections.abc import Mapping as _Mapping +from typing import ClassVar as _ClassVar, Optional as _Optional, Union as _Union + +DESCRIPTOR: _descriptor.FileDescriptor + +class HealthCheckRequest(_message.Message): + __slots__ = ("service",) + SERVICE_FIELD_NUMBER: _ClassVar[int] + service: str + def __init__(self, service: _Optional[str] = ...) -> None: ... + +class HealthCheckResponse(_message.Message): + __slots__ = ("status",) + class ServingStatus(int, metaclass=_enum_type_wrapper.EnumTypeWrapper): + __slots__ = () + UNKNOWN: _ClassVar[HealthCheckResponse.ServingStatus] + SERVING: _ClassVar[HealthCheckResponse.ServingStatus] + NOT_SERVING: _ClassVar[HealthCheckResponse.ServingStatus] + SERVICE_UNKNOWN: _ClassVar[HealthCheckResponse.ServingStatus] + UNKNOWN: HealthCheckResponse.ServingStatus + SERVING: HealthCheckResponse.ServingStatus + NOT_SERVING: HealthCheckResponse.ServingStatus + SERVICE_UNKNOWN: HealthCheckResponse.ServingStatus + STATUS_FIELD_NUMBER: _ClassVar[int] + status: HealthCheckResponse.ServingStatus + def __init__(self, status: _Optional[_Union[HealthCheckResponse.ServingStatus, str]] = ...) -> None: ... + +class HealthListRequest(_message.Message): + __slots__ = () + def __init__(self) -> None: ... + +class HealthListResponse(_message.Message): + __slots__ = ("statuses",) + class StatusesEntry(_message.Message): + __slots__ = ("key", "value") + KEY_FIELD_NUMBER: _ClassVar[int] + VALUE_FIELD_NUMBER: _ClassVar[int] + key: str + value: HealthCheckResponse + def __init__(self, key: _Optional[str] = ..., value: _Optional[_Union[HealthCheckResponse, _Mapping]] = ...) -> None: ... + STATUSES_FIELD_NUMBER: _ClassVar[int] + statuses: _containers.MessageMap[str, HealthCheckResponse] + def __init__(self, statuses: _Optional[_Mapping[str, HealthCheckResponse]] = ...) -> None: ... diff --git a/src/dubbo/_proto/grpc/reflection/__init__.py b/src/dubbo/_proto/grpc/reflection/__init__.py new file mode 100644 index 00000000..6c032d66 --- /dev/null +++ b/src/dubbo/_proto/grpc/reflection/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/src/dubbo/_proto/grpc/reflection/v1/__init__.py b/src/dubbo/_proto/grpc/reflection/v1/__init__.py new file mode 100644 index 00000000..6c032d66 --- /dev/null +++ b/src/dubbo/_proto/grpc/reflection/v1/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/src/dubbo/_proto/grpc/reflection/v1/reflection.proto b/src/dubbo/_proto/grpc/reflection/v1/reflection.proto new file mode 100644 index 00000000..1a2ceedc --- /dev/null +++ b/src/dubbo/_proto/grpc/reflection/v1/reflection.proto @@ -0,0 +1,147 @@ +// Copyright 2016 The gRPC Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Service exported by server reflection. A more complete description of how +// server reflection works can be found at +// https://github.com/grpc/grpc/blob/master/doc/server-reflection.md +// +// The canonical version of this proto can be found at +// https://github.com/grpc/grpc-proto/blob/master/grpc/reflection/v1/reflection.proto + +syntax = "proto3"; + +package grpc.reflection.v1; + +option go_package = "google.golang.org/grpc/reflection/grpc_reflection_v1"; +option java_multiple_files = true; +option java_package = "io.grpc.reflection.v1"; +option java_outer_classname = "ServerReflectionProto"; + +service ServerReflection { + // The reflection service is structured as a bidirectional stream, ensuring + // all related requests go to a single server. + rpc ServerReflectionInfo(stream ServerReflectionRequest) + returns (stream ServerReflectionResponse); +} + +// The message sent by the client when calling ServerReflectionInfo method. +message ServerReflectionRequest { + string host = 1; + // To use reflection service, the client should set one of the following + // fields in message_request. The server distinguishes requests by their + // defined field and then handles them using corresponding methods. + oneof message_request { + // Find a proto file by the file name. + string file_by_filename = 3; + + // Find the proto file that declares the given fully-qualified symbol name. + // This field should be a fully-qualified symbol name + // (e.g. .[.] or .). + string file_containing_symbol = 4; + + // Find the proto file which defines an extension extending the given + // message type with the given field number. + ExtensionRequest file_containing_extension = 5; + + // Finds the tag numbers used by all known extensions of the given message + // type, and appends them to ExtensionNumberResponse in an undefined order. + // Its corresponding method is best-effort: it's not guaranteed that the + // reflection service will implement this method, and it's not guaranteed + // that this method will provide all extensions. Returns + // StatusCode::UNIMPLEMENTED if it's not implemented. + // This field should be a fully-qualified type name. The format is + // . + string all_extension_numbers_of_type = 6; + + // List the full names of registered services. The content will not be + // checked. + string list_services = 7; + } +} + +// The type name and extension number sent by the client when requesting +// file_containing_extension. +message ExtensionRequest { + // Fully-qualified type name. The format should be . + string containing_type = 1; + int32 extension_number = 2; +} + +// The message sent by the server to answer ServerReflectionInfo method. +message ServerReflectionResponse { + string valid_host = 1; + ServerReflectionRequest original_request = 2; + // The server sets one of the following fields according to the message_request + // in the request. + oneof message_response { + // This message is used to answer file_by_filename, file_containing_symbol, + // file_containing_extension requests with transitive dependencies. + // As the repeated label is not allowed in oneof fields, we use a + // FileDescriptorResponse message to encapsulate the repeated fields. + // The reflection service is allowed to avoid sending FileDescriptorProtos + // that were previously sent in response to earlier requests in the stream. + FileDescriptorResponse file_descriptor_response = 4; + + // This message is used to answer all_extension_numbers_of_type requests. + ExtensionNumberResponse all_extension_numbers_response = 5; + + // This message is used to answer list_services requests. + ListServiceResponse list_services_response = 6; + + // This message is used when an error occurs. + ErrorResponse error_response = 7; + } +} + +// Serialized FileDescriptorProto messages sent by the server answering +// a file_by_filename, file_containing_symbol, or file_containing_extension +// request. +message FileDescriptorResponse { + // Serialized FileDescriptorProto messages. We avoid taking a dependency on + // descriptor.proto, which uses proto2 only features, by making them opaque + // bytes instead. + repeated bytes file_descriptor_proto = 1; +} + +// A list of extension numbers sent by the server answering +// all_extension_numbers_of_type request. +message ExtensionNumberResponse { + // Full name of the base type, including the package name. The format + // is . + string base_type_name = 1; + repeated int32 extension_number = 2; +} + +// A list of ServiceResponse sent by the server answering list_services request. +message ListServiceResponse { + // The information of each service may be expanded in the future, so we use + // ServiceResponse message to encapsulate it. + repeated ServiceResponse service = 1; +} + +// The information of a single service used by ListServiceResponse to answer +// list_services request. +message ServiceResponse { + // Full name of a registered service, including its package name. The format + // is . + string name = 1; +} + +// The error code and error message sent by the server when an error occurs. +message ErrorResponse { + // This field uses the error codes defined in grpc::StatusCode. + int32 error_code = 1; + string error_message = 2; +} + diff --git a/src/dubbo/_proto/grpc/reflection/v1/reflection_dubbo.py b/src/dubbo/_proto/grpc/reflection/v1/reflection_dubbo.py new file mode 100644 index 00000000..4c74e64c --- /dev/null +++ b/src/dubbo/_proto/grpc/reflection/v1/reflection_dubbo.py @@ -0,0 +1,33 @@ +# Generated by protoc-gen-python-dubbo. DO NOT EDIT! +# source: grpc/reflection/v1/reflection.proto +"""Dubbo service contracts of grpc/reflection/v1/reflection.proto.""" + +import abc +import typing + +import dubbo + +from dubbo._proto.grpc.reflection.v1 import reflection_pb2 + +__all__ = ["ServerReflection", "ServerReflectionServicer"] + + +@dubbo.service("grpc.reflection.v1.ServerReflection") +class ServerReflection(typing.Protocol): + + @dubbo.method("ServerReflectionInfo") + def server_reflection_info(self) -> dubbo.BidiStream[reflection_pb2.ServerReflectionRequest, reflection_pb2.ServerReflectionResponse]: + """The reflection service is structured as a bidirectional stream, ensuring + all related requests go to a single server. + """ + + +@dubbo.service("grpc.reflection.v1.ServerReflection") +class ServerReflectionServicer(abc.ABC): + + @dubbo.method("ServerReflectionInfo") + @abc.abstractmethod + async def server_reflection_info(self, stream: dubbo.Stream[reflection_pb2.ServerReflectionResponse, reflection_pb2.ServerReflectionRequest]) -> None: + """The reflection service is structured as a bidirectional stream, ensuring + all related requests go to a single server. + """ diff --git a/src/dubbo/_proto/grpc/reflection/v1/reflection_pb2.py b/src/dubbo/_proto/grpc/reflection/v1/reflection_pb2.py new file mode 100644 index 00000000..9999f933 --- /dev/null +++ b/src/dubbo/_proto/grpc/reflection/v1/reflection_pb2.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: grpc/reflection/v1/reflection.proto +# Protobuf Python Version: 7.35.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from dubbo._proto.pool import pool as _pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 7, + 35, + 1, + '', + 'grpc/reflection/v1/reflection.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _pool.AddSerializedFile(b'\n#grpc/reflection/v1/reflection.proto\x12\x12grpc.reflection.v1\"\x85\x02\n\x17ServerReflectionRequest\x12\x0c\n\x04host\x18\x01 \x01(\t\x12\x1a\n\x10\x66ile_by_filename\x18\x03 \x01(\tH\x00\x12 \n\x16\x66ile_containing_symbol\x18\x04 \x01(\tH\x00\x12I\n\x19\x66ile_containing_extension\x18\x05 \x01(\x0b\x32$.grpc.reflection.v1.ExtensionRequestH\x00\x12\'\n\x1d\x61ll_extension_numbers_of_type\x18\x06 \x01(\tH\x00\x12\x17\n\rlist_services\x18\x07 \x01(\tH\x00\x42\x11\n\x0fmessage_request\"E\n\x10\x45xtensionRequest\x12\x17\n\x0f\x63ontaining_type\x18\x01 \x01(\t\x12\x18\n\x10\x65xtension_number\x18\x02 \x01(\x05\"\xb8\x03\n\x18ServerReflectionResponse\x12\x12\n\nvalid_host\x18\x01 \x01(\t\x12\x45\n\x10original_request\x18\x02 \x01(\x0b\x32+.grpc.reflection.v1.ServerReflectionRequest\x12N\n\x18\x66ile_descriptor_response\x18\x04 \x01(\x0b\x32*.grpc.reflection.v1.FileDescriptorResponseH\x00\x12U\n\x1e\x61ll_extension_numbers_response\x18\x05 \x01(\x0b\x32+.grpc.reflection.v1.ExtensionNumberResponseH\x00\x12I\n\x16list_services_response\x18\x06 \x01(\x0b\x32\'.grpc.reflection.v1.ListServiceResponseH\x00\x12;\n\x0e\x65rror_response\x18\x07 \x01(\x0b\x32!.grpc.reflection.v1.ErrorResponseH\x00\x42\x12\n\x10message_response\"7\n\x16\x46ileDescriptorResponse\x12\x1d\n\x15\x66ile_descriptor_proto\x18\x01 \x03(\x0c\"K\n\x17\x45xtensionNumberResponse\x12\x16\n\x0e\x62\x61se_type_name\x18\x01 \x01(\t\x12\x18\n\x10\x65xtension_number\x18\x02 \x03(\x05\"K\n\x13ListServiceResponse\x12\x34\n\x07service\x18\x01 \x03(\x0b\x32#.grpc.reflection.v1.ServiceResponse\"\x1f\n\x0fServiceResponse\x12\x0c\n\x04name\x18\x01 \x01(\t\":\n\rErrorResponse\x12\x12\n\nerror_code\x18\x01 \x01(\x05\x12\x15\n\rerror_message\x18\x02 \x01(\t2\x89\x01\n\x10ServerReflection\x12u\n\x14ServerReflectionInfo\x12+.grpc.reflection.v1.ServerReflectionRequest\x1a,.grpc.reflection.v1.ServerReflectionResponse(\x01\x30\x01\x42\x66\n\x15io.grpc.reflection.v1B\x15ServerReflectionProtoP\x01Z4google.golang.org/grpc/reflection/grpc_reflection_v1b\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'dubbo._proto.grpc.reflection.v1.reflection_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + _globals['DESCRIPTOR']._loaded_options = None + _globals['DESCRIPTOR']._serialized_options = b'\n\025io.grpc.reflection.v1B\025ServerReflectionProtoP\001Z4google.golang.org/grpc/reflection/grpc_reflection_v1' + _globals['_SERVERREFLECTIONREQUEST']._serialized_start=60 + _globals['_SERVERREFLECTIONREQUEST']._serialized_end=321 + _globals['_EXTENSIONREQUEST']._serialized_start=323 + _globals['_EXTENSIONREQUEST']._serialized_end=392 + _globals['_SERVERREFLECTIONRESPONSE']._serialized_start=395 + _globals['_SERVERREFLECTIONRESPONSE']._serialized_end=835 + _globals['_FILEDESCRIPTORRESPONSE']._serialized_start=837 + _globals['_FILEDESCRIPTORRESPONSE']._serialized_end=892 + _globals['_EXTENSIONNUMBERRESPONSE']._serialized_start=894 + _globals['_EXTENSIONNUMBERRESPONSE']._serialized_end=969 + _globals['_LISTSERVICERESPONSE']._serialized_start=971 + _globals['_LISTSERVICERESPONSE']._serialized_end=1046 + _globals['_SERVICERESPONSE']._serialized_start=1048 + _globals['_SERVICERESPONSE']._serialized_end=1079 + _globals['_ERRORRESPONSE']._serialized_start=1081 + _globals['_ERRORRESPONSE']._serialized_end=1139 + _globals['_SERVERREFLECTION']._serialized_start=1142 + _globals['_SERVERREFLECTION']._serialized_end=1279 +# @@protoc_insertion_point(module_scope) diff --git a/src/dubbo/_proto/grpc/reflection/v1/reflection_pb2.pyi b/src/dubbo/_proto/grpc/reflection/v1/reflection_pb2.pyi new file mode 100644 index 00000000..ea428674 --- /dev/null +++ b/src/dubbo/_proto/grpc/reflection/v1/reflection_pb2.pyi @@ -0,0 +1,81 @@ +from google.protobuf.internal import containers as _containers +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from collections.abc import Iterable as _Iterable, Mapping as _Mapping +from typing import ClassVar as _ClassVar, Optional as _Optional, Union as _Union + +DESCRIPTOR: _descriptor.FileDescriptor + +class ServerReflectionRequest(_message.Message): + __slots__ = ("host", "file_by_filename", "file_containing_symbol", "file_containing_extension", "all_extension_numbers_of_type", "list_services") + HOST_FIELD_NUMBER: _ClassVar[int] + FILE_BY_FILENAME_FIELD_NUMBER: _ClassVar[int] + FILE_CONTAINING_SYMBOL_FIELD_NUMBER: _ClassVar[int] + FILE_CONTAINING_EXTENSION_FIELD_NUMBER: _ClassVar[int] + ALL_EXTENSION_NUMBERS_OF_TYPE_FIELD_NUMBER: _ClassVar[int] + LIST_SERVICES_FIELD_NUMBER: _ClassVar[int] + host: str + file_by_filename: str + file_containing_symbol: str + file_containing_extension: ExtensionRequest + all_extension_numbers_of_type: str + list_services: str + def __init__(self, host: _Optional[str] = ..., file_by_filename: _Optional[str] = ..., file_containing_symbol: _Optional[str] = ..., file_containing_extension: _Optional[_Union[ExtensionRequest, _Mapping]] = ..., all_extension_numbers_of_type: _Optional[str] = ..., list_services: _Optional[str] = ...) -> None: ... + +class ExtensionRequest(_message.Message): + __slots__ = ("containing_type", "extension_number") + CONTAINING_TYPE_FIELD_NUMBER: _ClassVar[int] + EXTENSION_NUMBER_FIELD_NUMBER: _ClassVar[int] + containing_type: str + extension_number: int + def __init__(self, containing_type: _Optional[str] = ..., extension_number: _Optional[int] = ...) -> None: ... + +class ServerReflectionResponse(_message.Message): + __slots__ = ("valid_host", "original_request", "file_descriptor_response", "all_extension_numbers_response", "list_services_response", "error_response") + VALID_HOST_FIELD_NUMBER: _ClassVar[int] + ORIGINAL_REQUEST_FIELD_NUMBER: _ClassVar[int] + FILE_DESCRIPTOR_RESPONSE_FIELD_NUMBER: _ClassVar[int] + ALL_EXTENSION_NUMBERS_RESPONSE_FIELD_NUMBER: _ClassVar[int] + LIST_SERVICES_RESPONSE_FIELD_NUMBER: _ClassVar[int] + ERROR_RESPONSE_FIELD_NUMBER: _ClassVar[int] + valid_host: str + original_request: ServerReflectionRequest + file_descriptor_response: FileDescriptorResponse + all_extension_numbers_response: ExtensionNumberResponse + list_services_response: ListServiceResponse + error_response: ErrorResponse + def __init__(self, valid_host: _Optional[str] = ..., original_request: _Optional[_Union[ServerReflectionRequest, _Mapping]] = ..., file_descriptor_response: _Optional[_Union[FileDescriptorResponse, _Mapping]] = ..., all_extension_numbers_response: _Optional[_Union[ExtensionNumberResponse, _Mapping]] = ..., list_services_response: _Optional[_Union[ListServiceResponse, _Mapping]] = ..., error_response: _Optional[_Union[ErrorResponse, _Mapping]] = ...) -> None: ... + +class FileDescriptorResponse(_message.Message): + __slots__ = ("file_descriptor_proto",) + FILE_DESCRIPTOR_PROTO_FIELD_NUMBER: _ClassVar[int] + file_descriptor_proto: _containers.RepeatedScalarFieldContainer[bytes] + def __init__(self, file_descriptor_proto: _Optional[_Iterable[bytes]] = ...) -> None: ... + +class ExtensionNumberResponse(_message.Message): + __slots__ = ("base_type_name", "extension_number") + BASE_TYPE_NAME_FIELD_NUMBER: _ClassVar[int] + EXTENSION_NUMBER_FIELD_NUMBER: _ClassVar[int] + base_type_name: str + extension_number: _containers.RepeatedScalarFieldContainer[int] + def __init__(self, base_type_name: _Optional[str] = ..., extension_number: _Optional[_Iterable[int]] = ...) -> None: ... + +class ListServiceResponse(_message.Message): + __slots__ = ("service",) + SERVICE_FIELD_NUMBER: _ClassVar[int] + service: _containers.RepeatedCompositeFieldContainer[ServiceResponse] + def __init__(self, service: _Optional[_Iterable[_Union[ServiceResponse, _Mapping]]] = ...) -> None: ... + +class ServiceResponse(_message.Message): + __slots__ = ("name",) + NAME_FIELD_NUMBER: _ClassVar[int] + name: str + def __init__(self, name: _Optional[str] = ...) -> None: ... + +class ErrorResponse(_message.Message): + __slots__ = ("error_code", "error_message") + ERROR_CODE_FIELD_NUMBER: _ClassVar[int] + ERROR_MESSAGE_FIELD_NUMBER: _ClassVar[int] + error_code: int + error_message: str + def __init__(self, error_code: _Optional[int] = ..., error_message: _Optional[str] = ...) -> None: ... diff --git a/src/dubbo/_proto/grpc/reflection/v1alpha/__init__.py b/src/dubbo/_proto/grpc/reflection/v1alpha/__init__.py new file mode 100644 index 00000000..6c032d66 --- /dev/null +++ b/src/dubbo/_proto/grpc/reflection/v1alpha/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/src/dubbo/_proto/grpc/reflection/v1alpha/reflection.proto b/src/dubbo/_proto/grpc/reflection/v1alpha/reflection.proto new file mode 100644 index 00000000..e8384db3 --- /dev/null +++ b/src/dubbo/_proto/grpc/reflection/v1alpha/reflection.proto @@ -0,0 +1,145 @@ +// Copyright 2016 The gRPC Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// Service exported by server reflection + + +// Warning: this entire file is deprecated. Use this instead: +// https://github.com/grpc/grpc-proto/blob/master/grpc/reflection/v1/reflection.proto + +syntax = "proto3"; + +package grpc.reflection.v1alpha; + +option deprecated = true; +option go_package = "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"; +option java_multiple_files = true; +option java_package = "io.grpc.reflection.v1alpha"; +option java_outer_classname = "ServerReflectionProto"; + +service ServerReflection { + // The reflection service is structured as a bidirectional stream, ensuring + // all related requests go to a single server. + rpc ServerReflectionInfo(stream ServerReflectionRequest) + returns (stream ServerReflectionResponse); +} + +// The message sent by the client when calling ServerReflectionInfo method. +message ServerReflectionRequest { + string host = 1; + // To use reflection service, the client should set one of the following + // fields in message_request. The server distinguishes requests by their + // defined field and then handles them using corresponding methods. + oneof message_request { + // Find a proto file by the file name. + string file_by_filename = 3; + + // Find the proto file that declares the given fully-qualified symbol name. + // This field should be a fully-qualified symbol name + // (e.g. .[.] or .). + string file_containing_symbol = 4; + + // Find the proto file which defines an extension extending the given + // message type with the given field number. + ExtensionRequest file_containing_extension = 5; + + // Finds the tag numbers used by all known extensions of extendee_type, and + // appends them to ExtensionNumberResponse in an undefined order. + // Its corresponding method is best-effort: it's not guaranteed that the + // reflection service will implement this method, and it's not guaranteed + // that this method will provide all extensions. Returns + // StatusCode::UNIMPLEMENTED if it's not implemented. + // This field should be a fully-qualified type name. The format is + // . + string all_extension_numbers_of_type = 6; + + // List the full names of registered services. The content will not be + // checked. + string list_services = 7; + } +} + +// The type name and extension number sent by the client when requesting +// file_containing_extension. +message ExtensionRequest { + // Fully-qualified type name. The format should be . + string containing_type = 1; + int32 extension_number = 2; +} + +// The message sent by the server to answer ServerReflectionInfo method. +message ServerReflectionResponse { + string valid_host = 1; + ServerReflectionRequest original_request = 2; + // The server set one of the following fields according to the message_request + // in the request. + oneof message_response { + // This message is used to answer file_by_filename, file_containing_symbol, + // file_containing_extension requests with transitive dependencies. As + // the repeated label is not allowed in oneof fields, we use a + // FileDescriptorResponse message to encapsulate the repeated fields. + // The reflection service is allowed to avoid sending FileDescriptorProtos + // that were previously sent in response to earlier requests in the stream. + FileDescriptorResponse file_descriptor_response = 4; + + // This message is used to answer all_extension_numbers_of_type request. + ExtensionNumberResponse all_extension_numbers_response = 5; + + // This message is used to answer list_services request. + ListServiceResponse list_services_response = 6; + + // This message is used when an error occurs. + ErrorResponse error_response = 7; + } +} + +// Serialized FileDescriptorProto messages sent by the server answering +// a file_by_filename, file_containing_symbol, or file_containing_extension +// request. +message FileDescriptorResponse { + // Serialized FileDescriptorProto messages. We avoid taking a dependency on + // descriptor.proto, which uses proto2 only features, by making them opaque + // bytes instead. + repeated bytes file_descriptor_proto = 1; +} + +// A list of extension numbers sent by the server answering +// all_extension_numbers_of_type request. +message ExtensionNumberResponse { + // Full name of the base type, including the package name. The format + // is . + string base_type_name = 1; + repeated int32 extension_number = 2; +} + +// A list of ServiceResponse sent by the server answering list_services request. +message ListServiceResponse { + // The information of each service may be expanded in the future, so we use + // ServiceResponse message to encapsulate it. + repeated ServiceResponse service = 1; +} + +// The information of a single service used by ListServiceResponse to answer +// list_services request. +message ServiceResponse { + // Full name of a registered service, including its package name. The format + // is . + string name = 1; +} + +// The error code and error message sent by the server when an error occurs. +message ErrorResponse { + // This field uses the error codes defined in grpc::StatusCode. + int32 error_code = 1; + string error_message = 2; +} diff --git a/src/dubbo/_proto/grpc/reflection/v1alpha/reflection_dubbo.py b/src/dubbo/_proto/grpc/reflection/v1alpha/reflection_dubbo.py new file mode 100644 index 00000000..e2c14f65 --- /dev/null +++ b/src/dubbo/_proto/grpc/reflection/v1alpha/reflection_dubbo.py @@ -0,0 +1,33 @@ +# Generated by protoc-gen-python-dubbo. DO NOT EDIT! +# source: grpc/reflection/v1alpha/reflection.proto +"""Dubbo service contracts of grpc/reflection/v1alpha/reflection.proto.""" + +import abc +import typing + +import dubbo + +from dubbo._proto.grpc.reflection.v1alpha import reflection_pb2 + +__all__ = ["ServerReflection", "ServerReflectionServicer"] + + +@dubbo.service("grpc.reflection.v1alpha.ServerReflection") +class ServerReflection(typing.Protocol): + + @dubbo.method("ServerReflectionInfo") + def server_reflection_info(self) -> dubbo.BidiStream[reflection_pb2.ServerReflectionRequest, reflection_pb2.ServerReflectionResponse]: + """The reflection service is structured as a bidirectional stream, ensuring + all related requests go to a single server. + """ + + +@dubbo.service("grpc.reflection.v1alpha.ServerReflection") +class ServerReflectionServicer(abc.ABC): + + @dubbo.method("ServerReflectionInfo") + @abc.abstractmethod + async def server_reflection_info(self, stream: dubbo.Stream[reflection_pb2.ServerReflectionResponse, reflection_pb2.ServerReflectionRequest]) -> None: + """The reflection service is structured as a bidirectional stream, ensuring + all related requests go to a single server. + """ diff --git a/src/dubbo/_proto/grpc/reflection/v1alpha/reflection_pb2.py b/src/dubbo/_proto/grpc/reflection/v1alpha/reflection_pb2.py new file mode 100644 index 00000000..9191a926 --- /dev/null +++ b/src/dubbo/_proto/grpc/reflection/v1alpha/reflection_pb2.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: grpc/reflection/v1alpha/reflection.proto +# Protobuf Python Version: 7.35.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from dubbo._proto.pool import pool as _pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 7, + 35, + 1, + '', + 'grpc/reflection/v1alpha/reflection.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _pool.AddSerializedFile(b'\n(grpc/reflection/v1alpha/reflection.proto\x12\x17grpc.reflection.v1alpha\"\x8a\x02\n\x17ServerReflectionRequest\x12\x0c\n\x04host\x18\x01 \x01(\t\x12\x1a\n\x10\x66ile_by_filename\x18\x03 \x01(\tH\x00\x12 \n\x16\x66ile_containing_symbol\x18\x04 \x01(\tH\x00\x12N\n\x19\x66ile_containing_extension\x18\x05 \x01(\x0b\x32).grpc.reflection.v1alpha.ExtensionRequestH\x00\x12\'\n\x1d\x61ll_extension_numbers_of_type\x18\x06 \x01(\tH\x00\x12\x17\n\rlist_services\x18\x07 \x01(\tH\x00\x42\x11\n\x0fmessage_request\"E\n\x10\x45xtensionRequest\x12\x17\n\x0f\x63ontaining_type\x18\x01 \x01(\t\x12\x18\n\x10\x65xtension_number\x18\x02 \x01(\x05\"\xd1\x03\n\x18ServerReflectionResponse\x12\x12\n\nvalid_host\x18\x01 \x01(\t\x12J\n\x10original_request\x18\x02 \x01(\x0b\x32\x30.grpc.reflection.v1alpha.ServerReflectionRequest\x12S\n\x18\x66ile_descriptor_response\x18\x04 \x01(\x0b\x32/.grpc.reflection.v1alpha.FileDescriptorResponseH\x00\x12Z\n\x1e\x61ll_extension_numbers_response\x18\x05 \x01(\x0b\x32\x30.grpc.reflection.v1alpha.ExtensionNumberResponseH\x00\x12N\n\x16list_services_response\x18\x06 \x01(\x0b\x32,.grpc.reflection.v1alpha.ListServiceResponseH\x00\x12@\n\x0e\x65rror_response\x18\x07 \x01(\x0b\x32&.grpc.reflection.v1alpha.ErrorResponseH\x00\x42\x12\n\x10message_response\"7\n\x16\x46ileDescriptorResponse\x12\x1d\n\x15\x66ile_descriptor_proto\x18\x01 \x03(\x0c\"K\n\x17\x45xtensionNumberResponse\x12\x16\n\x0e\x62\x61se_type_name\x18\x01 \x01(\t\x12\x18\n\x10\x65xtension_number\x18\x02 \x03(\x05\"P\n\x13ListServiceResponse\x12\x39\n\x07service\x18\x01 \x03(\x0b\x32(.grpc.reflection.v1alpha.ServiceResponse\"\x1f\n\x0fServiceResponse\x12\x0c\n\x04name\x18\x01 \x01(\t\":\n\rErrorResponse\x12\x12\n\nerror_code\x18\x01 \x01(\x05\x12\x15\n\rerror_message\x18\x02 \x01(\t2\x93\x01\n\x10ServerReflection\x12\x7f\n\x14ServerReflectionInfo\x12\x30.grpc.reflection.v1alpha.ServerReflectionRequest\x1a\x31.grpc.reflection.v1alpha.ServerReflectionResponse(\x01\x30\x01\x42s\n\x1aio.grpc.reflection.v1alphaB\x15ServerReflectionProtoP\x01Z9google.golang.org/grpc/reflection/grpc_reflection_v1alpha\xb8\x01\x01\x62\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'dubbo._proto.grpc.reflection.v1alpha.reflection_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + _globals['DESCRIPTOR']._loaded_options = None + _globals['DESCRIPTOR']._serialized_options = b'\n\032io.grpc.reflection.v1alphaB\025ServerReflectionProtoP\001Z9google.golang.org/grpc/reflection/grpc_reflection_v1alpha\270\001\001' + _globals['_SERVERREFLECTIONREQUEST']._serialized_start=70 + _globals['_SERVERREFLECTIONREQUEST']._serialized_end=336 + _globals['_EXTENSIONREQUEST']._serialized_start=338 + _globals['_EXTENSIONREQUEST']._serialized_end=407 + _globals['_SERVERREFLECTIONRESPONSE']._serialized_start=410 + _globals['_SERVERREFLECTIONRESPONSE']._serialized_end=875 + _globals['_FILEDESCRIPTORRESPONSE']._serialized_start=877 + _globals['_FILEDESCRIPTORRESPONSE']._serialized_end=932 + _globals['_EXTENSIONNUMBERRESPONSE']._serialized_start=934 + _globals['_EXTENSIONNUMBERRESPONSE']._serialized_end=1009 + _globals['_LISTSERVICERESPONSE']._serialized_start=1011 + _globals['_LISTSERVICERESPONSE']._serialized_end=1091 + _globals['_SERVICERESPONSE']._serialized_start=1093 + _globals['_SERVICERESPONSE']._serialized_end=1124 + _globals['_ERRORRESPONSE']._serialized_start=1126 + _globals['_ERRORRESPONSE']._serialized_end=1184 + _globals['_SERVERREFLECTION']._serialized_start=1187 + _globals['_SERVERREFLECTION']._serialized_end=1334 +# @@protoc_insertion_point(module_scope) diff --git a/src/dubbo/_proto/grpc/reflection/v1alpha/reflection_pb2.pyi b/src/dubbo/_proto/grpc/reflection/v1alpha/reflection_pb2.pyi new file mode 100644 index 00000000..ea428674 --- /dev/null +++ b/src/dubbo/_proto/grpc/reflection/v1alpha/reflection_pb2.pyi @@ -0,0 +1,81 @@ +from google.protobuf.internal import containers as _containers +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from collections.abc import Iterable as _Iterable, Mapping as _Mapping +from typing import ClassVar as _ClassVar, Optional as _Optional, Union as _Union + +DESCRIPTOR: _descriptor.FileDescriptor + +class ServerReflectionRequest(_message.Message): + __slots__ = ("host", "file_by_filename", "file_containing_symbol", "file_containing_extension", "all_extension_numbers_of_type", "list_services") + HOST_FIELD_NUMBER: _ClassVar[int] + FILE_BY_FILENAME_FIELD_NUMBER: _ClassVar[int] + FILE_CONTAINING_SYMBOL_FIELD_NUMBER: _ClassVar[int] + FILE_CONTAINING_EXTENSION_FIELD_NUMBER: _ClassVar[int] + ALL_EXTENSION_NUMBERS_OF_TYPE_FIELD_NUMBER: _ClassVar[int] + LIST_SERVICES_FIELD_NUMBER: _ClassVar[int] + host: str + file_by_filename: str + file_containing_symbol: str + file_containing_extension: ExtensionRequest + all_extension_numbers_of_type: str + list_services: str + def __init__(self, host: _Optional[str] = ..., file_by_filename: _Optional[str] = ..., file_containing_symbol: _Optional[str] = ..., file_containing_extension: _Optional[_Union[ExtensionRequest, _Mapping]] = ..., all_extension_numbers_of_type: _Optional[str] = ..., list_services: _Optional[str] = ...) -> None: ... + +class ExtensionRequest(_message.Message): + __slots__ = ("containing_type", "extension_number") + CONTAINING_TYPE_FIELD_NUMBER: _ClassVar[int] + EXTENSION_NUMBER_FIELD_NUMBER: _ClassVar[int] + containing_type: str + extension_number: int + def __init__(self, containing_type: _Optional[str] = ..., extension_number: _Optional[int] = ...) -> None: ... + +class ServerReflectionResponse(_message.Message): + __slots__ = ("valid_host", "original_request", "file_descriptor_response", "all_extension_numbers_response", "list_services_response", "error_response") + VALID_HOST_FIELD_NUMBER: _ClassVar[int] + ORIGINAL_REQUEST_FIELD_NUMBER: _ClassVar[int] + FILE_DESCRIPTOR_RESPONSE_FIELD_NUMBER: _ClassVar[int] + ALL_EXTENSION_NUMBERS_RESPONSE_FIELD_NUMBER: _ClassVar[int] + LIST_SERVICES_RESPONSE_FIELD_NUMBER: _ClassVar[int] + ERROR_RESPONSE_FIELD_NUMBER: _ClassVar[int] + valid_host: str + original_request: ServerReflectionRequest + file_descriptor_response: FileDescriptorResponse + all_extension_numbers_response: ExtensionNumberResponse + list_services_response: ListServiceResponse + error_response: ErrorResponse + def __init__(self, valid_host: _Optional[str] = ..., original_request: _Optional[_Union[ServerReflectionRequest, _Mapping]] = ..., file_descriptor_response: _Optional[_Union[FileDescriptorResponse, _Mapping]] = ..., all_extension_numbers_response: _Optional[_Union[ExtensionNumberResponse, _Mapping]] = ..., list_services_response: _Optional[_Union[ListServiceResponse, _Mapping]] = ..., error_response: _Optional[_Union[ErrorResponse, _Mapping]] = ...) -> None: ... + +class FileDescriptorResponse(_message.Message): + __slots__ = ("file_descriptor_proto",) + FILE_DESCRIPTOR_PROTO_FIELD_NUMBER: _ClassVar[int] + file_descriptor_proto: _containers.RepeatedScalarFieldContainer[bytes] + def __init__(self, file_descriptor_proto: _Optional[_Iterable[bytes]] = ...) -> None: ... + +class ExtensionNumberResponse(_message.Message): + __slots__ = ("base_type_name", "extension_number") + BASE_TYPE_NAME_FIELD_NUMBER: _ClassVar[int] + EXTENSION_NUMBER_FIELD_NUMBER: _ClassVar[int] + base_type_name: str + extension_number: _containers.RepeatedScalarFieldContainer[int] + def __init__(self, base_type_name: _Optional[str] = ..., extension_number: _Optional[_Iterable[int]] = ...) -> None: ... + +class ListServiceResponse(_message.Message): + __slots__ = ("service",) + SERVICE_FIELD_NUMBER: _ClassVar[int] + service: _containers.RepeatedCompositeFieldContainer[ServiceResponse] + def __init__(self, service: _Optional[_Iterable[_Union[ServiceResponse, _Mapping]]] = ...) -> None: ... + +class ServiceResponse(_message.Message): + __slots__ = ("name",) + NAME_FIELD_NUMBER: _ClassVar[int] + name: str + def __init__(self, name: _Optional[str] = ...) -> None: ... + +class ErrorResponse(_message.Message): + __slots__ = ("error_code", "error_message") + ERROR_CODE_FIELD_NUMBER: _ClassVar[int] + ERROR_MESSAGE_FIELD_NUMBER: _ClassVar[int] + error_code: int + error_message: str + def __init__(self, error_code: _Optional[int] = ..., error_message: _Optional[str] = ...) -> None: ... diff --git a/src/dubbo/_proto/org/__init__.py b/src/dubbo/_proto/org/__init__.py new file mode 100644 index 00000000..6c032d66 --- /dev/null +++ b/src/dubbo/_proto/org/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/src/dubbo/_proto/org/apache/__init__.py b/src/dubbo/_proto/org/apache/__init__.py new file mode 100644 index 00000000..6c032d66 --- /dev/null +++ b/src/dubbo/_proto/org/apache/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/src/dubbo/_proto/org/apache/dubbo/__init__.py b/src/dubbo/_proto/org/apache/dubbo/__init__.py new file mode 100644 index 00000000..6c032d66 --- /dev/null +++ b/src/dubbo/_proto/org/apache/dubbo/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/src/dubbo/_proto/org/apache/dubbo/metadata/__init__.py b/src/dubbo/_proto/org/apache/dubbo/metadata/__init__.py new file mode 100644 index 00000000..6c032d66 --- /dev/null +++ b/src/dubbo/_proto/org/apache/dubbo/metadata/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2.proto b/src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2.proto new file mode 100644 index 00000000..cffe6129 --- /dev/null +++ b/src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2.proto @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +syntax = "proto3"; +package org.apache.dubbo.metadata; + +option go_package = "dubbo.apache.org/dubbo-go/v3/metadata/triple_api;triple_api"; +option java_package = "org.apache.dubbo.metadata"; +option java_multiple_files = true; + +// Metadata service V2. +service MetadataServiceV2 { + // Retrieves metadata information. + rpc GetMetadataInfo(MetadataRequest) returns (MetadataInfoV2); + + // Retrieves OpenAPI information. + rpc GetOpenAPIInfo(OpenAPIRequest) returns (OpenAPIInfo); +} + +// Metadata request message. +message MetadataRequest { + // The revision of the metadata. + string revision = 1; +} + +// Metadata information message. +message MetadataInfoV2 { + // The application name. + string app = 1; + // The application version. + string version = 2; + // A map of service information. + map services = 3; +} + +// Service information message. +message ServiceInfoV2 { + // The service name. + string name = 1; + // The service group. + string group = 2; + // The service version. + string version = 3; + // The service protocol. + string protocol = 4; + // The service port. + int32 port = 5; + // The service path. + string path = 6; + // A map of service parameters. + map params = 7; +} + +// OpenAPI request message. +message OpenAPIRequest { + // The openAPI group. + string group = 1; + // The openAPI version, using a major.minor.patch versioning scheme + // e.g. 1.0.1 + string version = 2; + // The openAPI tags. Each tag is an or condition. + repeated string tag = 3; + // The openAPI services. Each service is an or condition. + repeated string service = 4; + // The openAPI specification version, using a major.minor.patch versioning scheme + // e.g. 3.0.1, 3.1.0 + // The default value is '3.0.1'. + string openapi = 5; + // The format of the response. + // The default value is 'JSON'. + optional OpenAPIFormat format = 6; + // Whether to pretty print for json. + // The default value is 'false'. + optional bool pretty = 7; +} + +// Response format enumeration. +enum OpenAPIFormat { + // JSON format. + JSON = 0; + // YAML format. + YAML = 1; + // PROTO format. + PROTO = 2; +} + +// OpenAPI information message. +message OpenAPIInfo { + // The OpenAPI definition. + string definition = 1; +} diff --git a/src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2_dubbo.py b/src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2_dubbo.py new file mode 100644 index 00000000..e05ef9fd --- /dev/null +++ b/src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2_dubbo.py @@ -0,0 +1,40 @@ +# Generated by protoc-gen-python-dubbo. DO NOT EDIT! +# source: org/apache/dubbo/metadata/metadata_service_v2.proto +"""Dubbo service contracts of org/apache/dubbo/metadata/metadata_service_v2.proto.""" + +import abc +import typing + +import dubbo + +from dubbo._proto.org.apache.dubbo.metadata import metadata_service_v2_pb2 + +__all__ = ["MetadataServiceV2", "MetadataServiceV2Servicer"] + + +@dubbo.service("org.apache.dubbo.metadata.MetadataServiceV2") +class MetadataServiceV2(typing.Protocol): + """Metadata service V2.""" + + @dubbo.method("GetMetadataInfo") + async def get_metadata_info(self, request: metadata_service_v2_pb2.MetadataRequest) -> metadata_service_v2_pb2.MetadataInfoV2: + """Retrieves metadata information.""" + + @dubbo.method("GetOpenAPIInfo") + async def get_open_api_info(self, request: metadata_service_v2_pb2.OpenAPIRequest) -> metadata_service_v2_pb2.OpenAPIInfo: + """Retrieves OpenAPI information.""" + + +@dubbo.service("org.apache.dubbo.metadata.MetadataServiceV2") +class MetadataServiceV2Servicer(abc.ABC): + """Metadata service V2.""" + + @dubbo.method("GetMetadataInfo") + @abc.abstractmethod + async def get_metadata_info(self, request: metadata_service_v2_pb2.MetadataRequest) -> metadata_service_v2_pb2.MetadataInfoV2: + """Retrieves metadata information.""" + + @dubbo.method("GetOpenAPIInfo") + @abc.abstractmethod + async def get_open_api_info(self, request: metadata_service_v2_pb2.OpenAPIRequest) -> metadata_service_v2_pb2.OpenAPIInfo: + """Retrieves OpenAPI information.""" diff --git a/src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2_pb2.py b/src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2_pb2.py new file mode 100644 index 00000000..41cea050 --- /dev/null +++ b/src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2_pb2.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: org/apache/dubbo/metadata/metadata_service_v2.proto +# Protobuf Python Version: 7.35.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from dubbo._proto.pool import pool as _pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 7, + 35, + 1, + '', + 'org/apache/dubbo/metadata/metadata_service_v2.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _pool.AddSerializedFile(b'\n3org/apache/dubbo/metadata/metadata_service_v2.proto\x12\x19org.apache.dubbo.metadata\"#\n\x0fMetadataRequest\x12\x10\n\x08revision\x18\x01 \x01(\t\"\xd4\x01\n\x0eMetadataInfoV2\x12\x0b\n\x03\x61pp\x18\x01 \x01(\t\x12\x0f\n\x07version\x18\x02 \x01(\t\x12I\n\x08services\x18\x03 \x03(\x0b\x32\x37.org.apache.dubbo.metadata.MetadataInfoV2.ServicesEntry\x1aY\n\rServicesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x37\n\x05value\x18\x02 \x01(\x0b\x32(.org.apache.dubbo.metadata.ServiceInfoV2:\x02\x38\x01\"\xe0\x01\n\rServiceInfoV2\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05group\x18\x02 \x01(\t\x12\x0f\n\x07version\x18\x03 \x01(\t\x12\x10\n\x08protocol\x18\x04 \x01(\t\x12\x0c\n\x04port\x18\x05 \x01(\x05\x12\x0c\n\x04path\x18\x06 \x01(\t\x12\x44\n\x06params\x18\x07 \x03(\x0b\x32\x34.org.apache.dubbo.metadata.ServiceInfoV2.ParamsEntry\x1a-\n\x0bParamsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\xc9\x01\n\x0eOpenAPIRequest\x12\r\n\x05group\x18\x01 \x01(\t\x12\x0f\n\x07version\x18\x02 \x01(\t\x12\x0b\n\x03tag\x18\x03 \x03(\t\x12\x0f\n\x07service\x18\x04 \x03(\t\x12\x0f\n\x07openapi\x18\x05 \x01(\t\x12=\n\x06\x66ormat\x18\x06 \x01(\x0e\x32(.org.apache.dubbo.metadata.OpenAPIFormatH\x00\x88\x01\x01\x12\x13\n\x06pretty\x18\x07 \x01(\x08H\x01\x88\x01\x01\x42\t\n\x07_formatB\t\n\x07_pretty\"!\n\x0bOpenAPIInfo\x12\x12\n\ndefinition\x18\x01 \x01(\t*.\n\rOpenAPIFormat\x12\x08\n\x04JSON\x10\x00\x12\x08\n\x04YAML\x10\x01\x12\t\n\x05PROTO\x10\x02\x32\xe2\x01\n\x11MetadataServiceV2\x12h\n\x0fGetMetadataInfo\x12*.org.apache.dubbo.metadata.MetadataRequest\x1a).org.apache.dubbo.metadata.MetadataInfoV2\x12\x63\n\x0eGetOpenAPIInfo\x12).org.apache.dubbo.metadata.OpenAPIRequest\x1a&.org.apache.dubbo.metadata.OpenAPIInfoBZ\n\x19org.apache.dubbo.metadataP\x01Z;dubbo.apache.org/dubbo-go/v3/metadata/triple_api;triple_apib\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'dubbo._proto.org.apache.dubbo.metadata.metadata_service_v2_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + _globals['DESCRIPTOR']._loaded_options = None + _globals['DESCRIPTOR']._serialized_options = b'\n\031org.apache.dubbo.metadataP\001Z;dubbo.apache.org/dubbo-go/v3/metadata/triple_api;triple_api' + _globals['_METADATAINFOV2_SERVICESENTRY']._loaded_options = None + _globals['_METADATAINFOV2_SERVICESENTRY']._serialized_options = b'8\001' + _globals['_SERVICEINFOV2_PARAMSENTRY']._loaded_options = None + _globals['_SERVICEINFOV2_PARAMSENTRY']._serialized_options = b'8\001' + _globals['_OPENAPIFORMAT']._serialized_start=800 + _globals['_OPENAPIFORMAT']._serialized_end=846 + _globals['_METADATAREQUEST']._serialized_start=82 + _globals['_METADATAREQUEST']._serialized_end=117 + _globals['_METADATAINFOV2']._serialized_start=120 + _globals['_METADATAINFOV2']._serialized_end=332 + _globals['_METADATAINFOV2_SERVICESENTRY']._serialized_start=243 + _globals['_METADATAINFOV2_SERVICESENTRY']._serialized_end=332 + _globals['_SERVICEINFOV2']._serialized_start=335 + _globals['_SERVICEINFOV2']._serialized_end=559 + _globals['_SERVICEINFOV2_PARAMSENTRY']._serialized_start=514 + _globals['_SERVICEINFOV2_PARAMSENTRY']._serialized_end=559 + _globals['_OPENAPIREQUEST']._serialized_start=562 + _globals['_OPENAPIREQUEST']._serialized_end=763 + _globals['_OPENAPIINFO']._serialized_start=765 + _globals['_OPENAPIINFO']._serialized_end=798 + _globals['_METADATASERVICEV2']._serialized_start=849 + _globals['_METADATASERVICEV2']._serialized_end=1075 +# @@protoc_insertion_point(module_scope) diff --git a/src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2_pb2.pyi b/src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2_pb2.pyi new file mode 100644 index 00000000..55279563 --- /dev/null +++ b/src/dubbo/_proto/org/apache/dubbo/metadata/metadata_service_v2_pb2.pyi @@ -0,0 +1,89 @@ +from google.protobuf.internal import containers as _containers +from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from collections.abc import Iterable as _Iterable, Mapping as _Mapping +from typing import ClassVar as _ClassVar, Optional as _Optional, Union as _Union + +DESCRIPTOR: _descriptor.FileDescriptor + +class OpenAPIFormat(int, metaclass=_enum_type_wrapper.EnumTypeWrapper): + __slots__ = () + JSON: _ClassVar[OpenAPIFormat] + YAML: _ClassVar[OpenAPIFormat] + PROTO: _ClassVar[OpenAPIFormat] +JSON: OpenAPIFormat +YAML: OpenAPIFormat +PROTO: OpenAPIFormat + +class MetadataRequest(_message.Message): + __slots__ = ("revision",) + REVISION_FIELD_NUMBER: _ClassVar[int] + revision: str + def __init__(self, revision: _Optional[str] = ...) -> None: ... + +class MetadataInfoV2(_message.Message): + __slots__ = ("app", "version", "services") + class ServicesEntry(_message.Message): + __slots__ = ("key", "value") + KEY_FIELD_NUMBER: _ClassVar[int] + VALUE_FIELD_NUMBER: _ClassVar[int] + key: str + value: ServiceInfoV2 + def __init__(self, key: _Optional[str] = ..., value: _Optional[_Union[ServiceInfoV2, _Mapping]] = ...) -> None: ... + APP_FIELD_NUMBER: _ClassVar[int] + VERSION_FIELD_NUMBER: _ClassVar[int] + SERVICES_FIELD_NUMBER: _ClassVar[int] + app: str + version: str + services: _containers.MessageMap[str, ServiceInfoV2] + def __init__(self, app: _Optional[str] = ..., version: _Optional[str] = ..., services: _Optional[_Mapping[str, ServiceInfoV2]] = ...) -> None: ... + +class ServiceInfoV2(_message.Message): + __slots__ = ("name", "group", "version", "protocol", "port", "path", "params") + class ParamsEntry(_message.Message): + __slots__ = ("key", "value") + KEY_FIELD_NUMBER: _ClassVar[int] + VALUE_FIELD_NUMBER: _ClassVar[int] + key: str + value: str + def __init__(self, key: _Optional[str] = ..., value: _Optional[str] = ...) -> None: ... + NAME_FIELD_NUMBER: _ClassVar[int] + GROUP_FIELD_NUMBER: _ClassVar[int] + VERSION_FIELD_NUMBER: _ClassVar[int] + PROTOCOL_FIELD_NUMBER: _ClassVar[int] + PORT_FIELD_NUMBER: _ClassVar[int] + PATH_FIELD_NUMBER: _ClassVar[int] + PARAMS_FIELD_NUMBER: _ClassVar[int] + name: str + group: str + version: str + protocol: str + port: int + path: str + params: _containers.ScalarMap[str, str] + def __init__(self, name: _Optional[str] = ..., group: _Optional[str] = ..., version: _Optional[str] = ..., protocol: _Optional[str] = ..., port: _Optional[int] = ..., path: _Optional[str] = ..., params: _Optional[_Mapping[str, str]] = ...) -> None: ... + +class OpenAPIRequest(_message.Message): + __slots__ = ("group", "version", "tag", "service", "openapi", "format", "pretty") + GROUP_FIELD_NUMBER: _ClassVar[int] + VERSION_FIELD_NUMBER: _ClassVar[int] + TAG_FIELD_NUMBER: _ClassVar[int] + SERVICE_FIELD_NUMBER: _ClassVar[int] + OPENAPI_FIELD_NUMBER: _ClassVar[int] + FORMAT_FIELD_NUMBER: _ClassVar[int] + PRETTY_FIELD_NUMBER: _ClassVar[int] + group: str + version: str + tag: _containers.RepeatedScalarFieldContainer[str] + service: _containers.RepeatedScalarFieldContainer[str] + openapi: str + format: OpenAPIFormat + pretty: bool + def __init__(self, group: _Optional[str] = ..., version: _Optional[str] = ..., tag: _Optional[_Iterable[str]] = ..., service: _Optional[_Iterable[str]] = ..., openapi: _Optional[str] = ..., format: _Optional[_Union[OpenAPIFormat, str]] = ..., pretty: _Optional[bool] = ...) -> None: ... + +class OpenAPIInfo(_message.Message): + __slots__ = ("definition",) + DEFINITION_FIELD_NUMBER: _ClassVar[int] + definition: str + def __init__(self, definition: _Optional[str] = ...) -> None: ... diff --git a/src/dubbo/_proto/org/apache/dubbo/triple/__init__.py b/src/dubbo/_proto/org/apache/dubbo/triple/__init__.py new file mode 100644 index 00000000..6c032d66 --- /dev/null +++ b/src/dubbo/_proto/org/apache/dubbo/triple/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/src/dubbo/_proto/org/apache/dubbo/triple/triple_wrapper.proto b/src/dubbo/_proto/org/apache/dubbo/triple/triple_wrapper.proto new file mode 100644 index 00000000..11dc7c07 --- /dev/null +++ b/src/dubbo/_proto/org/apache/dubbo/triple/triple_wrapper.proto @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +syntax = "proto3"; + +package org.apache.dubbo.triple; + +message TripleRequestWrapper { + // hessian4 + // json + string serializeType = 1; + repeated bytes args = 2; + repeated string argTypes = 3; +} + +message TripleResponseWrapper { + string serializeType = 1; + bytes data = 2; + string type = 3; +} + +message TripleExceptionWrapper { + string language = 1; + string serialization = 2; + string className = 3; + bytes data = 4; +} diff --git a/src/dubbo/_proto/org/apache/dubbo/triple/triple_wrapper_pb2.py b/src/dubbo/_proto/org/apache/dubbo/triple/triple_wrapper_pb2.py new file mode 100644 index 00000000..e851fc83 --- /dev/null +++ b/src/dubbo/_proto/org/apache/dubbo/triple/triple_wrapper_pb2.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: org/apache/dubbo/triple/triple_wrapper.proto +# Protobuf Python Version: 7.35.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from dubbo._proto.pool import pool as _pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 7, + 35, + 1, + '', + 'org/apache/dubbo/triple/triple_wrapper.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _pool.AddSerializedFile(b'\n,org/apache/dubbo/triple/triple_wrapper.proto\x12\x17org.apache.dubbo.triple\"M\n\x14TripleRequestWrapper\x12\x15\n\rserializeType\x18\x01 \x01(\t\x12\x0c\n\x04\x61rgs\x18\x02 \x03(\x0c\x12\x10\n\x08\x61rgTypes\x18\x03 \x03(\t\"J\n\x15TripleResponseWrapper\x12\x15\n\rserializeType\x18\x01 \x01(\t\x12\x0c\n\x04\x64\x61ta\x18\x02 \x01(\x0c\x12\x0c\n\x04type\x18\x03 \x01(\t\"b\n\x16TripleExceptionWrapper\x12\x10\n\x08language\x18\x01 \x01(\t\x12\x15\n\rserialization\x18\x02 \x01(\t\x12\x11\n\tclassName\x18\x03 \x01(\t\x12\x0c\n\x04\x64\x61ta\x18\x04 \x01(\x0c\x62\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'dubbo._proto.org.apache.dubbo.triple.triple_wrapper_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + DESCRIPTOR._loaded_options = None + _globals['_TRIPLEREQUESTWRAPPER']._serialized_start=73 + _globals['_TRIPLEREQUESTWRAPPER']._serialized_end=150 + _globals['_TRIPLERESPONSEWRAPPER']._serialized_start=152 + _globals['_TRIPLERESPONSEWRAPPER']._serialized_end=226 + _globals['_TRIPLEEXCEPTIONWRAPPER']._serialized_start=228 + _globals['_TRIPLEEXCEPTIONWRAPPER']._serialized_end=326 +# @@protoc_insertion_point(module_scope) diff --git a/src/dubbo/_proto/org/apache/dubbo/triple/triple_wrapper_pb2.pyi b/src/dubbo/_proto/org/apache/dubbo/triple/triple_wrapper_pb2.pyi new file mode 100644 index 00000000..2d80d8c0 --- /dev/null +++ b/src/dubbo/_proto/org/apache/dubbo/triple/triple_wrapper_pb2.pyi @@ -0,0 +1,39 @@ +from google.protobuf.internal import containers as _containers +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from collections.abc import Iterable as _Iterable +from typing import ClassVar as _ClassVar, Optional as _Optional + +DESCRIPTOR: _descriptor.FileDescriptor + +class TripleRequestWrapper(_message.Message): + __slots__ = ("serializeType", "args", "argTypes") + SERIALIZETYPE_FIELD_NUMBER: _ClassVar[int] + ARGS_FIELD_NUMBER: _ClassVar[int] + ARGTYPES_FIELD_NUMBER: _ClassVar[int] + serializeType: str + args: _containers.RepeatedScalarFieldContainer[bytes] + argTypes: _containers.RepeatedScalarFieldContainer[str] + def __init__(self, serializeType: _Optional[str] = ..., args: _Optional[_Iterable[bytes]] = ..., argTypes: _Optional[_Iterable[str]] = ...) -> None: ... + +class TripleResponseWrapper(_message.Message): + __slots__ = ("serializeType", "data", "type") + SERIALIZETYPE_FIELD_NUMBER: _ClassVar[int] + DATA_FIELD_NUMBER: _ClassVar[int] + TYPE_FIELD_NUMBER: _ClassVar[int] + serializeType: str + data: bytes + type: str + def __init__(self, serializeType: _Optional[str] = ..., data: _Optional[bytes] = ..., type: _Optional[str] = ...) -> None: ... + +class TripleExceptionWrapper(_message.Message): + __slots__ = ("language", "serialization", "className", "data") + LANGUAGE_FIELD_NUMBER: _ClassVar[int] + SERIALIZATION_FIELD_NUMBER: _ClassVar[int] + CLASSNAME_FIELD_NUMBER: _ClassVar[int] + DATA_FIELD_NUMBER: _ClassVar[int] + language: str + serialization: str + className: str + data: bytes + def __init__(self, language: _Optional[str] = ..., serialization: _Optional[str] = ..., className: _Optional[str] = ..., data: _Optional[bytes] = ...) -> None: ... diff --git a/src/dubbo/_proto/pool.py b/src/dubbo/_proto/pool.py new file mode 100644 index 00000000..663be559 --- /dev/null +++ b/src/dubbo/_proto/pool.py @@ -0,0 +1,34 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""The descriptor pool of the protos the framework itself uses. + +Their types are kept out of protobuf's default pool, where packages that +generate the same protos, such as googleapis-common-protos, register theirs. +""" + +from dubbo.utils import require_optional_dependency + +with require_optional_dependency("google.protobuf", extra="tri"): + from google.protobuf import any_pb2, descriptor_pool, message_factory + +__all__ = ["pool"] + +pool = descriptor_pool.DescriptorPool() +# The well-known types the protos import, as the protobuf runtime describes them. +pool.AddSerializedFile(any_pb2.DESCRIPTOR.serialized_pb) +# The pure Python runtime builds the class of a message type only when asked, and fields of that type need it. +message_factory.GetMessageClass(pool.FindMessageTypeByName("google.protobuf.Any")) diff --git a/src/dubbo/application.py b/src/dubbo/application.py new file mode 100644 index 00000000..45fc3015 --- /dev/null +++ b/src/dubbo/application.py @@ -0,0 +1,522 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The Dubbo application: its configuration, and the order it starts and stops in.""" + +import asyncio +import logging +import signal +from collections.abc import AsyncGenerator, Callable, Mapping +from contextlib import AbstractAsyncContextManager, AsyncExitStack, asynccontextmanager +from functools import partial +from os import PathLike +from typing import Self, TypeVar, cast + +import anyio + +from dubbo.cluster.reference import refer +from dubbo.config import ( + ApplicationConfig, + ConfigCenterConfig, + ConsumerConfig, + DubboConfig, + MetadataReportConfig, + ProtocolConfig, + ProviderConfig, + ReferenceConfig, + RegistryConfig, + ServiceConfig, + ShutdownConfig, + TLSConfig, +) +from dubbo.config.data import merge +from dubbo.config.loading import ConfigSource, load_config +from dubbo.config.structure import unstructure_config +from dubbo.config.urls import ( + direct_urls, + reference_registries, + reference_url, + service_urls, +) +from dubbo.constants import CHECK_KEY, DEFAULT_CHECK, DEFAULT_GENERIC, DEFAULT_SHUTWAIT +from dubbo.exceptions import RpcError, Status +from dubbo.extension import ApplicationScope +from dubbo.protocol import get_protocol +from dubbo.protocol.exported import export_services +from dubbo.registry.provider import register_services +from dubbo.rpc.client import GenericService, proxy +from dubbo.rpc.definition import Service, get_definition +from dubbo.rpc.invocation import Invocation, Invoker, Result +from dubbo.url import URL +from dubbo.utils.converters import boolean + +__all__ = ["Dubbo"] + +T = TypeVar("T") + +# Seconds a reference that checks waits at startup for a provider, as for one its own application registers. +_CHECK_GRACE = 3.0 +_CHECK_INTERVAL = 0.05 +# The signals that stop an application that serves forever. +_SIGNALS = (signal.SIGINT, signal.SIGTERM) + +_logger = logging.getLogger(__name__) + + +class Dubbo(anyio.AsyncContextManagerMixin): + """A Dubbo application: the services it exports, the references it calls, and their configuration. + + The application runs while ``async with`` holds it: entering starts it, + and leaving stops it, in the same task:: + + app = Dubbo("dubbo.yaml") + orders = app.refer(OrderService) + app.export(UserServiceImpl(orders)) + + async with app: + await app.serve_forever() + + Configuration merges from low to high priority: ``sources`` in order, + each a mapping or a file read by the parser of its suffix (``.yaml`` + needs ``apache-dubbo[yaml]``); the configuration center; environment + variables named with ``env_prefix``, such as + ``DUBBO__PROTOCOLS__TRI__PORT=50052``, ``__`` separating keys and JSON + giving a mapping or a list; then the keyword arguments, and the + ``config`` of `export` and `refer` and the ``url`` of `refer`. Mappings merge key by key; fields left as ``None`` keep the + values of lower layers. The configuration center is the one the other + layers set as ``config_center``, else the first registry that can serve + as one; it cannot set itself. ``env_prefix=None`` ignores the + environment. Nothing is read before the application starts. + + Starting prepares each reference to call the providers its ``urls`` + name and those its registries hold, connecting to each in the + background; enters ``lifespan``; serves each exported service on its + protocols, ``tri`` on port 50051 when the configuration defines none, + and registers it; then waits up to 3 seconds in all for the references + that check to find a provider. A failure closes what has started and + raises. + + Leaving ``async with`` stops in reverse: the services leave the + registries, stop and wait for their running calls, which may still + call the references, and then the references close, all within + ``shutdown.grace`` seconds, 10 by default, after which what still runs + is cancelled. Cancelling the task, or a second SIGINT or SIGTERM after + the one that ended `serve_forever`, stops at once, cancelling the + running calls. To run beside another framework, enter the application + where that framework starts and stops in one task, such as an ASGI + lifespan. + + ``lifespan`` takes the application and returns an async context manager + holding what the services use, such as a database pool. It is entered + once the references are ready and before the services serve, and + exited once they have stopped serving, before the references close. + While it enters, the references can call other applications, but not + the services of this one. + """ + + def __init__( + self, + *sources: ConfigSource, + application: ApplicationConfig | None = None, + registries: Mapping[str, RegistryConfig] | None = None, + protocols: Mapping[str, ProtocolConfig] | None = None, + provider: ProviderConfig | None = None, + consumer: ConsumerConfig | None = None, + config_center: ConfigCenterConfig | None = None, + metadata_report: MetadataReportConfig | None = None, + tls: TLSConfig | None = None, + shutdown: ShutdownConfig | None = None, + lifespan: Callable[[Self], AbstractAsyncContextManager[object]] | None = None, + env_prefix: str | None = "DUBBO__", + ) -> None: + for source in sources: + if not isinstance(source, (str, PathLike, Mapping)): + raise TypeError(f"configuration source must be a path or a mapping, not {type(source).__name__}") + + self._sources = sources + self._env_prefix = env_prefix + sections = { + "application": application, + "registries": registries, + "protocols": protocols, + "provider": provider, + "consumer": consumer, + "config_center": config_center, + "metadata_report": metadata_report, + "tls": tls, + "shutdown": shutdown, + } + self._code = cast(dict[str, object], unstructure_config(sections)) + self._lifespan = lifespan + self._config: DubboConfig | None = None + + # The services, and the contracts of references, by interface. + self._services: dict[str, Service] = {} + self._references: dict[str, Service] = {} + # The generic mode of each reference called generically. + self._generic: dict[str, str] = {} + # The url each reference is given in code. + self._urls: dict[str, str] = {} + # The settings each reference is given in code by refer, and the services and references the keyword + # arguments give settings, which export and refer cannot give again. + self._configs: dict[str, ReferenceConfig] = {} + self._configured_services = frozenset(provider.services if provider is not None else ()) + self._configured_references = frozenset(consumer.references if consumer is not None else ()) + # From the moment starting begins until stopping ends. + self._running = False + # Set while the application runs: what makes the calls of each reference. + self._invokers: dict[str, Invoker] = {} + # Set while the application runs: the URLs its services are served with. + self._exported: tuple[URL, ...] | None = None + # Whether serve_forever returned on a signal, so that another one while stopping stops at once. + self._signalled = False + + @property + def config(self) -> DubboConfig: + """The merged configuration, available once the application has started. + + Raises: + RuntimeError: The application has not started. + """ + if self._config is None: + raise RuntimeError("the configuration is available once the application has started") + return self._config + + @property + def exported_urls(self) -> tuple[URL, ...]: + """The URLs the services are served with, in the order they were exported, while the application runs. + + Each URL has the port bound, so that a service served on port 0 + tells the port it got. They include the services of the framework, + such as the MetadataService. + + Raises: + RuntimeError: The application is not running. + """ + if self._exported is None: + raise RuntimeError("the exported URLs are known while the application runs") + return self._exported + + def export(self, implementation: object, *, config: ServiceConfig | None = None) -> None: + """Expose ``implementation`` once the application starts. + + ``implementation`` is an object implementing a service contract, or + a `Service` whose methods all have handlers. The service takes its + settings from ``config``, or else from the entry of its name in + ``provider.services``. + + Raises: + RuntimeError: The application has started. + TypeError: ``implementation`` does not implement a valid service + contract, or leaves a method unimplemented. + ValueError: A service of the same name is already exported, or + the contract gives two methods the same name, or ``config`` + is given for a service that the ``provider`` argument + configures. + """ + self._check_not_started("export") + + service = implementation if isinstance(implementation, Service) else Service.from_implementation(implementation) + interface = service.interface + if interface in self._services: + raise ValueError(f"{interface} is already exported") + if config is not None: + if interface in self._configured_services: + raise ValueError(f"{interface} is already configured in provider.services") + merge(self._code, {"provider": {"services": {interface: unstructure_config(config)}}}) + + self._services[interface] = service + + def refer(self, contract: type[T], *, url: str | None = None, config: ReferenceConfig | None = None) -> T: + """Return an object of type ``contract`` that calls its service once the application starts. + + The service takes its settings from ``config``, or else from the + entry of its name in ``consumer.references``. ``url`` names the + provider to call directly, as in ``tri://127.0.0.1:50051``, over the + ``urls`` of that entry; it is the short form of ``config.urls``, + which may name it too, but no other. Referring to it again returns + another object calling the same service, and may repeat ``url`` and + ``config``. Calling before the application has started, or after it + has stopped, raises `RuntimeError`. + + Each method of the object has the name, signature, type annotations + and docstring of the method of ``contract`` it calls, as `inspect` + and `typing.get_type_hints` report them, so that it can be given + where a function is described by them, such as a tool of an agent. + + Raises: + RuntimeError: The application has started. + TypeError: ``contract`` is not a valid service contract. + ValueError: Another contract already refers to the same service, + or another ``url`` or ``config`` was given for it, or + ``config`` is given for a service that the ``consumer`` + argument configures, or ``url`` is not what ``config.urls`` + names, or the contract gives two methods the same name. + """ + self._check_not_started("refer") + + definition = get_definition(contract) + interface = definition.interface + if self._references.get(interface, definition) != definition: + raise ValueError(f"another contract already refers to {interface}") + self._refer_settings(interface, url, config) + self._references[interface] = definition + + return proxy(contract, partial(self._invoke, interface)) + + def refer_generic( + self, + interface: str, + *, + url: str | None = None, + config: ReferenceConfig | None = None, + generic: str = DEFAULT_GENERIC, + ) -> GenericService: + """Return a `GenericService` that calls the service ``interface`` by method name once the application starts. + + The service takes its settings from ``config``, or else from the + entry of its name in ``consumer.references``, which may configure + any method; ``url`` names the provider to call directly. Both are + taken as `refer` takes them. A contract + may refer to the same service, sharing its settings and providers. + ``generic`` names the form of the arguments and results, as + `GenericService` lists them. Calling before the application has + started, or after it has stopped, raises `RuntimeError`. + + Raises: + RuntimeError: The application has started. + ValueError: ``interface`` is empty, ``generic`` names no form, + another ``url``, ``config`` or ``generic`` was given for it, + or ``url`` and ``config`` are refused as `refer` refuses them. + """ + self._check_not_started("refer") + + if not interface: + raise ValueError("interface must not be empty") + service = GenericService(interface, partial(self._invoke, interface), generic=generic) + if self._generic.get(interface, generic) != generic: + raise ValueError(f"{interface} is already referred to with generic={self._generic[interface]}") + self._refer_settings(interface, url, config) + self._generic[interface] = generic + + return service + + async def serve_forever(self) -> None: + """Serve until the process receives SIGINT or SIGTERM, then return, so that leaving ``async with`` stops the application. + + Another SIGINT or SIGTERM while the application stops makes it stop + at once, as cancelling does. Where signals cannot be received, such + as on Windows or outside the main thread, it serves until cancelled. + + Raises: + RuntimeError: The application has not started. + """ + if self._config is None or not self._running: + raise RuntimeError("the application serves once it has started") + + try: + with anyio.open_signal_receiver(*_SIGNALS) as signals: + async for received in signals: + _logger.info("Stopping on %s", signal.Signals(received).name) + self._signalled = True + return + except (NotImplementedError, RuntimeError, ValueError): + # The services serve in their own tasks; this one only waits to be cancelled. + await anyio.sleep_forever() + + @asynccontextmanager + async def __asynccontextmanager__(self) -> AsyncGenerator[Self]: + """Start the application, reading and validating its configuration, and stop it on leaving. + + A failure closes what has been opened so far. Stopping, and the + closing after a failure, takes at most ``shutdown.grace`` in all; + what still runs then is cancelled. Cancelling the task stops at + once, without the waits. + + Raises: + RuntimeError: The application has already started. + dubbo.config.ConfigError: The configuration cannot be read or is + invalid, configures a method that its service does not have, + or gives a reference neither ``urls`` nor a registry. + dubbo.extension.ExtensionError: The configuration names an + extension that is not installed, or one cannot be loaded. + ValueError: A URL parameter is invalid. + OSError: An address cannot be bound. + dubbo.RpcError: ``UNAVAILABLE``: a reference that checks has no + provider. + dubbo.transport.zookeeper.ZookeeperError: A ZooKeeper registry + cannot be reached. + dubbo.transport.nacos.NacosError: A Nacos registry cannot be + reached. + """ + if self._running: + raise RuntimeError("the application has already started") + self._running = True + + started = False + ended: BaseException | None = None + forced = False + + def stop_at_once(received: signal.Signals) -> None: + nonlocal forced + if not forced: + _logger.info("Stopping at once on a second %s", received.name) + forced = True + stopping.cancel() + + # AnyIO receives signals only in a task, while a handler of the loop cancels the scope without one. + loop = asyncio.get_running_loop() + try: + # Entered before what the application opens, so that its deadline bounds the closing of all of it. + with anyio.CancelScope() as stopping: + async with AsyncExitStack() as stack: + try: + await self._start(stack) + started = True + yield self + except BaseException as error: + ended = error + raise + finally: + if isinstance(ended, anyio.get_cancelled_exc_class()): + # A cancellation of the task, as asyncio's, may reach it once; the closing must see it too. + forced = True + stopping.cancel() + else: + stopping.deadline = anyio.current_time() + self._shutdown_budget() + if self._signalled: + for received in _SIGNALS: + loop.add_signal_handler(received, stop_at_once, received) + if stopping.cancelled_caught and not forced: + _logger.warning( + "Stopping took longer than %.1f seconds; what still ran was cancelled", self._shutdown_budget() + ) + # The scope swallows the cancellation of its deadline, and with it what ended the application. + if stopping.cancelled_caught and ended is not None: + raise ended + finally: + if self._signalled: + for received in _SIGNALS: + loop.remove_signal_handler(received) + self._signalled = False + if not started: + self._config = None + self._running = False + + async def _invoke(self, interface: str, invocation: Invocation) -> Result: + try: + invoker = self._invokers[interface] + except KeyError: + raise RuntimeError(f"{interface} is called only while the application runs") from None + + return await invoker.invoke(invocation) + + async def _start(self, stack: AsyncExitStack) -> None: + """Open into ``stack`` what the application runs with, in the order that it closes in reverse.""" + # What the extensions of the application share, such as its protocols and the connections to its + # registries: each opens on first use, and all close after everything else. + scope = await stack.enter_async_context(ApplicationScope()) + config = await load_config(self._sources, env_prefix=self._env_prefix, code=self._code, scope=scope) + # From now on, so that the closing after a failure takes the shutdown budget it configures. + self._config = config + services = {interface: service_urls(config, service, scope) for interface, service in self._services.items()} + # A reference called only generically has no methods it knows. + definitions = {interface: Service(interface=interface, methods=()) for interface in self._generic} + definitions |= self._references + references = { + interface: reference_url(config, definition, scope, generic=interface in self._generic) + for interface, definition in definitions.items() + } + # A reference calls the providers its urls name directly and those its registries hold. + direct = {interface: direct_urls(config, url) for interface, url in references.items()} + registries = {interface: reference_registries(config, interface, scope) for interface in references} + + # References first, to close last, so that services can call them while they stop. Calls are refused + # before each closes. + for interface, url in references.items(): + invoker = await stack.enter_async_context( + refer( + url, + definitions[interface], + direct[interface], + registries[interface], + generic=None if interface in self._references else self._generic[interface], + ) + ) + self._invokers[interface] = invoker + stack.callback(self._invokers.pop, interface) + + # Before serving and after stopping to serve, so that the calls of the services find what it opens. + if self._lifespan is not None: + await stack.enter_async_context(self._lifespan(self)) + + exported = await stack.enter_async_context(export_services(config, services, self._services, scope)) + metadata_urls = await stack.enter_async_context(register_services(config, exported, scope)) + self._exported = (*(service.url for service in exported), *metadata_urls) + stack.callback(setattr, self, "_exported", None) + # Stopping tells the callers first, while the services leave the registries and keep serving. + for name in {url.protocol for urls in services.values() for url in urls}: + stack.callback((await get_protocol(name, scope)).announce_shutdown) + # After registering, so that a reference to a service of this application finds it. + await _check_references(references, self._invokers) + + def _refer_settings(self, interface: str, url: str | None, config: ReferenceConfig | None) -> None: + """Have the reference ``interface`` take ``config`` and call ``url`` directly, each given for it in code once.""" + if url is not None and self._urls.get(interface, url) != url: + raise ValueError(f"{interface} is already referred to at another url") + if config is not None: + if interface in self._configured_references: + raise ValueError(f"{interface} is already configured in consumer.references") + if self._configs.get(interface, config) != config: + raise ValueError(f"{interface} is already referred to with other settings") + given_url = self._urls.get(interface) if url is None else url + given = self._configs.get(interface) if config is None else config + if given_url is not None and given is not None and given.urls and given.urls != (given_url,): + raise ValueError(f"the url and the config of {interface} name different providers") + + if config is not None and interface not in self._configs: + self._configs[interface] = config + merge(self._code, {"consumer": {"references": {interface: unstructure_config(config)}}}) + if url is not None and interface not in self._urls: + self._urls[interface] = url + merge(self._code, {"consumer": {"references": {interface: {"urls": [url]}}}}) + + def _check_not_started(self, action: str) -> None: + if self._running: + raise RuntimeError(f"cannot {action} once the application has started") + + def _shutdown_budget(self) -> float: + grace = None if self._config is None else self._config.shutdown.grace + return DEFAULT_SHUTWAIT if grace is None else grace + + +async def _check_references(references: Mapping[str, URL], invokers: Mapping[str, Invoker]) -> None: + """Wait a moment for each reference that sets ``check`` to have a provider connected. + + Raises: + RpcError: ``UNAVAILABLE``: some have none. + """ + pending = [name for name, url in references.items() if url.get_parameter(CHECK_KEY, boolean, DEFAULT_CHECK)] + with anyio.move_on_after(_CHECK_GRACE): + while pending := [name for name in pending if not invokers[name].available]: + await anyio.sleep(_CHECK_INTERVAL) + + if pending: + raise RpcError( + Status.UNAVAILABLE, + f"no provider of {', '.join(sorted(pending))} is available; set check to false to start without one", + ) diff --git a/src/dubbo/bootstrap.py b/src/dubbo/bootstrap.py deleted file mode 100644 index 57921951..00000000 --- a/src/dubbo/bootstrap.py +++ /dev/null @@ -1,134 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import threading -from typing import Optional - -from dubbo.classes import SingletonBase -from dubbo.configs import ( - ApplicationConfig, - LoggerConfig, - ReferenceConfig, - RegistryConfig, -) -from dubbo.constants import common_constants -from dubbo.loggers import loggerFactory - - -class Dubbo(SingletonBase): - """ - Dubbo class. This class is used to initialize the Dubbo framework. - """ - - def __init__( - self, - application_config: Optional[ApplicationConfig] = None, - registry_config: Optional[RegistryConfig] = None, - logger_config: Optional[LoggerConfig] = None, - ): - """ - Initialize a new Dubbo bootstrap. - :param application_config: The application configuration. - :type application_config: Optional[ApplicationConfig] - :param registry_config: The registry configuration. - :type registry_config: Optional[RegistryConfig] - :param logger_config: The logger configuration. - :type logger_config: Optional[LoggerConfig] - """ - self._initialized = False - self._global_lock = threading.Lock() - - self._application_config = application_config - self._registry_config = registry_config - self._logger_config = logger_config - - # check and set the default configuration - self._check_default() - - # initialize the Dubbo framework - self._initialize() - - @property - def application_config(self) -> Optional[ApplicationConfig]: - """ - Get the application configuration. - :return: The application configuration. - :rtype: Optional[ApplicationConfig] - """ - return self._application_config - - @property - def registry_config(self) -> Optional[RegistryConfig]: - """ - Get the registry configuration. - :return: The registry configuration. - :rtype: Optional[RegistryConfig] - """ - return self._registry_config - - @property - def logger_config(self) -> Optional[LoggerConfig]: - """ - Get the logger configuration. - :return: The logger configuration. - :rtype: Optional[LoggerConfig] - """ - return self._logger_config - - def _check_default(self): - """ - Check and set the default configuration. - """ - # set default application configuration - if not self._application_config: - self._application_config = ApplicationConfig(common_constants.DUBBO_VALUE) - - if self._registry_config: - if not self._registry_config.version and self.application_config.version: - self._registry_config.version = self.application_config.version - - def _initialize(self): - """ - Initialize the Dubbo framework. - """ - with self._global_lock: - if self._initialized: - return - - # set logger configuration - if self._logger_config: - loggerFactory.set_config(self._logger_config) - - self._initialized = True - - def create_client(self, reference_config: ReferenceConfig): - """ - Create a new Dubbo client. - :param reference_config: The reference configuration. - :type reference_config: ReferenceConfig - """ - from dubbo import Client - - return Client(reference_config, self) - - def create_server(self, config): - """ - Create a new Dubbo server. - :param config: The service configuration. - :type config: ServiceConfig - """ - from dubbo import Server - - return Server(config, self) diff --git a/src/dubbo/classes.py b/src/dubbo/classes.py deleted file mode 100644 index 8d87299e..00000000 --- a/src/dubbo/classes.py +++ /dev/null @@ -1,246 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import abc -import threading -from typing import Any, Callable, Optional, Union - -from dubbo.types import DeserializingFunction, RpcType, RpcTypes, SerializingFunction - -__all__ = [ - "EOF", - "SingletonBase", - "MethodDescriptor", - "ReadStream", - "WriteStream", - "ReadWriteStream", -] - - -class _EOF: - """ - EOF is a class representing the end flag. - """ - - _repr_str = "" - - def __bool__(self): - return False - - def __len__(self): - return 0 - - def __repr__(self) -> str: - return self._repr_str - - def __str__(self) -> str: - return self._repr_str - - -# The EOF object -> global constant -EOF = _EOF() - - -class SingletonBase: - """ - Singleton base class. This class ensures that only one instance of a derived class exists. - - This implementation is thread-safe. - """ - - _instance = None - _instance_lock = threading.Lock() - - def __new__(cls, *args, **kwargs): - """ - Create a new instance of the class if it does not exist. - """ - if cls._instance is None: - with cls._instance_lock: - # double check - if cls._instance is None: - cls._instance = super().__new__(cls) - return cls._instance - - -class MethodDescriptor: - """ - MethodDescriptor is a descriptor for a method. - It contains the method name, the method, and the method's serialization and deserialization methods. - """ - - __slots__ = [ - "_callable_method", - "_method_name", - "_rpc_type", - "_arg_serialization", - "_return_serialization", - ] - - def __init__( - self, - method_name: str, - arg_serialization: tuple[Optional[SerializingFunction], Optional[DeserializingFunction]], - return_serialization: tuple[Optional[SerializingFunction], Optional[DeserializingFunction]], - rpc_type: Union[RpcType, RpcTypes, str] = RpcTypes.UNARY.value, - callable_method: Optional[Callable] = None, - ): - """ - Initialize the method model. - - :param method_name: - The name of the method. - :type method_name: str - - :param arg_serialization: - A tuple containing serialization and deserialization methods for the function's arguments. - :type arg_serialization: Optional[Tuple[SerializingFunction, DeserializingFunction]] - - :param return_serialization: - A tuple containing serialization and deserialization methods for the function's return values. - :type return_serialization: Optional[Tuple[SerializingFunction, DeserializingFunction]] - - :param rpc_type: - The RPC type. default is RpcTypes.UNARY. - :type rpc_type: RpcType - - :param callable_method: - The main callable method to be executed. - :type callable_method: Optional[Callable] - """ - self._method_name = method_name - self._arg_serialization = arg_serialization - self._return_serialization = return_serialization - self._callable_method = callable_method - - if isinstance(rpc_type, str): - rpc_type = RpcTypes.from_name(rpc_type) - elif isinstance(rpc_type, RpcTypes): - rpc_type = rpc_type.value - elif not isinstance(rpc_type, RpcType): - raise TypeError(f"rpc_type must be of type RpcType, RpcTypes, or str, not {type(rpc_type)}") - self._rpc_type = rpc_type - - def get_method(self) -> Callable: - """ - Get the callable method. - :return: The callable method. - :rtype: Callable - """ - return self._callable_method - - def get_method_name(self) -> str: - """ - Get the method name. - :return: The method name. - :rtype: str - """ - return self._method_name - - def get_rpc_type(self) -> RpcType: - """ - Get the RPC type. - :return: The RPC type. - :rtype: RpcType - """ - return self._rpc_type - - def get_arg_serializer(self) -> Optional[SerializingFunction]: - """ - Get the argument serializer. - :return: The argument serializer. If not set, return None. - :rtype: Optional[SerializingFunction] - """ - return self._arg_serialization[0] if self._arg_serialization else None - - def get_arg_deserializer(self) -> Optional[DeserializingFunction]: - """ - Get the argument deserializer. - :return: The argument deserializer. If not set, return None. - :rtype: Optional[DeserializingFunction] - """ - return self._arg_serialization[1] if self._arg_serialization else None - - def get_return_serializer(self) -> Optional[SerializingFunction]: - """ - Get the return value serializer. - :return: The return value serializer. If not set, return None. - :rtype: Optional[SerializingFunction] - """ - return self._return_serialization[0] if self._return_serialization else None - - def get_return_deserializer(self) -> Optional[DeserializingFunction]: - """ - Get the return value deserializer. - :return: The return value deserializer. If not set, return None. - :rtype: Optional[DeserializingFunction] - """ - return self._return_serialization[1] if self._return_serialization else None - - -class ReadStream(abc.ABC): - """ - ReadStream is an abstract class for reading streams. - """ - - @abc.abstractmethod - def read(self, *args, **kwargs) -> Any: - """ - Read the stream. - :param args: The arguments to pass to the read method. - :param kwargs: The keyword arguments to pass to the read method. - :return: The read value. - """ - raise NotImplementedError() - - -class WriteStream(abc.ABC): - """ - WriteStream is an abstract class for writing streams. - """ - - @abc.abstractmethod - def can_write_more(self) -> bool: - """ - Check if the stream can write more data. - :return: True if the stream can write more data, False otherwise. - :rtype: bool - """ - raise NotImplementedError() - - @abc.abstractmethod - def write(self, *args, **kwargs) -> None: - """ - Write to the stream. - :param args: The arguments to pass to the write method. - :param kwargs: The keyword arguments to pass to the write method. - """ - raise NotImplementedError() - - @abc.abstractmethod - def done_writing(self, **kwargs) -> None: - """ - Done writing to the stream. - :param kwargs: The keyword arguments to pass to the done - """ - raise NotImplementedError() - - -class ReadWriteStream(ReadStream, WriteStream, abc.ABC): - """ - ReadWriteStream is an abstract class for reading and writing streams. - """ - - pass diff --git a/src/dubbo/client.py b/src/dubbo/client.py deleted file mode 100644 index 33e6264d..00000000 --- a/src/dubbo/client.py +++ /dev/null @@ -1,163 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import threading -from typing import Optional - -from dubbo.bootstrap import Dubbo -from dubbo.classes import MethodDescriptor -from dubbo.configs import ReferenceConfig -from dubbo.constants import common_constants -from dubbo.extension import extensionLoader -from dubbo.protocol import Invoker, Protocol -from dubbo.proxy import RpcCallable, RpcCallableFactory -from dubbo.proxy.callables import DefaultRpcCallableFactory -from dubbo.registry.protocol import RegistryProtocol -from dubbo.types import ( - DeserializingFunction, - RpcTypes, - SerializingFunction, -) -from dubbo.url import URL - -__all__ = ["Client"] - - -class Client: - def __init__(self, reference: ReferenceConfig, dubbo: Optional[Dubbo] = None): - self._initialized = False - self._global_lock = threading.RLock() - - self._dubbo = dubbo or Dubbo() - self._reference = reference - - self._url: Optional[URL] = None - self._protocol: Optional[Protocol] = None - self._invoker: Optional[Invoker] = None - - self._callable_factory: RpcCallableFactory = DefaultRpcCallableFactory() - - # initialize the invoker - self._initialize() - - def _initialize(self): - """ - Initialize the invoker. - """ - with self._global_lock: - if self._initialized: - return - - # get the protocol - protocol = extensionLoader.get_extension(Protocol, self._reference.protocol)() - - registry_config = self._dubbo.registry_config - - self._protocol = RegistryProtocol(registry_config, protocol) if self._dubbo.registry_config else protocol - - # build url - reference_url = self._reference.to_url() - if registry_config: - self._url = registry_config.to_url().copy() - self._url.path = reference_url.path - for k, v in reference_url.parameters.items(): - self._url.parameters[k] = v - else: - self._url = reference_url - - # create invoker - self._invoker = self._protocol.refer(self._url) - - self._initialized = True - - def unary( - self, - method_name: str, - request_serializer: Optional[SerializingFunction] = None, - response_deserializer: Optional[DeserializingFunction] = None, - ) -> RpcCallable: - return self._callable( - MethodDescriptor( - method_name=method_name, - arg_serialization=(request_serializer, None), - return_serialization=(None, response_deserializer), - rpc_type=RpcTypes.UNARY.value, - ) - ) - - def client_stream( - self, - method_name: str, - request_serializer: Optional[SerializingFunction] = None, - response_deserializer: Optional[DeserializingFunction] = None, - ) -> RpcCallable: - return self._callable( - MethodDescriptor( - method_name=method_name, - arg_serialization=(request_serializer, None), - return_serialization=(None, response_deserializer), - rpc_type=RpcTypes.CLIENT_STREAM.value, - ) - ) - - def server_stream( - self, - method_name: str, - request_serializer: Optional[SerializingFunction] = None, - response_deserializer: Optional[DeserializingFunction] = None, - ) -> RpcCallable: - return self._callable( - MethodDescriptor( - method_name=method_name, - arg_serialization=(request_serializer, None), - return_serialization=(None, response_deserializer), - rpc_type=RpcTypes.SERVER_STREAM.value, - ) - ) - - def bi_stream( - self, - method_name: str, - request_serializer: Optional[SerializingFunction] = None, - response_deserializer: Optional[DeserializingFunction] = None, - ) -> RpcCallable: - # create method descriptor - return self._callable( - MethodDescriptor( - method_name=method_name, - arg_serialization=(request_serializer, None), - return_serialization=(None, response_deserializer), - rpc_type=RpcTypes.BI_STREAM.value, - ) - ) - - def _callable(self, method_descriptor: MethodDescriptor) -> RpcCallable: - """ - Generate a proxy for the given method - :param method_descriptor: The method descriptor. - :return: The proxy. - :rtype: RpcCallable - """ - # get invoker - url = self._invoker.get_url() - - # clone url - url = url.copy() - url.parameters[common_constants.METHOD_KEY] = method_descriptor.get_method_name() - # set method descriptor - url.attributes[common_constants.METHOD_DESCRIPTOR_KEY] = method_descriptor - - # create proxy - return self._callable_factory.get_callable(self._invoker, url) diff --git a/src/dubbo/cluster/__init__.py b/src/dubbo/cluster/__init__.py index 0260f692..8a2a9b14 100644 --- a/src/dubbo/cluster/__init__.py +++ b/src/dubbo/cluster/__init__.py @@ -1,19 +1,37 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Choosing the provider a call goes to among those of a referenced service.""" -from ._interfaces import Cluster, Directory, LoadBalance +from .base import BaseCluster, Cluster, create_cluster +from .directory import Directory, DynamicDirectory, Refer, StaticDirectory +from .loadbalance import LoadBalance +from .router import Router, RouterChain, create_routers -__all__ = ["Cluster", "Directory", "LoadBalance"] +__all__ = [ + "BaseCluster", + "Cluster", + "Directory", + "DynamicDirectory", + "LoadBalance", + "Refer", + "Router", + "RouterChain", + "StaticDirectory", + "create_cluster", + "create_routers", +] diff --git a/src/dubbo/cluster/_interfaces.py b/src/dubbo/cluster/_interfaces.py deleted file mode 100644 index f6c999b6..00000000 --- a/src/dubbo/cluster/_interfaces.py +++ /dev/null @@ -1,75 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import abc -from typing import Optional - -from dubbo.node import Node -from dubbo.protocol import Invocation, Invoker - -__all__ = ["Directory", "LoadBalance", "Cluster"] - - -class Directory(Node, abc.ABC): - """ - Directory interface. - """ - - @abc.abstractmethod - def get_list(self, invocation: Invocation) -> list[Invoker]: - """ - List the directory. - :param invocation: The invocation. - :type invocation: Invocation - :return: The list of invokers. - :rtype: List - """ - raise NotImplementedError() - - -class LoadBalance(abc.ABC): - """ - The load balance interface. - """ - - @abc.abstractmethod - def select(self, invokers: list[Invoker], invocation: Invocation) -> Optional[Invoker]: - """ - Select an invoker from the list. - :param invokers: The invokers. - :type invokers: List[Invoker] - :param invocation: The invocation. - :type invocation: Invocation - :return: The selected invoker. If no invoker is selected, return None. - :rtype: Optional[Invoker] - """ - raise NotImplementedError() - - -class Cluster(abc.ABC): - """ - Cluster interface. - """ - - @abc.abstractmethod - def join(self, directory: Directory) -> Invoker: - """ - Join the cluster. - :param directory: The directory. - :type directory: Directory - :return: The cluster invoker. - :rtype: Invoker - """ - raise NotImplementedError() diff --git a/src/dubbo/cluster/available.py b/src/dubbo/cluster/available.py new file mode 100644 index 00000000..fd995399 --- /dev/null +++ b/src/dubbo/cluster/available.py @@ -0,0 +1,36 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Sequence + +from dubbo.exceptions import RpcError, Status +from dubbo.rpc.invocation import Invocation, Invoker, Result + +from .base import BaseCluster + +__all__ = ["AvailableCluster"] + + +class AvailableCluster(BaseCluster): + """Makes each call once, on the first available invoker of the directory, without a load balance.""" + + async def _invoke(self, invocation: Invocation, invokers: Sequence[Invoker]) -> Result: + for invoker in invokers: + if invoker.available: + return await invoker.invoke(invocation) + + return Result(error=RpcError(Status.UNAVAILABLE, f"no provider of {invocation.interface} is available")) diff --git a/src/dubbo/cluster/base.py b/src/dubbo/cluster/base.py new file mode 100644 index 00000000..01b8208d --- /dev/null +++ b/src/dubbo/cluster/base.py @@ -0,0 +1,173 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from abc import ABC, abstractmethod +from collections.abc import Sequence +from contextlib import AsyncExitStack + +from dubbo.constants import ( + CLUSTER_KEY, + DEFAULT_CLUSTER, + DEFAULT_LOADBALANCE, + DEFAULT_STICKY, + LOADBALANCE_KEY, + STICKY_KEY, +) +from dubbo.exceptions import RpcError, Status +from dubbo.extension import extension_point, extensions +from dubbo.rpc.invocation import Invocation, Invoker, Result +from dubbo.url import URL +from dubbo.utils.converters import boolean + +from .directory import Directory +from .loadbalance import LoadBalance + +__all__ = ["BaseCluster", "Cluster", "available_invokers", "create_cluster"] + + +@extension_point("apache_dubbo.cluster") +class Cluster(Invoker, typing.Protocol): + """Makes each call of a reference through its providers: which it tries, how often, and what a failure returns. + + Implement the `Invoker` contract with ``__init__(url, directory)``, or + subclass `BaseCluster`, and install the class under the entry point + group ``apache_dubbo.cluster``; the ``cluster`` parameter of the + reference names it, ``failover`` by default. + + `create_cluster` creates one with the URL of the reference, whose + parameters, such as ``loadbalance`` and ``retries``, configure it, and + the directory it asks for candidates on every attempt, and enters it + before its first call. It owns the directory: closing the cluster + closes it. It is an invoker over the invokers of the directory, so a + directory may hold clusters too, and it is available while the + directory is. + + ``invoke`` runs in the event loop, for many calls at once, and returns + a failure in `Result.error`. A call that finds no invoker in the + directory ends with ``UNAVAILABLE``; otherwise each attempt chooses + among the available invokers, or among all of them when none is, + asking the one it chooses first and the others only when that one is + not available. + """ + + def __init__(self, url: URL, directory: Directory) -> None: ... + + +class BaseCluster(Cluster, ABC): + """The part of a cluster every strategy shares; a strategy implements `_invoke`. + + A call that the directory has no invoker for ends with ``UNAVAILABLE`` + before the strategy sees it. + + Each attempt chooses its invoker with the load balance of the method + called: the one ``{method}.loadbalance`` names, else the one + ``loadbalance`` names, else ``random``. With ``{method}.sticky``, else + ``sticky``, true, it chooses the invoker it chose last again while that + one is among the candidates and available. + + Attributes: + directory: Where the invokers of each attempt come from. + """ + + def __init__(self, url: URL, directory: Directory) -> None: + super().__init__(url, directory) + + self._url = url + self.directory = directory + self._load_balance = _load_balance(url.parameters.get(LOADBALANCE_KEY, DEFAULT_LOADBALANCE), url) + self._load_balances = { + method: _load_balance(name, url) for method, name in url.get_method_parameters(LOADBALANCE_KEY, str).items() + } + self._sticky = url.get_parameter(STICKY_KEY, boolean, DEFAULT_STICKY) + self._stickies = url.get_method_parameters(STICKY_KEY, boolean) + self._last: Invoker | None = None + + @property + def url(self) -> URL: + return self._url + + @property + def available(self) -> bool: + return self.directory.available + + async def invoke(self, invocation: Invocation) -> Result: + invokers = self.directory.candidates(invocation) + if not invokers: + return Result(error=RpcError(Status.UNAVAILABLE, f"no provider of {invocation.interface} is available")) + + return await self._invoke(invocation, invokers) + + async def aclose(self) -> None: + await self.directory.aclose() + + def _select(self, invokers: Sequence[Invoker], invocation: Invocation) -> Invoker: + """Return the invoker of an attempt of ``invocation`` among ``invokers``, as the load balance of its method chooses. + + One chosen while unavailable is chosen again among the available + ones, if any, so that an attempt asks one invoker whether it is + available while all are. + """ + sticky = self._stickies.get(invocation.method, self._sticky) + last = self._last + if sticky and last is not None and last in invokers and last.available: + return last + + load_balance = self._load_balances.get(invocation.method, self._load_balance) + chosen = load_balance.select(invokers, invocation) + if not chosen.available: + available = available_invokers(invokers) + if available is not invokers: + chosen = load_balance.select(available, invocation) + + if sticky: + self._last = chosen + return chosen + + @abstractmethod + async def _invoke(self, invocation: Invocation, invokers: Sequence[Invoker]) -> Result: + """Make the call through ``invokers``, which holds at least one, and return how it ended.""" + + +def available_invokers(invokers: Sequence[Invoker]) -> Sequence[Invoker]: + """Return those of ``invokers`` that are available, ``invokers`` itself when all or none are.""" + available = [invoker for invoker in invokers if invoker.available] + return invokers if len(available) == len(invokers) or not available else available + + +async def create_cluster(url: URL, directory: Directory) -> Cluster: + """Open ``directory`` and return the cluster the ``cluster`` parameter of ``url`` names over it, ``failover`` when absent. + + The cluster is entered, and owns ``directory`` from the call on: closing + the cluster closes it, and so does a failure to create or enter the + cluster. + + Raises: + ExtensionError: No implementation has that name. + """ + async with AsyncExitStack() as stack: + stack.push_async_callback(directory.aclose) + await directory.__aenter__() + cluster = extensions.get(Cluster, url.parameters.get(CLUSTER_KEY, DEFAULT_CLUSTER))(url, directory) + await cluster.__aenter__() + stack.pop_all() + + return cluster + + +def _load_balance(name: str, url: URL) -> LoadBalance: + return extensions.get(LoadBalance, name)(url) diff --git a/src/dubbo/cluster/broadcast.py b/src/dubbo/cluster/broadcast.py new file mode 100644 index 00000000..205f78a7 --- /dev/null +++ b/src/dubbo/cluster/broadcast.py @@ -0,0 +1,77 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +from collections.abc import Sequence + +from dubbo.constants import BROADCAST_FAIL_PERCENT_KEY +from dubbo.rpc.definition import RpcType +from dubbo.rpc.invocation import Invocation, Invoker, Result +from dubbo.url import URL + +from .base import BaseCluster, available_invokers +from .directory import Directory + +__all__ = ["BroadcastCluster"] + +_logger = logging.getLogger(__name__) + + +class BroadcastCluster(BaseCluster): + """Makes a unary call on every invoker, one after another, and returns the last failure, else the last result. + + Any error counts as a failure, the method's own too. The calls stop + once ``broadcast.fail.percent`` percent of the invokers, rounded down, + have failed; 100, the default, and 0 call all of them. A streaming call + is made once, on the invoker the load balance chooses. + + Raises: + ValueError: ``broadcast.fail.percent`` is not between 0 and 100. + """ + + def __init__(self, url: URL, directory: Directory) -> None: + super().__init__(url, directory) + self._fail_percent = url.get_parameter(BROADCAST_FAIL_PERCENT_KEY, int, 100) + if not 0 <= self._fail_percent <= 100: + raise ValueError(f"{BROADCAST_FAIL_PERCENT_KEY} must be between 0 and 100, not {self._fail_percent}") + + async def _invoke(self, invocation: Invocation, invokers: Sequence[Invoker]) -> Result: + if invocation.definition.rpc_type is not RpcType.UNARY: + return await self._select(invokers, invocation).invoke(invocation) + + invokers = available_invokers(invokers) + failures_allowed = len(invokers) * self._fail_percent // 100 or len(invokers) + failure: Result | None = None + failures = 0 + for invoker in invokers: + result = await invoker.invoke(invocation) + if result.error is None: + continue + + _logger.warning( + "Broadcasting %s.%s to %s failed", + invocation.interface, + invocation.method, + invoker.url, + exc_info=result.error, + ) + failure = result + failures += 1 + if failures == failures_allowed: + break + + return failure or result diff --git a/src/dubbo/cluster/configurator.py b/src/dubbo/cluster/configurator.py new file mode 100644 index 00000000..b76fa726 --- /dev/null +++ b/src/dubbo/cluster/configurator.py @@ -0,0 +1,276 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Override rules, which change the parameters of the URLs the consumers and the providers of a service use.""" + +import logging +from collections.abc import Callable, Mapping, Sequence +from contextlib import AsyncExitStack +from functools import partial +from typing import Literal, Self, cast + +import attrs + +from dubbo.constants import APPLICATION_KEY +from dubbo.extension import Resource +from dubbo.url import CONFIG_CENTER_URL, URL +from dubbo.utils.net import match_address, split_address + +from .rule import ParamMatch, RuleWatch, StringMatch, entries, flag, glob, mapping, rule_key + +__all__ = ["Overrides", "Side"] + +_logger = logging.getLogger(__name__) + +_SUFFIX = ".configurators" +# Addresses of a rule that stand for any host. +_ANY_HOSTS = frozenset({"0.0.0.0", "*"}) + +# The side of a service whose URLs the configs of a rule change. +Side = Literal["consumer", "provider"] + + +@attrs.define(frozen=True, kw_only=True) +class _AddressMatch: + """A test of an address by the first of its fields that is set. + + ``cird`` is the address itself or an IP expression, as tag rules list + providers; ``wildcard`` is ``*`` or ``0.0.0.0`` for any address, else a + pattern with at most one ``*``; ``exact`` is the address itself. + """ + + cird: str | None = None + wildcard: str | None = None + exact: str | None = None + + @classmethod + def from_rule(cls, value: object, name: str) -> Self: + tests = mapping(value, name) + return cls( + **{field: str(tests[field]) for field in ("cird", "wildcard", "exact") if tests.get(field) is not None} + ) + + def matches(self, address: str | None) -> bool: + if address is None: + return False + if self.cird is not None: + if address == self.cird: + return True + host, port = split_address(address) + try: + return match_address(self.cird, host, int(port) if port else None) + except ValueError: + _logger.warning( + "Cannot match %s with the address %r of an override rule; it does not match", + address, + self.cird, + exc_info=True, + ) + return False + if self.wildcard is not None: + return self.wildcard in _ANY_HOSTS or glob(self.wildcard, address) + return address == self.exact + + +@attrs.define(frozen=True, kw_only=True) +class _Match: + """The ``match`` of a config, which takes in what passes every test it sets.""" + + # The host on the side of the config, and the provider. + address: _AddressMatch | None + provider_address: _AddressMatch | None + # Each passes what one of its tests passes. + services: tuple[StringMatch, ...] | None + applications: tuple[StringMatch, ...] | None + params: tuple[ParamMatch, ...] + + @classmethod + def from_rule(cls, value: object) -> Self: + """Read ``address``, ``providerAddress``, ``service``, ``app`` or ``application``, and ``param``.""" + entry = mapping(value, "a match") + + def address(name: str) -> _AddressMatch | None: + return None if entry.get(name) is None else _AddressMatch.from_rule(entry[name], name) + + def oneof(name: str) -> tuple[StringMatch, ...] | None: + if entry.get(name) is None: + return None + return tuple(StringMatch.from_rule(item, name) for item in entries(mapping(entry[name], name), "oneof")) + + return cls( + address=address("address"), + provider_address=address("providerAddress"), + services=oneof("service"), + applications=oneof("app" if entry.get("app") is not None else "application"), + params=tuple(ParamMatch.from_rule(item) for item in entries(entry, "param")), + ) + + def matches(self, url: URL, host: str | None) -> bool: + parameters = url.parameters + application = parameters.get(APPLICATION_KEY) + return ( + (self.address is None or self.address.matches(host)) + and (self.provider_address is None or self.provider_address.matches(url.address)) + and (self.services is None or any(test.matches(url.service_key) for test in self.services)) + and (self.applications is None or any(test.matches(application) for test in self.applications)) + and all(param.matches(parameters) for param in self.params) + ) + + +@attrs.define(frozen=True, kw_only=True) +class _Override: + """Parameters for the URLs used at ``hosts`` of ``providers``, of ``services`` in ``applications``; an empty set matches any.""" + + hosts: frozenset[str] + # Each a host and a port, either None for any. + providers: frozenset[tuple[str | None, int | None]] + services: frozenset[str] + applications: frozenset[str] + match: _Match | None + parameters: Mapping[str, str] + + def applies(self, url: URL, host: str | None) -> bool: + """Return whether it applies to ``url``, a URL of a provider used at ``host``.""" + return ( + (not self.hosts or host in self.hosts) + and (not self.providers or any(_at(provider, url) for provider in self.providers)) + and (not self.services or url.service_key in self.services) + and (not self.applications or url.parameters.get(APPLICATION_KEY) in self.applications) + and (self.match is None or self.match.matches(url, host)) + ) + + +class Overrides(Resource): + """The override rules of one side of a service, which change the parameters of the URLs of its providers that side uses. + + ``url`` is the URL of a reference for ``consumer``, which calls with the + URLs of providers, and the URL a provider registers the service with for + ``provider``. The rules are in the configuration center the attribute + ``CONFIG_CENTER_URL`` of ``url`` names: ``{application}.configurators``, then + ``{interface}:{version}:{group}.configurators``, whose parameters win. + Their configs of ``side`` apply where their addresses and ``match`` take + in the host of ``url``. ``changed`` is called after they change. Without + a configuration center, they change nothing. + + The parameters take effect where the URLs are read: for consumers, those + each provider is called with, such as ``timeout`` and ``weight``, and + ``disabled`` or ``enabled``, but not those of the reference, such as + ``cluster``, ``retries`` and ``loadbalance``; for providers, what they + register, and so what consumers read from them, and the filters they + serve through, but not the settings of their protocols. + + Entering ``async with`` reads them, and closing stops following them. + """ + + def __init__(self, url: URL, side: Side, changed: Callable[[], None] = lambda: None) -> None: + application = url.parameters.get(APPLICATION_KEY) + self._url = url + # The keys of the rules, the one whose parameters win last. + self._keys = [*([application + _SUFFIX] if application else []), rule_key(url) + _SUFFIX] + center = cast(URL | None, url.attributes.get(CONFIG_CENTER_URL)) + self._rules = RuleWatch(center, partial(_parse_rule, side=side), changed) + self._stack = AsyncExitStack() + + def configure(self, urls: Sequence[URL]) -> list[URL]: + """Return ``urls``, URLs of providers, with the parameters of the overrides that apply to each.""" + rules = self._rules.rules + overrides = [override for key in self._keys for override in rules.get(key, ())] + if not overrides: + return list(urls) + + host = self._url.host + return [ + url.update_parameters( + { + name: value + for override in overrides + if override.applies(url, host) + for name, value in override.parameters.items() + } + ) + for url in urls + ] + + async def aclose(self) -> None: + await self._stack.aclose() + + async def __aenter__(self) -> Self: + async with AsyncExitStack() as stack: + await stack.enter_async_context(self._rules) + await self._rules.follow(*self._keys) + self._stack = stack.pop_all() + + return self + + +def _parse_rule(data: Mapping[str, object], side: Side) -> tuple[_Override, ...] | None: + """Return the overrides of ``side`` that ``data`` holds, those for particular hosts last, or ``None`` for none. + + A rule of scope ``application`` has the application as ``key`` and may + list ``services``; one of scope ``service`` has the service, as + ``group/interface:version``, and may list ``applications``. Each of its + ``configs`` gives ``parameters`` for ``side: consumer`` or ``provider``, + the ``addresses`` of the hosts on that side, the ``providerAddresses`` of + the providers, as ``host``, ``host:port``, ``[ipv6]:port`` or + ``0.0.0.0:port``, and a ``match`` that the URLs must also pass. + + Raises: + ValueError: ``data`` is not an override rule. + """ + key = data.get("key") + if not isinstance(key, str) or not key: + raise ValueError("an override rule needs a key") + + by_application = data.get("scope") == "application" + overrides = [] + for entry in entries(data, "configs"): + config = mapping(entry, "a config") + if config.get("side") != side or not flag(config, "enabled", True): + continue + + parameters = {name: str(value) for name, value in mapping(config.get("parameters") or {}, "parameters").items()} + if not parameters: + raise ValueError("a config of an override rule needs parameters") + listed = { + name: frozenset(str(item) for item in entries(config, name)) - {"*"} + for name in ("services", "applications") + } + hosts = frozenset(str(address) for address in entries(config, "addresses")) + overrides.append( + _Override( + hosts=frozenset() if hosts & _ANY_HOSTS else hosts, + providers=frozenset(_provider(str(address)) for address in entries(config, "providerAddresses")), + services=listed["services"] if by_application else frozenset({key}), + applications=frozenset({key}) if by_application else listed["applications"], + match=None if config.get("match") is None else _Match.from_rule(config["match"]), + parameters=parameters, + ) + ) + + if not overrides or not flag(data, "enabled", True): + return None + return tuple(sorted(overrides, key=lambda override: bool(override.hosts))) + + +def _provider(address: str) -> tuple[str | None, int | None]: + host, port = split_address(address) + return (None if host in _ANY_HOSTS else host), (None if port in (None, "*") else int(port)) + + +def _at(provider: tuple[str | None, int | None], url: URL) -> bool: + host, port = provider + return host in (None, url.host) and port in (None, url.port) diff --git a/src/dubbo/cluster/directories.py b/src/dubbo/cluster/directories.py deleted file mode 100644 index cb13a332..00000000 --- a/src/dubbo/cluster/directories.py +++ /dev/null @@ -1,66 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from dubbo.cluster import Directory -from dubbo.protocol import Invoker, Protocol -from dubbo.registry import NotifyListener, Registry -from dubbo.url import URL - - -class RegistryDirectory(Directory, NotifyListener): - """ - The registry directory. - """ - - def __init__(self, registry: Registry, protocol: Protocol, url: URL): - self._registry = registry - self._protocol = protocol - - self._url = url - - self._invokers: dict[str, Invoker] = {} - - # subscribe - self._registry.subscribe(url, self) - - def get_list(self, invocation) -> list[Invoker]: - return list(self._invokers.values()) - - def notify(self, urls: list[URL]) -> None: - old_invokers = self._invokers - self._invokers = {} - - # create new invokers - for url in urls: - k = str(url) - if k in old_invokers: - self._invokers[k] = old_invokers[k] - del old_invokers[k] - else: - self._invokers[k] = self._protocol.refer(url) - - # destroy old invokers - for invoker in old_invokers.values(): - invoker.destroy() - - def get_url(self) -> URL: - return self._url - - def is_available(self) -> bool: - return self._registry.is_available() - - def destroy(self) -> None: - self._registry.destroy() diff --git a/src/dubbo/cluster/directory/__init__.py b/src/dubbo/cluster/directory/__init__.py new file mode 100644 index 00000000..c0014989 --- /dev/null +++ b/src/dubbo/cluster/directory/__init__.py @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The providers a reference may call: the contract its cluster asks, and where the providers come from.""" + +from .base import Directory +from .dynamic import DynamicDirectory, Refer +from .static import StaticDirectory + +__all__ = ["Directory", "DynamicDirectory", "Refer", "StaticDirectory"] diff --git a/src/dubbo/cluster/directory/base.py b/src/dubbo/cluster/directory/base.py new file mode 100644 index 00000000..9d71e2dc --- /dev/null +++ b/src/dubbo/cluster/directory/base.py @@ -0,0 +1,43 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from collections.abc import Sequence + +from dubbo.extension import Resource +from dubbo.rpc.invocation import Invocation, Invoker + +__all__ = ["Directory"] + + +class Directory(Resource, typing.Protocol): + """The invokers of the providers a reference may call, which its cluster asks for on every attempt. + + It owns the invokers it holds: closing it closes them. + """ + + @property + def available(self) -> bool: + """Whether one of its invokers is available.""" + ... + + def candidates(self, invocation: Invocation) -> Sequence[Invoker]: + """Return the invokers ``invocation`` may go to now, possibly none. + + While they do not change, the same sequence object is returned. + """ + ... diff --git a/src/dubbo/cluster/directory/dynamic.py b/src/dubbo/cluster/directory/dynamic.py new file mode 100644 index 00000000..abe3c032 --- /dev/null +++ b/src/dubbo/cluster/directory/dynamic.py @@ -0,0 +1,158 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +from collections.abc import AsyncIterator, Awaitable, Callable, Sequence +from contextlib import AbstractAsyncContextManager, AsyncExitStack +from typing import Self + +import anyio +from anyio.abc import TaskGroup + +from dubbo.constants import GROUP_KEY, VERSION_KEY +from dubbo.extension import ExtensionError +from dubbo.rpc.invocation import Invocation, Invoker +from dubbo.url import PROVIDER_URL, URL +from dubbo.utils import create_background_task_group, follow, release_shield + +from ..router import Router, RouterChain +from .base import Directory + +__all__ = ["DynamicDirectory", "Refer"] + +_logger = logging.getLogger(__name__) + + +# Returns an invoker that calls the provider a URL names. +Refer = Callable[[URL], Awaitable[Invoker]] + +# The protocol, host, port, path, group and version that tell providers apart. +_Identity = tuple[str, str | None, int | None, str, str, str] + + +class DynamicDirectory(Directory): + """The invokers of the URLs ``subscribe()`` gives, each the URL to call a provider with, made by ``refer``. + + Providers are told apart by protocol, host, port, path, group and version; + the first URL of each is called, and a provider whose URL, and the URL it + published, ``PROVIDER_URL``, do not change keeps its invoker. Entering + ``async with`` waits for the first URLs, and fails if they cannot be had. + A subscription that fails or ends after them breaks its contract; that is + logged, the invokers are kept, and it is subscribed again after a delay. + + It owns ``routers``, which act as one ``RouterChain``: they open before + the first URLs, take each new set of invokers before calls see it, narrow + the candidates of each call in turn, and close with it. + """ + + def __init__( + self, + subscribe: Callable[[], AbstractAsyncContextManager[AsyncIterator[list[URL]]]], + refer: Refer, + name: str, + routers: Sequence[Router] = (), + ) -> None: + """``name`` tells, in logs, whose providers these are.""" + self._subscribe = subscribe + self._refer = refer + self._name = name + self._chain = RouterChain(routers) + self._invokers: dict[_Identity, Invoker] = {} + # The URL each invoker was referred with, which a protocol may have filled in for the invoker's own. + self._referred: dict[_Identity, URL] = {} + self._choices: tuple[Invoker, ...] = () + self._stack = AsyncExitStack() + # Set once entered; runs the subscription and the closing of gone providers. + self._task_group: TaskGroup + + @property + def available(self) -> bool: + return any(invoker.available for invoker in self._choices) + + def candidates(self, invocation: Invocation) -> Sequence[Invoker]: + return self._chain.route(self._choices, invocation) + + async def aclose(self) -> None: + await self._stack.aclose() + + async def __aenter__(self) -> Self: + async with AsyncExitStack() as stack: + await stack.enter_async_context(self._chain) + stack.push_async_callback(self._close_invokers) + task_group = self._task_group = await stack.enter_async_context(create_background_task_group()) + stack.callback(task_group.cancel_scope.cancel) + await task_group.start(follow, self._subscribe, self._update, f"the providers of {self._name}") + self._stack = stack.pop_all() + + return self + + async def _update(self, urls: list[URL]) -> None: + """Refer the providers of ``urls`` that are new or changed, close those that are gone, and tell the routers.""" + wanted: dict[_Identity, URL] = {} + for url in urls: + wanted.setdefault(_identity(url), url) + + invokers: dict[_Identity, Invoker] = {} + referred_with: dict[_Identity, URL] = {} + referred: list[Invoker] = [] + try: + for identity, url in wanted.items(): + invoker = self._invokers.get(identity) + if invoker is None or _changed(self._referred[identity], url): + try: + invoker = await self._refer(url) + except (ExtensionError, OSError, TypeError, ValueError): + _logger.warning( + "Cannot call the provider %s of %s; leaving it out", url, self._name, exc_info=True + ) + continue + referred.append(invoker) + invokers[identity] = invoker + referred_with[identity] = url + except BaseException: + # Invokers made for an update that does not happen belong to no one else; they have taken no calls. + with release_shield(): + async with anyio.create_task_group() as task_group: + for invoker in referred: + task_group.start_soon(invoker.aclose) + raise + + gone = [invoker for identity, invoker in self._invokers.items() if invokers.get(identity) is not invoker] + self._invokers, self._referred = invokers, referred_with + self._choices = tuple(invokers.values()) + # The invoker of a gone provider finishes its running calls without holding up the update. + for invoker in gone: + self._task_group.start_soon(invoker.aclose) + self._chain.notify(self._choices) + + async def _close_invokers(self) -> None: + invokers, self._invokers, self._referred, self._choices = self._invokers, {}, {}, () + try: + self._chain.notify(self._choices) + finally: + async with anyio.create_task_group() as task_group: + for invoker in invokers.values(): + task_group.start_soon(invoker.aclose) + + +def _identity(url: URL) -> _Identity: + parameters = url.parameters + return url.protocol, url.host, url.port, url.path, parameters.get(GROUP_KEY, ""), parameters.get(VERSION_KEY, "") + + +def _changed(current: URL, url: URL) -> bool: + return current != url or current.attributes.get(PROVIDER_URL) != url.attributes.get(PROVIDER_URL) diff --git a/src/dubbo/cluster/directory/static.py b/src/dubbo/cluster/directory/static.py new file mode 100644 index 00000000..52b8b54a --- /dev/null +++ b/src/dubbo/cluster/directory/static.py @@ -0,0 +1,58 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Sequence +from contextlib import AsyncExitStack +from typing import Self + +from dubbo.rpc.invocation import Invocation, Invoker + +from ..router import Router, RouterChain +from .base import Directory + +__all__ = ["StaticDirectory"] + + +class StaticDirectory(Directory): + """A fixed set of invokers, which closing it closes. + + It owns ``routers``, which act as one ``RouterChain``: entering ``async + with`` opens them and gives them the invokers, they narrow the + candidates of each call in turn, and they close first. + """ + + def __init__(self, invokers: Sequence[Invoker], routers: Sequence[Router] = ()) -> None: + self._invokers = tuple(invokers) + self._chain = RouterChain(routers) + + @property + def available(self) -> bool: + return any(invoker.available for invoker in self._invokers) + + def candidates(self, invocation: Invocation) -> Sequence[Invoker]: + return self._chain.route(self._invokers, invocation) + + async def aclose(self) -> None: + async with AsyncExitStack() as stack: + for invoker in self._invokers: + stack.push_async_callback(invoker.aclose) + stack.push_async_callback(self._chain.aclose) + + async def __aenter__(self) -> Self: + await self._chain.__aenter__() + self._chain.notify(self._invokers) + return self diff --git a/src/dubbo/cluster/failback.py b/src/dubbo/cluster/failback.py new file mode 100644 index 00000000..0ec4d114 --- /dev/null +++ b/src/dubbo/cluster/failback.py @@ -0,0 +1,133 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +from collections.abc import Sequence +from contextlib import AsyncExitStack +from typing import Self + +import anyio +from anyio.abc import TaskGroup + +from dubbo.constants import FAILBACK_TASKS_KEY, RETRIES_KEY +from dubbo.exceptions import RemoteError +from dubbo.rpc.definition import RpcType +from dubbo.rpc.invocation import Invocation, Invoker, Result +from dubbo.url import URL + +from .base import BaseCluster +from .directory import Directory + +__all__ = ["FailbackCluster"] + +_logger = logging.getLogger(__name__) + +_RETRIES = 3 +_TASKS = 100 +_RETRY_INTERVAL = 5.0 # Seconds. + + +class FailbackCluster(BaseCluster): + """Makes each call once and returns nothing instead of a failure, then makes the call again in the background. + + A unary call that fails other than with the error the method raised + returns ``None``, and is made again every 5 seconds, on another + candidate than the last when there is one, until it succeeds or has + been made ``retries`` more times, 3 by default. At most + ``failbacktasks`` calls, 100 by default, wait to be made again; beyond + them a failed call is dropped. Closing the cluster drops those waiting. + A streaming call returns how it opened. + + Raises: + ValueError: ``retries`` is negative or ``failbacktasks`` is not positive. + """ + + def __init__(self, url: URL, directory: Directory) -> None: + super().__init__(url, directory) + self._retries = url.get_parameter(RETRIES_KEY, int, _RETRIES) + self._tasks = url.get_parameter(FAILBACK_TASKS_KEY, int, _TASKS) + if self._retries < 0 or self._tasks <= 0: + raise ValueError(f"{RETRIES_KEY} must not be negative and {FAILBACK_TASKS_KEY} must be positive") + self._waiting = 0 + self._stack = AsyncExitStack() + # Set once entered; makes the failed calls again. + self._task_group: TaskGroup | None = None + + async def aclose(self) -> None: + try: + await self._stack.aclose() + finally: + await super().aclose() + + async def __aenter__(self) -> Self: + async with AsyncExitStack() as stack: + task_group = self._task_group = await stack.enter_async_context(anyio.create_task_group()) + stack.callback(task_group.cancel_scope.cancel) + self._stack = stack.pop_all() + + return self + + async def _invoke(self, invocation: Invocation, invokers: Sequence[Invoker]) -> Result: + invoker = self._select(invokers, invocation) + result = await invoker.invoke(invocation) + if not _failed(result) or invocation.definition.rpc_type is not RpcType.UNARY: + return result + + if self._task_group is None: + raise RuntimeError("the failback cluster is not open") + if not self._retries: + _logger.warning("A call of %s.%s failed; it returns None", *_name(invocation), exc_info=result.error) + elif self._waiting >= self._tasks: + _logger.error( + "A call of %s.%s failed while %d others wait to be made again; it returns None and is dropped", + *_name(invocation), + self._waiting, + exc_info=result.error, + ) + else: + _logger.warning( + "A call of %s.%s failed; it returns None and is made again in the background", + *_name(invocation), + exc_info=result.error, + ) + self._waiting += 1 + self._task_group.start_soon(self._retry, invocation, invoker) + return Result() + + async def _retry(self, invocation: Invocation, last: Invoker) -> None: + try: + for _ in range(self._retries): + await anyio.sleep(_RETRY_INTERVAL) + invokers = self.directory.candidates(invocation) + if not invokers: + continue + last = self._select([invoker for invoker in invokers if invoker is not last] or invokers, invocation) + if not _failed(await last.invoke(invocation)): + return + _logger.error("A call of %s.%s failed %d more times; it is dropped", *_name(invocation), self._retries) + except Exception: + _logger.exception("A call of %s.%s failed to be made again; it is dropped", *_name(invocation)) + finally: + self._waiting -= 1 + + +def _failed(result: Result) -> bool: + return result.error is not None and not isinstance(result.error, RemoteError) + + +def _name(invocation: Invocation) -> tuple[str, str]: + return invocation.interface, invocation.method diff --git a/src/dubbo/cluster/failfast.py b/src/dubbo/cluster/failfast.py new file mode 100644 index 00000000..8528bd05 --- /dev/null +++ b/src/dubbo/cluster/failfast.py @@ -0,0 +1,31 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Sequence + +from dubbo.rpc.invocation import Invocation, Invoker, Result + +from .base import BaseCluster + +__all__ = ["FailfastCluster"] + + +class FailfastCluster(BaseCluster): + """Makes each call once, on the invoker the load balance chooses, and returns how it ended.""" + + async def _invoke(self, invocation: Invocation, invokers: Sequence[Invoker]) -> Result: + return await self._select(invokers, invocation).invoke(invocation) diff --git a/src/dubbo/cluster/failfast_cluster.py b/src/dubbo/cluster/failfast_cluster.py deleted file mode 100644 index 85ed01ef..00000000 --- a/src/dubbo/cluster/failfast_cluster.py +++ /dev/null @@ -1,70 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from dubbo.cluster import Cluster, Directory, LoadBalance -from dubbo.cluster.loadbalances import CpuLoadBalance -from dubbo.constants import common_constants -from dubbo.extension import extensionLoader -from dubbo.protocol import Invoker, Result -from dubbo.protocol.triple.exceptions import RpcError -from dubbo.url import URL - - -class FailfastInvoker(Invoker): - """ - FailfastInvoker - """ - - def __init__(self, directory, url: URL): - self._directory = directory - - self._load_balance = extensionLoader.get_extension( - LoadBalance, url.parameters.get(common_constants.LOADBALANCE_KEY, "random") - )() - - if isinstance(self._load_balance, CpuLoadBalance): - self._load_balance.set_monitor(directory) - - def invoke(self, invocation) -> Result: - # get the invokers - invokers = self._directory.get_list(invocation) - if not invokers: - raise RpcError("No provider available for the service") - - # select the invoker - invoker = self._load_balance.select(invokers, invocation) - - # invoke the invoker - return invoker.invoke(invocation) - - def get_url(self) -> URL: - return self._directory.get_url() - - def is_available(self) -> bool: - return self._directory.is_available() - - def destroy(self): - self._directory.destroy() - - -class FailfastCluster(Cluster): - """ - Execute exactly once, which means this policy will throw an exception immediately in case of an invocation error. - Usually used for non-idempotent write operations - """ - - def join(self, directory: Directory) -> Invoker: - return FailfastInvoker(directory, directory.get_url()) diff --git a/src/dubbo/cluster/failover.py b/src/dubbo/cluster/failover.py new file mode 100644 index 00000000..cf34e07c --- /dev/null +++ b/src/dubbo/cluster/failover.py @@ -0,0 +1,76 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Sequence + +from dubbo.constants import DEFAULT_RETRIES, RETRIES_KEY +from dubbo.exceptions import RemoteError, RpcError, Status +from dubbo.rpc.definition import RpcType +from dubbo.rpc.invocation import Invocation, Invoker, Result +from dubbo.url import URL + +from .base import BaseCluster +from .directory import Directory + +__all__ = ["FailoverCluster"] + + +class FailoverCluster(BaseCluster): + """Retries a unary call that fails with ``UNAVAILABLE`` on a provider it has not tried, while any remains. + + A call makes at most ``{method}.retries``, else ``retries``, else 2 + attempts after the first. A streaming call makes one attempt. Each + retry asks the directory for the candidates again; when none is left, + the call ends with the last failure. + """ + + def __init__(self, url: URL, directory: Directory) -> None: + super().__init__(url, directory) + self._attempts = url.get_parameter(RETRIES_KEY, int, DEFAULT_RETRIES) + 1 + self._method_attempts = { + method: retries + 1 for method, retries in url.get_method_parameters(RETRIES_KEY, int).items() + } + + async def _invoke(self, invocation: Invocation, invokers: Sequence[Invoker]) -> Result: + attempts = self._get_attempts(invocation) + tried: list[Invoker] = [] + candidates = invokers + while True: + invoker = self._select(candidates, invocation) + result = await invoker.invoke(invocation) + attempts -= 1 + if attempts <= 0 or not _retryable(result): + return result + + tried.append(invoker) + invokers = self.directory.candidates(invocation) + if not invokers: + return result + + candidates = tuple(other for other in invokers if other not in tried) or invokers + + def _get_attempts(self, invocation: Invocation) -> int: + if invocation.definition.rpc_type is not RpcType.UNARY: + return 1 + + return self._method_attempts.get(invocation.method, self._attempts) + + +def _retryable(result: Result) -> bool: + # A RemoteError is the answer of the method, which a retry would run again. + error = result.error + return isinstance(error, RpcError) and not isinstance(error, RemoteError) and error.status is Status.UNAVAILABLE diff --git a/src/dubbo/cluster/failsafe.py b/src/dubbo/cluster/failsafe.py new file mode 100644 index 00000000..550a16b2 --- /dev/null +++ b/src/dubbo/cluster/failsafe.py @@ -0,0 +1,49 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +from collections.abc import Sequence + +from dubbo.rpc.definition import RpcType +from dubbo.rpc.invocation import Invocation, Invoker, Result + +from .base import BaseCluster + +__all__ = ["FailsafeCluster"] + +_logger = logging.getLogger(__name__) + + +class FailsafeCluster(BaseCluster): + """Makes each call once, on the invoker the load balance chooses, and returns nothing instead of a failure. + + A unary call that fails, whatever the failure, is logged and returns + ``None``. A streaming call returns how it opened. + """ + + async def _invoke(self, invocation: Invocation, invokers: Sequence[Invoker]) -> Result: + result = await self._select(invokers, invocation).invoke(invocation) + if result.error is None or invocation.definition.rpc_type is not RpcType.UNARY: + return result + + _logger.warning( + "A call of %s.%s failed; it returns None instead", + invocation.interface, + invocation.method, + exc_info=result.error, + ) + return Result() diff --git a/src/dubbo/cluster/forking.py b/src/dubbo/cluster/forking.py new file mode 100644 index 00000000..90136cf5 --- /dev/null +++ b/src/dubbo/cluster/forking.py @@ -0,0 +1,87 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Sequence + +import anyio + +from dubbo.constants import DEFAULT_FORKS, FORKS_KEY +from dubbo.exceptions import RemoteError +from dubbo.rpc.definition import RpcType +from dubbo.rpc.invocation import Invocation, Invoker, Result +from dubbo.url import URL + +from .base import BaseCluster, available_invokers +from .directory import Directory + +__all__ = ["ForkingCluster"] + + +class ForkingCluster(BaseCluster): + """Makes a unary call on several invokers at once and returns the first answer, cancelling the other calls. + + It calls ``forks`` invokers, 2 by default, that the load balance chooses + one after another, or all the available ones when ``forks`` is not below + their number or not positive. An answer is a result without an error or + with the error the method raised; when none answers, the call ends with + the last failure. A streaming call is made once, on the invoker the load + balance chooses. + """ + + def __init__(self, url: URL, directory: Directory) -> None: + super().__init__(url, directory) + self._forks = url.get_parameter(FORKS_KEY, int, DEFAULT_FORKS) + + async def _invoke(self, invocation: Invocation, invokers: Sequence[Invoker]) -> Result: + if invocation.definition.rpc_type is not RpcType.UNARY: + return await self._select(invokers, invocation).invoke(invocation) + + chosen = self._choose(invokers, invocation) + if len(chosen) == 1: + return await chosen[0].invoke(invocation) + + results: list[Result] = [] + async with anyio.create_task_group() as task_group: + + async def call(invoker: Invoker) -> None: + result = await invoker.invoke(invocation) + results.append(result) + if _answered(result): + task_group.cancel_scope.cancel() + + for invoker in chosen: + task_group.start_soon(call, invoker) + + answers = [result for result in results if _answered(result)] + return answers[0] if answers else results[-1] + + def _choose(self, invokers: Sequence[Invoker], invocation: Invocation) -> Sequence[Invoker]: + if not 0 < self._forks < len(invokers): + return available_invokers(invokers) + + chosen: list[Invoker] = [] + remaining = invokers + while len(chosen) < self._forks: + invoker = self._select(remaining, invocation) + chosen.append(invoker) + # A new sequence, since a load balance may keep what it derived from one by identity. + remaining = tuple(other for other in remaining if other is not invoker) + return chosen + + +def _answered(result: Result) -> bool: + return result.error is None or isinstance(result.error, RemoteError) diff --git a/src/dubbo/cluster/loadbalance/__init__.py b/src/dubbo/cluster/loadbalance/__init__.py new file mode 100644 index 00000000..c1a80153 --- /dev/null +++ b/src/dubbo/cluster/loadbalance/__init__.py @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .base import LoadBalance + +__all__ = ["LoadBalance"] diff --git a/src/dubbo/cluster/loadbalance/base.py b/src/dubbo/cluster/loadbalance/base.py new file mode 100644 index 00000000..655af647 --- /dev/null +++ b/src/dubbo/cluster/loadbalance/base.py @@ -0,0 +1,162 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +import time +import typing +from collections.abc import Callable, Sequence +from typing import Generic, TypeVar + +from dubbo.constants import DEFAULT_WARMUP, DEFAULT_WEIGHT, TIMESTAMP_KEY, WARMUP_KEY, WEIGHT_KEY +from dubbo.extension import extension_point +from dubbo.rpc.invocation import Invocation, Invoker +from dubbo.url import URL +from dubbo.utils.converters import milliseconds + +__all__ = ["LoadBalance", "PerSequence", "Weights"] + +_logger = logging.getLogger(__name__) + +# The sequences of invokers kept for each method. +_SEQUENCES = 4 + +T = TypeVar("T") + + +# The weight a provider sets for a method, when it registered in seconds since the epoch, and its warmup in seconds. +_Settings = tuple[int, float, float] + + +@extension_point("apache_dubbo.loadbalance") +class LoadBalance(typing.Protocol): + """Chooses the provider an attempt of a call goes to. + + Implement ``__init__(url)`` and ``select``, and install the class under + the entry point group ``apache_dubbo.loadbalance``; ``loadbalance`` and + ``{method}.loadbalance`` name it, ``random`` by default. A cluster + creates one with the URL of the reference, and one more for each method + that names its own, and calls ``select`` on every attempt, in the event + loop, for many calls at once. ``invokers`` stays the same object while + the providers and their routes do not change, so what is derived from + it may be kept by identity, as `PerSequence` keeps it. It holds nothing + and is never closed. + """ + + def __init__(self, url: URL) -> None: ... + + def select(self, invokers: Sequence[Invoker], invocation: Invocation) -> Invoker: + """Return one of ``invokers``, which holds at least one, for ``invocation``; it neither blocks nor raises.""" + ... + + +class PerSequence(Generic[T]): + """What a load balance derives from each sequence of invokers it chooses among, for a method, for the last few used. + + Routing can offer the invokers of each call as one of a few sequences, + each the same object while the providers do not change, so one is kept + for each of the last 4 sequences used with a method. A sequence is told + apart by identity and held while kept, so that its id is not reused. + """ + + def __init__(self, derive: Callable[[Sequence[Invoker], str], T]) -> None: + """``derive`` returns what to keep for a sequence and a method.""" + self._derive = derive + # By method, then by the id of the sequence, the least recently used first: the sequence and what it gave. + self._kept: dict[str, dict[int, tuple[Sequence[Invoker], T]]] = {} + + def get(self, invokers: Sequence[Invoker], method: str) -> T: + """Return what is kept for ``invokers`` and ``method``, derived on first use.""" + kept = self._kept.get(method) + if kept is None: + kept = self._kept[method] = {} + + key = id(invokers) + entry = kept.pop(key, None) + if entry is None: + if len(kept) >= _SEQUENCES: + del kept[next(iter(kept))] + entry = (invokers, self._derive(invokers, method)) + kept[key] = entry + return entry[1] + + +class Weights: + """The weights of the providers a load balance chooses among, for each method. + + The weight of a provider for a method is the parameter ``{method}.weight`` + of its URL, else ``weight``, else 100; an invalid one counts as 100. A + provider that registered, by its ``timestamp``, less than ``warmup`` ago, + 10 minutes by default, weighs in proportion to the time since, and at + least 1. The settings are read once for each sequence of invokers a + `PerSequence` keeps; the weights, too, and while one warms up; until + then the same list is returned. + """ + + def __init__(self) -> None: + self._weighed = PerSequence(_weighed) + + def get(self, invokers: Sequence[Invoker], method: str) -> list[int]: + """Return the weight of each of ``invokers`` for ``method``, in order.""" + return self._weighed.get(invokers, method).weights() + + +class _Weighed: + """The weights of one sequence of providers for a method, from the settings each of them sets.""" + + def __init__(self, settings: list[_Settings]) -> None: + self._settings = settings + # None while one warms up. + self._weights: list[int] | None = None + + def weights(self) -> list[int]: + if self._weights is not None: + return self._weights + + now = time.time() + computed = [_weight(settings, now) for settings in self._settings] + weights = [weight for weight, _ in computed] + if not any(warming for _, warming in computed): + self._weights = weights + return weights + + +def _weighed(invokers: Sequence[Invoker], method: str) -> _Weighed: + return _Weighed([_settings(invoker.url, method) for invoker in invokers]) + + +def _settings(url: URL, method: str) -> _Settings: + """Return the weight, registration time and warmup the provider at ``url`` sets for ``method``.""" + try: + default = url.get_parameter(WEIGHT_KEY, int, DEFAULT_WEIGHT) + weight = max(url.get_parameter(f"{method}.{WEIGHT_KEY}", int, default), 0) + registered = url.get_parameter(TIMESTAMP_KEY, int, 0) / 1000 + warmup = url.get_parameter(WARMUP_KEY, milliseconds, DEFAULT_WARMUP) + except ValueError: + _logger.warning("Provider %s has an invalid weight, timestamp or warmup; it weighs %d", url, DEFAULT_WEIGHT) + return DEFAULT_WEIGHT, 0, 0 + + return weight, registered, warmup + + +def _weight(settings: _Settings, now: float) -> tuple[int, bool]: + """Return the weight of a provider with ``settings`` at ``now``, and whether it still warms up.""" + weight, registered, warmup = settings + uptime = now - registered + if weight == 0 or registered <= 0 or warmup == 0 or uptime >= warmup: + return weight, False + # A clock behind that of the provider counts it as just registered. + return max(1, min(weight, int(max(uptime, 0) / warmup * weight))), True diff --git a/src/dubbo/cluster/loadbalance/consistenthash.py b/src/dubbo/cluster/loadbalance/consistenthash.py new file mode 100644 index 00000000..6629956b --- /dev/null +++ b/src/dubbo/cluster/loadbalance/consistenthash.py @@ -0,0 +1,106 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import bisect +import hashlib +from collections.abc import Sequence + +from dubbo.constants import HASH_ARGUMENTS_KEY, HASH_NODES_KEY +from dubbo.rpc.invocation import Invocation, Invoker +from dubbo.url import URL +from dubbo.utils.converters import to_text + +from .base import LoadBalance, PerSequence + +__all__ = ["ConsistentHashLoadBalance"] + +_NODES = 160 +_ARGUMENTS = (0,) + + +class ConsistentHashLoadBalance(LoadBalance): + """Chooses the provider that the arguments of a call hash to, so that equal arguments go to the same provider. + + It is ketama consistent hashing over a ring of 32-bit points. Each + provider owns ``{method}.hash.nodes``, else ``hash.nodes``, else 160 + points: for ``i`` from 0 up to a quarter of them, the MD5 digest of its + address followed by ``i``, as in ``10.0.0.1:20880`` and ``0``, read as + four little-endian integers; of two providers on one point, the later + keeps it. A call goes to the owner of the first point at or after the + first such integer of the MD5 digest of its key, wrapping around. The + key is the arguments at the indexes ``{method}.hash.arguments``, else + ``hash.arguments``, else ``0``, separated by commas, as text one after + the other, ``None`` as ``null`` and booleans as ``true`` and ``false``; + an index beyond the arguments adds nothing. Weights play no part. A ring + is built for each sequence of invokers a `PerSequence` keeps. + + Raises: + ValueError: ``hash.nodes`` is below 4, or ``hash.arguments`` holds + something other than integers. + """ + + def __init__(self, url: URL) -> None: + self._nodes = url.get_parameter(HASH_NODES_KEY, int, _NODES) + self._method_nodes = url.get_method_parameters(HASH_NODES_KEY, int) + if min([self._nodes, *self._method_nodes.values()]) < 4: + raise ValueError(f"{HASH_NODES_KEY} must be at least 4") + self._arguments = url.get_parameter(HASH_ARGUMENTS_KEY, _indexes, _ARGUMENTS) + self._method_arguments = url.get_method_parameters(HASH_ARGUMENTS_KEY, _indexes) + self._rings = PerSequence(lambda invokers, method: _Ring(invokers, self._method_nodes.get(method, self._nodes))) + + def select(self, invokers: Sequence[Invoker], invocation: Invocation) -> Invoker: + if len(invokers) == 1: + return invokers[0] + + method = invocation.method + arguments = invocation.arguments + indexes = self._method_arguments.get(method, self._arguments) + key = "".join(to_text(arguments[index]) for index in indexes if 0 <= index < len(arguments)) + return self._rings.get(invokers, method).get(key) + + +class _Ring: + """The points of the providers on the ring, in order, and the owner of each.""" + + def __init__(self, invokers: Sequence[Invoker], nodes: int) -> None: + owners: dict[int, Invoker] = {} + for invoker in invokers: + address = invoker.url.address + for index in range(nodes // 4): + digest = _md5(f"{address}{index}") + for number in range(4): + owners[_point(digest, number)] = invoker + + self._points = sorted(owners) + self._owners = [owners[point] for point in self._points] + + def get(self, key: str) -> Invoker: + """Return the owner of the first point at or after the point of ``key``, wrapping around.""" + index = bisect.bisect_left(self._points, _point(_md5(key), 0)) + return self._owners[index % len(self._points)] + + +def _md5(text: str) -> bytes: + return hashlib.md5(text.encode(), usedforsecurity=False).digest() + + +def _point(digest: bytes, number: int) -> int: + return int.from_bytes(digest[number * 4 : number * 4 + 4], "little") + + +def _indexes(value: str) -> tuple[int, ...]: + return tuple(int(index) for index in value.split(",")) diff --git a/src/dubbo/cluster/loadbalance/leastactive.py b/src/dubbo/cluster/loadbalance/leastactive.py new file mode 100644 index 00000000..3fd3c3b7 --- /dev/null +++ b/src/dubbo/cluster/loadbalance/leastactive.py @@ -0,0 +1,71 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import random +from collections.abc import Sequence + +from dubbo.filter.activecount import active_counts +from dubbo.rpc.invocation import Invocation, Invoker +from dubbo.url import URL + +from .base import LoadBalance, Weights + +__all__ = ["LeastActiveLoadBalance"] + + +class LeastActiveLoadBalance(LoadBalance): + """Chooses the provider with the fewest calls of the method under way, among those tied at random by weight. + + The weights are those of ``Weights``; a provider of weight 0 is never + chosen, unless all weigh 0, when they weigh the same. The calls under + way are those the application makes, in the ``ActiveCounts`` of its + scope, which the filter of each attempt on a provider counts while this + load balance is set. + + Raises: + RuntimeError: No application made the URL of the reference. + """ + + def __init__(self, url: URL) -> None: + self._counts = active_counts(url) + self._weights = Weights() + + def select(self, invokers: Sequence[Invoker], invocation: Invocation) -> Invoker: + if len(invokers) == 1: + return invokers[0] + + method = invocation.method + weights = self._weights.get(invokers, method) + if not any(weights): + weights = [1] * len(invokers) + + least: list[Invoker] = [] + least_weights: list[int] = [] + least_active = 0 + for invoker, weight in zip(invokers, weights, strict=True): + if not weight: + continue + active = self._counts.get(invoker.url, method) + if not least or active < least_active: + least, least_weights, least_active = [invoker], [weight], active + elif active == least_active: + least.append(invoker) + least_weights.append(weight) + + if len(least) == 1: + return least[0] + return random.choices(least, weights=least_weights)[0] diff --git a/src/dubbo/cluster/loadbalance/random.py b/src/dubbo/cluster/loadbalance/random.py new file mode 100644 index 00000000..bbef510b --- /dev/null +++ b/src/dubbo/cluster/loadbalance/random.py @@ -0,0 +1,63 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import itertools +import random +from collections.abc import Sequence + +from dubbo.rpc.invocation import Invocation, Invoker +from dubbo.url import URL + +from .base import LoadBalance, Weights + +__all__ = ["RandomLoadBalance"] + + +class RandomLoadBalance(LoadBalance): + """Chooses a provider at random, in proportion to its weight. + + The weights are those of ``Weights``. When all invokers weigh the same, + or all weigh 0, each is equally likely. + """ + + def __init__(self, url: URL) -> None: + self._weights = Weights() + # By method: the weights the running totals were computed from, and the totals, None when all are equal. + self._cum_weights: dict[str, tuple[list[int], list[int] | None]] = {} + + def select(self, invokers: Sequence[Invoker], invocation: Invocation) -> Invoker: + if len(invokers) == 1: + return invokers[0] + + method = invocation.method + weights = self._weights.get(invokers, method) + weighed, cum_weights = self._cum_weights.get(method, (None, None)) + if weights is not weighed: + cum_weights = _cum_weights(weights) + self._cum_weights[method] = (weights, cum_weights) + + if cum_weights is None: + return random.choice(invokers) + + return random.choices(invokers, cum_weights=cum_weights)[0] + + +def _cum_weights(weights: list[int]) -> list[int] | None: + if len(set(weights)) == 1: + return None + + return list(itertools.accumulate(weights)) diff --git a/src/dubbo/cluster/loadbalance/roundrobin.py b/src/dubbo/cluster/loadbalance/roundrobin.py new file mode 100644 index 00000000..7a06211d --- /dev/null +++ b/src/dubbo/cluster/loadbalance/roundrobin.py @@ -0,0 +1,85 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Sequence + +from dubbo.rpc.invocation import Invocation, Invoker +from dubbo.url import URL + +from .base import LoadBalance, PerSequence, Weights + +__all__ = ["RoundRobinLoadBalance"] + + +class RoundRobinLoadBalance(LoadBalance): + """Chooses the providers in turn, each as often as its weight, spread out as evenly as they can be. + + It is the smooth weighted round robin of nginx: on each call every + provider gains its weight, the one with the most is chosen, and it loses + the total of the weights. Providers of weights 5, 1 and 1 are chosen in + the order a, a, b, a, c, a, a. The weights are those of ``Weights``; a + provider of weight 0 is never chosen, unless all weigh 0, when they take + turns. Each sequence of invokers a `PerSequence` keeps takes turns of + its own, so that each of the sets of providers routing alternates + between is spread evenly. A new sequence starts from the turns of the + one started before it, so that a provider keeps its place while the + invokers change, and starts at none when it joins them. + """ + + def __init__(self, url: URL) -> None: + self._weights = Weights() + # What each invoker of a sequence has gained. + self._gains = PerSequence(self._start) + # By method: the sequence started last, and its gains. + self._last: dict[str, tuple[Sequence[Invoker], list[int]]] = {} + + def select(self, invokers: Sequence[Invoker], invocation: Invocation) -> Invoker: + if len(invokers) == 1: + return invokers[0] + + method = invocation.method + weights = self._weights.get(invokers, method) + gains = self._gains.get(invokers, method) + chosen = _take_turn(gains, weights) + if chosen < 0: + chosen = _take_turn(gains, [1] * len(gains)) + return invokers[chosen] + + def _start(self, invokers: Sequence[Invoker], method: str) -> list[int]: + """Return the gains of ``invokers``, those of the sequence started last for the invokers it holds.""" + last, gains = self._last.get(method, ((), [])) + # By identity, since invokers need not be hashable. + kept = {id(invoker): gain for invoker, gain in zip(last, gains, strict=True)} + gains = [kept.get(id(invoker), 0) for invoker in invokers] + self._last[method] = (invokers, gains) + return gains + + +def _take_turn(gains: list[int], weights: list[int]) -> int: + """Add ``weights`` to ``gains``, take their total from the greatest, and return its index, or -1 if all weigh 0.""" + chosen = -1 + total = 0 + for index, weight in enumerate(weights): + if weight: + gains[index] += weight + total += weight + if chosen < 0 or gains[index] > gains[chosen]: + chosen = index + + if chosen >= 0: + gains[chosen] -= total + return chosen diff --git a/src/dubbo/cluster/loadbalances.py b/src/dubbo/cluster/loadbalances.py deleted file mode 100644 index 850d2272..00000000 --- a/src/dubbo/cluster/loadbalances.py +++ /dev/null @@ -1,101 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import abc -import random -from typing import Optional - -from dubbo.cluster import LoadBalance -from dubbo.cluster.monitor.cpu import CpuMonitor -from dubbo.protocol import Invocation, Invoker - - -class AbstractLoadBalance(LoadBalance, abc.ABC): - """ - The abstract load balance. - """ - - def select(self, invokers: list[Invoker], invocation: Invocation) -> Optional[Invoker]: - if not invokers: - return None - - if len(invokers) == 1: - return invokers[0] - - return self.do_select(invokers, invocation) - - @abc.abstractmethod - def do_select(self, invokers: list[Invoker], invocation: Invocation) -> Optional[Invoker]: - """ - Do select an invoker from the list. - :param invokers: The invokers. - :type invokers: List[Invoker] - :param invocation: The invocation. - :type invocation: Invocation - :return: The selected invoker. If no invoker is selected, return None. - :rtype: Optional[Invoker] - """ - raise NotImplementedError() - - -class RandomLoadBalance(AbstractLoadBalance): - """ - Random load balance. - """ - - def do_select(self, invokers: list[Invoker], invocation: Invocation) -> Optional[Invoker]: - randint = random.randint(0, len(invokers) - 1) - return invokers[randint] - - -class CpuLoadBalance(AbstractLoadBalance): - """ - CPU load balance. - """ - - def __init__(self): - self._monitor: Optional[CpuMonitor] = None - - def set_monitor(self, monitor: CpuMonitor) -> None: - """ - Set the CPU monitor. - :param monitor: The CPU monitor. - :type monitor: CpuMonitor - """ - self._monitor = monitor - - def do_select(self, invokers: list[Invoker], invocation: Invocation) -> Optional[Invoker]: - # get the CPU usage - cpu_usages = self._monitor.get_cpu_usage(invokers) - # Select the caller with the lowest CPU usage, 0 means CPU usage is unknown. - available_invokers = [] - unknown_invokers = [] - - for invoker, cpu_usage in cpu_usages.items(): - if cpu_usage == 0: - unknown_invokers.append((cpu_usage, invoker)) - else: - available_invokers.append((cpu_usage, invoker)) - - if available_invokers: - # sort and select the invoker with the lowest CPU usage - available_invokers.sort(key=lambda x: x[0]) - return available_invokers[0][1] - elif unknown_invokers: - # get the invoker with unknown CPU usage randomly - randint = random.randint(0, len(unknown_invokers) - 1) - return unknown_invokers[randint][1] - else: - return None diff --git a/src/dubbo/cluster/monitor/__init__.py b/src/dubbo/cluster/monitor/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/src/dubbo/cluster/monitor/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/src/dubbo/cluster/monitor/cpu.py b/src/dubbo/cluster/monitor/cpu.py deleted file mode 100644 index 4df5d516..00000000 --- a/src/dubbo/cluster/monitor/cpu.py +++ /dev/null @@ -1,165 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import threading - -from dubbo.cluster.directories import RegistryDirectory -from dubbo.loggers import loggerFactory -from dubbo.protocol import Invoker, Protocol -from dubbo.protocol.invocation import RpcInvocation -from dubbo.proxy.handlers import RpcMethodHandler, RpcServiceHandler -from dubbo.registry import Registry -from dubbo.url import URL -from dubbo.utils import CpuUtils - -_LOGGER = loggerFactory.get_logger() - -_cpu_invocation = RpcInvocation( - "org.apache.dubbo.MetricsService", - "cpu", - str(1).encode("utf-8"), -) - - -class CpuMonitor(RegistryDirectory): - """ - The CPU monitor. - """ - - def __init__(self, registry: Registry, protocol: Protocol, url: URL): - super().__init__(registry, protocol, url) - - # interval - self._interval = 5 - - # about CPU usage - self._usages_lock = threading.Lock() - self._cpu_usages: dict[Invoker, float] = {} - - # running invokers - self._running_invokers: dict[str, Invoker] = {} - - # thread - self._started = False - self._thread: threading.Thread = threading.Thread(target=self._monitor_cpu, daemon=True) - self._stop_event: threading.Event = threading.Event() - - # start the monitor - self.start() - - def start(self) -> None: - """ - Start the monitor. - """ - if self._stop_event.is_set(): - raise RuntimeError("The monitor has been stopped.") - elif self._started: - return - - self._started = True - self._thread.start() - _LOGGER.info("The CPU monitor has been started.") - - def stop(self) -> None: - """ - Stop the monitor. - """ - if self._stop_event.is_set(): - return - # notify the thread to stop - self._stop_event.set() - - def _monitor_cpu(self) -> None: - """ - Monitor the CPU usage. - """ - while True: - # get available invokers - available_invokers = {url: invoker for url, invoker in self._invokers.items() if invoker.is_available()} - - # update the running invokers - self._running_invokers = available_invokers - - # update the CPU usage - with self._usages_lock: - self._cpu_usages = { - invoker: usage - for invoker, usage in self._cpu_usages.items() - if invoker in available_invokers.values() - } - - # get the CPU usage for each invoker - for url, invoker in self._running_invokers.items(): - if invoker.is_available(): - try: - result = invoker.invoke(_cpu_invocation) - cpu_usage = float(result.value().decode("utf-8")) - self._cpu_usages[invoker] = cpu_usage - except Exception: - _LOGGER.error("Failed to get the CPU usage for invoker %s: %s", url, str) - # remove the cpu usage - self._remove_cpu_usage(invoker) - - # wait for the interval or stop - if self._stop_event.wait(self._interval): - _LOGGER.info("The CPU monitor has been stopped.") - break - - def get_cpu_usage(self, invokers: list[Invoker]) -> dict[Invoker, float]: - """ - Get the CPU usage for the invoker. - :param invokers: The invokers. - :type invokers: List[Invoker] - :return: The CPU usage. - :rtype: Dict[Invoker, float] - """ - with self._usages_lock: - return {invoker: self._cpu_usages.get(invoker, 0) for invoker in invokers} - - def _remove_cpu_usage(self, invoker: Invoker) -> None: - with self._usages_lock: - self._cpu_usages.pop(invoker) - - -class CpuInnerRpcHandler: - """ - The CPU inner RPC handler. - """ - - @staticmethod - def get_service_handler() -> RpcServiceHandler: - """ - Get the service handler. - :return: The service handler. - :rtype: RpcServiceHandler - """ - return RpcServiceHandler( - "org.apache.dubbo.MetricsService", - [ - RpcMethodHandler.unary(CpuInnerRpcHandler.get_cpu_usage, method_name="cpu"), - ], - ) - - @staticmethod - def get_cpu_usage(interval) -> bytes: - """ - Get the CPU usage. - :param interval: The interval. - :type interval: bytes - :return: The CPU usage. - :rtype: bytes - """ - float_value = CpuUtils.get_total_cpu_usage(interval=int(interval.decode("utf-8"))) - return str(float_value).encode("utf-8") diff --git a/src/dubbo/cluster/reference.py b/src/dubbo/cluster/reference.py new file mode 100644 index 00000000..591125f1 --- /dev/null +++ b/src/dubbo/cluster/reference.py @@ -0,0 +1,198 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""How a reference calls its providers: those it names, and those its registries hold.""" + +from collections.abc import AsyncGenerator, Sequence +from contextlib import AsyncExitStack, aclosing, asynccontextmanager +from functools import partial + +from dubbo.cluster import DynamicDirectory, StaticDirectory, create_cluster, create_routers +from dubbo.config import RegistryMode +from dubbo.constants import ( + CLUSTER_KEY, + DEFAULT_ROUTERS, + GROUP_KEY, + PREFERRED_KEY, + PROVIDED_BY_KEY, + REFERENCE_FILTER_KEY, + REGISTRY_PREFERRED_KEY, + REGISTRY_ZONE_KEY, + ROUTER_KEY, + VERSION_KEY, + WEIGHT_KEY, + ZONE_AWARE_CLUSTER, + ZONE_KEY, +) +from dubbo.extension import ApplicationScope +from dubbo.filter import chain_filters, get_attempt_filters, get_filters +from dubbo.protocol import get_protocol +from dubbo.registry import registry_mode +from dubbo.registry.consumer import Consumer, register_consumer +from dubbo.registry.discovery import subscribe_by_instance, subscribe_by_interface +from dubbo.registry.registration import registered_host +from dubbo.rpc.definition import Service +from dubbo.rpc.invocation import Invoker +from dubbo.url import URL +from dubbo.utils.converters import boolean, comma_separated + +__all__ = ["refer"] + + +@asynccontextmanager +async def refer( + url: URL, definition: Service, providers: Sequence[URL], registries: Sequence[URL], *, generic: str | None +) -> AsyncGenerator[Invoker]: + """Yield the invoker of the reference ``url`` until the context exits, registered as a consumer meanwhile. + + It calls ``providers``, the providers ``url`` names directly, and the + providers ``registries`` hold, connecting to each in the background. + The parameters of ``url`` say how: the cluster each set of providers is + called through, ``cluster``, the applications that provide the + service, ``provided-by``, the routers that narrow the providers of each + call, ``router``, the filters each call goes through once, whatever the + retries, ``reference.filter``, and the settings each attempt on a + provider takes its filters from, such as ``actives`` and + ``reference.attempt-filter``. Without registries, ``providers`` are one + set. Otherwise each registry gives one invoker, and each of + ``providers`` is one besides; with several, the ``zone-aware`` cluster + chooses among them by the ``preferred``, ``zone`` and ``weight`` of + each registry. + + The reference calls from its host, else the local address that reaches + ``registries``, and is registered as a consumer as + `dubbo.registry.consumer.register_consumer` describes. + + Raises: + RuntimeError: ``url`` or a registry belongs to no running application. + ValueError: A parameter of ``url`` or of a registry is invalid. + ZookeeperError: A ZooKeeper registry cannot be reached. + """ + url = url.replace(host=await registered_host(url.host, registries)) + + invoker = await _create_invoker(url, definition, providers, registries) + async with aclosing(invoker), register_consumer(url, definition, registries, generic=generic): + yield chain_filters(invoker, get_filters(url.get_parameter(REFERENCE_FILTER_KEY, comma_separated, ()), url)) + + +async def _create_invoker( + url: URL, definition: Service, providers: Sequence[URL], registries: Sequence[URL] +) -> Invoker: + """Return the invoker of the providers of the reference ``url``, which the caller closes, as `refer` describes.""" + scope = url.scope + routers = [] if registries else create_routers(url.get_parameter(ROUTER_KEY, comma_separated, DEFAULT_ROUTERS), url) + # The parameters that choose among registries are not those of the calls. + consumer = Consumer( + interface=url.path, + group=url.parameters.get(GROUP_KEY), + version=url.parameters.get(VERSION_KEY), + parameters=url.parameters, + attributes=url.attributes, + ) + invokers = [] + async with AsyncExitStack() as stack: + for registry in registries: + invoker = await _refer_registry(registry, consumer, definition, url.update_parameters(_choice(registry))) + stack.push_async_callback(invoker.aclose) + invokers.append(invoker) + for provider in providers: + invoker = await _refer_provider(provider, definition, scope) + stack.push_async_callback(invoker.aclose) + invokers.append(invoker) + # The caller, or the cluster over them, owns them from here. + stack.pop_all() + + if not registries: + return await create_cluster(url, StaticDirectory(invokers, routers)) + if len(invokers) == 1: + return invokers[0] + return await create_cluster(url.update_parameters({CLUSTER_KEY: ZONE_AWARE_CLUSTER}), StaticDirectory(invokers)) + + +def _choice(registry: URL) -> dict[str, str]: + """Return the parameters that choose among the invokers of several registries, from those of ``registry``. + + Raises: + ValueError: ``preferred`` is not a boolean. + """ + parameters = registry.parameters + choice = {} + if registry.get_parameter(PREFERRED_KEY, boolean, False): + choice[REGISTRY_PREFERRED_KEY] = "true" + if parameters.get(ZONE_KEY): + choice[REGISTRY_ZONE_KEY] = parameters[ZONE_KEY] + if WEIGHT_KEY in parameters: + choice[WEIGHT_KEY] = parameters[WEIGHT_KEY] + + return choice + + +async def _refer_registry(registry: URL, consumer: Consumer, definition: Service, url: URL) -> Invoker: + """Return the invoker of the providers of ``consumer`` that ``registry`` holds, found as its mode says. + + In mode ``all``, the ``zone-aware`` cluster calls those found by + instance while there are any, else those found by interface. The caller + closes the invoker. + """ + mode = registry_mode(registry) + interface = url.path + apps = url.get_parameter(PROVIDED_BY_KEY, comma_separated, None) + routers = url.get_parameter(ROUTER_KEY, comma_separated, DEFAULT_ROUTERS) + refer = partial(_refer_provider, definition=definition, scope=registry.scope) + + name = f"{interface} in {registry}" + clusters: list[Invoker] = [] + async with AsyncExitStack() as stack: + if mode is not RegistryMode.INTERFACE: + # In mode all, these are called while there are any. + preferred = url.update_parameters({REGISTRY_PREFERRED_KEY: "true"}) + directory = DynamicDirectory( + lambda: consumer.watch(subscribe_by_instance(registry, interface, apps), preferred), + refer, + name, + create_routers(routers, preferred), + ) + clusters.append(await create_cluster(preferred, directory)) + stack.push_async_callback(clusters[-1].aclose) + if mode is not RegistryMode.INSTANCE: + directory = DynamicDirectory( + lambda: consumer.watch( + subscribe_by_interface(registry, interface, group=consumer.group, version=consumer.version), url + ), + refer, + name, + create_routers(routers, url), + ) + clusters.append(await create_cluster(url, directory)) + stack.push_async_callback(clusters[-1].aclose) + # The caller, or the zone-aware cluster, owns them from here. + stack.pop_all() + + if len(clusters) == 1: + return clusters[0] + return await create_cluster(url.update_parameters({CLUSTER_KEY: ZONE_AWARE_CLUSTER}), StaticDirectory(clusters)) + + +async def _refer_provider(provider: URL, definition: Service, scope: ApplicationScope) -> Invoker: + """Return the invoker of ``provider``, each attempt on it through the filters its settings add; the caller closes it.""" + protocol = await get_protocol(provider.protocol, scope) + invoker = await protocol.refer(provider, definition) + try: + return chain_filters(invoker, get_attempt_filters(invoker.url)) + except BaseException: + await invoker.aclose() + raise diff --git a/src/dubbo/cluster/router/__init__.py b/src/dubbo/cluster/router/__init__.py new file mode 100644 index 00000000..f346364e --- /dev/null +++ b/src/dubbo/cluster/router/__init__.py @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .base import Router, create_routers +from .chain import RouterChain + +__all__ = ["Router", "RouterChain", "create_routers"] diff --git a/src/dubbo/cluster/router/base.py b/src/dubbo/cluster/router/base.py new file mode 100644 index 00000000..629ec1ea --- /dev/null +++ b/src/dubbo/cluster/router/base.py @@ -0,0 +1,97 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from collections.abc import Sequence +from typing import Self, cast + +from dubbo.constants import REMOTE_APPLICATION_KEY +from dubbo.extension import Resource, extension_point, extensions +from dubbo.rpc.invocation import Invocation, Invoker +from dubbo.url import PROVIDER_URL, URL + +__all__ = ["Router", "create_routers", "providers_by_application", "published"] + + +@extension_point("apache_dubbo.router") +class Router(Resource, typing.Protocol): + """Narrows the providers a call of a reference may go to, before its cluster chooses among them. + + Implement ``__init__(url)``, ``notify`` and ``route``, with + ``__aenter__`` and ``aclose`` when it follows something, and install the + class under the entry point group ``apache_dubbo.router``; ``router`` + (``ReferenceConfig.routers``) names the routers of a reference in order, + ``tag`` then ``condition`` by default, and they act as one + ``RouterChain``. + + One is created with the URL of the reference for each of its + directories: the providers of each registry, once per discovery mode, + or, without registries, the providers its ``urls`` name. Its directory + enters and closes it. The attributes of ``url`` hold the application + scope under ``APPLICATION_SCOPE`` and, if the application has one, the + URL of its configuration center under ``CONFIG_CENTER_URL``, whose rules + ``RuleWatch`` follows. + + ``notify`` gets each new list of providers before calls are routed + among them; ``route`` runs on every attempt, for many calls at once. + Both run in the event loop and must not block; work that depends only + on the providers belongs in ``notify``. + """ + + def __init__(self, url: URL) -> None: ... + + def notify(self, invokers: Sequence[Invoker]) -> None: + """Take the providers of the reference, which changed, before calls are routed among them.""" + ... + + def route(self, invokers: Sequence[Invoker], invocation: Invocation) -> Sequence[Invoker]: + """Return those of ``invokers`` that ``invocation`` may go to, possibly none. + + Returning ``invokers`` itself when it narrows nothing keeps the + sequence the same object while the providers do not change. + """ + ... + + async def aclose(self) -> None: + """Stop following it.""" + ... + + async def __aenter__(self) -> Self: + """Start following what the routing depends on, such as rules.""" + ... + + +def create_routers(names: Sequence[str], url: URL) -> list[Router]: + """Create the routers ``names`` names, in order, each with the URL of the reference; the directory that takes them closes them. + + Raises: + ExtensionError: A router is not installed. + """ + return [extensions.get(Router, name)(url) for name in names] + + +def published(invoker: Invoker) -> URL: + """Return the URL the provider of ``invoker`` published, which the settings of the calls do not change.""" + return cast(URL, invoker.url.attributes.get(PROVIDER_URL, invoker.url)) + + +def providers_by_application(invokers: Sequence[Invoker]) -> dict[str | None, list[Invoker]]: + """Return ``invokers`` in order by the application of their providers, ``None`` for those that name none.""" + applications: dict[str | None, list[Invoker]] = {} + for invoker in invokers: + applications.setdefault(invoker.url.parameters.get(REMOTE_APPLICATION_KEY), []).append(invoker) + return applications diff --git a/src/dubbo/cluster/router/chain.py b/src/dubbo/cluster/router/chain.py new file mode 100644 index 00000000..65ea5e1b --- /dev/null +++ b/src/dubbo/cluster/router/chain.py @@ -0,0 +1,61 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Sequence +from contextlib import AsyncExitStack +from typing import Self + +from dubbo.extension import Resource +from dubbo.rpc.invocation import Invocation, Invoker + +from .base import Router + +__all__ = ["RouterChain"] + + +class RouterChain(Resource): + """Routers that act as one ``Router``: each takes every set of providers whole, and routes a call among what those before it left. + + Without routers, a call may go to every provider. Entering ``async with`` + opens the routers in order, and closing closes them in reverse. + """ + + def __init__(self, routers: Sequence[Router] = ()) -> None: + self._routers = tuple(routers) + self._stack = AsyncExitStack() + + def notify(self, invokers: Sequence[Invoker]) -> None: + """Tell every router of the providers, which changed.""" + for router in self._routers: + router.notify(invokers) + + def route(self, invokers: Sequence[Invoker], invocation: Invocation) -> Sequence[Invoker]: + """Return those of ``invokers`` that every router, in turn, lets ``invocation`` go to.""" + for router in self._routers: + invokers = router.route(invokers, invocation) + return invokers + + async def aclose(self) -> None: + await self._stack.aclose() + + async def __aenter__(self) -> Self: + async with AsyncExitStack() as stack: + for router in self._routers: + await stack.enter_async_context(router) # ty: ignore[invalid-argument-type] + self._stack = stack.pop_all() + + return self diff --git a/src/dubbo/cluster/router/condition.py b/src/dubbo/cluster/router/condition.py new file mode 100644 index 00000000..4821035d --- /dev/null +++ b/src/dubbo/cluster/router/condition.py @@ -0,0 +1,394 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import random +import re +from collections.abc import Callable, Mapping, Sequence +from contextlib import AsyncExitStack +from typing import Self, cast + +import attrs + +from dubbo.constants import APPLICATION_KEY +from dubbo.rpc.invocation import Invocation, Invoker +from dubbo.url import CONFIG_CENTER_URL, URL +from dubbo.utils.converters import to_text + +from ..rule import RuleWatch, entries, flag, glob, mapping, rule_key +from .base import Router, providers_by_application, published + +__all__ = ["ConditionRouter"] + +_SUFFIX = ".condition-router" + +_CLAUSE = re.compile(r"\s*([^\s=!&]+)\s*(!=|=)\s*(.*?)\s*") +_ARGUMENT = re.compile(r"arguments\[([0-9]+)\]") +_ATTACHMENT = re.compile(r"attachments\[(.+)\]") +_INTEGER = re.compile(r"[+-]?[0-9]+") + +# Tests a value, given the URL of the reference that ``$key`` refers to. +_Pattern = Callable[[str, URL], bool] + +# The most providers selected by destination kept, one for each destination and sequence of providers routed. +_SELECTIONS = 256 + + +@attrs.define(frozen=True, kw_only=True) +class _Matcher: + """A key whose value matches none of ``mismatches`` and, if there are any, one of ``matches``.""" + + key: str + matches: tuple[_Pattern, ...] + mismatches: tuple[_Pattern, ...] + + def accepts(self, value: str | None, consumer: URL) -> bool: + if value is None or any(pattern(value, consumer) for pattern in self.mismatches): + return False + return not self.matches or any(pattern(value, consumer) for pattern in self.matches) + + +@attrs.define(frozen=True, kw_only=True) +class _Destination: + """The providers every one of ``then`` accepts, chosen in proportion to ``weight``.""" + + then: tuple[_Matcher, ...] + weight: int + + +@attrs.define(frozen=True, kw_only=True) +class _Condition: + """The calls ``when`` accepts go to one of ``destinations``; with none, they are blocked.""" + + when: tuple[_Matcher, ...] + destinations: tuple[_Destination, ...] + + +@attrs.define(frozen=True, kw_only=True) +class _ConditionRule: + force: bool + conditions: tuple[_Condition, ...] + + +class ConditionRouter(Router): + """Sends the calls each condition of a rule accepts to the providers it names. + + The rules are in the configuration center: ``{interface}:{version}:{group}.condition-router`` + for the service, then ``{provider application}.condition-router`` for + the providers of each application but the consumer's, then + ``{consumer application}.condition-router``, each applied to what those + before it left. ``when`` and ``from`` match the URL of the reference and + the call, by its ``method``, ``arguments[i]``, as text with ``None`` as + ``null`` and booleans as ``true`` and ``false``, and ``attachments[key]``; + ``then`` and ``to`` match the URLs of providers, where ``$key`` stands for + that of the reference. + + The rules of the service and of the consumer application are read before + entering ``async with`` returns; those of the provider applications once + the providers name them. The providers each ``then`` and ``to`` selects + are kept for the providers they were selected among, so that a call + only tests ``when`` and ``from``, and a route stays the same sequence + while the providers do not change. + """ + + def __init__(self, url: URL) -> None: + center = cast(URL | None, url.attributes.get(CONFIG_CENTER_URL)) + self._url = url + self._selections = _Selections(url) + # The providers of each application among the last providers grouped. + self._grouped: Sequence[Invoker] | None = None + self._groups: dict[str | None, list[Invoker]] = {} + self._application = url.parameters.get(APPLICATION_KEY) + self._service = RuleWatch(center, _parse_rule) + self._provider = RuleWatch(center, _parse_rule) + self._consumer = RuleWatch(center, _parse_rule) + self._stack = AsyncExitStack() + + def notify(self, invokers: Sequence[Invoker]) -> None: + self._selections.clear() + # Without providers, the rules of the last ones stay for the next. + if invokers: + applications = providers_by_application(invokers).keys() - {None, self._application} + self._provider.follow_soon(*(f"{app}{_SUFFIX}" for app in applications)) + + def route(self, invokers: Sequence[Invoker], invocation: Invocation) -> Sequence[Invoker]: + invokers = self._route_by(self._service, invokers, invocation) + if self._provider.rules and invokers: + invokers = self._route_by_application(invokers, invocation) + return self._route_by(self._consumer, invokers, invocation) + + async def aclose(self) -> None: + await self._stack.aclose() + + async def __aenter__(self) -> Self: + async with AsyncExitStack() as stack: + for rules in (self._service, self._provider, self._consumer): + await stack.enter_async_context(rules) + await self._service.follow(rule_key(self._url) + _SUFFIX) + if self._application: + await self._consumer.follow(self._application + _SUFFIX) + self._stack = stack.pop_all() + + return self + + def _route_by( + self, rules: RuleWatch[_ConditionRule], invokers: Sequence[Invoker], invocation: Invocation + ) -> Sequence[Invoker]: + for rule in rules.rules.values(): + if invokers: + invokers = _route(rule, invokers, self._selections, invocation) + return invokers + + def _route_by_application(self, invokers: Sequence[Invoker], invocation: Invocation) -> Sequence[Invoker]: + """Route the providers of each application by the rule of that application.""" + if invokers is not self._grouped: + self._grouped, self._groups = invokers, providers_by_application(invokers) + + parts = [] + for application, group in self._groups.items(): + rule = self._provider.rules.get(f"{application}{_SUFFIX}") + parts.append(group if rule is None else _route(rule, group, self._selections, invocation)) + if all(part is group for part, group in zip(parts, self._groups.values(), strict=True)): + return invokers + return self._selections.join(parts) + + +def _parse_rule(data: Mapping[str, object]) -> _ConditionRule | None: + """Return the condition rule ``data`` holds, or ``None`` if it is disabled or has no conditions. + + A condition is a ``when => then`` string, or a mapping of ``from`` and + ``to``, a list of destinations chosen by weight. + + Raises: + ValueError: ``data`` is not a condition rule. + """ + if not flag(data, "enabled", True): + return None + + conditions = tuple( + _parse_expression(entry) if isinstance(entry, str) else _parse_destinations(entry) + for entry in entries(data, "conditions") + ) + if not conditions: + return None + return _ConditionRule(force=flag(data, "force", False), conditions=conditions) + + +def _parse_expression(text: str) -> _Condition: + """Parse ``when => then``; without ``when`` or with ``true`` it accepts every call, and without ``then`` or with ``false`` it blocks them. + + Raises: + ValueError: ``text`` is blank. + """ + if not text.strip(): + raise ValueError("a condition must not be blank; write => to block every call") + when, arrow, then = text.partition("=>") + if not arrow: + when, then = "", when + when, then = when.strip(), then.strip() + + destinations = () if then in ("", "false") else (_Destination(then=_parse_side(then, then=True), weight=100),) + return _Condition(when=_parse_when(when), destinations=destinations) + + +def _parse_destinations(value: object) -> _Condition: + """Parse ``from`` and ``to``; without ``from`` it accepts every call, and a destination without ``match`` holds every provider.""" + entry = mapping(value, "a condition") + destinations = [] + for item in entries(entry, "to"): + target = mapping(item, "a destination") + weight = int(str(target.get("weight", 100))) + if weight <= 0: + raise ValueError(f"the weight of a destination must be positive, not {weight}") + then = str(target.get("match") or "").strip() + destinations.append(_Destination(then=_parse_side(then, then=True) if then else (), weight=weight)) + + source = mapping(entry.get("from") or {}, "from") + return _Condition(when=_parse_when(str(source.get("match") or "").strip()), destinations=tuple(destinations)) + + +def _parse_when(text: str) -> tuple[_Matcher, ...]: + return () if text in ("", "true") else _parse_side(text, then=False) + + +def _parse_side(text: str, *, then: bool) -> tuple[_Matcher, ...]: + """Parse clauses such as ``host = 10.0.0.* & zone != gray,blue``, where a key named twice gets the values of both. + + ``then`` tells the side that names providers, whose values may refer to the reference. + """ + sides: dict[str, tuple[list[_Pattern], list[_Pattern]]] = {} + for clause in text.split("&"): + found = _CLAUSE.fullmatch(clause) + values = found[3].split(",") if found else [] + if found is None or not all(value.strip() for value in values): + raise ValueError(f"cannot read {clause.strip()!r} in the condition {text!r}") + + key = found[1].removeprefix("consumer.").removeprefix("provider.") + matches, mismatches = sides.setdefault(key, ([], [])) + (mismatches if found[2] == "!=" else matches).extend(_compile(value.strip(), then=then) for value in values) + + return tuple( + _Matcher(key=key, matches=tuple(matches), mismatches=tuple(mismatches)) + for key, (matches, mismatches) in sides.items() + ) + + +def _compile(pattern: str, *, then: bool) -> _Pattern: + """Compile a range such as ``1~9`` or ``~9``, or a glob such as ``10.0.*``. + + On the side that names providers, ``$key`` is the glob that ``key`` of the reference holds. + """ + if "~" in pattern: + low, _, high = pattern.partition("~") + if not (low or high): + raise ValueError(f"the range {pattern!r} has no bound") + start, end = int(low) if low else None, int(high) if high else None + + def in_range(value: str, consumer: URL) -> bool: + if not _INTEGER.fullmatch(value): + return False + try: + number = int(value) + # Python refuses to convert more digits than sys.get_int_max_str_digits(). + except ValueError: + return False + return (start is None or start <= number) and (end is None or number <= end) + + return in_range + + if then and pattern.startswith("$"): + key = pattern[1:] + return lambda value, consumer: glob(_url_value(consumer, key), value) + + return lambda value, consumer: glob(pattern, value) + + +def _url_value(url: URL, key: str) -> str | None: + """Return the ``host``, ``port``, ``protocol``, ``path`` or ``address`` of ``url``, else its parameter ``key``.""" + match key: + case "host": + return url.host + case "port": + return str(url.port) if url.port else None + case "protocol": + return url.protocol + case "path": + return url.path or None + case "address": + return url.address or None + case _: + return url.parameters.get(key) + + +class _Selections: + """The providers each destination selects among a sequence of providers, so that a selection stays the same sequence. + + A selection is kept for the destination and the sequence it was made + from, and a join of the selections of several applications for the + sequences joined, until ``clear``. + """ + + def __init__(self, consumer: URL) -> None: + # The URL of the reference, which ``$key`` refers to. + self.consumer = consumer + self._selected: dict[tuple[int, int], tuple[_Destination, Sequence[Invoker], Sequence[Invoker]]] = {} + self._joined: dict[tuple[int, ...], tuple[tuple[Sequence[Invoker], ...], Sequence[Invoker]]] = {} + + def get(self, destination: _Destination, invokers: Sequence[Invoker]) -> Sequence[Invoker]: + """Return those of ``invokers`` that every matcher of ``destination`` accepts, ``invokers`` itself if all.""" + key = id(destination), id(invokers) + kept = self._selected.get(key) + # The entry holds both, so neither id is reused while it is kept. + if kept is not None: + return kept[2] + + consumer = self.consumer + selected = [ + invoker + for invoker in invokers + if all( + matcher.accepts(_url_value(published(invoker), matcher.key), consumer) for matcher in destination.then + ) + ] + result = invokers if len(selected) == len(invokers) else selected + if len(self._selected) >= _SELECTIONS: + self._selected.clear() + self._selected[key] = (destination, invokers, result) + return result + + def join(self, parts: Sequence[Sequence[Invoker]]) -> Sequence[Invoker]: + """Return the providers of ``parts`` in order, the same sequence for the same parts.""" + key = tuple(map(id, parts)) + kept = self._joined.get(key) + # The entry holds the parts, so no id is reused while it is kept. + if kept is not None: + return kept[1] + + joined = [invoker for part in parts for invoker in part] + if len(self._joined) >= _SELECTIONS: + self._joined.clear() + self._joined[key] = (tuple(parts), joined) + return joined + + def clear(self) -> None: + """Forget every selection and join.""" + self._selected.clear() + self._joined.clear() + + +def _route( + rule: _ConditionRule, invokers: Sequence[Invoker], selections: _Selections, invocation: Invocation +) -> Sequence[Invoker]: + """Apply the conditions of ``rule`` in turn, each to the providers those before it left. + + A condition that leaves none keeps the providers, unless the rule is forced. + """ + consumer = selections.consumer + for condition in rule.conditions: + if not invokers: + break + if not all( + matcher.accepts(_call_value(matcher.key, consumer, invocation), consumer) for matcher in condition.when + ): + continue + if not condition.destinations: + return () + + found = [] + for destination in condition.destinations: + selected = selections.get(destination, invokers) + if selected: + found.append((selected, destination.weight)) + if found: + invokers = random.choices([selected for selected, _ in found], [weight for _, weight in found])[0] + elif rule.force: + return () + return invokers + + +def _call_value(key: str, consumer: URL, invocation: Invocation) -> str | None: + """Return the ``method``, ``arguments[i]`` or ``attachments[key]`` of ``invocation``, else what ``key`` names in ``consumer``.""" + if key in ("method", "methods"): + return invocation.method + if found := _ARGUMENT.fullmatch(key): + index = int(found[1]) + if index >= len(invocation.arguments): + return None + return to_text(invocation.arguments[index]) + if found := _ATTACHMENT.fullmatch(key): + value = invocation.attachments.get(found[1]) + return value if isinstance(value, str) else None + return _url_value(consumer, key) diff --git a/src/dubbo/cluster/router/tag.py b/src/dubbo/cluster/router/tag.py new file mode 100644 index 00000000..24b5d768 --- /dev/null +++ b/src/dubbo/cluster/router/tag.py @@ -0,0 +1,310 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import ipaddress +import logging +from collections.abc import Callable, Mapping, Sequence +from typing import Self, cast + +import attrs + +from dubbo.constants import FORCE_TAG_KEY, TAG_KEY +from dubbo.rpc.invocation import Invocation, Invoker +from dubbo.url import CONFIG_CENTER_URL, URL +from dubbo.utils.converters import boolean, is_true +from dubbo.utils.net import match_address, split_address + +from ..rule import ParamMatch, RuleWatch, entries, flag, mapping +from .base import Router, providers_by_application, published + +__all__ = ["TagRouter"] + +_logger = logging.getLogger(__name__) + +_SUFFIX = ".tag-router" + +# A provider, as tag rules address it: its host and port. +_Endpoint = tuple[str | None, int | None] +_IPAddress = ipaddress.IPv4Address | ipaddress.IPv6Address + +# The most routes kept for one sequence of providers, one for each tag asked for and whether it is forced. +_ROUTES = 64 + + +@attrs.define(frozen=True, kw_only=True) +class _Tag: + """The providers of a tag: those at ``addresses``, else those every one of ``match`` accepts.""" + + name: str + addresses: tuple[str, ...] + match: tuple[ParamMatch, ...] | None + + +@attrs.define(frozen=True, kw_only=True) +class _TagRule: + force: bool + tags: tuple[_Tag, ...] + + +class TagRouter(Router): + """Sends a call to the providers of the tag it asks for, and a call that asks for none to the untagged. + + A call asks for the ``dubbo.tag`` attachment, else the ``dubbo.tag`` + parameter of the reference; ``*`` asks for every provider. A provider has + the tag of the ``dubbo.tag`` parameter it publishes. With the + configuration center, the rule ``{provider application}.tag-router`` of + each application can tag its providers by address or by the parameters + they publish instead; ``a|b|c`` then asks for the first of ``a|b|c``, + ``a|b`` and ``a`` the rules name. When no provider has the tag, the call + goes to the untagged, unless ``dubbo.force.tag`` of the call or the + reference is ``true``, or a forced rule tags by address. + + The providers of each tag of the rules are found when the providers or + the rules change, so a call looks them up. The route of each tag is + kept for the providers it was found among, so that it stays the same + sequence until they or the rules change. + + Raises: + ValueError: ``dubbo.force.tag`` of the reference is not a boolean. + """ + + def __init__(self, url: URL) -> None: + self._tag = url.parameters.get(TAG_KEY) + self._force = url.get_parameter(FORCE_TAG_KEY, boolean, False) + self._invokers: Sequence[Invoker] = () + # The providers of each tag of the rules, of any of them, and the tags of forced rules. + self._tagged: dict[str, frozenset[_Endpoint]] = {} + self._all_tagged: frozenset[_Endpoint] = frozenset() + self._forced: frozenset[str] = frozenset() + # The routes among the last providers routed, by the tag asked for and whether it is forced. + self._routed: Sequence[Invoker] | None = None + self._routes: dict[tuple[str | None, bool], Sequence[Invoker]] = {} + self._rules = RuleWatch(cast(URL | None, url.attributes.get(CONFIG_CENTER_URL)), _parse_rule, self._resolve) + + def notify(self, invokers: Sequence[Invoker]) -> None: + self._invokers = invokers + # Without providers, the rules of the last ones stay for the next. + if invokers: + applications = providers_by_application(invokers).keys() - {None} + self._rules.follow_soon(*(f"{app}{_SUFFIX}" for app in applications)) + self._resolve() + + def route(self, invokers: Sequence[Invoker], invocation: Invocation) -> Sequence[Invoker]: + if not invokers: + return invokers + + tag = _attachment(invocation, TAG_KEY) or self._tag + if tag == "*": + return invokers + + forced = _attachment(invocation, FORCE_TAG_KEY) + force = is_true(forced) if forced else self._force + if invokers is not self._routed: + self._routed, self._routes = invokers, {} + routed = self._routes.get((tag, force)) + if routed is None: + if len(self._routes) >= _ROUTES: + self._routes.clear() + routed = self._routes[tag, force] = self._route(invokers, tag, force) + return routed + + async def aclose(self) -> None: + await self._rules.aclose() + + async def __aenter__(self) -> Self: + await self._rules.__aenter__() + return self + + def _route(self, invokers: Sequence[Invoker], tag: str | None, force: bool) -> Sequence[Invoker]: + if not self._rules.rules: + return self._route_by_parameter(invokers, tag, force) + + if tag: + name = self._select(tag, force) + if name is not None: + tagged = self._tagged[name] + result = _narrow(invokers, lambda invoker: _endpoint(invoker.url) in tagged) + if result or name in self._forced: + return result + else: + result = _narrow(invokers, lambda invoker: _tag(invoker) == tag) + if result or force: + return result + + all_tagged = self._all_tagged + return _narrow(invokers, lambda invoker: _endpoint(invoker.url) not in all_tagged and _untagged(invoker)) + + def _route_by_parameter(self, invokers: Sequence[Invoker], tag: str | None, force: bool) -> Sequence[Invoker]: + if not tag: + return _narrow(invokers, _untagged) + + result = _narrow(invokers, lambda invoker: _tag(invoker) == tag) + if not result and not force: + return _narrow(invokers, _untagged) + return result + + def _select(self, tag: str, force: bool) -> str | None: + """Return ``tag``, or the first of its levels, that the rules name; ``None`` if they name none.""" + if force or "|" not in tag: + return tag if tag in self._tagged else None + + levels = tag.split("|") + for end in range(len(levels), 0, -1): + name = "|".join(levels[:end]) + if name in self._tagged: + return name + return None + + def _resolve(self) -> None: + tagged: dict[str, frozenset[_Endpoint]] = {} + forced: set[str] = set() + applications = providers_by_application(self._invokers) + for key, rule in self._rules.rules.items(): + # The rule of an application tags its providers alone. + own = applications.get(key.removesuffix(_SUFFIX), []) + addresses = _Addresses(own) + for tag in rule.tags: + if tag.addresses: + found = addresses.listed(tag.addresses) + else: + match = tag.match or () + found = frozenset( + _endpoint(invoker.url) + for invoker in own + if all(test.matches(published(invoker).parameters) for test in match) + ) + # A tag by parameters that no provider has is named by no rule. + if not found: + continue + tagged[tag.name] = tagged.get(tag.name, frozenset()) | found + if rule.force: + forced.add(tag.name) + + self._tagged = tagged + self._all_tagged = frozenset().union(*tagged.values()) + self._forced = frozenset(forced) + self._routed = None + + +def _parse_rule(data: Mapping[str, object]) -> _TagRule | None: + """Return the tag rule ``data`` holds, or ``None`` if it is disabled or tags nothing. + + Raises: + ValueError: ``data`` is not a tag rule. + """ + tags = tuple(_parse_tag(entry) for entry in entries(data, "tags")) + if not tags or not flag(data, "enabled", True): + return None + return _TagRule(force=flag(data, "force", False), tags=tags) + + +def _parse_tag(value: object) -> _Tag: + entry = mapping(value, "a tag") + name = entry.get("name") + if not isinstance(name, str): + raise ValueError("a tag of a tag rule needs a name") + + addresses = tuple(str(address).strip() for address in entries(entry, "addresses")) + match = None + if entry.get("match") is not None: + match = tuple(ParamMatch.from_rule(item) for item in entries(entry, "match")) + if not addresses and match is None: + raise ValueError(f"tag {name} needs addresses or match") + return _Tag(name=name, addresses=addresses, match=match) + + +def _attachment(invocation: Invocation, key: str) -> str | None: + value = invocation.attachments.get(key) + return value if isinstance(value, str) else None + + +def _narrow(invokers: Sequence[Invoker], keep: Callable[[Invoker], bool]) -> Sequence[Invoker]: + kept = [invoker for invoker in invokers if keep(invoker)] + return invokers if len(kept) == len(invokers) else kept + + +def _endpoint(url: URL) -> _Endpoint: + return url.host, url.port + + +def _tag(invoker: Invoker) -> str | None: + return published(invoker).parameters.get(TAG_KEY) + + +def _untagged(invoker: Invoker) -> bool: + return not _tag(invoker) + + +class _Addresses: + """The providers of one application, as tag rules list them by address. + + A pattern that names one address is looked up; any other is tested + against each provider. + """ + + def __init__(self, invokers: Sequence[Invoker]) -> None: + self._urls = [invoker.url for invoker in invokers] + self._hosts: dict[_IPAddress, set[_Endpoint]] = {} + self._endpoints: dict[tuple[_IPAddress, int], set[_Endpoint]] = {} + # Those whose host is not an IP address, which every pattern is tested against. + self._named: list[URL] = [] + for url in self._urls: + try: + address = ipaddress.ip_address(url.host) # ty: ignore[invalid-argument-type] + except ValueError: + self._named.append(url) + continue + self._hosts.setdefault(address, set()).add(_endpoint(url)) + self._endpoints.setdefault((address, url.port or 0), set()).add(_endpoint(url)) + + def listed(self, patterns: Sequence[str]) -> frozenset[_Endpoint]: + """Return the providers one of ``patterns`` lists.""" + found: set[_Endpoint] = set() + for pattern in patterns: + exact = _exact(pattern) + if exact is None: + found.update(_endpoint(url) for url in self._urls if _listed(pattern, url)) + continue + + address, port = exact + found |= self._hosts.get(address, set()) if port is None else self._endpoints.get((address, port), set()) + found.update(_endpoint(url) for url in self._named if _listed(pattern, url)) + return frozenset(found) + + +def _exact(pattern: str) -> tuple[_IPAddress, int | None] | None: + """Return the IP address and the port, if any, of ``pattern`` when it names one address; else ``None``.""" + host, port = split_address(pattern) + if port is not None and not (port.isdecimal() and str(int(port)) == port): + return None + try: + return ipaddress.ip_address(host), None if port is None else int(port) + except ValueError: + return None + + +def _listed(pattern: str, url: URL) -> bool: + try: + return match_address(pattern, url.host, url.port) + except ValueError: + _logger.warning( + "Cannot match the provider %s with the address %r of a tag rule; it is not listed", + url, + pattern, + exc_info=True, + ) + return False diff --git a/src/dubbo/cluster/rule.py b/src/dubbo/cluster/rule.py new file mode 100644 index 00000000..11ded417 --- /dev/null +++ b/src/dubbo/cluster/rule.py @@ -0,0 +1,283 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Governance rules, such as routing and override rules, which the cluster follows in the configuration center.""" + +import logging +import re +from collections.abc import Callable, Mapping +from contextlib import AsyncExitStack +from typing import Generic, Self, TypeVar, cast + +import anyio +import attrs +from anyio.abc import TaskGroup, TaskStatus + +from dubbo.config.exceptions import ConfigError +from dubbo.config.parsers import get_parser +from dubbo.config_center import ConfigCenter, get_config_center +from dubbo.constants import GROUP_KEY, VERSION_KEY +from dubbo.extension import Resource +from dubbo.url import URL +from dubbo.utils import create_background_task_group, follow +from dubbo.utils.converters import is_true + +__all__ = ["ParamMatch", "RuleWatch", "StringMatch", "entries", "flag", "glob", "mapping", "rule_key"] + +_logger = logging.getLogger(__name__) + +# The group of every governance rule in the configuration center. +_GROUP = "dubbo" +# The tests of a StringMatch, in the order it applies them. +_STRING_MATCHES = ("exact", "prefix", "regex", "wildcard", "empty", "noempty") + +R = TypeVar("R") + + +class RuleWatch(Resource, Generic[R]): + """The rules under a set of keys in the configuration center ``url`` names, read by ``parse``. + + Each rule is YAML; ``parse`` takes it as a mapping and returns ``None`` + for one that has no effect. ``rules`` holds the latest rule of each key + followed that has one, none while ``url`` is ``None``, and ``changed`` is + called after it changes. A rule that cannot be read is logged, and the + one before stays. + + Entering ``async with`` connects, and closing stops following. + """ + + def __init__( + self, + url: URL | None, + parse: Callable[[Mapping[str, object]], R | None], + changed: Callable[[], None] = lambda: None, + ) -> None: + self.rules: dict[str, R] = {} + self._url = url + self._parse = parse + self._changed = changed + # The scope of the follower of each key followed. + self._scopes: dict[str, anyio.CancelScope] = {} + self._stack = AsyncExitStack() + # Set once entered with a configuration center. + self._center: ConfigCenter | None = None + self._task_group: TaskGroup | None = None + + async def follow(self, *keys: str) -> None: + """Follow the rules under ``keys`` instead, returning once each new one has been read, or failed to be, the first time. + + The keys still followed keep their rules. + """ + if self._task_group is not None: + for key in self._move(keys): + await self._task_group.start(self._follow, key, self._scopes[key]) + + def follow_soon(self, *keys: str) -> None: + """Follow the rules under ``keys`` instead, reading each new one soon; the keys still followed keep their rules.""" + if self._task_group is not None: + for key in self._move(keys): + self._task_group.start_soon(self._follow, key, self._scopes[key]) + + async def aclose(self) -> None: + await self._stack.aclose() + + async def __aenter__(self) -> Self: + if self._url is None: + return self + + async with AsyncExitStack() as stack: + self._center = await get_config_center(self._url) + task_group = self._task_group = await stack.enter_async_context(create_background_task_group()) + stack.callback(task_group.cancel_scope.cancel) + self._stack = stack.pop_all() + + return self + + def _move(self, keys: tuple[str, ...]) -> list[str]: + """Stop following the keys not in ``keys``, and return those of ``keys`` to start following.""" + dropped = [key for key in self._scopes if key not in keys] + for key in dropped: + self._scopes.pop(key).cancel() + added = [key for key in dict.fromkeys(keys) if key not in self._scopes] + for key in added: + self._scopes[key] = anyio.CancelScope() + + removed = [key for key in dropped if self.rules.pop(key, None) is not None] + if removed: + self._changed() + return added + + async def _follow( + self, key: str, scope: anyio.CancelScope, *, task_status: TaskStatus[None] = anyio.TASK_STATUS_IGNORED + ) -> None: + center = self._center + assert center is not None + + async def receive(text: str | None) -> None: + # A follower of a key no longer followed sets nothing. + if self._scopes.get(key) is scope: + self._receive(key, text) + + with scope: + await follow( + lambda: center.watch(key, group=_GROUP), + receive, + f"the rule {key}", + retry_first=True, + task_status=task_status, + ) + + def _receive(self, key: str, text: str | None) -> None: + if text is None or not text.strip(): + self._set(key, None) + return + + try: + rule = self._parse(get_parser("yaml").loads(text)) + except (ConfigError, ValueError) as error: + # Without the cause, whose message quotes the text, which may hold secrets. + _logger.warning("Cannot read the rule %s; the one before stays: %s", key, error) + return + self._set(key, rule) + + def _set(self, key: str, rule: R | None) -> None: + if rule is None: + self.rules.pop(key, None) + else: + self.rules[key] = rule + self._changed() + + +def rule_key(url: URL) -> str: + """Return the key of the rules of the service ``url`` refers to: ``{interface}:{version}:{group}``, with the colons of empty parts kept.""" + parameters = url.parameters + return f"{url.path}:{parameters.get(VERSION_KEY, '')}:{parameters.get(GROUP_KEY, '')}" + + +def flag(data: Mapping[str, object], key: str, default: bool) -> bool: + """Return the boolean ``key`` of ``data``: true when it reads ``true`` in any case, ``default`` when absent.""" + value = data.get(key) + return default if value is None else is_true(value) + + +def mapping(value: object, name: str) -> Mapping[str, object]: + """Return ``value``, the mapping ``name`` of a rule. + + Raises: + ValueError: ``value`` is not a mapping. + """ + if not isinstance(value, Mapping): + raise ValueError(f"{name} of a rule must be a mapping") + return cast(Mapping[str, object], value) + + +def entries(data: Mapping[str, object], key: str) -> list[object]: + """Return the list ``key`` of ``data``, empty when absent. + + Raises: + ValueError: The value is not a list. + """ + value = data.get(key) + if value is None: + return [] + if not isinstance(value, list): + raise ValueError(f"{key} of a rule must be a list") + return cast(list[object], value) + + +def glob(pattern: str | None, value: str) -> bool: + """Match ``value`` with ``pattern``, in which the last ``*`` stands for any text and every other character for itself.""" + if pattern == "*": + return True + if not pattern or not value: + return not pattern and not value + + prefix, star, suffix = pattern.rpartition("*") + if not star: + return value == pattern + return value.startswith(prefix) and value.endswith(suffix) + + +@attrs.define(frozen=True, kw_only=True) +class StringMatch: + """A test of a text in a rule, by the first of its fields that is set and applies.""" + + exact: str | None = None + prefix: str | None = None + regex: re.Pattern[str] | None = None + wildcard: str | None = None + empty: str | None = None + noempty: str | None = None + + @classmethod + def from_rule(cls, value: object, name: str) -> Self: + """Read the test ``name`` of a rule, a mapping of ``exact``, ``prefix``, ``regex``, ``wildcard``, ``empty`` or ``noempty``. + + Raises: + ValueError: ``value`` is not a mapping, or its regex is invalid. + """ + tests = mapping(value, name) + fields = {field: str(tests[field]) for field in _STRING_MATCHES if tests.get(field) is not None} + regex = None + if "regex" in fields: + try: + regex = re.compile(fields.pop("regex")) + except re.error as error: + raise ValueError(f"{name} has an invalid regex") from error + return cls(regex=regex, **fields) + + def matches(self, value: str | None) -> bool: + if value is not None: + if self.exact is not None: + return value == self.exact + if self.prefix is not None: + return value.startswith(self.prefix) + if self.regex is not None: + return self.regex.fullmatch(value) is not None + if self.wildcard is not None: + return self.wildcard in ("*", value) + if self.empty is not None: + return not value + return self.noempty is not None and bool(value) + + +@attrs.define(frozen=True, kw_only=True) +class ParamMatch: + """A test of one URL parameter in a rule; one without a value matches nothing.""" + + key: str + value: StringMatch | None + + @classmethod + def from_rule(cls, value: object) -> Self: + """Read a mapping of ``key`` and ``value``, the test of the parameter. + + Raises: + ValueError: ``value`` is not such a mapping. + """ + entry = mapping(value, "a match") + key = entry.get("key") + if not isinstance(key, str): + raise ValueError("a match of a parameter needs a key") + + test = entry.get("value") + return cls( + key=key, value=None if test is None else StringMatch.from_rule(test, f"the value of the match of {key}") + ) + + def matches(self, parameters: Mapping[str, str]) -> bool: + return self.value is not None and self.value.matches(parameters.get(self.key)) diff --git a/src/dubbo/cluster/zoneaware.py b/src/dubbo/cluster/zoneaware.py new file mode 100644 index 00000000..cb970e67 --- /dev/null +++ b/src/dubbo/cluster/zoneaware.py @@ -0,0 +1,63 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Sequence + +from dubbo.constants import REGISTRY_PREFERRED_KEY, REGISTRY_ZONE_FORCE_KEY, REGISTRY_ZONE_KEY +from dubbo.exceptions import RpcError, Status +from dubbo.rpc.invocation import Invocation, Invoker, Result +from dubbo.utils.converters import is_true + +from .base import BaseCluster + +__all__ = ["ZoneAwareCluster"] + + +class ZoneAwareCluster(BaseCluster): + """Makes each call through the invoker of one of the registries of a reference. + + It takes the first available invoker whose URL sets + ``registry.preferred`` to ``true``. Else, when the ``registry.zone`` + attachment of the call names a zone, it takes the first available + invoker whose URL has that ``registry.zone``; finding none ends the call + with ``UNAVAILABLE`` if the ``registry.zone.force`` attachment is + ``true``. Else it takes the invoker the load balance chooses among the + available ones, by the ``weight`` of its URL; when none is available, + the call ends with ``UNAVAILABLE``. + """ + + async def _invoke(self, invocation: Invocation, invokers: Sequence[Invoker]) -> Result: + for invoker in invokers: + if invoker.available and is_true(invoker.url.parameters.get(REGISTRY_PREFERRED_KEY)): + return await invoker.invoke(invocation) + + zone = invocation.attachments.get(REGISTRY_ZONE_KEY) + if zone: + for invoker in invokers: + if invoker.available and invoker.url.parameters.get(REGISTRY_ZONE_KEY) == zone: + return await invoker.invoke(invocation) + if is_true(invocation.attachments.get(REGISTRY_ZONE_FORCE_KEY)): + error = RpcError( + Status.UNAVAILABLE, f"no provider of {invocation.interface} is available in zone {zone}" + ) + return Result(error=error) + + chosen = self._select(invokers, invocation) + if chosen.available: + return await chosen.invoke(invocation) + + return Result(error=RpcError(Status.UNAVAILABLE, f"no provider of {invocation.interface} is available")) diff --git a/src/dubbo/compression/__init__.py b/src/dubbo/compression/__init__.py index eb016893..9c6fef6d 100644 --- a/src/dubbo/compression/__init__.py +++ b/src/dubbo/compression/__init__.py @@ -1,22 +1,20 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. -from ._interfaces import Compressor, Decompressor -from .bzip2s import Bzip2 -from .gzips import Gzip -from .identities import Identity +from .base import Compressor, get_compressor -__all__ = ["Compressor", "Decompressor", "Identity", "Gzip", "Bzip2"] +__all__ = ["Compressor", "get_compressor"] diff --git a/src/dubbo/compression/_interfaces.py b/src/dubbo/compression/_interfaces.py deleted file mode 100644 index d7a85136..00000000 --- a/src/dubbo/compression/_interfaces.py +++ /dev/null @@ -1,69 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc - -__all__ = ["MessageEncoding", "Compressor", "Decompressor"] - - -class MessageEncoding(abc.ABC): - """ - The message encoding interface. - """ - - @classmethod - @abc.abstractmethod - def get_message_encoding(cls) -> str: - """ - Get message encoding of current compression - :return: The message encoding. - :rtype: str - """ - raise NotImplementedError() - - -class Compressor(MessageEncoding, abc.ABC): - """ - The compression interface. - """ - - @abc.abstractmethod - def compress(self, data: bytes) -> bytes: - """ - Compress the data. - :param data: The data to compress. - :type data: bytes - :return: The compressed data. - :rtype: bytes - """ - raise NotImplementedError() - - -class Decompressor(MessageEncoding, abc.ABC): - """ - The decompressor interface. - """ - - @abc.abstractmethod - def decompress(self, data: bytes) -> bytes: - """ - Decompress the data. - :param data: The data to decompress. - :type data: bytes - :return: The decompressed data. - :rtype: bytes - """ - raise NotImplementedError() diff --git a/src/dubbo/compression/base.py b/src/dubbo/compression/base.py new file mode 100644 index 00000000..76c7dc25 --- /dev/null +++ b/src/dubbo/compression/base.py @@ -0,0 +1,89 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +import zlib + +from dubbo.extension import extension_point, extensions +from dubbo.url import URL + +__all__ = ["Compressor", "bounded_decompress", "get_compressor"] + + +@extension_point("apache_dubbo.compression") +class Compressor(typing.Protocol): + """A message compression, named by the encoding it travels as, such as ``gzip``. + + Implement ``__init__(url)``, ``compress`` and ``decompress``, and install + it under the entry point group ``apache_dubbo.compression``, named by its + encoding. Every installed compressor is offered in + ``grpc-accept-encoding``; the ``compressor`` parameter picks the one a + side sends with. A Triple server or client creates one with its URL on + first use and keeps it. Both methods run in the event loop for every + message, so they must be quick. The encoding ``identity`` leaves messages + as they are and has no implementation. + """ + + def __init__(self, url: URL) -> None: ... + + def compress(self, data: bytes) -> bytes: + """Return ``data`` compressed.""" + ... + + def decompress(self, data: bytes, max_length: int) -> bytes: + """Return ``data`` decompressed, or only its first ``max_length`` bytes when it is longer. + + Producing no more than ``max_length`` bytes bounds the memory a small + compressed message can take. `bounded_decompress` does it with a + decompressor of the standard library. + + Raises: + ValueError: ``data`` is malformed or cut short. + """ + ... + + +def get_compressor(name: str, url: URL) -> Compressor: + """Return a compressor of the encoding ``name``, such as ``gzip``, created with ``url``. + + Raises: + ExtensionError: No compressor is installed under ``name``. + """ + return extensions.get(Compressor, name)(url) + + +class _Decompressor(typing.Protocol): + @property + def eof(self) -> bool: ... + + def decompress(self, data: bytes, max_length: int = -1, /) -> bytes: ... + + +def bounded_decompress(decompressor: _Decompressor, data: bytes, max_length: int) -> bytes: + """Return ``data`` decompressed by ``decompressor``, such as ``zlib.decompressobj()``, as `Compressor.decompress` does. + + Raises: + ValueError: ``data`` is malformed or cut short. + """ + try: + result = decompressor.decompress(data, max_length) + except (zlib.error, OSError) as error: + raise ValueError(f"malformed compressed data: {error}") from None + + if len(result) < max_length and not decompressor.eof: + raise ValueError("compressed data is cut short") + return result diff --git a/src/dubbo/compression/bzip2.py b/src/dubbo/compression/bzip2.py new file mode 100644 index 00000000..160281a4 --- /dev/null +++ b/src/dubbo/compression/bzip2.py @@ -0,0 +1,37 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import bz2 + +from dubbo.url import URL + +from .base import Compressor, bounded_decompress + +__all__ = ["Bzip2Compressor"] + + +class Bzip2Compressor(Compressor): + """Compress messages in the bzip2 format.""" + + def __init__(self, url: URL) -> None: + pass + + def compress(self, data: bytes) -> bytes: + return bz2.compress(data) + + def decompress(self, data: bytes, max_length: int) -> bytes: + return bounded_decompress(bz2.BZ2Decompressor(), data, max_length) diff --git a/src/dubbo/compression/bzip2s.py b/src/dubbo/compression/bzip2s.py deleted file mode 100644 index 92b2bf0b..00000000 --- a/src/dubbo/compression/bzip2s.py +++ /dev/null @@ -1,56 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import bz2 - -from dubbo.compression import Compressor, Decompressor - - -class Bzip2(Compressor, Decompressor): - """ - The BZIP2 compression and decompressor. - """ - - _MESSAGE_ENCODING = "bzip2" - - @classmethod - def get_message_encoding(cls) -> str: - """ - Get message encoding of current compression - :return: The message encoding. - :rtype: str - """ - return cls._MESSAGE_ENCODING - - def compress(self, data: bytes) -> bytes: - """ - Compress the data. - :param data: The data to compress. - :type data: bytes - :return: The compressed data. - :rtype: bytes - """ - return bz2.compress(data) - - def decompress(self, data: bytes) -> bytes: - """ - Decompress the data. - :param data: The data to decompress. - :type data: bytes - :return: The decompressed data. - :rtype: bytes - """ - return bz2.decompress(data) diff --git a/src/dubbo/compression/deflate.py b/src/dubbo/compression/deflate.py new file mode 100644 index 00000000..4a84f612 --- /dev/null +++ b/src/dubbo/compression/deflate.py @@ -0,0 +1,39 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import zlib + +from dubbo.url import URL + +from .base import Compressor, bounded_decompress + +__all__ = ["DeflateCompressor"] + +_WBITS = zlib.MAX_WBITS + + +class DeflateCompressor(Compressor): + """Compress messages in the zlib format.""" + + def __init__(self, url: URL) -> None: + pass + + def compress(self, data: bytes) -> bytes: + return zlib.compress(data, wbits=_WBITS) + + def decompress(self, data: bytes, max_length: int) -> bytes: + return bounded_decompress(zlib.decompressobj(_WBITS), data, max_length) diff --git a/src/dubbo/compression/gzip.py b/src/dubbo/compression/gzip.py new file mode 100644 index 00000000..75490d90 --- /dev/null +++ b/src/dubbo/compression/gzip.py @@ -0,0 +1,61 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import zlib + +from dubbo.url import URL + +from .base import Compressor, bounded_decompress + +__all__ = ["GzipCompressor"] + +_WBITS = zlib.MAX_WBITS | 16 +_CHUNK = 16 * 1024 # Bytes of input given at a time after the first member. + + +class GzipCompressor(Compressor): + """Compress messages in the gzip format.""" + + def __init__(self, url: URL) -> None: + pass + + def compress(self, data: bytes) -> bytes: + return zlib.compress(data, wbits=_WBITS) + + def decompress(self, data: bytes, max_length: int) -> bytes: + decompressor = zlib.decompressobj(_WBITS) + result = bounded_decompress(decompressor, data, max_length) + if not decompressor.unused_data or len(result) >= max_length: + return result + + # A gzip message is a sequence of members that share the one limit. The members after the first get the + # input in chunks, so that the copy zlib makes of the input left after each member stays short. + rest, offset, pieces, length = memoryview(decompressor.unused_data), 0, [result], len(result) + try: + while offset < len(rest) and length < max_length: + decompressor = zlib.decompressobj(_WBITS) + while not decompressor.eof and offset < len(rest) and length < max_length: + chunk = rest[offset : offset + _CHUNK] + pieces.append(decompressor.decompress(chunk, max_length - length)) + length += len(pieces[-1]) + offset += len(chunk) - len(decompressor.unconsumed_tail) - len(decompressor.unused_data) + if not decompressor.eof and length < max_length: + raise ValueError("compressed data is cut short") + except zlib.error as error: + raise ValueError(f"malformed compressed data: {error}") from None + + return b"".join(pieces) diff --git a/src/dubbo/compression/gzips.py b/src/dubbo/compression/gzips.py deleted file mode 100644 index 4b9ac598..00000000 --- a/src/dubbo/compression/gzips.py +++ /dev/null @@ -1,58 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import gzip - -from dubbo.compression import Compressor, Decompressor - -__all__ = ["Gzip"] - - -class Gzip(Compressor, Decompressor): - """ - The GZIP compression and decompressor. - """ - - _MESSAGE_ENCODING = "gzip" - - @classmethod - def get_message_encoding(cls) -> str: - """ - Get message encoding of current compression - :return: The message encoding. - :rtype: str - """ - return cls._MESSAGE_ENCODING - - def compress(self, data: bytes) -> bytes: - """ - Compress the data. - :param data: The data to compress. - :type data: bytes - :return: The compressed data. - :rtype: bytes - """ - return gzip.compress(data) - - def decompress(self, data: bytes) -> bytes: - """ - Decompress the data. - :param data: The data to decompress. - :type data: bytes - :return: The decompressed data. - :rtype: bytes - """ - return gzip.decompress(data) diff --git a/src/dubbo/compression/identities.py b/src/dubbo/compression/identities.py deleted file mode 100644 index 4f8d085a..00000000 --- a/src/dubbo/compression/identities.py +++ /dev/null @@ -1,57 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from dubbo.classes import SingletonBase -from dubbo.compression import Compressor, Decompressor - -__all__ = ["Identity"] - - -class Identity(Compressor, Decompressor, SingletonBase): - """ - The identity compression and decompressor.It does not compress or decompress the data. - """ - - _MESSAGE_ENCODING = "identity" - - @classmethod - def get_message_encoding(cls) -> str: - """ - Get message encoding of current compression - :return: The message encoding. - :rtype: str - """ - return cls._MESSAGE_ENCODING - - def compress(self, data: bytes) -> bytes: - """ - Compress the data. - :param data: The data to compress. - :type data: bytes - :return: The compressed data. - :rtype: bytes - """ - return data - - def decompress(self, data: bytes) -> bytes: - """ - Decompress the data. - :param data: The data to decompress. - :type data: bytes - :return: The decompressed data. - :rtype: bytes - """ - return data diff --git a/src/dubbo/config/__init__.py b/src/dubbo/config/__init__.py new file mode 100644 index 00000000..0a0a0e90 --- /dev/null +++ b/src/dubbo/config/__init__.py @@ -0,0 +1,64 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .data import ConfigData +from .exceptions import ConfigError, ConfigParseError, ConfigReadError +from .models import ( + ApplicationConfig, + ConfigCenterConfig, + ConsumerConfig, + DubboConfig, + DubboProtocolConfig, + MetadataReportConfig, + MetadataType, + MethodConfig, + ProtocolConfig, + ProviderConfig, + ReferenceConfig, + RegistryConfig, + RegistryMode, + ServiceConfig, + ShutdownConfig, + TLSConfig, + TripleConfig, +) +from .parsers import ConfigParser + +__all__ = [ + "ApplicationConfig", + "ConfigCenterConfig", + "ConfigData", + "ConfigError", + "ConfigParseError", + "ConfigParser", + "ConfigReadError", + "ConsumerConfig", + "DubboConfig", + "DubboProtocolConfig", + "MetadataReportConfig", + "MetadataType", + "MethodConfig", + "ProtocolConfig", + "ProviderConfig", + "ReferenceConfig", + "RegistryConfig", + "RegistryMode", + "ServiceConfig", + "ShutdownConfig", + "TLSConfig", + "TripleConfig", +] diff --git a/src/dubbo/config/data.py b/src/dubbo/config/data.py new file mode 100644 index 00000000..5544b011 --- /dev/null +++ b/src/dubbo/config/data.py @@ -0,0 +1,62 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Mapping, Sequence +from typing import cast + +__all__ = ["ConfigData", "insert_path", "merge"] + +ConfigData = Mapping[str, object] + + +def merge(target: dict[str, object], incoming: ConfigData) -> None: + """Merge ``incoming`` into ``target``: mappings merge, other values replace. + + Every mapping in ``target`` is created here, so sources are never modified. + Lists and scalars are shared; nothing mutates them. + """ + for key, value in incoming.items(): + if not isinstance(value, Mapping): + target[key] = value + continue + + section = target.get(key) + if not isinstance(section, dict): + section = target[key] = {} + merge(cast(dict[str, object], section), cast(ConfigData, value)) + + +def insert_path(root: dict[str, object], path: Sequence[str], value: object) -> None: + """Set a nested value, rejecting empty segments and conflicting paths. + + A path conflicts when it repeats an earlier one or when one path would be + both a value and a section, regardless of insertion order. + """ + if not all(path): + raise ValueError("empty path segment") + + current = root + for segment in path[:-1]: + child = current.setdefault(segment, {}) + if not isinstance(child, dict): + raise ValueError("conflicting path") + current = cast(dict[str, object], child) + + # This also catches two inputs that name the same path. + if path[-1] in current: + raise ValueError("conflicting path") + current[path[-1]] = value diff --git a/src/dubbo/config/exceptions.py b/src/dubbo/config/exceptions.py new file mode 100644 index 00000000..25315cc9 --- /dev/null +++ b/src/dubbo/config/exceptions.py @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from dubbo.exceptions import DubboError + +__all__ = ["ConfigError", "ConfigParseError", "ConfigReadError"] + + +class ConfigError(DubboError): + """Base class for configuration loading and model errors.""" + + +class ConfigParseError(ConfigError): + """A document has invalid syntax or an unsupported root structure.""" + + +class ConfigReadError(ConfigError): + """A source could not be read or normalized into configuration data.""" diff --git a/src/dubbo/config/fields.py b/src/dubbo/config/fields.py new file mode 100644 index 00000000..51ddfa86 --- /dev/null +++ b/src/dubbo/config/fields.py @@ -0,0 +1,250 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""How configuration fields meet the outside: the text read into them, and the URL they become. + +The environment variable a field declares is an input alias, read when the +configuration loads; the URL parameter is the output, written when the +configuration becomes URLs. A field may declare both, as in +``metadata=env_variable("X") | url_parameter("x")``. +""" + +import json +import os +from collections.abc import Callable, Mapping +from typing import Any, cast, get_args, get_origin + +import attrs + +from dubbo.utils.annotations import UNIONS +from dubbo.utils.converters import to_text + +from .data import ConfigData + +__all__ = [ + "check_address_keys", + "check_url_keys", + "decode_json", + "env_variable", + "read_declared_env", + "to_url_parameters", + "url_nested", + "url_parameter", +] + +# The metadata keys, namespaced as attrs recommends. +_ENV_VARIABLE = "dubbo.env_variable" +_URL = "dubbo.url" + + +def env_variable(name: str) -> dict[str, object]: + """Declare, as ``attrs.field`` metadata, the environment variable that also sets a field. + + ``name`` is unprefixed, as Dubbo in every language reads it, such as + ``DUBBO_IP_TO_REGISTRY``. + """ + return {_ENV_VARIABLE: name} + + +def read_declared_env(cls: type[attrs.AttrsInstance]) -> ConfigData: + """Read the environment variables that the fields of ``cls``, and of the configurations it nests, declare. + + Values stay strings until the configuration converts them. + """ + data: dict[str, object] = {} + for field in attrs.fields(cls): + name = field.metadata.get(_ENV_VARIABLE) + nested = _attrs_class(field.type) + if name is not None and os.environ.get(name): + data[field.name] = os.environ[name] + elif nested is not None and (values := read_declared_env(nested)): + data[field.name] = values + + return data + + +def decode_json(data: ConfigData, cls: type[attrs.AttrsInstance]) -> ConfigData: + """Decode the text of ``data`` that stands where ``cls`` expects a mapping, a list or a section, as JSON. + + Other text, and keys that ``cls`` does not know, stay as they are, for + the configuration to convert or reject. + + Raises: + ValueError: Such text is not JSON; the message names its path. + """ + return cast(ConfigData, _decoded(data, cls, ())) + + +def url_parameter(key: str, encode: Callable[[Any], str] = to_text, *, default: object = None) -> dict[str, object]: + """Declare, as ``attrs.field`` metadata, that a field becomes the URL parameter ``key``. + + ``encode`` turns a value into the parameter text; by default booleans + become ``true`` or ``false`` and other values ``str()``. ``default`` is + the value that ``None`` stands for; when it is ``None`` too, an unset + field adds no parameter. + """ + return {_URL: _URLParameter(key, encode, default)} + + +def url_nested(key: str | None = None) -> dict[str, object]: + """Declare, as ``attrs.field`` metadata, that the URL parameters of a nested configuration join those of its own. + + With ``key``, each parameter comes after it and a dot, as in + ``triple.compressor``. A mapping joins each entry under its key: text as + it is, and a configuration with its parameters after the key and a dot, + as in ``getUser.timeout``. Declared fields override the text of mappings. + """ + return {_URL: _URLNested("" if key is None else f"{key}.")} + + +def to_url_parameters(*configs: attrs.AttrsInstance | None) -> dict[str, str]: + """Collect the URL parameters that the fields of ``configs`` declare. + + Configurations apply from low to high priority, so a later one overrides + an earlier one, as a service overrides its provider; ``None`` stands for + one that sets nothing. A field left as ``None`` keeps the lower value, or + adds its default if no configuration sets it. + """ + defaults: dict[str, str] = {} + extra: dict[str, str] = {} + declared: dict[str, str] = {} + for config in configs: + if config is not None: + _collect(config, "", defaults, extra, declared) + + return defaults | extra | declared + + +def check_url_keys(config: attrs.AttrsInstance, parameters: Mapping[str, str]) -> None: + """Check that ``parameters`` sets no key that a field of ``config`` declares. + + A configuration that overrides others needs it: a field of a lower one + would override such a parameter. + + Raises: + ValueError: ``parameters`` sets a key that a field declares. + """ + for name, declared in _declared(type(config)).items(): + if declared.key in parameters: + raise ValueError(f"set the {name} field instead of the {declared.key!r} parameter") + + +def check_address_keys(config: attrs.AttrsInstance, parameters: Mapping[str, str], query: Mapping[str, str]) -> None: + """Check that the places that set a key of the URL of an address agree. + + The places are a field of ``config`` that is set, its ``parameters`` and + the ``query`` of its address; a key they set alike is set once. The + message names the key alone, as a value may be a secret. + + Raises: + ValueError: Two places set a key to different values. + """ + for name, declared in _declared(type(config)).items(): + value = getattr(config, name) + if value is None: + continue + encoded = declared.encode(value) + if parameters.get(declared.key, encoded) != encoded or query.get(declared.key, encoded) != encoded: + raise ValueError(f"the {name} field and the {declared.key!r} parameter differ") + for key, value in parameters.items(): + if query.get(key, value) != value: + raise ValueError(f"parameter {key!r} differs from the one in the address") + + +@attrs.define(frozen=True) +class _URLParameter: + key: str + encode: Callable[[Any], str] + default: object + + +@attrs.define(frozen=True) +class _URLNested: + prefix: str + + +def _decoded(value: object, target: object, path: tuple[str, ...]) -> object: + target = _without_none(target) + nested = _attrs_class(target) + if isinstance(value, str): + if nested is None and get_origin(target) not in (dict, list, tuple): + return value + try: + return json.loads(value) + except ValueError as error: + raise ValueError(f"the value of {'.'.join(path)!r} must be JSON") from error + + if not isinstance(value, dict): + return value + + items = cast(dict[str, object], value).items() + if nested is not None: + fields = attrs.fields_dict(nested) + return {key: _decoded(item, fields[key].type, (*path, key)) if key in fields else item for key, item in items} + if get_origin(target) is dict: + item_type = get_args(target)[1] + return {key: _decoded(item, item_type, (*path, key)) for key, item in items} + + return value + + +def _attrs_class(annotation: object) -> type[attrs.AttrsInstance] | None: + """Return the attrs class ``annotation`` names, alone or as ``X | None``.""" + annotation = _without_none(annotation) + return annotation if isinstance(annotation, type) and attrs.has(annotation) else None + + +def _without_none(annotation: object) -> object: + """Unwrap ``X | None`` to ``X``; return any other type unchanged.""" + if get_origin(annotation) in UNIONS: + options = [option for option in get_args(annotation) if option is not type(None)] + if len(options) == 1: + return options[0] + return annotation + + +def _collect( + config: attrs.AttrsInstance, prefix: str, defaults: dict[str, str], extra: dict[str, str], declared: dict[str, str] +) -> None: + for field in attrs.fields(type(config)): + value = getattr(config, field.name) + match field.metadata.get(_URL): + case _URLParameter(key, encode, default): + if value is not None: + declared[prefix + key] = encode(value) + elif default is not None: + defaults[prefix + key] = encode(default) + case _URLNested(nested): + _flatten(value, prefix + nested, defaults, extra, declared) + + +def _flatten( + value: object, prefix: str, defaults: dict[str, str], extra: dict[str, str], declared: dict[str, str] +) -> None: + if attrs.has(type(value)): + _collect(value, prefix, defaults, extra, declared) + elif isinstance(value, Mapping): + for key, item in cast(Mapping[str, object], value).items(): + if isinstance(item, str): + extra[prefix + key] = item + else: + _flatten(item, f"{prefix}{key}.", defaults, extra, declared) + + +def _declared(cls: type[attrs.AttrsInstance]) -> dict[str, _URLParameter]: + fields = attrs.fields(cls) + return {field.name: field.metadata[_URL] for field in fields if isinstance(field.metadata.get(_URL), _URLParameter)} diff --git a/src/dubbo/config/loading.py b/src/dubbo/config/loading.py new file mode 100644 index 00000000..02424bf7 --- /dev/null +++ b/src/dubbo/config/loading.py @@ -0,0 +1,224 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +import os +from collections.abc import Iterable, Mapping +from os import PathLike +from pathlib import Path, PurePosixPath +from typing import cast + +from dubbo.config_center import ConfigCenter, get_config_center +from dubbo.constants import DEFAULT_CONFIG_CENTER_CHECK, DEFAULT_CONFIG_CENTER_FILE, DEFAULT_CONFIG_CENTER_GROUP +from dubbo.extension import ApplicationScope, ExtensionError, extensions +from dubbo.url import APPLICATION_SCOPE + +from .data import ConfigData, insert_path, merge +from .exceptions import ConfigError, ConfigParseError, ConfigReadError +from .fields import decode_json, read_declared_env +from .models import ConfigCenterConfig, DubboConfig, RegistryConfig +from .parsers import ConfigParser, get_parser +from .structure import structure_config, unstructure_config + +__all__ = ["ConfigSource", "load_config"] + +# A file path, read with the parser for its suffix, or configuration data. +ConfigSource = str | PathLike[str] | Mapping[str, object] + +_logger = logging.getLogger(__name__) + + +async def load_config( + sources: Iterable[ConfigSource], + *, + env_prefix: str | None, + code: ConfigData, + scope: ApplicationScope, +) -> DubboConfig: + """Read, merge and validate the configuration of one application. + + The layers merge from low to high priority: ``sources`` in order, the + configuration center, the environment variables named with + ``env_prefix`` unless it is ``None``, then ``code``, the configuration + set in code as plain data without unset fields. + The variables that fields declare with ``env_variable``, such as + ``DUBBO_IP_TO_REGISTRY``, are in the layer of the environment, below the + prefixed ones. + + The configuration center is set by the other layers, so they are read + first; when they set none, the first of their registries that serves as + one is it. The application of ``scope`` keeps it open for its other + readers. + + Raises: + ConfigError: The configuration cannot be read or is invalid. + """ + files = [_read_source(source) for source in sources] + env = {} if env_prefix is None else _merged(read_declared_env(DubboConfig), _read_prefixed_env(env_prefix)) + + # The configuration center is set by the local layers alone, or else is a registry they set. + local = _merged(*files, env, code) + center = local.get("config_center") + config = None + derived: ConfigData = {} + if center is not None: + config = structure_config(cast(ConfigData, center), ConfigCenterConfig, path="config.config_center") + elif (config := _registry_as_config_center(local)) is not None: + derived = {"config_center": cast(ConfigData, unstructure_config(config))} + remote = {} if config is None else await _read_config_center(config, scope) + + return structure_config(_merged(derived, *files, remote, env, code), DubboConfig) + + +def _registry_as_config_center(local: ConfigData) -> ConfigCenterConfig | None: + """Return the configuration center of the first registry of ``local`` that serves as one, if any.""" + data = cast(ConfigData, local.get("registries", {})) + registries = structure_config(data, dict[str, RegistryConfig], path="config.registries") + kinds = extensions.names(ConfigCenter) + for name, registry in registries.items(): + use = registry.use_as_config_center + if use or (use is None and registry.to_url().protocol in kinds): + try: + return ConfigCenterConfig.from_registry(registry) + except ValueError as error: + raise ConfigError(f"invalid configuration: {error} @ config.registries.{name}") from None + return None + + +def _merged(*layers: ConfigData) -> dict[str, object]: + """Merge layers from low to high priority. + + Mappings merge recursively; any other value, including a list, replaces + the lower one. + """ + data: dict[str, object] = {} + for layer in layers: + merge(data, layer) + return data + + +def _read_file(path: str | PathLike[str]) -> ConfigData: + """Read one file with the parser named by its suffix. + + Raises: + ConfigReadError: No parser matches, or the file cannot be read or decoded. + ConfigParseError: The parser rejects its content. + """ + path = Path(path) + parser = _parser(str(path), None) + + try: + text = path.read_text(encoding="utf-8") + except (OSError, UnicodeError) as error: + raise ConfigReadError(f"cannot read configuration file {str(path)!r}") from error + + try: + return parser.loads(text) + except ConfigParseError as error: + raise ConfigParseError(f"{error} in {str(path)!r}") from error.__cause__ + + +def _read_source(source: ConfigSource) -> ConfigData: + return cast(ConfigData, source) if isinstance(source, Mapping) else _read_file(source) + + +async def _read_config_center(config: ConfigCenterConfig, scope: ApplicationScope) -> ConfigData: + """Read the configuration stored under ``config_file`` in ``group``. + + The configuration center is the one the application of ``scope`` + shares, which stays open until the application stops. + + Returns: + The parsed configuration; empty when the entry is missing or blank, + or cannot be read and ``check`` is false. + + Raises: + ConfigReadError: No implementation matches the scheme, no parser + matches ``format`` or the suffix of the key, or the entry cannot + be read and ``check`` is not false. + ConfigParseError: The entry has invalid content. + ConfigError: The entry sets ``config_center``. + """ + url = config.to_url().replace(attributes={APPLICATION_SCOPE: scope}) + key = config.config_file or DEFAULT_CONFIG_CENTER_FILE + group = config.group or DEFAULT_CONFIG_CENTER_GROUP + parser = _parser(key, config.format) + check = DEFAULT_CONFIG_CENTER_CHECK if config.check is None else config.check + + try: + center = await get_config_center(url) + text = await center.get(key, group=group) + # A missing implementation is a configuration mistake, which check does not excuse. + except ExtensionError as error: + raise ConfigReadError(f"cannot load configuration center {url.protocol!r} for {url}") from error + # Implementations raise the errors of their own clients. + except Exception as error: + if check: + raise ConfigReadError(f"cannot read configuration center {url}") from error + _logger.warning("Starting without configuration center %s", url, exc_info=True) + return {} + + if text is None or not text.strip(): + return {} + + try: + data = parser.loads(text) + except ConfigParseError as error: + raise ConfigParseError(f"{error} in {key!r} of group {group!r}") from error.__cause__ + # The configuration center is already connected and cannot move itself. + if "config_center" in data: + raise ConfigError(f"configuration center entry {key!r} must not set config_center") + return data + + +def _parser(source: str, format: str | None) -> ConfigParser: + """Return the parser ``format`` names, else the one the suffix of ``source``, a path or key, names.""" + name = format or PurePosixPath(source).suffix.removeprefix(".") + if not name: + raise ConfigReadError(f"cannot select a parser for {source!r}: it has no suffix and no format is set") + + try: + return get_parser(name) + except ConfigReadError as error: + raise ConfigReadError(f"{error} for {source!r}") from error.__cause__ + + +def _read_prefixed_env(prefix: str) -> ConfigData: + """Read the environment variables named with ``prefix`` as nested, lowercase keys. + + ``__`` separates path segments: DUBBO__PROTOCOLS__TRI__PORT sets + ``protocols.tri.port``. A variable that targets a mapping, list or nested + configuration holds JSON, which keeps keys such as dotted service names + intact. Other values stay strings until the configuration converts them. + + Raises: + ConfigReadError: Two variables collide after normalization, a path has + an empty segment, or a JSON value is invalid. + """ + tree: dict[str, object] = {} + for name, value in os.environ.items(): + if not name.startswith(prefix): + continue + try: + insert_path(tree, name[len(prefix) :].lower().split("__"), value) + except ValueError as error: + raise ConfigReadError(f"invalid configuration path in environment variable {name!r}: {error}") from None + + try: + return decode_json(tree, DubboConfig) + except ValueError as error: + raise ConfigReadError(f"invalid environment configuration: {error}") from error.__cause__ diff --git a/src/dubbo/config/models.py b/src/dubbo/config/models.py new file mode 100644 index 00000000..3b2991e5 --- /dev/null +++ b/src/dubbo/config/models.py @@ -0,0 +1,1083 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import enum +import os +import re +import ssl +from collections.abc import Mapping +from typing import Self + +import attrs +from attrs import converters, validators + +from dubbo.constants import ( + ACCESSLOG_KEY, + ACTIVES_KEY, + APPLICATION_KEY, + ARCHITECTURE_KEY, + BACKUP_KEY, + CA_CERT_FILE_KEY, + CHECK_KEY, + CLUSTER_KEY, + COMPRESSOR_KEY, + CONNECT_TIMEOUT_KEY, + CONNECTION_INITIAL_WINDOW_SIZE_KEY, + DEFAULT_CONFIG_CENTER_TIMEOUT, + DEFAULT_PROTOCOL, + DEPRECATED_KEY, + ENVIRONMENT_KEY, + EXECUTES_KEY, + GROUP_KEY, + HEALTH_ENABLED_KEY, + HEARTBEAT_KEY, + HEARTBEAT_TIMEOUT_KEY, + INITIAL_WINDOW_SIZE_KEY, + KEEP_ALIVE_INTERVAL_KEY, + KEEP_ALIVE_TIMEOUT_KEY, + LOADBALANCE_KEY, + MAX_CONCURRENT_CALLS_KEY, + MAX_CONCURRENT_STREAMS_KEY, + MAX_HEADER_LIST_SIZE_KEY, + MAX_RECEIVE_MESSAGE_SIZE_KEY, + NAMESPACE_KEY, + ORGANIZATION_KEY, + OWNER_KEY, + PAYLOAD_KEY, + PREFERRED_KEY, + PROVIDED_BY_KEY, + REFERENCE_FILTER_KEY, + REFLECTION_ENABLED_KEY, + REGISTER_KEY, + REGISTER_MODE_KEY, + RETRIES_KEY, + ROUTER_KEY, + SERIALIZATION_KEY, + SERVICE_FILTER_KEY, + SHUTWAIT_KEY, + STICKY_KEY, + SUBSCRIBE_KEY, + TAG_KEY, + TIMEOUT_KEY, + TLS_CERT_FILE_KEY, + TLS_KEY_FILE_KEY, + TLS_SERVER_NAME_KEY, + TOKEN_KEY, + TPS_INTERVAL_KEY, + TPS_KEY, + TRIPLE_KEY, + VERSION_KEY, + WARMUP_KEY, + WEIGHT_KEY, + ZONE_KEY, +) +from dubbo.filter.base import ATTEMPT_FILTER_KEY +from dubbo.url import URL +from dubbo.utils.converters import milliseconds, to_milliseconds + +from .fields import check_address_keys, check_url_keys, env_variable, to_url_parameters, url_nested, url_parameter + +__all__ = [ + "ApplicationConfig", + "ConfigCenterConfig", + "ConsumerConfig", + "DubboConfig", + "DubboProtocolConfig", + "MetadataReportConfig", + "MetadataType", + "MethodConfig", + "ProtocolConfig", + "ProviderConfig", + "ReferenceConfig", + "RegistryConfig", + "RegistryMode", + "ServiceConfig", + "ShutdownConfig", + "TLSConfig", + "TripleConfig", +] + +_positive = validators.optional(validators.gt(0)) +_non_negative = validators.optional(validators.ge(0)) +_names = validators.optional(validators.deep_iterable(validators.instance_of(str), validators.instance_of(tuple))) +_parameters = validators.deep_mapping(validators.instance_of(str), validators.instance_of(str)) + + +# Scheme, authority, then the path and query, of an address with comma-separated hosts. +_ADDRESS = re.compile(r"(?P[^:/?]+)://(?P[^/?]*)(?P.*)", re.DOTALL) + + +def _address_url(address: str) -> URL: + """Return the URL of an address, the hosts after the first moved to ``backup``. + + Raises: + ValueError: The address has no scheme or host, an empty host, or + lists further hosts both after commas and in ``backup``. + """ + match = _ADDRESS.fullmatch(address.strip()) + if match is None: + raise ValueError("needs a scheme, as in zookeeper://127.0.0.1:2181") + + userinfo, at, hosts = match["authority"].rpartition("@") + host, *backups = hosts.split(",") + if not all(backups): + raise ValueError("lists an empty host") + + url = URL.parse(f"{match['scheme']}://{userinfo}{at}{host}{match['rest']}") + if url.host is None: + raise ValueError("needs a host, as in zookeeper://127.0.0.1:2181") + if not backups: + return url + + if BACKUP_KEY in url.parameters: + raise ValueError(f"lists further hosts both after commas and in {BACKUP_KEY!r}") + return url.update_parameters({BACKUP_KEY: ",".join(backups)}) + + +def _address(_: object, attribute: "attrs.Attribute[str]", value: str) -> None: + try: + _address_url(value) + except ValueError as error: + raise ValueError(f"{attribute.name} {error}") from None + + +def _url(_: object, attribute: "attrs.Attribute[str]", value: str) -> None: + try: + url = URL.parse(value) + except ValueError as error: + raise ValueError(f"{attribute.name} {error}") from None + if url.host is None: + raise ValueError(f"{attribute.name} needs a host, as in tri://127.0.0.1:50051") + + +def _token(_: object, attribute: "attrs.Attribute[bool | str | None]", value: bool | str | None) -> None: + if value == "": + raise ValueError(f"{attribute.name} must not be empty; set it to false to require none") + + +_urls = validators.optional( + validators.deep_iterable(validators.and_(validators.instance_of(str), _url), validators.instance_of(tuple)) +) + +# The URL parameters that the fields of services, references and methods become. +_GROUP = url_parameter(GROUP_KEY) +_VERSION = url_parameter(VERSION_KEY) +_TIMEOUT = url_parameter(TIMEOUT_KEY, to_milliseconds) +_RETRIES = url_parameter(RETRIES_KEY) +_WEIGHT = url_parameter(WEIGHT_KEY) +_WARMUP = url_parameter(WARMUP_KEY, to_milliseconds) +_TAG = url_parameter(TAG_KEY) +_CLUSTER = url_parameter(CLUSTER_KEY) +_LOADBALANCE = url_parameter(LOADBALANCE_KEY) +_STICKY = url_parameter(STICKY_KEY) +_CHECK = url_parameter(CHECK_KEY) +_SERVICE_FILTERS = url_parameter(SERVICE_FILTER_KEY, ",".join) +_REFERENCE_FILTERS = url_parameter(REFERENCE_FILTER_KEY, ",".join) +_ATTEMPT_FILTERS = url_parameter(ATTEMPT_FILTER_KEY, ",".join) +_ROUTERS = url_parameter(ROUTER_KEY, ",".join) +_TOKEN = url_parameter(TOKEN_KEY) +_ACCESSLOG = url_parameter(ACCESSLOG_KEY) +_EXECUTES = url_parameter(EXECUTES_KEY) +_TPS = url_parameter(TPS_KEY) +_TPS_INTERVAL = url_parameter(TPS_INTERVAL_KEY, to_milliseconds) +_DEPRECATED = url_parameter(DEPRECATED_KEY) +_ACTIVES = url_parameter(ACTIVES_KEY) +_SERIALIZATION = url_parameter(SERIALIZATION_KEY) + + +class RegistryMode(enum.StrEnum): + """How an application registers its services and discovers providers in a registry. + + Attributes: + INTERFACE: Providers register each service URL, and consumers + discover them by interface. + INSTANCE: Providers register one instance per application, which + serves its metadata, and consumers discover the instances of the + applications that provide an interface. + ALL: Providers register both ways. Consumers call the providers + found by instance while there are any, else those found by + interface. + """ + + INTERFACE = "interface" + INSTANCE = "instance" + ALL = "all" + + +class MetadataType(enum.StrEnum): + """Where consumers read the metadata of an application's instances. + + Attributes: + LOCAL: Each instance serves its metadata itself, through + MetadataServiceV2 over tri, else the MetadataService 1.0.0 over + dubbo, which needs the hessian2 extra. + REMOTE: The metadata is stored in `DubboConfig.metadata_report`, else + in the registry. + """ + + LOCAL = "local" + REMOTE = "remote" + + +# Classes run from leaves to the root: field annotations are evaluated when each +# class is created, and structure_config reads them as real types. +# +# Optional fields default to None, meaning "not set": a lower configuration +# layer or the enclosing section supplies the value. Effective defaults are +# applied where the configuration is used, so None never hides a lower layer. + + +@attrs.define(frozen=True, kw_only=True) +class ApplicationConfig: + """Identify the application that provides or consumes services. + + Attributes: + name: Application name, shown to registries and governance tools; + required once a registry is defined, since registries group + instances by it. + version: Application version, if any. + owner: People responsible for the application, separated by commas. + organization: Organization that owns the application. + architecture: Architecture of the application, as its owners + describe it, such as a business domain. + environment: Environment the application runs in, such as + ``develop``, ``test`` or ``product``. + metadata_type: Where consumers read the metadata of this + application's instances; ``None`` means ``local``. + advertised_host: Address that registries and the rules of others + see for this application, when the address it listens on + cannot be reached, as behind NAT or in a container; ``None`` + finds one. The ``DUBBO_IP_TO_REGISTRY`` environment variable + sets it. + advertised_port: Port registered in place of the one it listens on + for each protocol whose ``advertised_port`` is not set; ``None`` + registers that one. The ``DUBBO_PORT_TO_REGISTRY`` environment + variable sets it. + """ + + name: str | None = attrs.field( + default=None, validator=validators.optional(validators.min_len(1)), metadata=url_parameter(APPLICATION_KEY) + ) + version: str | None = None + owner: str | None = attrs.field(default=None, metadata=url_parameter(OWNER_KEY)) + organization: str | None = attrs.field(default=None, metadata=url_parameter(ORGANIZATION_KEY)) + architecture: str | None = attrs.field(default=None, metadata=url_parameter(ARCHITECTURE_KEY)) + environment: str | None = attrs.field(default=None, metadata=url_parameter(ENVIRONMENT_KEY)) + metadata_type: MetadataType | None = None + advertised_host: str | None = attrs.field(default=None, metadata=env_variable("DUBBO_IP_TO_REGISTRY")) + advertised_port: int | None = attrs.field( + default=None, + validator=validators.optional([validators.ge(1), validators.le(65535)]), + metadata=env_variable("DUBBO_PORT_TO_REGISTRY"), + ) + + +@attrs.define(frozen=True, kw_only=True) +class RegistryConfig: + """Connect to one registry. + + Attributes: + address: Registry URL; its scheme selects the registry implementation, + as in ``zookeeper://127.0.0.1:2181``. A cluster lists further hosts + after commas, as in ``zookeeper://zk1:2181,zk2:2181``. Query + parameters reach the implementation. + group: Keeps the data of the registry apart from that of others in + the same cluster; in ZooKeeper, the root node of it, ``dubbo`` + by default. + namespace: Nacos namespace ID that the data of the registry is in; + ``None`` means ``public``. ZooKeeper ignores it. + mode: How services register and providers are discovered; + ``None`` means ``all``. + register: Whether the application registers its services and + references with the registry; ``None`` means it does. + subscribe: Whether references discover providers through the + registry; ``None`` means they do. + preferred: Whether a reference of several registries calls the + providers of this one while it has any. + zone: Zone of the registry, which calls whose ``registry.zone`` + attachment names it go to first. + weight: Share of the calls of a reference of several registries + that go to this one, relative to the others; ``None`` means 100. + parameters: Options for the implementation, such as ``session``, and + for what is registered, such as ``simplified`` and + ``extra-keys``, added to the URL query. They merge key by key + across configuration layers, which a query string cannot. + use_as_config_center: Whether the registry also serves as the + configuration center when none is set; ``None`` lets the first + registry whose kind can serve as one do so. + + Raises: + ValueError: A parameter and a query parameter of the address, or + either and a field that is set, set one key to different values. + """ + + address: str = attrs.field(validator=_address) + group: str | None = attrs.field(default=None, metadata=url_parameter(GROUP_KEY)) + namespace: str | None = attrs.field(default=None, metadata=url_parameter(NAMESPACE_KEY)) + mode: RegistryMode | None = attrs.field(default=None, metadata=url_parameter(REGISTER_MODE_KEY)) + register: bool | None = attrs.field(default=None, metadata=url_parameter(REGISTER_KEY)) + subscribe: bool | None = attrs.field(default=None, metadata=url_parameter(SUBSCRIBE_KEY)) + preferred: bool | None = attrs.field(default=None, metadata=url_parameter(PREFERRED_KEY)) + zone: str | None = attrs.field(default=None, metadata=url_parameter(ZONE_KEY)) + weight: int | None = attrs.field(default=None, validator=_non_negative, metadata=url_parameter(WEIGHT_KEY)) + parameters: dict[str, str] = attrs.field(factory=dict, validator=_parameters, metadata=url_nested()) + use_as_config_center: bool | None = None + + def __attrs_post_init__(self) -> None: + # Each key appears once in the URL that to_url builds. + check_address_keys(self, self.parameters, _address_url(self.address).parameters) + + def to_url(self) -> URL: + """Return the URL of the registry, which creates its implementations and says how to use it. + + The address keeps its query parameters, and the fields that are set + and ``parameters`` are added. + """ + url = _address_url(self.address) + return url.replace(parameters={**to_url_parameters(self), **url.parameters}) + + +@attrs.define(frozen=True, kw_only=True) +class TripleConfig: + """Tune the Triple protocol, on the side whose configuration holds it. + + A protocol's settings tune its server; the consumer's and a reference's + tune the calls they make. ``None`` leaves a value to the protocol, or for + a reference, to the consumer. + + Attributes: + max_receive_message_size: Bytes of the largest message received; + ``None`` means 4 MiB. + compressor: Name of the compression of the messages sent, such as + ``gzip``; ``None`` sends them uncompressed. A server compresses + only for callers that accept it. + max_concurrent_streams: Calls the other side may run at once on one + connection; ``None`` means 100. + initial_window_size: Bytes the other side may send on one call + before it waits for more credit; ``None`` means a window that + starts at 1 MiB and grows with the bandwidth-delay product + measured on the connection, up to 16 MiB. + connection_initial_window_size: Bytes the other side may send on one + connection before it waits for more credit; ``None`` means 16 MiB. + max_header_list_size: Bytes of the largest header block received; + ``None`` means 64 KiB. + keep_alive_interval: Seconds without traffic before a PING checks + the connection; ``None`` sends no PING. + keep_alive_timeout: Seconds to wait for the PING acknowledgement + before the connection closes; ``None`` means 20. + connect_timeout: Seconds a caller waits for a connection to be + established before the call fails as unavailable; ``None`` + means 3. + health_enabled: Whether a server also serves + ``grpc.health.v1.Health``; ``None`` means no. + reflection_enabled: Whether a server also serves + ``grpc.reflection.v1.ServerReflection`` and its earlier + ``grpc.reflection.v1alpha``; ``None`` means no. + parameters: Further options of the protocol and its transport, as + text, such as ``stream-send-buffer-size``. A reference's merge key + by key over the consumer's. + + The settings become URL parameters after ``triple.``, as in + ``triple.compressor``. + + Raises: + ValueError: A parameter is one that a field sets. + """ + + max_receive_message_size: int | None = attrs.field( + default=None, validator=_positive, metadata=url_parameter(MAX_RECEIVE_MESSAGE_SIZE_KEY) + ) + compressor: str | None = attrs.field(default=None, metadata=url_parameter(COMPRESSOR_KEY)) + max_concurrent_streams: int | None = attrs.field( + default=None, validator=_positive, metadata=url_parameter(MAX_CONCURRENT_STREAMS_KEY) + ) + initial_window_size: int | None = attrs.field( + default=None, validator=_positive, metadata=url_parameter(INITIAL_WINDOW_SIZE_KEY) + ) + connection_initial_window_size: int | None = attrs.field( + default=None, validator=_positive, metadata=url_parameter(CONNECTION_INITIAL_WINDOW_SIZE_KEY) + ) + max_header_list_size: int | None = attrs.field( + default=None, validator=_positive, metadata=url_parameter(MAX_HEADER_LIST_SIZE_KEY) + ) + keep_alive_interval: float | None = attrs.field( + default=None, validator=_positive, metadata=url_parameter(KEEP_ALIVE_INTERVAL_KEY, to_milliseconds) + ) + keep_alive_timeout: float | None = attrs.field( + default=None, validator=_positive, metadata=url_parameter(KEEP_ALIVE_TIMEOUT_KEY, to_milliseconds) + ) + connect_timeout: float | None = attrs.field( + default=None, validator=_positive, metadata=url_parameter(CONNECT_TIMEOUT_KEY, to_milliseconds) + ) + health_enabled: bool | None = attrs.field(default=None, metadata=url_parameter(HEALTH_ENABLED_KEY)) + reflection_enabled: bool | None = attrs.field(default=None, metadata=url_parameter(REFLECTION_ENABLED_KEY)) + parameters: dict[str, str] = attrs.field(factory=dict, validator=_parameters, metadata=url_nested()) + + def __attrs_post_init__(self) -> None: + check_url_keys(self, self.parameters) + + +@attrs.define(frozen=True, kw_only=True) +class DubboProtocolConfig: + """Tune a ``dubbo`` server. + + ``None`` leaves a value to the protocol. The settings become the URL + parameters other languages read, such as ``payload`` and ``heartbeat``. + + Attributes: + payload: Bytes of the largest request or response body; ``None`` + means 8 MiB. + heartbeat: Seconds of silence before a consumer sends a heartbeat, + which also sets ``heartbeat_timeout``; ``None`` means 60. + heartbeat_timeout: Seconds without reading before a connection + closes; at least two heartbeats, ``None`` means three. + max_concurrent_calls: Calls the server runs at once; one more is + refused. ``None`` means 200, and 0 any number. + """ + + payload: int | None = attrs.field(default=None, validator=_positive, metadata=url_parameter(PAYLOAD_KEY)) + heartbeat: float | None = attrs.field( + default=None, validator=_positive, metadata=url_parameter(HEARTBEAT_KEY, to_milliseconds) + ) + heartbeat_timeout: float | None = attrs.field( + default=None, validator=_positive, metadata=url_parameter(HEARTBEAT_TIMEOUT_KEY, to_milliseconds) + ) + max_concurrent_calls: int | None = attrs.field( + default=None, validator=_non_negative, metadata=url_parameter(MAX_CONCURRENT_CALLS_KEY) + ) + + +@attrs.define(frozen=True, kw_only=True) +class ProtocolConfig: + """Accept requests with one protocol. + + Attributes: + name: Protocol name, such as ``tri``; it selects the implementation. + ``None`` takes the key of the protocol in ``DubboConfig.protocols``, + so that ``{"tri": ProtocolConfig(port=50051)}`` serves ``tri``. + host: Address to listen on; ``None`` means ``0.0.0.0``, every IPv4 + interface. + port: Port to listen on, 0 to let the operating system assign one, or + ``None`` for the protocol's default: 50051 for ``tri``, 20880 for + ``dubbo``. + advertised_port: Port registered in place of the one it listens on, + as behind NAT or a port mapping; ``None`` leaves it to + ``application.advertised_port``. + dubbo: Settings of a ``dubbo`` server. + triple: Settings of a ``tri`` server. + + A protocol ignores the settings of the others. + """ + + name: str | None = attrs.field(default=None, validator=validators.optional(validators.min_len(1))) + host: str | None = None + port: int | None = attrs.field( + default=None, validator=validators.optional([validators.ge(0), validators.le(65535)]) + ) + advertised_port: int | None = attrs.field( + default=None, validator=validators.optional([validators.ge(1), validators.le(65535)]) + ) + dubbo: DubboProtocolConfig = attrs.field(factory=DubboProtocolConfig, metadata=url_nested()) + triple: TripleConfig = attrs.field(factory=TripleConfig, metadata=url_nested(TRIPLE_KEY)) + + +@attrs.define(frozen=True, kw_only=True) +class MetadataReportConfig: + """Where application-level discovery stores the metadata of instances and the applications that provide each interface, when not in the registries. + + The metadata of instances is stored there when + ``application.metadata_type`` is ``remote``. + + Attributes: + address: Metadata report URL; its scheme selects the implementation, + as in ``zookeeper://127.0.0.1:2181``. A cluster lists further + hosts after commas. Query parameters reach the implementation. + group: Keeps the data apart from that of others in the same cluster; + ``None`` leaves it to the implementation. + namespace: Nacos namespace ID that the data is in; ``None`` means + ``public``. ZooKeeper ignores it. + parameters: Options for the implementation, such as ``timeout``, + added to the URL query. They merge key by key across + configuration layers, which a query string cannot. + + Raises: + ValueError: A parameter and a query parameter of the address, or + either and a field that is set, set one key to different values. + """ + + address: str = attrs.field(validator=_address) + group: str | None = attrs.field(default=None, metadata=url_parameter(GROUP_KEY)) + namespace: str | None = attrs.field(default=None, metadata=url_parameter(NAMESPACE_KEY)) + parameters: dict[str, str] = attrs.field(factory=dict, validator=_parameters, metadata=url_nested()) + + def __attrs_post_init__(self) -> None: + # Each key appears once in the URL that to_url builds. + check_address_keys(self, self.parameters, _address_url(self.address).parameters) + + def to_url(self) -> URL: + """Return the URL of the metadata report, which creates its implementation. + + The address keeps its query parameters, and the fields that are set + and ``parameters`` are added. + """ + url = _address_url(self.address) + return url.replace(parameters={**to_url_parameters(self), **url.parameters}) + + +@attrs.define(frozen=True, kw_only=True) +class ConfigCenterConfig: + """Read configuration from a configuration center at startup. + + The entry under the key ``config_file`` in ``group`` is read once. It ranks + above the configuration sources and below environment variables and code. + + Attributes: + address: Configuration center URL; its scheme selects the + implementation, as in ``zookeeper://127.0.0.1:2181``. A cluster + lists further hosts after commas. Query parameters reach the + implementation. + namespace: Isolates the entries of one environment; ``None`` leaves + it to the implementation, such as ``dubbo`` for ZooKeeper, whose + entries are under ``/{namespace}/config``. + group: Group of the entry; ``None`` means ``dubbo``. + config_file: Key of the entry; ``None`` means ``dubbo.yaml``. + format: Name of the parser for the entry, such as ``yaml``; ``None`` + uses the suffix of ``config_file``. + timeout: Seconds each operation of the implementation may take; must + be positive; ``None`` means 30. + check: Whether startup fails when the entry cannot be read; when + false, startup continues without it. ``None`` means true. + parameters: Options for the implementation, such as ``session``, + added to the URL query. They merge key by key across + configuration layers, which a query string cannot. + + Raises: + ValueError: A parameter and a query parameter of the address, or + either and a field that is set, set one key to different values. + """ + + address: str = attrs.field(validator=_address) + namespace: str | None = attrs.field(default=None, metadata=url_parameter(NAMESPACE_KEY)) + group: str | None = None + config_file: str | None = None + format: str | None = None + timeout: float | None = attrs.field( + default=None, + validator=_positive, + metadata=url_parameter(TIMEOUT_KEY, to_milliseconds, default=DEFAULT_CONFIG_CENTER_TIMEOUT), + ) + check: bool | None = None + parameters: dict[str, str] = attrs.field(factory=dict, validator=_parameters, metadata=url_nested()) + + @classmethod + def from_registry(cls, registry: RegistryConfig) -> Self: + """Return the configuration center that ``registry`` also serves as. + + It has the address and the options of the registry; the namespace of + the registry, else its group, becomes its namespace, and a + ``timeout`` option its timeout. + + Raises: + ValueError: The ``timeout`` of the registry is not whole milliseconds. + """ + url = _address_url(registry.address) + parameters: dict[str, str] = {**url.parameters, **registry.parameters} + timeout = parameters.pop(TIMEOUT_KEY, None) + group = parameters.pop(GROUP_KEY, None) or registry.group + namespace = parameters.pop(NAMESPACE_KEY, None) or registry.namespace + return cls( + address=url.replace(parameters={}).render_as_string(hide_secrets=False), + namespace=namespace or group, + timeout=None if timeout is None else milliseconds(timeout), + parameters=parameters, + ) + + def __attrs_post_init__(self) -> None: + # Each key appears once in the URL that to_url builds. + check_address_keys(self, self.parameters, _address_url(self.address).parameters) + + def to_url(self) -> URL: + """Return the URL that creates the implementation. + + The address keeps its query parameters, and the fields that become + URL parameters, with their defaults when left as ``None`` and the + address does not set them, and ``parameters`` are added. + """ + url = _address_url(self.address) + return url.replace(parameters={**to_url_parameters(self), **url.parameters}) + + +@attrs.define(frozen=True, kw_only=True) +class MethodConfig: + """Override call settings for one method. + + ``None`` inherits the value of the enclosing service or reference. A + setting of the other side, such as ``retries`` of a service, does + nothing. + + Attributes: + timeout: Seconds a unary call may take before it fails; must be + positive. + retries: Additional attempts after a failed call, for a reference. + loadbalance: Name of the load balance that chooses the provider of + each call of the method, for a reference. + sticky: Whether each call of the method goes to the provider the + call before went to while that one is available, for a reference. + weight: Share of the calls of the method a provider takes among its + providers, relative to their weights, for a service; must not + be negative. + executes: Calls of the method a provider serves at once, for a + service; one more fails as unavailable. ``None`` and 0 serve + any number. + tps: Calls of the method a provider serves in each ``tps_interval``, + counted apart from the other methods, for a service; one more + fails as unavailable. + tps_interval: Seconds of each window ``tps`` counts calls in, for a + service. + deprecated: Whether consumers log a warning the first time they + call the method, for a service. + actives: Calls of the method a consumer makes to one provider at + once, for a reference; one more waits for one of them to end, up + to its timeout, then fails as unavailable. ``None`` and 0 make + any number. + """ + + timeout: float | None = attrs.field(default=None, validator=_positive, metadata=_TIMEOUT) + retries: int | None = attrs.field(default=None, validator=_non_negative, metadata=_RETRIES) + loadbalance: str | None = attrs.field(default=None, metadata=_LOADBALANCE) + sticky: bool | None = attrs.field(default=None, metadata=_STICKY) + weight: int | None = attrs.field(default=None, validator=_non_negative, metadata=_WEIGHT) + executes: int | None = attrs.field(default=None, validator=_non_negative, metadata=_EXECUTES) + tps: int | None = attrs.field(default=None, validator=_non_negative, metadata=_TPS) + tps_interval: float | None = attrs.field(default=None, validator=_positive, metadata=_TPS_INTERVAL) + deprecated: bool | None = attrs.field(default=None, metadata=_DEPRECATED) + actives: int | None = attrs.field(default=None, validator=_non_negative, metadata=_ACTIVES) + + +@attrs.define(frozen=True, kw_only=True) +class ServiceConfig: + """Override provider defaults for one exposed service. + + The implementation is registered in code and matched to this entry by + service name. ``None`` inherits the provider value. + + Attributes: + group: Service group, part of the service identity. + version: Service version, part of the service identity. + timeout: Seconds a unary call may take before it fails; must be + positive. Registries publish it to consumers that set none. + weight: Share of the calls the service takes among its providers, + relative to their weights; must not be negative. ``None`` weighs 100. + warmup: Seconds after a provider registers over which its weight + rises to the full; ``None`` means 600. + tag: Tag of the service, which calls asking for it go to first. + serialization: Name of the format the messages of the service are + encoded in; ``None`` means protobuf over + ``tri`` and hessian2 over ``dubbo``. + registries: Names from ``DubboConfig.registries`` to register with. + protocols: Names from ``DubboConfig.protocols`` to expose the service on. + filters: Names of the filters each call to the service runs + through, the first outermost, after those its settings add. + token: Secret that each call must attach, which registries publish + to consumers; true makes a random one, false requires none. + accesslog: Whether each call is logged at INFO to the + ``dubbo.accesslog`` logger. + executes: Calls of each method served at once; one more fails as + unavailable. ``None`` and 0 serve any number. + tps: Calls served in each ``tps_interval``, counted over all methods + but those that set their own; one more fails as unavailable. + ``None`` and 0 serve any number. + tps_interval: Seconds of each window ``tps`` counts calls in; + ``None`` means 60. + deprecated: Whether consumers log a warning the first time they + call each method. + parameters: Further URL parameters, below those the settings here + produce. + methods: Overrides keyed by method name. + """ + + group: str | None = attrs.field(default=None, metadata=_GROUP) + version: str | None = attrs.field(default=None, metadata=_VERSION) + timeout: float | None = attrs.field(default=None, validator=_positive, metadata=_TIMEOUT) + weight: int | None = attrs.field(default=None, validator=_non_negative, metadata=_WEIGHT) + warmup: float | None = attrs.field(default=None, validator=_non_negative, metadata=_WARMUP) + tag: str | None = attrs.field(default=None, metadata=_TAG) + serialization: str | None = attrs.field(default=None, metadata=_SERIALIZATION) + registries: tuple[str, ...] | None = attrs.field(default=None, validator=_names) + protocols: tuple[str, ...] | None = attrs.field(default=None, validator=_names) + filters: tuple[str, ...] | None = attrs.field(default=None, validator=_names, metadata=_SERVICE_FILTERS) + token: bool | str | None = attrs.field(default=None, validator=_token, metadata=_TOKEN) + accesslog: bool | None = attrs.field(default=None, metadata=_ACCESSLOG) + executes: int | None = attrs.field(default=None, validator=_non_negative, metadata=_EXECUTES) + tps: int | None = attrs.field(default=None, validator=_non_negative, metadata=_TPS) + tps_interval: float | None = attrs.field(default=None, validator=_positive, metadata=_TPS_INTERVAL) + deprecated: bool | None = attrs.field(default=None, metadata=_DEPRECATED) + parameters: dict[str, str] = attrs.field(factory=dict, validator=_parameters, metadata=url_nested()) + methods: dict[str, MethodConfig] = attrs.field(factory=dict, metadata=url_nested()) + + def __attrs_post_init__(self) -> None: + check_url_keys(self, self.parameters) + + +@attrs.define(frozen=True, kw_only=True) +class ReferenceConfig: + """Override consumer defaults for one referenced service. + + ``None`` inherits the consumer value. + + Attributes: + urls: Addresses of the providers to call directly instead of + discovering them, as in ``tri://10.0.0.5:50051``; the scheme of + each selects its protocol. A URL without a path calls the service + by its name. Query parameters reach the protocol, below those the + settings here produce. A reference with urls also calls the + providers of the registries it sets itself, but not those of the + consumer's. + group: Group of the service to call. + version: Version of the service to call. + timeout: Seconds a unary call may take before it fails; must be + positive. ``None`` takes the provider's, else 1. + retries: Further attempts, on other providers, after an attempt fails + with ``UNAVAILABLE``, as when none can take it; ``None`` means 2. + cluster: Name of the cluster that makes each call through the + providers; ``None`` means ``failover``, which makes the retries. + loadbalance: Name of the load balance that chooses the provider of + each call; ``None`` chooses at random by weight. + sticky: Whether each call goes to the provider the call before went + to while that one is available, the load balance choosing only + when it is not; ``None`` means false. + check: Whether startup fails with `RpcError` ``UNAVAILABLE`` when no + provider is connected within 3 seconds; ``None`` means true. + tag: Tag of the providers that calls go to first, when a call does + not ask for one itself. + serialization: Name of the format the messages of the calls are + encoded in; ``None`` means protobuf over + ``tri`` and hessian2 over ``dubbo``. + registries: Names from ``DubboConfig.registries`` to discover providers + in, besides those ``urls`` names. + provided_by: Names of the applications that provide the service, for + registries in ``instance`` or ``all`` mode; ``None`` looks + them up in the registry. + triple: Settings of calls over ``tri``; ``None`` fields take the consumer's. + filters: Names of the filters each call runs through, the first + outermost, once per call whatever the retries. + attempt_filters: Names of the filters each attempt of a call runs + through, the first outermost, on the provider it goes to, after + those the settings add. + routers: Names of the routers that narrow the providers of each + call, in order; ``None`` takes the consumer's. + actives: Calls of each method made to one provider at once; one + more waits for one of them to end, up to its timeout, then fails + as unavailable. ``None`` and 0 make any number. + parameters: Further URL parameters, below those the settings here + produce. + methods: Overrides keyed by method name. + """ + + urls: tuple[str, ...] | None = attrs.field(default=None, validator=_urls) + group: str | None = attrs.field(default=None, metadata=_GROUP) + version: str | None = attrs.field(default=None, metadata=_VERSION) + timeout: float | None = attrs.field(default=None, validator=_positive, metadata=_TIMEOUT) + retries: int | None = attrs.field(default=None, validator=_non_negative, metadata=_RETRIES) + cluster: str | None = attrs.field(default=None, metadata=_CLUSTER) + loadbalance: str | None = attrs.field(default=None, metadata=_LOADBALANCE) + sticky: bool | None = attrs.field(default=None, metadata=_STICKY) + check: bool | None = attrs.field(default=None, metadata=_CHECK) + tag: str | None = attrs.field(default=None, metadata=_TAG) + serialization: str | None = attrs.field(default=None, metadata=_SERIALIZATION) + registries: tuple[str, ...] | None = attrs.field(default=None, validator=_names) + provided_by: tuple[str, ...] | None = attrs.field( + default=None, validator=_names, metadata=url_parameter(PROVIDED_BY_KEY, ",".join) + ) + triple: TripleConfig = attrs.field(factory=TripleConfig, metadata=url_nested(TRIPLE_KEY)) + filters: tuple[str, ...] | None = attrs.field(default=None, validator=_names, metadata=_REFERENCE_FILTERS) + attempt_filters: tuple[str, ...] | None = attrs.field(default=None, validator=_names, metadata=_ATTEMPT_FILTERS) + routers: tuple[str, ...] | None = attrs.field(default=None, validator=_names, metadata=_ROUTERS) + actives: int | None = attrs.field(default=None, validator=_non_negative, metadata=_ACTIVES) + parameters: dict[str, str] = attrs.field(factory=dict, validator=_parameters, metadata=url_nested()) + methods: dict[str, MethodConfig] = attrs.field(factory=dict, metadata=url_nested()) + + def __attrs_post_init__(self) -> None: + check_url_keys(self, self.parameters) + + +@attrs.define(frozen=True, kw_only=True) +class ProviderConfig: + """Defaults for every exposed service, with per-service overrides. + + Attributes: + group: Service group, part of the service identity. + version: Service version, part of the service identity. + timeout: Seconds a unary call may take before it fails; must be + positive. Registries publish it to consumers that set none. + weight: Share of the calls each service takes among its providers, + relative to their weights; must not be negative. ``None`` weighs 100. + warmup: Seconds after a provider registers over which its weight + rises to the full; ``None`` means 600. + tag: Tag of the services, which calls asking for it go to first. + serialization: Name of the format the messages of the services are + encoded in; ``None`` means protobuf over + ``tri`` and hessian2 over ``dubbo``. + registries: Names from ``DubboConfig.registries`` to register with; + ``None`` uses all of them. + protocols: Names from ``DubboConfig.protocols`` to expose services on; + ``None`` uses all of them. + filters: Names of the filters each call to a service runs through, + the first outermost, after those its settings add; ``None`` runs + no others. + token: Secret that each call must attach, which registries publish + to consumers; true makes a random one, false requires none. + accesslog: Whether each call is logged at INFO to the + ``dubbo.accesslog`` logger. + executes: Calls of each method served at once; one more fails as + unavailable. ``None`` and 0 serve any number. + tps: Calls served in each ``tps_interval``, counted over all methods + but those that set their own; one more fails as unavailable. + ``None`` and 0 serve any number. + tps_interval: Seconds of each window ``tps`` counts calls in; + ``None`` means 60. + parameters: Further URL parameters, below those the settings here + produce. + services: Overrides keyed by service name. + """ + + group: str | None = attrs.field(default=None, metadata=_GROUP) + version: str | None = attrs.field(default=None, metadata=_VERSION) + timeout: float | None = attrs.field(default=None, validator=_positive, metadata=_TIMEOUT) + weight: int | None = attrs.field(default=None, validator=_non_negative, metadata=_WEIGHT) + warmup: float | None = attrs.field(default=None, validator=_non_negative, metadata=_WARMUP) + tag: str | None = attrs.field(default=None, metadata=_TAG) + serialization: str | None = attrs.field(default=None, metadata=_SERIALIZATION) + registries: tuple[str, ...] | None = attrs.field(default=None, validator=_names) + protocols: tuple[str, ...] | None = attrs.field(default=None, validator=_names) + filters: tuple[str, ...] | None = attrs.field(default=None, validator=_names, metadata=_SERVICE_FILTERS) + token: bool | str | None = attrs.field(default=None, validator=_token, metadata=_TOKEN) + accesslog: bool | None = attrs.field(default=None, metadata=_ACCESSLOG) + executes: int | None = attrs.field(default=None, validator=_non_negative, metadata=_EXECUTES) + tps: int | None = attrs.field(default=None, validator=_non_negative, metadata=_TPS) + tps_interval: float | None = attrs.field(default=None, validator=_positive, metadata=_TPS_INTERVAL) + parameters: dict[str, str] = attrs.field(factory=dict, validator=_parameters, metadata=url_nested()) + services: dict[str, ServiceConfig] = attrs.field(factory=dict) + + def __attrs_post_init__(self) -> None: + check_url_keys(self, self.parameters) + + +@attrs.define(frozen=True, kw_only=True) +class ConsumerConfig: + """Defaults for every referenced service, with per-reference overrides. + + Attributes: + group: Group of the services to call. + version: Version of the services to call. + timeout: Seconds a unary call may take before it fails; must be + positive. ``None`` takes the provider's, else 1. + retries: Further attempts, on other providers, after an attempt fails + with ``UNAVAILABLE``, as when none can take it; ``None`` means 2. + cluster: Name of the cluster that makes each call through the + providers; ``None`` means ``failover``, which makes the retries. + loadbalance: Name of the load balance that chooses the provider of + each call; ``None`` chooses at random by weight. + sticky: Whether each call goes to the provider the call before went + to while that one is available, the load balance choosing only + when it is not; ``None`` means false. + check: Whether startup fails with `RpcError` ``UNAVAILABLE`` when no + provider is connected within 3 seconds; ``None`` means true. + tag: Tag of the providers that calls go to first, when a call does + not ask for one itself. + serialization: Name of the format the messages of the calls are + encoded in; ``None`` means protobuf over + ``tri`` and hessian2 over ``dubbo``. + registries: Names from ``DubboConfig.registries`` to discover providers + in; ``None`` uses all of them. References that set ``urls`` use none. + triple: Settings of calls over ``tri``. + filters: Names of the filters each call runs through, the first + outermost, once per call whatever the retries; ``None`` runs none. + attempt_filters: Names of the filters each attempt of a call runs + through, the first outermost, on the provider it goes to, after + those the settings add; ``None`` runs no others. + routers: Names of the routers that narrow the providers of each + call, in order; ``None`` runs ``tag``, then ``condition``. + actives: Calls of each method made to one provider at once; one + more waits for one of them to end, up to its timeout, then fails + as unavailable. ``None`` and 0 make any number. + parameters: Further URL parameters, below those the settings here + produce. + references: Overrides keyed by service name. + """ + + group: str | None = attrs.field(default=None, metadata=_GROUP) + version: str | None = attrs.field(default=None, metadata=_VERSION) + timeout: float | None = attrs.field(default=None, validator=_positive, metadata=_TIMEOUT) + retries: int | None = attrs.field(default=None, validator=_non_negative, metadata=_RETRIES) + cluster: str | None = attrs.field(default=None, metadata=_CLUSTER) + loadbalance: str | None = attrs.field(default=None, metadata=_LOADBALANCE) + sticky: bool | None = attrs.field(default=None, metadata=_STICKY) + check: bool | None = attrs.field(default=None, metadata=_CHECK) + tag: str | None = attrs.field(default=None, metadata=_TAG) + serialization: str | None = attrs.field(default=None, metadata=_SERIALIZATION) + registries: tuple[str, ...] | None = attrs.field(default=None, validator=_names) + triple: TripleConfig = attrs.field(factory=TripleConfig, metadata=url_nested(TRIPLE_KEY)) + filters: tuple[str, ...] | None = attrs.field(default=None, validator=_names, metadata=_REFERENCE_FILTERS) + attempt_filters: tuple[str, ...] | None = attrs.field(default=None, validator=_names, metadata=_ATTEMPT_FILTERS) + routers: tuple[str, ...] | None = attrs.field(default=None, validator=_names, metadata=_ROUTERS) + actives: int | None = attrs.field(default=None, validator=_non_negative, metadata=_ACTIVES) + parameters: dict[str, str] = attrs.field(factory=dict, validator=_parameters, metadata=url_nested()) + references: dict[str, ReferenceConfig] = attrs.field(factory=dict) + + def __attrs_post_init__(self) -> None: + check_url_keys(self, self.parameters) + + +@attrs.define(frozen=True, kw_only=True) +class ShutdownConfig: + """How the application stops. + + It first tells callers it is stopping and leaves the registries, then + keeps serving for ``unregister_wait``, so that callers notice and turn + to other providers. It then stops taking calls and lets the running + ones, served and made, finish before cancelling them. All of it takes + at most ``grace``; what still runs then is cancelled. An application + whose task is cancelled stops at once, without these waits. + + Attributes: + unregister_wait: Seconds the services keep serving after they leave + the registries; ``None`` waits 3, and nothing is waited for + without registries. + grace: Seconds stopping may take in all; ``None`` means 10. A server + waits at most as long for its running calls. + """ + + unregister_wait: float | None = attrs.field(default=None, validator=_non_negative) + grace: float | None = attrs.field( + default=None, validator=_non_negative, metadata=url_parameter(SHUTWAIT_KEY, to_milliseconds) + ) + + +@attrs.define(frozen=True, kw_only=True) +class TLSConfig: + """Secure with TLS the connections the application serves and those it opens. + + Servers and clients each build a TLS context from the files, unless code + gives that side a context, which is used as it is. For ``tri`` it must + offer ALPN ``h2``, as ``context.set_alpn_protocols(["h2"])`` does. Code + may give the files as paths, which are kept as text. + + Attributes: + certfile: PEM file of the certificate chain to present, which a + server requires and a client presents when asked. + keyfile: PEM file of the private key of ``certfile``; ``None`` when + ``certfile`` holds it. + cafile: PEM file of the certificates to trust. A client trusts them + instead of the system certificates; a server with them requires + each client to present a certificate they sign. + server_hostname: Name a client checks the server certificate carries; + ``None`` takes the host of the provider. + server_context: Context of the servers, in place of the files; only + code can set it. + client_context: Context of the clients, in place of the files; only + code can set it. + """ + + certfile: str | None = attrs.field( + default=None, converter=converters.optional(os.fspath), metadata=url_parameter(TLS_CERT_FILE_KEY) + ) + keyfile: str | None = attrs.field( + default=None, converter=converters.optional(os.fspath), metadata=url_parameter(TLS_KEY_FILE_KEY) + ) + cafile: str | None = attrs.field( + default=None, converter=converters.optional(os.fspath), metadata=url_parameter(CA_CERT_FILE_KEY) + ) + server_hostname: str | None = attrs.field(default=None, metadata=url_parameter(TLS_SERVER_NAME_KEY)) + server_context: ssl.SSLContext | None = attrs.field( + default=None, validator=validators.optional(validators.instance_of(ssl.SSLContext)) + ) + client_context: ssl.SSLContext | None = attrs.field( + default=None, validator=validators.optional(validators.instance_of(ssl.SSLContext)) + ) + + +@attrs.define(frozen=True, kw_only=True) +class DubboConfig: + """The complete configuration of one Dubbo application. + + Attributes: + application: Identity of this application. + registries: Registries keyed by the names that providers, services, + consumers and references select them by. + protocols: Protocols keyed by the names that providers and services + select them by; ``tri`` with its defaults when none is defined. + provider: Settings for services this application exposes. + consumer: Settings for services this application calls. + config_center: Where to read further configuration and the rules + that change calls; ``None`` uses a registry that serves as one, + if any. + metadata_report: Where application-level discovery stores metadata + and the applications of each interface; ``None`` stores them in + each registry. + tls: TLS of the connections the application serves and opens; + ``None`` leaves them in cleartext. + shutdown: How the application stops. + + Raises: + ValueError: A registry is defined but ``application.name`` is not; + a provider, service, consumer or reference selects a registry or + protocol that is not defined; or ``application.advertised_port`` + would be registered for several protocols, which cannot share + one port. + """ + + application: ApplicationConfig = attrs.field(factory=ApplicationConfig) + registries: dict[str, RegistryConfig] = attrs.field(factory=dict) + protocols: dict[str, ProtocolConfig] = attrs.field( + factory=lambda: {DEFAULT_PROTOCOL: ProtocolConfig(name=DEFAULT_PROTOCOL)} + ) + provider: ProviderConfig = attrs.field(factory=ProviderConfig) + consumer: ConsumerConfig = attrs.field(factory=ConsumerConfig) + config_center: ConfigCenterConfig | None = None + metadata_report: MetadataReportConfig | None = None + tls: TLSConfig | None = None + shutdown: ShutdownConfig = attrs.field(factory=ShutdownConfig) + + def __attrs_post_init__(self) -> None: + if self.registries and self.application.name is None: + raise ValueError("application.name is required once a registry is defined") + if self.application.advertised_port is not None: + sharing = [name for name, protocol in self.protocols.items() if protocol.advertised_port is None] + if len(sharing) > 1: + raise ValueError( + f"application.advertised_port would be registered for the protocols {', '.join(map(repr, sharing))}; " + "set advertised_port on each of them" + ) + + # Field validators see one value; selected names refer to other sections. + provider, consumer = self.provider, self.consumer + _check_names("provider", provider.registries, self.registries, "registry") + _check_names("provider", provider.protocols, self.protocols, "protocol") + for name, service in provider.services.items(): + _check_names(f"service {name!r}", service.registries, self.registries, "registry") + _check_names(f"service {name!r}", service.protocols, self.protocols, "protocol") + + _check_names("consumer", consumer.registries, self.registries, "registry") + for name, reference in consumer.references.items(): + _check_names(f"reference {name!r}", reference.registries, self.registries, "registry") + + +def _check_names(owner: str, selected: tuple[str, ...] | None, defined: Mapping[str, object], kind: str) -> None: + for name in selected or (): + if name not in defined: + raise ValueError(f"{owner} selects undefined {kind} {name!r}") diff --git a/src/dubbo/config/parsers/__init__.py b/src/dubbo/config/parsers/__init__.py new file mode 100644 index 00000000..e4145226 --- /dev/null +++ b/src/dubbo/config/parsers/__init__.py @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .base import ConfigParser, get_parser + +__all__ = ["ConfigParser", "get_parser"] diff --git a/src/dubbo/config/parsers/base.py b/src/dubbo/config/parsers/base.py new file mode 100644 index 00000000..eb6a8a90 --- /dev/null +++ b/src/dubbo/config/parsers/base.py @@ -0,0 +1,57 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing + +from dubbo.config.data import ConfigData +from dubbo.config.exceptions import ConfigReadError +from dubbo.extension import ExtensionError, extension_point, extensions + +__all__ = ["ConfigParser", "get_parser"] + + +@extension_point("apache_dubbo.config.parser") +class ConfigParser(typing.Protocol): + """Reads one configuration format, such as YAML, into nested data. + + Implementations take no arguments to create. + """ + + def loads(self, text: str, /) -> ConfigData: + """Return the data ``text`` holds. + + The result is a mapping with string keys whose sections are nested + mappings, in the shape of DubboConfig: ``{"application": {"name": + "orders"}}``. Scalars keep the format's native types or stay strings + to be converted later. Callers treat the result as read-only. + + Raises: + ConfigParseError: Invalid syntax or a root that is not a mapping. + """ + ... + + +def get_parser(name: str) -> ConfigParser: + """Return the parser of the format ``name``, such as ``yaml`` or ``json``, in any case. + + Raises: + ConfigReadError: No parser by that name loads. + """ + try: + return extensions.get(ConfigParser, name.lower())() + except ExtensionError as error: + raise ConfigReadError(f"cannot load configuration parser {name!r}") from error diff --git a/src/dubbo/config/parsers/json.py b/src/dubbo/config/parsers/json.py new file mode 100644 index 00000000..ddf418d0 --- /dev/null +++ b/src/dubbo/config/parsers/json.py @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import json +from collections.abc import Mapping + +from dubbo.config.data import ConfigData +from dubbo.config.exceptions import ConfigParseError + +from .base import ConfigParser + +__all__ = ["JsonParser"] + + +class JsonParser(ConfigParser): + """Reads a JSON object with the standard library's decoding rules.""" + + def loads(self, text: str, /) -> ConfigData: + try: + data = json.loads(text) + except (ValueError, RecursionError) as error: + raise ConfigParseError("invalid JSON configuration") from error + + if not isinstance(data, Mapping): + raise ConfigParseError("configuration must have a mapping at its root") + return data diff --git a/src/dubbo/config/parsers/properties.py b/src/dubbo/config/parsers/properties.py new file mode 100644 index 00000000..d2869673 --- /dev/null +++ b/src/dubbo/config/parsers/properties.py @@ -0,0 +1,91 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import re + +from dubbo.config.data import ConfigData, insert_path +from dubbo.config.exceptions import ConfigParseError +from dubbo.config.fields import decode_json +from dubbo.config.models import DubboConfig +from dubbo.utils import require_optional_dependency + +with require_optional_dependency("dotproperties", extra="properties"): + import dotproperties + +from .base import ConfigParser + +__all__ = ["PropertiesParser"] + + +# A segment of a key: in brackets, which may hold dots, or up to the next dot or bracket. +_SEGMENT = re.compile(r"\[([^\[\]]+)\]|([^.\[\]]+)") + + +class PropertiesParser(ConfigParser): + """Reads Java properties, nesting dotted keys: ``a.b=1`` becomes ``{"a": {"b": "1"}}``. + + A segment in brackets keeps its dots, as Spring Boot writes map keys, so + that a service is named whole: ``provider.services[com.example.Greeter].timeout``, + or ``provider.services.[com.example.Greeter].timeout``. A value where + the configuration expects a list, a mapping or a section holds JSON, as + an environment variable does: + ``consumer.references[com.example.Echo].urls=["tri://127.0.0.1:50051"]``. + Other values stay strings. An invalid escape, an empty key segment, an + unclosed bracket, a key that is both a value and a section, or such a + value that is not JSON raises ConfigParseError. + """ + + def loads(self, text: str, /) -> ConfigData: + try: + flat = dotproperties.loads(text) + except ValueError as error: + raise ConfigParseError("invalid properties configuration") from error + + result: dict[str, object] = {} + key = "" + try: + for key, value in flat.items(): + insert_path(result, _segments(key), value) + except ValueError as error: + raise ConfigParseError(f"invalid properties key {key!r}: {error}") from None + + try: + return decode_json(result, DubboConfig) + except ValueError as error: + raise ConfigParseError(f"invalid properties configuration: {error}") from error.__cause__ + + +def _segments(key: str) -> list[str]: + """Split ``key`` at the dots outside brackets: ``a[b.c].d`` and ``a.[b.c].d`` are ``a``, ``b.c`` and ``d``. + + Raises: + ValueError: A segment is empty or a bracket is not closed. + """ + segments = [] + position = 0 + while True: + found = _SEGMENT.match(key, position) + if found is None: + raise ValueError(f"no key segment at position {position}") + segments.append(found[1] if found[1] is not None else found[2]) + position = found.end() + if position == len(key): + return segments + if key[position] == ".": + position += 1 + elif key[position] != "[": + raise ValueError(f"no key segment at position {position}") diff --git a/src/dubbo/config/parsers/yaml.py b/src/dubbo/config/parsers/yaml.py new file mode 100644 index 00000000..ed650ed0 --- /dev/null +++ b/src/dubbo/config/parsers/yaml.py @@ -0,0 +1,90 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Hashable, Mapping +from typing import cast + +from dubbo.config.data import ConfigData +from dubbo.config.exceptions import ConfigParseError +from dubbo.utils import require_optional_dependency + +with require_optional_dependency("yaml", extra="yaml"): + import yaml + from yaml.error import Mark + from yaml.nodes import CollectionNode, MappingNode, Node + +from .base import ConfigParser + +__all__ = ["YamlParser"] + + +# The most nodes that aliases may add to a document, each standing for a copy of what it names. +_MAX_ALIASED_NODES = 10_000 + + +class YamlParser(ConfigParser): + """Reads a YAML mapping with safe constructors and acyclic aliases.""" + + def loads(self, text: str, /) -> ConfigData: + loader = _ConfigLoader(text) + try: + node = loader.get_single_node() + if node is not None: + sizes: dict[Node, int] = {} + if _expanded_size(node, sizes) - len(sizes) > _MAX_ALIASED_NODES: + raise ConfigParseError(f"YAML aliases add more than {_MAX_ALIASED_NODES} nodes") + data = loader.construct_document(node) if node is not None else None + except (yaml.YAMLError, RecursionError) as error: + raise ConfigParseError("invalid YAML configuration") from error + finally: + loader.dispose() + + if not isinstance(data, Mapping): + raise ConfigParseError("configuration must have a mapping at its root") + return data + + +class _ConfigLoader(yaml.SafeLoader): + def construct_object(self, node: Node, deep: bool = False) -> object: + # Eager construction lets PyYAML reject cycles while preserving ordinary aliases. + return super().construct_object(node, deep=True) + + def construct_mapping(self, node: MappingNode, deep: bool = False) -> dict[Hashable, object]: + # YAML permits keys of any type; configuration paths require strings. + mapping = super().construct_mapping(node, deep=deep) + if any(not isinstance(key, str) for key in mapping): + # Composed nodes carry their position. + line = cast(Mark, node.start_mark).line + 1 + raise ConfigParseError(f"configuration keys must be strings, in the mapping at line {line}") + return mapping + + +def _expanded_size(node: Node, sizes: dict[Node, int]) -> int: + """Return the number of nodes ``node`` holds with each alias counted as a copy of its anchor.""" + if node in sizes: + return sizes[node] + + # A cycle counts once here; construction rejects it. + sizes[node] = 1 + if isinstance(node, MappingNode): + children = [child for pair in node.value for child in pair] + elif isinstance(node, CollectionNode): + children = node.value + else: + children = [] + sizes[node] = 1 + sum(_expanded_size(child, sizes) for child in children) + return sizes[node] diff --git a/src/dubbo/config/structure.py b/src/dubbo/config/structure.py new file mode 100644 index 00000000..f55eb68c --- /dev/null +++ b/src/dubbo/config/structure.py @@ -0,0 +1,184 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import enum +import ssl +from collections.abc import Mapping +from typing import TypeVar, cast + +import cattrs +from cattrs.v import format_exception + +from dubbo.utils.converters import boolean + +from .data import ConfigData +from .exceptions import ConfigError + +__all__ = ["structure_config", "unstructure_config"] + +T = TypeVar("T") + + +def structure_config(data: ConfigData, cls: type[T], *, path: str = "config") -> T: + """Build a configuration object of type ``cls`` from merged data, found at ``path`` for the error messages. + + Raises: + ConfigError: Unknown keys, wrong types, invalid values or undefined + references. The message names the path of each problem. + """ + if not isinstance(data, Mapping): + raise ConfigError(f"invalid configuration: expected a mapping, got {type(data).__name__} @ {path}") + + try: + return _converter.structure(data, cls) + except cattrs.BaseValidationError as error: + # Each problem on a line of its own; the message holds all that the nested cattrs errors tell. + details = "".join( + f"\n {detail}" for detail in cattrs.transform_error(error, path=path, format_exception=_describe) + ) + raise ConfigError(f"invalid configuration:{details}") from None + + +def unstructure_config(value: object) -> object: + """Turn configuration objects into plain data, leaving out unset fields. + + ``None`` marks a field as unset, so it is dropped rather than merged over + a value from a lower layer. + """ + return _without_unset(_converter.unstructure(value)) + + +def _without_unset(data: object) -> object: + if not isinstance(data, dict): + return data + items = cast(dict[str, object], data).items() + return {key: _without_unset(item) for key, item in items if item is not None} + + +def _describe(error: BaseException, target: type | None) -> str: + """Format one failure, keeping the messages of validators and hooks. + + The cattrs formatter reduces every TypeError and ValueError to "invalid + value"; the messages written here and by attrs validators say what is wrong. + """ + if isinstance(error, (TypeError, ValueError)) and str(error): + return str(error) + return format_exception(error, target) + + +# Hooks accept native values and the strings that environment variables and +# properties files produce, and reject everything else, such as True or 1.5 +# for an integer. + + +def _structure_str(value: object, _: object) -> str: + if not isinstance(value, str): + raise TypeError(f"expected a string, got {value!r}") + return value + + +def _structure_bool(value: object, _: object) -> bool: + if isinstance(value, bool): + return value + if isinstance(value, str): + try: + return boolean(value.strip()) + except ValueError: + raise ValueError(f"expected a boolean, got {value!r}") from None + raise TypeError(f"expected a boolean, got {value!r}") + + +def _structure_int(value: object, _: object) -> int: + if isinstance(value, int) and not isinstance(value, bool): + return value + if isinstance(value, str): + try: + return int(value.strip()) + except ValueError: + raise ValueError(f"expected an integer, got {value!r}") from None + raise TypeError(f"expected an integer, got {value!r}") + + +def _structure_float(value: object, _: object) -> float: + if isinstance(value, (int, float)) and not isinstance(value, bool): + return float(value) + if isinstance(value, str): + try: + return float(value.strip()) + except ValueError: + raise ValueError(f"expected a number, got {value!r}") from None + raise TypeError(f"expected a number, got {value!r}") + + +def _structure_bool_or_str(value: object, _: object) -> bool | str | None: + if value is not None and not isinstance(value, (bool, str)): + raise TypeError(f"expected a boolean or a string, got {value!r}") + return value + + +def _structure_enum(value: object, target: type[enum.Enum]) -> enum.Enum: + try: + return target(value) + except ValueError: + choices = ", ".join(repr(member.value) for member in target) + raise ValueError(f"expected one of {choices}, got {value!r}") from None + + +def _structure_ssl_context(value: object, _: object) -> ssl.SSLContext: + # Only code gives a context; it passes through merging as it is. + if not isinstance(value, ssl.SSLContext): + raise TypeError(f"expected an ssl.SSLContext, got {value!r}") + return value + + +def _structure_names(value: object, _: object) -> tuple[str, ...]: + # A bare string is rejected: as an iterable it would split into characters. + if not isinstance(value, (list, tuple)): + raise TypeError(f"expected a list of names, got {value!r}") + return tuple(_structure_str(item, str) for item in cast(list[object], value)) + + +def _structure_parameters(value: object, _: object) -> dict[str, str]: + # Parameters become URL query values, which are strings; files also write + # numbers and booleans there, as in "session-timeout: 3000". + if not isinstance(value, dict): + raise TypeError(f"expected a mapping of parameters, got {value!r}") + + parameters = {} + for key, item in cast(dict[object, object], value).items(): + if isinstance(item, bool): + item = "true" if item else "false" + elif isinstance(item, (int, float)): + item = str(item) + parameters[_structure_str(key, str)] = _structure_str(item, str) + return parameters + + +# Unknown keys fail instead of being dropped, so typos surface as errors. +_converter = cattrs.Converter(forbid_extra_keys=True) +_converter.register_structure_hook(str, _structure_str) +_converter.register_structure_hook(bool, _structure_bool) +_converter.register_structure_hook(int, _structure_int) +_converter.register_structure_hook(float, _structure_float) +_converter.register_structure_hook(ssl.SSLContext, _structure_ssl_context) +# StrEnum comes before str in the method resolution order of a string enum. +_converter.register_structure_hook(enum.Enum, _structure_enum) +_converter.register_structure_hook(enum.StrEnum, _structure_enum) +# Predicate registrations: dispatch by class cannot match generic aliases. +_converter.register_structure_hook_func(lambda target: target == tuple[str, ...], _structure_names) +_converter.register_structure_hook_func(lambda target: target == dict[str, str], _structure_parameters) +_converter.register_structure_hook_func(lambda target: target == bool | str | None, _structure_bool_or_str) diff --git a/src/dubbo/config/urls.py b/src/dubbo/config/urls.py new file mode 100644 index 00000000..ca3bbdeb --- /dev/null +++ b/src/dubbo/config/urls.py @@ -0,0 +1,303 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The URLs that the configuration gives each service and reference: those served, called and registered with.""" + +import uuid +from collections.abc import Collection, Mapping +from typing import TypeVar + +import attrs + +from dubbo.constants import ( + DEFAULT_PROTOCOL_HOST, + DEFAULT_SUBSCRIBE, + SSL_ENABLED_KEY, + SUBSCRIBE_KEY, + TAG_KEY, + TOKEN_KEY, +) +from dubbo.extension import ApplicationScope +from dubbo.rpc.definition import Service +from dubbo.url import ( + ADVERTISED_PORT, + APPLICATION_SCOPE, + CONFIG_CENTER_URL, + METADATA_CONSUMER_URL, + METADATA_REPORT_URL, + PROVIDER_URL, + SSL_CONTEXT, + URL, +) +from dubbo.utils.converters import boolean + +from .exceptions import ConfigError +from .fields import to_url_parameters +from .models import DubboConfig, ProtocolConfig, ReferenceConfig, ServiceConfig, TLSConfig + +__all__ = [ + "direct_urls", + "internal_service_urls", + "reference_registries", + "reference_url", + "service_registries", + "service_urls", +] + +T = TypeVar("T") + +# The settings of a method that only its providers read, which provider URLs carry to consumers. +_SERVICE_METHOD_FIELDS = ("weight", "deprecated", "executes", "tps", "tps_interval") + + +def service_urls(config: DubboConfig, service: Service, scope: ApplicationScope) -> list[URL]: + """Return the URL ``service`` is served with on each of its protocols, in the application of ``scope``. + + The parameters hold its settings, such as ``service.filter``, the + service's over the provider's, and those of ``tls``; the attributes hold + the scope and the configuration center of the application, and the + server context of ``tls``, if set. Protocols that neither selects are + all those defined. A ``token`` of true becomes one random token, which + each protocol shares, and one of false none. + + Raises: + ConfigError: The configuration of the service names a method it does not have. + """ + interface = service.interface + provider = config.provider + configured = provider.services.get(interface) or ServiceConfig() + _check_methods(f"service {interface!r}", configured.methods, service) + + token = uuid.uuid4().hex + urls = [] + for name in _service_protocols(config, interface): + protocol = config.protocols[name] + parameters = _tls_parameters(config.tls) | to_url_parameters( + config.shutdown, protocol, config.application, provider, configured + ) + urls.append( + URL( + protocol=protocol.name or name, + host=protocol.host or DEFAULT_PROTOCOL_HOST, + port=protocol.port, + path=interface, + parameters=_with_token(parameters, token), + attributes=_attributes(config, scope, config.tls and config.tls.server_context) + | _advertised_port(config, protocol), + ) + ) + + return urls + + +def internal_service_urls(config: DubboConfig, interfaces: Collection[str], scope: ApplicationScope) -> dict[str, URL]: + """Return the URL a service of the framework itself, such as the MetadataService, is served with on each protocol. + + The protocols are those that serve ``interfaces``, keyed by name; of + several of one name, the first is taken. The parameters hold the + settings of the protocol, of ``application``, ``shutdown`` and ``tls``, + so that the service shares the server of ``interfaces``, but none of the + provider or of a service; the attributes hold the scope and the server + context of ``tls``, if set. The URLs have no path. + """ + urls: dict[str, URL] = {} + names = dict.fromkeys(name for interface in interfaces for name in _service_protocols(config, interface)) + for name in names: + protocol = config.protocols[name] + protocol_name = protocol.name or name + if protocol_name in urls: + continue + urls[protocol_name] = URL( + protocol=protocol_name, + host=protocol.host or DEFAULT_PROTOCOL_HOST, + port=protocol.port, + parameters=_tls_parameters(config.tls) | to_url_parameters(config.shutdown, protocol, config.application), + attributes={APPLICATION_SCOPE: scope} + | _ssl_context(config.tls and config.tls.server_context) + | _advertised_port(config, protocol), + ) + + return urls + + +def service_registries(config: DubboConfig, interface: str, scope: ApplicationScope) -> list[URL]: + """Return the URL of each registry the service ``interface`` is registered with, in the application of ``scope``. + + Registries that neither the service nor the provider selects are all + those defined; registration skips those that set ``register`` to false. + """ + provider = config.provider + service = provider.services.get(interface) or ServiceConfig() + + names = _first(service.registries, provider.registries, tuple(config.registries)) + return [_registry(config, name, scope) for name in names] + + +def reference_url(config: DubboConfig, service: Service, scope: ApplicationScope, *, generic: bool = False) -> URL: + """Return the URL of the reference to ``service`` in the application of ``scope``. + + It is ``consumer://{advertised_host}/{interface}``, its host ``None`` + unless ``application.advertised_host`` is set. The parameters hold the + settings of the reference, such as ``cluster``, and of its calls, which + provider URLs take; the reference's come over the consumer's, field by + field within ``triple``, and those of ``tls``, but not the settings of + methods that only providers read, such as ``weight``, which would + replace those of providers. The attributes hold the scope and the + configuration center of the application, and the client context of + ``tls``, if set. + + A ``generic`` reference calls methods by name, beyond those of + ``service``, so its configuration may name any method. + + Raises: + ConfigError: The configuration of the reference names a method the + service does not have, and the reference is not generic. + """ + interface = service.interface + consumer = config.consumer + reference = consumer.references.get(interface) or ReferenceConfig() + if not generic: + _check_methods(f"reference {interface!r}", reference.methods, service) + + methods = { + name: attrs.evolve(method, **dict.fromkeys(_SERVICE_METHOD_FIELDS)) + for name, method in reference.methods.items() + } + parameters = _tls_parameters(config.tls) | to_url_parameters( + config.shutdown, config.application, consumer, attrs.evolve(reference, methods=methods) + ) + return URL( + protocol="consumer", + host=config.application.advertised_host, + path=interface, + parameters=parameters, + attributes=_attributes(config, scope, config.tls and config.tls.client_context), + ) + + +def direct_urls(config: DubboConfig, reference: URL) -> list[URL]: + """Return the URLs of the providers that the reference ``reference`` calls directly, if it names any in ``urls``. + + Each takes the parameters of ``reference`` over its own, but for the tag, + which stays as written; its attributes; and the name of the service as + its path when it has none. The attribute ``PROVIDER_URL`` keeps it as + written, with that path. + """ + interface = reference.path + texts = (config.consumer.references.get(interface) or ReferenceConfig()).urls or () + parameters = {key: value for key, value in reference.parameters.items() if key != TAG_KEY} + + urls = [] + for text in texts: + url = URL.parse(text) + url = url.replace(path=url.path or interface) + urls.append(url.replace(attributes={**reference.attributes, PROVIDER_URL: url}).update_parameters(parameters)) + return urls + + +def reference_registries(config: DubboConfig, interface: str, scope: ApplicationScope) -> list[URL]: + """Return the URL of each registry the reference ``interface`` discovers providers in, in the application of ``scope``. + + A reference that sets ``urls`` discovers only in the registries it + selects itself, if any. Registries that neither the reference nor the + consumer selects are all those defined, less those that set + ``subscribe`` to false. + + Raises: + ConfigError: A reference without ``urls`` selects no registry, or + none of those selected subscribes. + """ + consumer = config.consumer + reference = consumer.references.get(interface) or ReferenceConfig() + owner = f"reference {interface!r}" + + if reference.urls: + names = reference.registries or () + else: + names = _first(reference.registries, consumer.registries, tuple(config.registries)) + if not names: + raise ConfigError(f"{owner} needs urls, as in [tri://127.0.0.1:50051], or a registry") + registries = [_registry(config, name, scope) for name in names] + subscribed = [url for url in registries if url.get_parameter(SUBSCRIBE_KEY, boolean, DEFAULT_SUBSCRIBE)] + if registries and not subscribed: + raise ConfigError(f"{owner} subscribes to none of its registries, which all set subscribe to false") + + return subscribed + + +def _with_token(parameters: dict[str, str], generated: str) -> dict[str, str]: + """Return ``parameters`` with a ``token`` of true replaced by ``generated``, and one of false left out.""" + match parameters.get(TOKEN_KEY): + case "true": + return parameters | {TOKEN_KEY: generated} + case "false": + return {key: value for key, value in parameters.items() if key != TOKEN_KEY} + case _: + return parameters + + +def _service_protocols(config: DubboConfig, interface: str) -> tuple[str, ...]: + """Return the names of the protocols the service ``interface`` is served with.""" + provider = config.provider + configured = provider.services.get(interface) or ServiceConfig() + return _first(configured.protocols, provider.protocols, tuple(config.protocols)) + + +def _registry(config: DubboConfig, name: str, scope: ApplicationScope) -> URL: + # The MetadataService of instances is called with the TLS settings of the application. + consumer = URL( + protocol="consumer", + parameters=_tls_parameters(config.tls), + attributes={APPLICATION_SCOPE: scope} | _ssl_context(config.tls and config.tls.client_context), + ) + attributes: dict[str, object] = {APPLICATION_SCOPE: scope, METADATA_CONSUMER_URL: consumer} + if config.metadata_report is not None: + attributes[METADATA_REPORT_URL] = config.metadata_report.to_url().replace(attributes={APPLICATION_SCOPE: scope}) + + return config.registries[name].to_url().replace(attributes=attributes) + + +def _attributes(config: DubboConfig, scope: ApplicationScope, ssl_context: object) -> dict[str, object]: + attributes: dict[str, object] = {APPLICATION_SCOPE: scope} + if config.config_center is not None: + attributes[CONFIG_CENTER_URL] = config.config_center.to_url().replace(attributes={APPLICATION_SCOPE: scope}) + + return attributes | _ssl_context(ssl_context) + + +def _advertised_port(config: DubboConfig, protocol: ProtocolConfig) -> dict[str, object]: + port = protocol.advertised_port or config.application.advertised_port + return {} if port is None else {ADVERTISED_PORT: port} + + +def _tls_parameters(tls: TLSConfig | None) -> dict[str, str]: + return {} if tls is None else {SSL_ENABLED_KEY: "true"} | to_url_parameters(tls) + + +def _ssl_context(context: object) -> dict[str, object]: + return {} if context is None else {SSL_CONTEXT: context} + + +def _check_methods(owner: str, configured: Mapping[str, object], service: Service) -> None: + unknown = sorted(set(configured) - {method.name for method in service.methods}) + if unknown: + raise ConfigError(f"{owner} configures methods it does not have: {', '.join(unknown)}") + + +def _first(*values: tuple[T, ...] | None) -> tuple[T, ...]: + """Return the first of ``values`` that is not ``None``, else an empty tuple.""" + return next((value for value in values if value is not None), ()) diff --git a/src/dubbo/config_center/__init__.py b/src/dubbo/config_center/__init__.py new file mode 100644 index 00000000..22b4f1d9 --- /dev/null +++ b/src/dubbo/config_center/__init__.py @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .base import ConfigCenter, get_config_center + +__all__ = ["ConfigCenter", "get_config_center"] diff --git a/src/dubbo/config_center/base.py b/src/dubbo/config_center/base.py new file mode 100644 index 00000000..3f590ac3 --- /dev/null +++ b/src/dubbo/config_center/base.py @@ -0,0 +1,98 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from collections.abc import AsyncIterator +from contextlib import AbstractAsyncContextManager +from typing import Self + +from dubbo.extension import Resource, extension_point, extensions +from dubbo.url import URL + +__all__ = ["ConfigCenter", "get_config_center"] + + +@extension_point("apache_dubbo.config_center") +class ConfigCenter(Resource, typing.Protocol): + """Read and watch text entries stored by key and group in a configuration center. + + The implementation is named by the scheme of the configuration center URL + and created with that URL, which carries the address, the query parameters + and ``ConfigCenterConfig.parameters``, and ``timeout`` in milliseconds: the + limit for each operation. It is installed under the entry point group + ``apache_dubbo.config_center``, named by that scheme. + + Entering ``async with`` connects, and closing disconnects. The application + opens one instance per URL, through `get_config_center`, reads its + configuration at startup, and keeps it open while it runs, for the + override and routing rules that watch it. Clients that other extensions of + the application also use come from getters that share them through + ``url.scope``, such as `get_zookeeper_client`: take them on entering and + leave them open on closing, as the scope closes them. + + Attributes: + url: The URL the instance was created with. + """ + + url: URL + + def __init__(self, url: URL) -> None: + self.url = url + + async def get(self, key: str, *, group: str) -> str | None: + """Return the text under ``key`` in ``group``, or ``None`` if the entry does not exist. + + Raises: + Exception: Any error of its client when the entry cannot be read; + startup decides by ``check`` whether that fails it. + """ + ... + + def watch(self, key: str, *, group: str) -> AbstractAsyncContextManager[AsyncIterator[str | None]]: + """Watch the text under ``key`` in ``group`` until the context exits. + + The iterator yields the current text first, then the text after each + change, with ``None`` while the entry does not exist. Each entry holds + a complete document, so only the latest text matters: changes made + while the consumer is busy may be skipped, but the latest is always + yielded. The first text may fail, raising the error of the client; + the rules that watch then subscribe again after a delay. + """ + ... + + async def aclose(self) -> None: + """Disconnect from the configuration center.""" + ... + + async def __aenter__(self) -> Self: + """Connect to the configuration center.""" + ... + + +async def get_config_center(url: URL) -> ConfigCenter: + """Return the configuration center ``url`` names, the same instance for the same URL in its application. + + The application of ``url.scope`` connects it on first use and + disconnects it when it stops. + + Raises: + ExtensionError: No implementation has the scheme of ``url``. + RuntimeError: ``url`` belongs to no running application. + """ + scope = url.scope + implementation = extensions.get(ConfigCenter, url.protocol) + return await scope.share((implementation, url), lambda: implementation(url)) diff --git a/src/dubbo/config_center/nacos.py b/src/dubbo/config_center/nacos.py new file mode 100644 index 00000000..ec9463d3 --- /dev/null +++ b/src/dubbo/config_center/nacos.py @@ -0,0 +1,66 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import AsyncGenerator, AsyncIterator +from contextlib import asynccontextmanager +from typing import Self + +from dubbo.transport import nacos +from dubbo.url import URL + +from .base import ConfigCenter + +__all__ = ["NacosConfigCenter"] + + +class NacosConfigCenter(ConfigCenter): + """A ``ConfigCenter`` that stores each entry as a Nacos configuration. + + The entry of ``key`` in ``group`` is the configuration whose data id is + ``key`` in the Nacos group ``group``, in the namespace that the + ``namespace`` URL parameter names. The client comes from + ``get_nacos_config_client``, shared with the other users of an equal + connection. + """ + + def __init__(self, url: URL) -> None: + super().__init__(url) + self._client: nacos.NacosConfigClient | None = None + + async def get(self, key: str, *, group: str) -> str | None: + client = self._connected() + + return await client.get(key, group) + + @asynccontextmanager + async def watch(self, key: str, *, group: str) -> AsyncGenerator[AsyncIterator[str | None]]: + client = self._connected() + + async with client.watch(key, group) as contents: + yield contents + + async def aclose(self) -> None: + self._client = None + + async def __aenter__(self) -> Self: + self._client = await nacos.get_nacos_config_client(self.url) + return self + + def _connected(self) -> nacos.NacosConfigClient: + if self._client is None: + raise RuntimeError("the configuration center is not connected") + return self._client diff --git a/src/dubbo/config_center/zookeeper.py b/src/dubbo/config_center/zookeeper.py new file mode 100644 index 00000000..e9b6dbbe --- /dev/null +++ b/src/dubbo/config_center/zookeeper.py @@ -0,0 +1,75 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import AsyncGenerator, AsyncIterator +from contextlib import asynccontextmanager +from typing import Self + +from dubbo.constants import DEFAULT_ROOT, NAMESPACE_KEY +from dubbo.transport import zookeeper +from dubbo.url import URL + +from .base import ConfigCenter + +__all__ = ["ZookeeperConfigCenter"] + + +class ZookeeperConfigCenter(ConfigCenter): + """A ``ConfigCenter`` that stores each entry as the UTF-8 text of a ZooKeeper node. + + The node of ``key`` in ``group`` is ``/{namespace}/config/{group}/{key}``; + the ``namespace`` URL parameter is ``dubbo`` by default. The client comes + from ``get_zookeeper_client``, shared with the other users of an equal + connection. + """ + + def __init__(self, url: URL) -> None: + super().__init__(url) + self._root = f"/{url.parameters.get(NAMESPACE_KEY, DEFAULT_ROOT)}/config" + self._client: zookeeper.ZookeeperClient | None = None + + async def get(self, key: str, *, group: str) -> str | None: + client = self._connected() + + data = await client.get(self._path(key, group)) + return _text(data) + + @asynccontextmanager + async def watch(self, key: str, *, group: str) -> AsyncGenerator[AsyncIterator[str | None]]: + client = self._connected() + + async with client.watch(self._path(key, group)) as values: + yield (_text(data) async for data in values) + + async def aclose(self) -> None: + self._client = None + + async def __aenter__(self) -> Self: + self._client = await zookeeper.get_zookeeper_client(self.url) + return self + + def _path(self, key: str, group: str) -> str: + return f"{self._root}/{group}/{key}" + + def _connected(self) -> zookeeper.ZookeeperClient: + if self._client is None: + raise RuntimeError("the configuration center is not connected") + return self._client + + +def _text(data: bytes | None) -> str | None: + return None if data is None else data.decode() diff --git a/src/dubbo/configs.py b/src/dubbo/configs.py deleted file mode 100644 index f7a85d7e..00000000 --- a/src/dubbo/configs.py +++ /dev/null @@ -1,911 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import abc -from dataclasses import dataclass -from typing import Optional, Union - -from dubbo.constants import ( - common_constants, - config_constants, - logger_constants, - registry_constants, -) -from dubbo.proxy.handlers import RpcServiceHandler -from dubbo.url import URL, create_url -from dubbo.utils import NetworkUtils - -__all__ = [ - "ApplicationConfig", - "ReferenceConfig", - "ServiceConfig", - "RegistryConfig", - "LoggerConfig", -] - - -class AbstractConfig(abc.ABC): - """ - Abstract configuration class. - """ - - __slots__ = ["id"] - - def __init__(self): - # Identifier for this configuration. - self.id: Optional[str] = None - - -class ApplicationConfig(AbstractConfig): - """ - Configuration for the dubbo application. - """ - - __slots__ = [ - "_name", - "_version", - "_owner", - "_organization", - "_architecture", - "_environment", - ] - - def __init__( - self, - name: str, - version: Optional[str] = None, - owner: Optional[str] = None, - organization: Optional[str] = None, - architecture: Optional[str] = None, - environment: Optional[str] = None, - ): - """ - Initialize the application configuration. - :param name: The name of the application. - :type name: str - :param version: The version of the application. - :type version: Optional[str] - :param owner: The owner of the application. - :type owner: Optional[str] - :param organization: The organization(BU) of the application. - :type organization: Optional[str] - :param architecture: The architecture of the application. - :type architecture: Optional[str] - :param environment: The environment of the application. e.g. dev, test, prod. - :type environment: Optional[str] - """ - super().__init__() - - self._name = name - self._version = version - self._owner = owner - self._organization = organization - self._architecture = architecture - - self._environment = self._ensure_environment(environment) - - @property - def name(self) -> str: - """ - Get the name of the application. - :return: The name of the application. - :rtype: str - """ - return self._name - - @name.setter - def name(self, name: str) -> None: - """ - Set the name of the application. - :param name: The name of the application. - :type name: str - """ - self._name = name - - @property - def version(self) -> Optional[str]: - """ - Get the version of the application. - :return: The version of the application. - :rtype: Optional[str] - """ - return self._version - - @version.setter - def version(self, version: str) -> None: - """ - Set the version of the application. - :param version: The version of the application. - :type version: str - """ - self._version = version - - @property - def owner(self) -> Optional[str]: - """ - Get the owner of the application. - :return: The owner of the application. - :rtype: Optional[str] - """ - return self._owner - - @owner.setter - def owner(self, owner: str) -> None: - """ - Set the owner of the application. - :param owner: The owner of the application. - :type owner: str - """ - self._owner = owner - - @property - def organization(self) -> Optional[str]: - """ - Get the organization(BU) of the application. - :return: The organization(BU) of the application. - :rtype: Optional[str] - """ - return self._organization - - @organization.setter - def organization(self, organization: str) -> None: - """ - Set the organization(BU) of the application. - :param organization: The organization(BU) of the application. - :type organization: str - """ - self._organization = organization - - @property - def architecture(self) -> Optional[str]: - """ - Get the architecture of the application. - :return: The architecture of the application. - :rtype: Optional[str] - """ - return self._architecture - - @architecture.setter - def architecture(self, architecture: str) -> None: - """ - Set the architecture of the application. - :param architecture: The architecture of the application. - :type architecture: str - """ - self._architecture = architecture - - @property - def environment(self) -> str: - """ - Get the environment of the application. - :return: The environment of the application. - :rtype: str - """ - return self._environment - - @environment.setter - def environment(self, environment: str) -> None: - """ - Set the environment of the application. - :param environment: The environment of the application. - :type environment: str - """ - self._environment = self._ensure_environment(environment) - - @staticmethod - def _ensure_environment(environment: Optional[str]) -> str: - """ - Ensure the environment is valid. - :param environment: The environment. - :type environment: Optional[str] - :return: The environment. If the environment is None, return the default environment. - :rtype: str - """ - if not environment: - return config_constants.PRODUCTION_ENVIRONMENT - - # ignore case - environment = environment.lower() - - allowed_environments = [ - config_constants.TEST_ENVIRONMENT, - config_constants.DEVELOPMENT_ENVIRONMENT, - config_constants.PRODUCTION_ENVIRONMENT, - ] - - if environment not in allowed_environments: - raise ValueError( - f"Unsupported environment: {environment}, " - f"only support {allowed_environments}, " - f"default is {config_constants.PRODUCTION_ENVIRONMENT}." - ) - - return environment - - -class ReferenceConfig(AbstractConfig): - """ - Configuration for the dubbo reference. - """ - - __slots__ = ["_protocol", "_service", "_host", "_port"] - - def __init__( - self, - protocol: str, - service: str, - host: Optional[str] = None, - port: Optional[int] = None, - ): - """ - Initialize the reference configuration. - :param protocol: The protocol of the server. - :type protocol: str - :param service: The name of the server. - :type service: str - :param host: The host of the server. - :type host: Optional[str] - :param port: The port of the server. - :type port: Optional[int] - """ - super().__init__() - self._protocol = protocol - self._service = service - self._host = host - self._port = port - - @property - def protocol(self) -> str: - """ - Get the protocol of the server. - :return: The protocol of the server. - :rtype: str - """ - return self._protocol - - @protocol.setter - def protocol(self, protocol: str) -> None: - """ - Set the protocol of the server. - :param protocol: The protocol of the server. - :type protocol: str - """ - self._protocol = protocol - - @property - def service(self) -> str: - """ - Get the name of the service. - :return: The name of the service. - :rtype: str - """ - return self._service - - @service.setter - def service(self, service: str) -> None: - """ - Set the name of the service. - :param service: The name of the service. - :type service: str - """ - self._service = service - - @property - def host(self) -> Optional[str]: - """ - Get the host of the server. - :return: The host of the server. - :rtype: Optional[str] - """ - return self._host - - @host.setter - def host(self, host: str) -> None: - """ - Set the host of the server. - :param host: The host of the server. - :type host: str - """ - self._host = host - - @property - def port(self) -> Optional[int]: - """ - Get the port of the server. - :return: The port of the server. - :rtype: Optional[int] - """ - return self._port - - @port.setter - def port(self, port: int) -> None: - """ - Set the port of the server. - :param port: The port of the server. - :type port: int - """ - self._port = port - - def to_url(self) -> URL: - """ - Convert the reference configuration to a URL. - :return: The URL. - :rtype: URL - """ - return URL( - scheme=self.protocol, - host=self.host, - port=self.port, - path=self.service, - parameters={common_constants.SERVICE_KEY: self.service}, - ) - - @classmethod - def from_url(cls, url: Union[str, URL]) -> "ReferenceConfig": - """ - Create a reference configuration from a URL. - :param url: The URL. - :type url: Union[str,URL] - :return: The reference configuration. - :rtype: ReferenceConfig - """ - if isinstance(url, str): - url = create_url(url) - return cls( - protocol=url.scheme, - service=url.parameters.get(common_constants.SERVICE_KEY, url.path), - host=url.host, - port=url.port, - ) - - -class ServiceConfig(AbstractConfig): - """ - Configuration for the dubbo service. - """ - - def __init__( - self, - service_handler: RpcServiceHandler, - host: Optional[str] = None, - port: Optional[int] = None, - protocol: Optional[str] = None, - ): - super().__init__() - - self._service_handler = service_handler - self._host = host or NetworkUtils.get_local_address() or common_constants.LOCAL_HOST_VALUE - self._port = port or common_constants.DEFAULT_PORT - self._protocol = protocol or common_constants.TRIPLE_SHORT - - @property - def service_handler(self) -> RpcServiceHandler: - """ - Get the service handler. - :return: The service handler. - :rtype: RpcServiceHandler - """ - return self._service_handler - - @service_handler.setter - def service_handler(self, service_handler: RpcServiceHandler) -> None: - """ - Set the service handler. - :param service_handler: The service handler. - :type service_handler: RpcServiceHandler - """ - self._service_handler = service_handler - - @property - def host(self) -> str: - """ - Get the host of the service. - :return: The host of the service. - :rtype: str - """ - return self._host - - @host.setter - def host(self, host: str) -> None: - """ - Set the host of the service. - :param host: The host of the service. - :type host: str - """ - self._host = host - - @property - def port(self) -> int: - """ - Get the port of the service. - :return: The port of the service. - :rtype: int - """ - return self._port - - @port.setter - def port(self, port: int) -> None: - """ - Set the port of the service. - :param port: The port of the service. - :type port: int - """ - self._port = port - - @property - def protocol(self) -> str: - """ - Get the protocol of the service. - :return: The protocol of the service. - :rtype: str - """ - return self._protocol - - @protocol.setter - def protocol(self, protocol: str) -> None: - """ - Set the protocol of the service. - :param protocol: The protocol of the service. - :type protocol: str - """ - self._protocol = protocol - - def to_url(self) -> URL: - """ - Convert the service configuration to a URL. - :return: The URL. - :rtype: URL - """ - return URL( - scheme=self.protocol, - host=self.host, - port=self.port, - parameters={common_constants.SERVICE_KEY: self.service_handler.service_name}, - attributes={common_constants.SERVICE_HANDLER_KEY: self.service_handler}, - ) - - -class RegistryConfig(AbstractConfig): - """ - Configuration for the registry. - """ - - __slots__ = [ - "_protocol", - "_host", - "_port", - "_username", - "_password", - "_load_balance", - "_group", - "_version", - ] - - def __init__( - self, - protocol: str, - host: str, - port: int, - username: Optional[str] = None, - password: Optional[str] = None, - load_balance: Optional[str] = None, - group: Optional[str] = None, - version: Optional[str] = None, - ): - """ - Initialize the registry configuration. - :param protocol: The protocol of the registry. - :type protocol: str - :param host: The host of the registry. - :type host: str - :param port: The port of the registry. - :type port: int - :param username: The username of the registry. - :type username: Optional[str] - :param password: The password of the registry. - :type password: Optional[str] - :param load_balance: The load balance of the registry. - :type load_balance: Optional[str] - :param group: The group of the registry. - :type group: Optional[str] - :param version: The version of the registry. - :type version: Optional[str] - """ - super().__init__() - - self._protocol = protocol - self._host = host - self._port = port - self._username = username - self._password = password - self._load_balance = load_balance - self._group = group - self._version = version - - @property - def protocol(self) -> str: - """ - Get the protocol of the registry. - :return: The protocol of the registry. - :rtype: str - """ - return self._protocol - - @protocol.setter - def protocol(self, protocol: str) -> None: - """ - Set the protocol of the registry. - :param protocol: The protocol of the registry. - :type protocol: str - """ - self._protocol = protocol - - @property - def host(self) -> str: - """ - Get the host of the registry. - :return: The host of the registry. - :rtype: str - """ - return self._host - - @host.setter - def host(self, host: str) -> None: - """ - Set the host of the registry. - :param host: The host of the registry. - :type host: str - """ - self._host = host - - @property - def port(self) -> int: - """ - Get the port of the registry. - :return: The port of the registry. - :rtype: int - """ - return self._port - - @port.setter - def port(self, port: int) -> None: - """ - Set the port of the registry. - :param port: The port of the registry. - :type port: int - """ - self._port = port - - @property - def username(self) -> Optional[str]: - """ - Get the username of the registry. - :return: The username of the registry. - :rtype: Optional[str] - """ - return self._username - - @username.setter - def username(self, username: str) -> None: - """ - Set the username of the registry. - :param username: The username of the registry. - :type username: str - """ - self._username = username - - @property - def password(self) -> Optional[str]: - """ - Get the password of the registry. - :return: The password of the registry. - :rtype: Optional[str] - """ - return self._password - - @password.setter - def password(self, password: str) -> None: - """ - Set the password of the registry. - :param password: The password of the registry. - :type password: str - """ - self._password = password - - @property - def load_balance(self) -> Optional[str]: - """ - Get the load balance of the registry. - :return: The load balance of the registry. - :rtype: Optional[str] - """ - return self._load_balance - - @load_balance.setter - def load_balance(self, load_balance: str) -> None: - """ - Set the load balance of the registry. - :param load_balance: The load balance of the registry. - :type load_balance: str - """ - self._load_balance = load_balance - - @property - def group(self) -> Optional[str]: - """ - Get the group of the registry. - :return: The group of the registry. - :rtype: Optional[str] - """ - return self._group - - @group.setter - def group(self, group: str) -> None: - """ - Set the group of the registry. - :param group: The group of the registry. - :type group: str - """ - self._group = group - - @property - def version(self) -> Optional[str]: - """ - Get the version of the registry. - :return: The version of the registry. - :rtype: Optional[str] - """ - return self._version - - @version.setter - def version(self, version: str) -> None: - """ - Set the version of the registry. - :param version: The version of the registry. - :type version: str - """ - self._version = version - - def to_url(self) -> URL: - """ - Convert the registry configuration to a URL. - :return: The URL. - :rtype: URL - """ - parameters = {} - if self.load_balance: - parameters[registry_constants.LOAD_BALANCE_KEY] = self.load_balance - if self.group: - parameters[config_constants.GROUP] = self.group - if self.version: - parameters[config_constants.VERSION] = self.version - - return URL( - scheme=self.protocol, - host=self.host, - port=self.port, - username=self.username, - password=self.password, - parameters=parameters, - ) - - @classmethod - def from_url(cls, url: Union[str, URL]) -> "RegistryConfig": - """ - Create a registry configuration from a URL. - :param url: The URL. - :type url: Union[str,URL] - :return: The registry configuration. - :rtype: RegistryConfig - """ - if isinstance(url, str): - url = create_url(url) - return cls( - protocol=url.scheme, - host=url.host, - port=url.port, - username=url.username, - password=url.password, - load_balance=url.parameters.get(registry_constants.LOAD_BALANCE_KEY), - group=url.parameters.get(config_constants.GROUP), - version=url.parameters.get(config_constants.VERSION), - ) - - -class LoggerConfig(AbstractConfig): - """ - Logger Configuration. - """ - - @dataclass - class ConsoleConfig: - """ - Console logger configuration. - - :param formatter: Console formatter. - :type formatter: Optional[str] - """ - - formatter: Optional[str] = None - - @dataclass - class FileConfig: - """ - File logger configuration. - - :param file_formatter: File formatter. - :type file_formatter: Optional[str] - :param file_dir: File directory. - :type file_dir: str - :param file_name: File name. - :type file_name: str - :param rotate: File rotate type. - :type rotate: logger_constants.FileRotateType - :param backup_count: Backup count. - :type backup_count: int - :param max_bytes: Max bytes. - :type max_bytes: int - :param interval: Interval. - :type interval: int - """ - - file_formatter: Optional[str] = None - file_dir: str = logger_constants.DEFAULT_FILE_DIR_VALUE - file_name: str = logger_constants.DEFAULT_FILE_NAME_VALUE - rotate: logger_constants.FileRotateType = logger_constants.FileRotateType.NONE - backup_count: int = logger_constants.DEFAULT_FILE_BACKUP_COUNT_VALUE - max_bytes: int = logger_constants.DEFAULT_FILE_MAX_BYTES_VALUE - interval: int = logger_constants.DEFAULT_FILE_INTERVAL_VALUE - - __slots__ = [ - "_level", - "_global_formatter", - "_console_enabled", - "_console_config", - "_file_enabled", - "_file_config", - ] - - def __init__( - self, - level: str = logger_constants.DEFAULT_LEVEL_VALUE, - formatter: Optional[str] = None, - console_enabled: bool = logger_constants.DEFAULT_CONSOLE_ENABLED_VALUE, - file_enabled: bool = logger_constants.DEFAULT_FILE_ENABLED_VALUE, - ): - """ - Initialize the logger configuration. - :param level: The logger level. - :type level: str, default is "INFO". - :param console_enabled: Whether to enable console logger. - :type console_enabled: bool, default is True. - :param file_enabled: Whether to enable file logger. - """ - super().__init__() - # logger level - self._level = level.upper() - - # global formatter - self._global_formatter = formatter - - # console logger - self._console_enabled = console_enabled - self._console_config = LoggerConfig.ConsoleConfig() - - # file logger - self._file_enabled = file_enabled - self._file_config = LoggerConfig.FileConfig() - - @property - def level(self) -> str: - """ - Get logger level. - :return: The logger level. - :rtype: str - """ - return self._level - - @level.setter - def level(self, level: str) -> None: - """ - Set logger level. - :param level: The logger level. - :type level: str - """ - if self._level != level.upper(): - self._level = level.upper() - - @property - def global_formatter(self) -> Optional[str]: - """ - Get global formatter. - :return: The global formatter. - :rtype: Optional[str] - """ - return self._global_formatter - - def is_console_enabled(self) -> bool: - """ - Check if console logger is enabled. - :return: True if console logger is enabled, otherwise False. - :rtype: bool - """ - return self._console_enabled - - def enable_console(self) -> None: - """ - Enable console logger. - """ - self._console_enabled = True - - def disable_console(self) -> None: - """ - Disable console logger. - """ - self._console_enabled = False - - @property - def console_config(self) -> ConsoleConfig: - """ - Get console logger configuration. - :return: Console logger configuration. - :rtype: ConsoleConfig - """ - return self._console_config - - def set_console(self, console_config: ConsoleConfig): - """ - Set console logger configuration. - :param console_config: Console logger configuration. - :type console_config: ConsoleConfig - """ - self._console_config = console_config - - def is_file_enabled(self) -> bool: - """ - Check if file logger is enabled. - :return: True if file logger is enabled, otherwise False. - :rtype: bool - """ - return self._file_enabled - - def enable_file(self) -> None: - """ - Enable file logger. - """ - self._file_enabled = True - - def disable_file(self) -> None: - """ - Disable file logger. - """ - self._file_enabled = False - - @property - def file_config(self) -> FileConfig: - """ - Get file logger configuration. - :return: File logger configuration. - :rtype: FileConfig - """ - return self._file_config - - def set_file(self, file_config: FileConfig) -> None: - """ - Set file logger configuration. - :param file_config: File logger configuration. - :type file_config: FileConfig - """ - self._file_config = file_config diff --git a/src/dubbo/constants.py b/src/dubbo/constants.py new file mode 100644 index 00000000..92a06163 --- /dev/null +++ b/src/dubbo/constants.py @@ -0,0 +1,344 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Dubbo vocabulary shared with other languages, and the defaults of the framework. + +Three groups of names live here, in this order: + +- ``*_KEY``: the key of a URL parameter or a call attachment that Dubbo + implementations in other languages share. +- Values: what is neither a key nor a default, such as the name of a + built-in implementation that other languages share. +- ``DEFAULT_*``: the value a configuration field left as ``None``, or a URL + that leaves out its parameter, stands for. + +Constants private to one module stay in that module. Within each group +names are sorted; a comment gives only what the name cannot, such as a unit +or the values it takes. A time in a URL parameter is whole milliseconds; a +``DEFAULT_*`` time, like the configuration field it stands for, is seconds. +""" + +from collections.abc import Mapping +from types import MappingProxyType + +__all__ = [ + "ACCESSLOG_KEY", + "ACCESS_KEY_KEY", + "ACTIVES_KEY", + "APPLICATION_KEY", + "ARCHITECTURE_KEY", + "BACKUP_KEY", + "BROADCAST_FAIL_PERCENT_KEY", + "CATEGORY_KEY", + "CA_CERT_FILE_KEY", + "CHECK_KEY", + "CLIENT_KEY", + "CLUSTER_KEY", + "COMPRESSOR_KEY", + "CONNECTION_INITIAL_WINDOW_SIZE_KEY", + "CONNECT_TIMEOUT_KEY", + "CONSUMERS_CATEGORY", + "DEFAULT_CHECK", + "DEFAULT_CLUSTER", + "DEFAULT_CONFIG_CENTER_CHECK", + "DEFAULT_CONFIG_CENTER_FILE", + "DEFAULT_CONFIG_CENTER_GROUP", + "DEFAULT_CONFIG_CENTER_TIMEOUT", + "DEFAULT_CONNECTION_INITIAL_WINDOW_SIZE", + "DEFAULT_CONNECT_TIMEOUT", + "DEFAULT_DUBBO_PORT", + "DEFAULT_FORKS", + "DEFAULT_GENERIC", + "DEFAULT_HEARTBEAT", + "DEFAULT_INITIAL_WINDOW_SIZE", + "DEFAULT_JAVA_SERIALIZATION", + "DEFAULT_KEEP_ALIVE_TIMEOUT", + "DEFAULT_LOADBALANCE", + "DEFAULT_MAX_CONCURRENT_CALLS", + "DEFAULT_MAX_CONCURRENT_STREAMS", + "DEFAULT_MAX_HEADER_LIST_SIZE", + "DEFAULT_MAX_RECEIVE_MESSAGE_SIZE", + "DEFAULT_METADATA_TYPE", + "DEFAULT_PAYLOAD", + "DEFAULT_PROTOCOL", + "DEFAULT_PROTOCOL_HOST", + "DEFAULT_REGISTER", + "DEFAULT_REGISTRY_MODE", + "DEFAULT_RETRIES", + "DEFAULT_ROOT", + "DEFAULT_ROUTERS", + "DEFAULT_SERIALIZATION", + "DEFAULT_SHUTWAIT", + "DEFAULT_STICKY", + "DEFAULT_SUBSCRIBE", + "DEFAULT_TIMEOUT", + "DEFAULT_TPS_INTERVAL", + "DEFAULT_TRIPLE_PORT", + "DEFAULT_UNREGISTER_WAIT", + "DEFAULT_WARMUP", + "DEFAULT_WEIGHT", + "DEPRECATED_KEY", + "DUBBO_VERSION", + "DUBBO_VERSION_KEY", + "ENDPOINTS_KEY", + "ENVIRONMENT_KEY", + "EXECUTES_KEY", + "EXTRA_KEYS_KEY", + "FAILBACK_TASKS_KEY", + "FORCE_TAG_KEY", + "FORKS_KEY", + "GENERIC_KEY", + "GROUP_KEY", + "HASH_ARGUMENTS_KEY", + "HASH_NODES_KEY", + "HEALTH_ENABLED_KEY", + "HEARTBEAT_KEY", + "HEARTBEAT_TIMEOUT_KEY", + "INITIAL_WINDOW_SIZE_KEY", + "INTERFACE_KEY", + "KEEP_ALIVE_INTERVAL_KEY", + "KEEP_ALIVE_TIMEOUT_KEY", + "LEAST_ACTIVE_LOADBALANCE", + "LOADBALANCE_KEY", + "MAX_CONCURRENT_CALLS_KEY", + "MAX_CONCURRENT_STREAMS_KEY", + "MAX_HEADER_LIST_SIZE_KEY", + "MAX_RECEIVE_MESSAGE_SIZE_KEY", + "METADATA_REVISION_KEY", + "METADATA_SERVICE_URL_PARAMS_KEY", + "METADATA_SERVICE_VERSION_KEY", + "METADATA_STORAGE_TYPE_KEY", + "METHODS_KEY", + "NAMESPACE_KEY", + "ORGANIZATION_KEY", + "OWNER_KEY", + "PATH_KEY", + "PAYLOAD_KEY", + "PREFERRED_KEY", + "PREFER_SERIALIZATION_KEY", + "PROVIDED_BY_KEY", + "PROVIDERS_CATEGORY", + "REFERENCE_FILTER_KEY", + "REFLECTION_ENABLED_KEY", + "REGISTER_KEY", + "REGISTER_MODE_KEY", + "REGISTRY_PREFERRED_KEY", + "REGISTRY_ZONE_FORCE_KEY", + "REGISTRY_ZONE_KEY", + "RELEASE_KEY", + "REMOTE_APPLICATION_KEY", + "RETRIES_KEY", + "ROUTER_KEY", + "SECRET_KEY_KEY", + "SERIALIZATION_IDS", + "SERIALIZATION_KEY", + "SERVER_KEY", + "SERVICE_FILTER_KEY", + "SESSION_KEY", + "SHUTWAIT_KEY", + "SIDE_KEY", + "SIMPLIFIED_KEY", + "SSL_ENABLED_KEY", + "STICKY_KEY", + "SUBSCRIBE_KEY", + "TAG_KEY", + "TIMEOUT_KEY", + "TIMESTAMP_KEY", + "TLS_CERT_FILE_KEY", + "TLS_KEY_FILE_KEY", + "TLS_SERVER_NAME_KEY", + "TOKEN_KEY", + "TPS_INTERVAL_KEY", + "TPS_KEY", + "TRIPLE_KEY", + "VERSION_KEY", + "WARMUP_KEY", + "WEIGHT_KEY", + "ZONE_AWARE_CLUSTER", + "ZONE_KEY", +] + +# ── Keys ───────────────────────────────────────────────────────────────── + +# Keys of URL parameters. +ACCESSLOG_KEY = "accesslog" # "true" logs each call a provider serves. +ACCESS_KEY_KEY = "accessKey" # Key that signs the requests to a registry or configuration center, such as Nacos. +ACTIVES_KEY = "actives" # Calls of a method a consumer makes to one provider at once. +APPLICATION_KEY = "application" # Name of the application that calls or serves. +ARCHITECTURE_KEY = "architecture" # Architecture of the application, as its owners describe it. +BACKUP_KEY = "backup" # Further hosts of a cluster, separated by commas. +BROADCAST_FAIL_PERCENT_KEY = ( + "broadcast.fail.percent" # Failures, as a percentage of the providers, that stop a broadcast. +) +CHECK_KEY = "check" # "false" lets a reference start without a provider. +CLIENT_KEY = "client" # Name of the client implementation. +CLUSTER_KEY = "cluster" +DEPRECATED_KEY = "deprecated" # "true" on a service or method that consumers are warned about. +ENVIRONMENT_KEY = "environment" # Environment the application runs in, such as "test" or "product". +EXECUTES_KEY = "executes" # Calls of a method a provider serves at once. +FAILBACK_TASKS_KEY = "failbacktasks" # Failed calls that may wait at once to be made again. +FORKS_KEY = "forks" # Providers the forking cluster calls at once. +GENERIC_KEY = "generic" # The mode of a call that names its method without a contract, such as "true". +GROUP_KEY = "group" # Part of the service identity. +HASH_ARGUMENTS_KEY = "hash.arguments" # Indexes of the arguments a call hashes, separated by commas. +HASH_NODES_KEY = "hash.nodes" # Points of each provider on the ring of consistent hashing. +LOADBALANCE_KEY = "loadbalance" +NAMESPACE_KEY = "namespace" # Isolates the data of a registry or configuration center. +ORGANIZATION_KEY = "organization" # Organization that owns the application. +OWNER_KEY = "owner" # People responsible for the application, separated by commas. +PROVIDED_BY_KEY = "provided-by" # Applications that provide a referenced service, separated by commas. +REFERENCE_FILTER_KEY = "reference.filter" # Filters of a reference, separated by commas. +RETRIES_KEY = "retries" # Attempts after a failed one that a call may make. +ROUTER_KEY = "router" # Routers of a reference, separated by commas. +SECRET_KEY_KEY = "secretKey" # Secret of "accessKey". +SERIALIZATION_KEY = "serialization" +SERVER_KEY = "server" # Name of the server implementation. +SERVICE_FILTER_KEY = "service.filter" # Filters of a service, separated by commas. +SESSION_KEY = "session" # Milliseconds a ZooKeeper session survives without a connection. +SHUTWAIT_KEY = "shutwait" # Milliseconds a closing server waits for running requests. +STICKY_KEY = "sticky" # "true" calls the provider of the call before while it is available. +TIMEOUT_KEY = "timeout" # Milliseconds. +TOKEN_KEY = "token" # Secret a provider registers, which each call to it attaches. +TPS_INTERVAL_KEY = "tps.interval" # Milliseconds of each window that "tps" counts calls in. +TPS_KEY = "tps" # Calls a provider serves in each window. +VERSION_KEY = "version" # Part of the service identity. +WARMUP_KEY = "warmup" # Milliseconds after it registers over which a provider's weight rises to the full. +WEIGHT_KEY = "weight" # Share of the calls a provider takes, relative to the others. + +# Keys of the URLs that registries hold. +CATEGORY_KEY = "category" # "providers", "consumers", "routers" or "configurators". +DUBBO_VERSION_KEY = "dubbo" # Version of the Dubbo protocol model, DUBBO_VERSION. +INTERFACE_KEY = "interface" +METHODS_KEY = "methods" # Separated by commas. +PATH_KEY = "path" # Interface a Dubbo request calls, among its attachments. +RELEASE_KEY = "release" # Version of the framework that registered the URL. +REMOTE_APPLICATION_KEY = "remote.application" # On the URL a consumer calls a provider with. +SIDE_KEY = "side" # "provider" or "consumer". +TIMESTAMP_KEY = "timestamp" # Milliseconds since the epoch when the URL was registered. + +# Keys of registry URLs. +EXTRA_KEYS_KEY = "extra-keys" # Further parameters, separated by commas, that simplified URLs keep. +PREFERRED_KEY = "preferred" # "true" on the registry whose providers a reference calls first. +REGISTER_KEY = "register" # "false" registers nothing with the registry. +REGISTER_MODE_KEY = "register-mode" # "interface", "instance" or "all". +SIMPLIFIED_KEY = "simplified" # "true" registers URLs with only the parameters consumers need. +SUBSCRIBE_KEY = "subscribe" # "false" discovers no providers in the registry. +ZONE_KEY = "zone" + +# Keys of the metadata of the application instances that registries hold. +ENDPOINTS_KEY = "dubbo.endpoints" # JSON: the port of each protocol it serves. +METADATA_REVISION_KEY = "dubbo.metadata.revision" +METADATA_SERVICE_URL_PARAMS_KEY = "dubbo.metadata-service.url-params" # JSON: protocol and port of its MetadataService. +METADATA_SERVICE_VERSION_KEY = "meta-v" # "2.0.0" for MetadataServiceV2. +METADATA_STORAGE_TYPE_KEY = "dubbo.metadata.storage-type" # "local" or "remote". + +# Keys of tag routing, on provider and consumer URLs and in call attachments. +FORCE_TAG_KEY = "dubbo.force.tag" # "true" fails a call that finds no provider of its tag. +TAG_KEY = "dubbo.tag" + +# Keys that choose among the registries of a reference, on the invoker of each registry and in call attachments. +REGISTRY_PREFERRED_KEY = "registry.preferred" # "true" on the invoker of the registry tried first. +REGISTRY_ZONE_FORCE_KEY = "registry.zone.force" # "true" fails a call that finds no registry in its zone. +REGISTRY_ZONE_KEY = "registry.zone" + +# Keys of Triple settings, each after TRIPLE_KEY and a dot, as in "triple.compressor". +COMPRESSOR_KEY = "compressor" # Of the messages a caller or server sends. +CONNECTION_INITIAL_WINDOW_SIZE_KEY = "connection-initial-window-size" # Bytes. +CONNECT_TIMEOUT_KEY = "connect-timeout" # Milliseconds a caller waits for a connection to be established. +HEALTH_ENABLED_KEY = "health-enabled" # "true" serves grpc.health.v1.Health. +INITIAL_WINDOW_SIZE_KEY = "initial-window-size" # Bytes, for each stream. +KEEP_ALIVE_INTERVAL_KEY = "keep-alive-interval" # Milliseconds without traffic before a PING. +KEEP_ALIVE_TIMEOUT_KEY = "keep-alive-timeout" # Milliseconds to wait for the PING acknowledgement. +MAX_CONCURRENT_STREAMS_KEY = "max-concurrent-streams" +MAX_HEADER_LIST_SIZE_KEY = "max-header-list-size" # Bytes. +MAX_RECEIVE_MESSAGE_SIZE_KEY = "max-receive-message-size" # Bytes of the largest message a server or caller receives. +REFLECTION_ENABLED_KEY = "reflection-enabled" # "true" serves grpc.reflection.v1 and v1alpha ServerReflection. +TRIPLE_KEY = "triple" + +# Keys of Dubbo protocol settings. +HEARTBEAT_KEY = "heartbeat" # Milliseconds without traffic before a consumer sends a heartbeat. +HEARTBEAT_TIMEOUT_KEY = "heartbeat.timeout" # Milliseconds without reading before a connection is closed. +MAX_CONCURRENT_CALLS_KEY = "max-concurrent-calls" # Calls a Dubbo server runs at once, 0 for any number. +PAYLOAD_KEY = "payload" # Bytes of the largest body a request or response may have. +PREFER_SERIALIZATION_KEY = "prefer.serialization" # Serializations a consumer should use, preferred first. + +# Keys of TLS settings. +CA_CERT_FILE_KEY = "ca-cert-file" # PEM file of the certificates to trust. +SSL_ENABLED_KEY = "ssl-enabled" # "true" enables TLS. +TLS_CERT_FILE_KEY = "tls-cert-file" # PEM file of the own certificate chain. +TLS_KEY_FILE_KEY = "tls-key-file" # PEM file of the own private key. +TLS_SERVER_NAME_KEY = "tls-server-name" # Name the server certificate must carry. + +# ── Values ─────────────────────────────────────────────────────────────── + +CONSUMERS_CATEGORY = "consumers" # The category of the URLs that consumers register. +DUBBO_VERSION = "2.0.2" # Version of the Dubbo protocol model that calls and registered URLs carry. +LEAST_ACTIVE_LOADBALANCE = "leastactive" # Chooses the provider with the fewest calls under way. +PROVIDERS_CATEGORY = "providers" # The category of the URLs that providers register. +# The id of each serialization in the header of a Dubbo frame. +SERIALIZATION_IDS: Mapping[str, int] = MappingProxyType({"fastjson2": 23, "hessian2": 2}) +ZONE_AWARE_CLUSTER = "zone-aware" # Chooses among the registries of a reference. + +# ── Defaults ───────────────────────────────────────────────────────────── + +# Of the application and its registries. +DEFAULT_METADATA_TYPE = "local" # Consumers ask each instance. +DEFAULT_REGISTER = True +DEFAULT_REGISTRY_MODE = "all" # Register and discover both by interface and by instance. +DEFAULT_ROOT = "dubbo" # The ZooKeeper node a registry, metadata report or configuration center keeps its nodes under. +DEFAULT_SUBSCRIBE = True + +# Of protocols and services. +DEFAULT_CONNECTION_INITIAL_WINDOW_SIZE = 16 * 1024 * 1024 # Bytes. +DEFAULT_CONNECT_TIMEOUT = 3.0 # Seconds. +DEFAULT_DUBBO_PORT = 20880 +DEFAULT_GENERIC = "true" # Objects travel as maps naming their Java class under "class". +DEFAULT_HEARTBEAT = 60.0 # Seconds. +# Bytes a stream window starts at, before it grows with the bandwidth-delay product measured on the connection. +DEFAULT_INITIAL_WINDOW_SIZE = 1024 * 1024 +DEFAULT_JAVA_SERIALIZATION = "hessian2" # Where values travel as Java objects, as in the Dubbo protocol. +DEFAULT_KEEP_ALIVE_TIMEOUT = 20.0 # Seconds. +DEFAULT_MAX_CONCURRENT_CALLS = 200 +DEFAULT_MAX_CONCURRENT_STREAMS = 100 +DEFAULT_MAX_HEADER_LIST_SIZE = 64 * 1024 # Bytes. +DEFAULT_MAX_RECEIVE_MESSAGE_SIZE = 4 * 1024 * 1024 # Bytes. +DEFAULT_PAYLOAD = 8 * 1024 * 1024 # Bytes. +DEFAULT_PROTOCOL = "tri" # The protocol DubboConfig has when it defines none. +DEFAULT_PROTOCOL_HOST = "0.0.0.0" # Every IPv4 interface. +DEFAULT_SERIALIZATION = "protobuf" +DEFAULT_SHUTWAIT = 10.0 # Seconds. +DEFAULT_TPS_INTERVAL = 60.0 # Seconds. +DEFAULT_TRIPLE_PORT = 50051 +DEFAULT_UNREGISTER_WAIT = 3.0 # Seconds. +DEFAULT_WARMUP = 600.0 # Seconds. +DEFAULT_WEIGHT = 100 + +# Of references. +DEFAULT_CHECK = True # Startup fails without a provider. +DEFAULT_CLUSTER = "failover" +DEFAULT_FORKS = 2 +DEFAULT_LOADBALANCE = "random" +DEFAULT_RETRIES = 2 +DEFAULT_ROUTERS = ("tag", "condition") +DEFAULT_STICKY = False +DEFAULT_TIMEOUT = 1.0 # Seconds a unary call may take. + +# Of the configuration center. +DEFAULT_CONFIG_CENTER_CHECK = True +DEFAULT_CONFIG_CENTER_FILE = "dubbo.yaml" +DEFAULT_CONFIG_CENTER_GROUP = "dubbo" +DEFAULT_CONFIG_CENTER_TIMEOUT = 30.0 # Seconds. diff --git a/src/dubbo/constants/__init__.py b/src/dubbo/constants/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/src/dubbo/constants/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/src/dubbo/constants/common_constants.py b/src/dubbo/constants/common_constants.py deleted file mode 100644 index c997ac8e..00000000 --- a/src/dubbo/constants/common_constants.py +++ /dev/null @@ -1,68 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -DUBBO_VALUE = "dubbo" - -REFER_KEY = "refer" -EXPORT_KEY = "export" - -PROTOCOL_KEY = "protocol" -TRIPLE = "triple" -TRIPLE_SHORT = "tri" - -SIDE_KEY = "side" -SERVER_VALUE = "server" -CLIENT_VALUE = "client" - -METHOD_KEY = "method" -SERVICE_KEY = "service" - -SERVICE_HANDLER_KEY = "service-handler" - -GROUP_KEY = "group" - -LOCAL_HOST_KEY = "localhost" -LOCAL_HOST_VALUE = "127.0.0.1" -DEFAULT_PORT = 50051 - -SSL_ENABLED_KEY = "ssl-enabled" - -SERIALIZATION_KEY = "serialization" -SERIALIZER_KEY = "serializer" -DESERIALIZER_KEY = "deserializer" - - -COMPRESSION_KEY = "compression" -COMPRESSOR_KEY = "compressor" -DECOMPRESSOR_KEY = "decompressor" - - -TRANSPORTER_KEY = "transporter" -TRANSPORTER_DEFAULT_VALUE = "aio" - -TRUE_VALUE = "true" -FALSE_VALUE = "false" - -RPC_TYPE_KEY = "rpc-type" - -METHOD_DESCRIPTOR_KEY = "method-descriptor" - -LOADBALANCE_KEY = "loadbalance" - -PATH_SEPARATOR = "/" -PROTOCOL_SEPARATOR = "://" -ANY_VALUE = "*" -COMMA_SEPARATOR = "," diff --git a/src/dubbo/constants/config_constants.py b/src/dubbo/constants/config_constants.py deleted file mode 100644 index aa8830c8..00000000 --- a/src/dubbo/constants/config_constants.py +++ /dev/null @@ -1,26 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -ENVIRONMENT = "environment" -TEST_ENVIRONMENT = "test" -DEVELOPMENT_ENVIRONMENT = "develop" -PRODUCTION_ENVIRONMENT = "product" - -VERSION = "version" -GROUP = "group" - -TRANSPORT = "transport" -AIO_TRANSPORT = "aio" diff --git a/src/dubbo/constants/logger_constants.py b/src/dubbo/constants/logger_constants.py deleted file mode 100644 index 8d8e8020..00000000 --- a/src/dubbo/constants/logger_constants.py +++ /dev/null @@ -1,83 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import enum -import os - -__all__ = [ - "FileRotateType", - "LEVEL_KEY", - "CONSOLE_ENABLED_KEY", - "FILE_ENABLED_KEY", - "FILE_DIR_KEY", - "FILE_NAME_KEY", - "FILE_ROTATE_KEY", - "FILE_MAX_BYTES_KEY", - "FILE_INTERVAL_KEY", - "FILE_BACKUP_COUNT_KEY", - "DEFAULT_LEVEL_VALUE", - "DEFAULT_CONSOLE_ENABLED_VALUE", - "DEFAULT_FILE_ENABLED_VALUE", - "DEFAULT_FILE_DIR_VALUE", - "DEFAULT_FILE_NAME_VALUE", - "DEFAULT_FILE_MAX_BYTES_VALUE", - "DEFAULT_FILE_INTERVAL_VALUE", - "DEFAULT_FILE_BACKUP_COUNT_VALUE", -] - - -@enum.unique -class FileRotateType(enum.Enum): - """ - The file rotating type enum. - - :cvar NONE: No rotating. - :cvar SIZE: Rotate the file by size. - :cvar TIME: Rotate the file by time. - """ - - NONE = "NONE" - SIZE = "SIZE" - TIME = "TIME" - - -"""logger config keys""" -# global config -LEVEL_KEY = "logger.level" - -# console config -CONSOLE_ENABLED_KEY = "logger.console.enable" - -# file logger -FILE_ENABLED_KEY = "logger.file.enable" -FILE_DIR_KEY = "logger.file.dir" -FILE_NAME_KEY = "logger.file.name" -FILE_ROTATE_KEY = "logger.file.rotate" -FILE_MAX_BYTES_KEY = "logger.file.maxbytes" -FILE_INTERVAL_KEY = "logger.file.interval" -FILE_BACKUP_COUNT_KEY = "logger.file.backupcount" - -"""some logger default value""" -DEFAULT_LEVEL_VALUE = "INFO" -# console -DEFAULT_CONSOLE_ENABLED_VALUE = True -# file -DEFAULT_FILE_ENABLED_VALUE = False -DEFAULT_FILE_DIR_VALUE = os.path.expanduser("~") -DEFAULT_FILE_NAME_VALUE = "dubbo.log" -DEFAULT_FILE_MAX_BYTES_VALUE = 10 * 1024 * 1024 -DEFAULT_FILE_INTERVAL_VALUE = 1 -DEFAULT_FILE_BACKUP_COUNT_VALUE = 10 diff --git a/src/dubbo/constants/registry_constants.py b/src/dubbo/constants/registry_constants.py deleted file mode 100644 index 6ac69a43..00000000 --- a/src/dubbo/constants/registry_constants.py +++ /dev/null @@ -1,24 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -REGISTRY_KEY = "registry" -DYNAMIC_KEY = "dynamic" -CATEGORY_KEY = "category" -PROVIDERS_CATEGORY = "providers" -CONSUMERS_CATEGORY = "consumers" - - -LOAD_BALANCE_KEY = "loadbalance" diff --git a/src/dubbo/exceptions.py b/src/dubbo/exceptions.py new file mode 100644 index 00000000..0dfa91e2 --- /dev/null +++ b/src/dubbo/exceptions.py @@ -0,0 +1,124 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import enum +from collections.abc import Mapping +from types import MappingProxyType +from typing import Any + +__all__ = ["DubboError", "EndOfStream", "RemoteError", "RpcError", "Status"] + + +class DubboError(Exception): + """Base class for framework-defined exceptions.""" + + +class EndOfStream(DubboError): + """Raised by `ReceiveStream.receive` once the other side has ended its messages; ``async for`` stops on it.""" + + def __init__(self) -> None: + super().__init__("the other side ended what it sends") + + +class Status(enum.IntEnum): + """Why a call ended: the gRPC status codes, which every protocol maps to its wire format. + + The framework itself ends a call with: + + - ``UNAVAILABLE``: no provider could take it: none was found, the + connection failed or closed, or a limit such as ``executes``, ``tps`` + or ``actives`` was reached. The default ``failover`` cluster retries + only this status, on another provider. + - ``DEADLINE_EXCEEDED``: the ``timeout`` of a unary call passed. + - ``PERMISSION_DENIED``: the call lacks the provider's ``token``. + - ``UNIMPLEMENTED``: the provider has no such method. + - ``UNKNOWN``: the handler raised an exception that names no status. + """ + + OK = 0 + CANCELLED = 1 + UNKNOWN = 2 + INVALID_ARGUMENT = 3 + DEADLINE_EXCEEDED = 4 + NOT_FOUND = 5 + ALREADY_EXISTS = 6 + PERMISSION_DENIED = 7 + RESOURCE_EXHAUSTED = 8 + FAILED_PRECONDITION = 9 + ABORTED = 10 + OUT_OF_RANGE = 11 + UNIMPLEMENTED = 12 + INTERNAL = 13 + UNAVAILABLE = 14 + DATA_LOSS = 15 + UNAUTHENTICATED = 16 + + +class RpcError(DubboError): + """A call failed with a status. + + A handler raises it to fail its call with ``status``; the caller receives + an `RpcError` of the same status and message. Over a format of Java + objects, such as Dubbo with ``hessian2``, it arrives as a `RemoteError` of + ``org.apache.dubbo.rpc.RpcException``, of the same status where that + exception has a code for it, and another exception as a `RemoteError` of + ``java.lang.RuntimeException``; otherwise another exception arrives as + `Status.UNKNOWN`. A protocol may carry more about the failure in an error + of its own, such as the details of `dubbo.protocol.triple.TripleError`. + + Attributes: + status: Why the call failed. + message: Description for people. + """ + + def __init__(self, status: Status, message: str = "") -> None: + super().__init__(status, message) + self.status = status + self.message = message + + def __str__(self) -> str: + return f"{self.status.name}: {self.message}" if self.message else self.status.name + + +class RemoteError(RpcError): + """An exception the code of the other side raised, of a class it names, such as ``java.lang.IllegalStateException``. + + A caller receives it for an exception the method of a provider raised; + a handler raises it to fail its call with an exception of + ``class_name``. It is the answer of the method, so a cluster never + retries it. + + Attributes: + class_name: The class of the exception, as its language names it. + fields: The other fields of the exception, such as ``code``, or the + ``cause`` and ``stackTrace`` of a Java throwable. + """ + + def __init__( + self, + class_name: str, + message: str = "", + *, + fields: Mapping[str, Any] | None = None, + status: Status = Status.UNKNOWN, + ) -> None: + super().__init__(status, message) + self.class_name = class_name + self.fields: Mapping[str, Any] = MappingProxyType(dict(fields or {})) + + def __str__(self) -> str: + return f"{self.class_name}: {self.message}" if self.message else self.class_name diff --git a/src/dubbo/extension/__init__.py b/src/dubbo/extension/__init__.py index 6af90b2f..28c0a390 100644 --- a/src/dubbo/extension/__init__.py +++ b/src/dubbo/extension/__init__.py @@ -1,21 +1,23 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from dubbo.extension.extension_loader import ExtensionError, ExtensionLoader as _ExtensionLoader +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. -__all__ = ["ExtensionError", "extensionLoader"] +from .exceptions import ExtensionError +from .loader import Extensions, extension_point, extensions +from .resource import Resource +from .scope import ApplicationScope -extensionLoader = _ExtensionLoader() +__all__ = ["ApplicationScope", "ExtensionError", "Extensions", "Resource", "extension_point", "extensions"] diff --git a/src/dubbo/extension/exceptions.py b/src/dubbo/extension/exceptions.py new file mode 100644 index 00000000..dd0b5dd6 --- /dev/null +++ b/src/dubbo/extension/exceptions.py @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from dubbo.exceptions import DubboError + +__all__ = ["ExtensionError"] + + +class ExtensionError(DubboError): + """An extension could not be registered or loaded.""" diff --git a/src/dubbo/extension/extension_loader.py b/src/dubbo/extension/extension_loader.py deleted file mode 100644 index 1f9e8142..00000000 --- a/src/dubbo/extension/extension_loader.py +++ /dev/null @@ -1,91 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import importlib -from typing import Any - -from dubbo.classes import SingletonBase -from dubbo.extension import registries as registries_module - - -class ExtensionError(Exception): - """ - Extension error. - """ - - def __init__(self, message: str): - """ - Initialize the extension error. - :param message: The error message. - :type message: str - """ - super().__init__(message) - - -class ExtensionLoader(SingletonBase): - """ - Singleton class for loading extension implementations. - """ - - def __init__(self): - """ - Initialize the extension loader. - - Load all the registries from the registries module. - """ - if not hasattr(self, "_initialized"): # Ensure __init__ runs only once - self._registries = {} - for name in registries_module.registries: - registry = getattr(registries_module, name) - self._registries[registry.interface] = registry.impls - self._initialized = True - - def get_extension(self, interface: Any, impl_name: str) -> Any: - """ - Get the extension implementation for the interface. - - :param interface: Interface class. - :type interface: Any - :param impl_name: Implementation name. - :type impl_name: str - :return: Extension implementation class. - :rtype: Any - :raises ExtensionError: If the interface or implementation is not found. - """ - # Get the registry for the interface - impls = self._registries.get(interface) - if not impls: - raise ExtensionError(f"Interface '{interface.__name__}' is not supported.") - - # Get the full name of the implementation - full_name = impls.get(impl_name) - if not full_name: - raise ExtensionError(f"Implementation '{impl_name}' for interface '{interface.__name__}' is not exist.") - - try: - # Split the full name into module and class - module_name, class_name = full_name.rsplit(".", 1) - - # Load the module and get the class - module = importlib.import_module(module_name) - subclass = getattr(module, class_name) - - # Return the subclass - return subclass - except Exception as e: - raise ExtensionError( - f"Failed to load extension '{impl_name}' for interface '{interface.__name__}'. \nDetail: {e}" - ) diff --git a/src/dubbo/extension/loader.py b/src/dubbo/extension/loader.py new file mode 100644 index 00000000..742fbdf6 --- /dev/null +++ b/src/dubbo/extension/loader.py @@ -0,0 +1,173 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Callable +from functools import cache +from importlib import metadata +from typing import ParamSpec, TypeVar, cast + +from .exceptions import ExtensionError + +__all__ = ["Extensions", "extension_point", "extensions"] + +P = ParamSpec("P") +T = TypeVar("T") + +_Entry = metadata.EntryPoint | Callable[..., object] + +# Declared extension points and their entry point groups, filled by extension_point. +_POINTS: dict[object, str] = {} +# The implementation each point uses when none is named. +_DEFAULTS: dict[object, str] = {} + + +def extension_point(group: str, *, default: str | None = None) -> Callable[[T], T]: + """Declare a contract as an extension point discovered from an entry point group. + + The contract is a class or a function stub; its call signature types the + implementations registered for it. It is returned unchanged. ``default`` + names the implementation that ``Extensions.get`` returns when no name is + given. + + Implementations install under the entry point ``group`` and are found by + the entry point name, which a URL scheme or parameter gives:: + + [project.entry-points."apache_dubbo.loadbalance"] + p2c = "my_package.balance:P2CLoadBalance" + + `Extensions.register` adds one at runtime instead, as tests do. + + Use a function stub when the contract is one stateless operation whose + result depends only on its arguments. Use a class when implementations hold + state, own a lifecycle, or provide several methods. When unsure, use a + class. Either way, the contract's docstring states what implementations + must provide. + """ + + def declare(point: T) -> T: + _POINTS[point] = group + if default is not None: + _DEFAULTS[point] = default + return point + + return declare + + +class Extensions: + """The implementations of the declared extension points, by name. + + An implementation is any callable with its point's call signature: a class + or factory for a class contract, a function for a function contract. + + Use the shared ``extensions`` instance; a separate instance isolates + registrations, for example in tests. Installed entry points are discovered + on first use and kept as a snapshot, and a plugin is imported only when its + name is first requested. Names are unique per point across installed and + registered implementations. Register during setup, before concurrent use. + """ + + def __init__(self) -> None: + self._discover = cache(metadata.entry_points) + # Per point: entry points not yet loaded, or callables, by name. + self._points: dict[object, dict[str, _Entry]] = {} + + def register(self, point: Callable[P, T], name: str, implementation: Callable[P, T]) -> None: + """Add an implementation without calling it. + + Raises: + ExtensionError: The point is not declared or the name is taken, + including by an installed entry point that is not loaded yet. + TypeError: The implementation is not callable. + """ + entries = self._entries(point) + if name in entries: + raise ExtensionError(f"duplicate extension {name!r} in group {_POINTS[point]!r}") + if not callable(implementation): + raise TypeError("extension implementation must be callable") + + entries[name] = implementation + + def get(self, point: Callable[P, T], name: str | None) -> Callable[P, T]: + """Return the implementation named ``name``, importing its plugin if needed. + + ``None`` names the default that the point declares. + + Raises: + ExtensionError: The point or the name is unknown, and the message + names the installed ones; the name is ``None`` and the point + declares no default; importing the plugin fails, with the + original exception as the cause; or the imported object is + not callable. + """ + entries = self._entries(point) + group = _POINTS[point] + if name is None: + name = _DEFAULTS.get(point) + if name is None: + raise ExtensionError(f"no extension named and no default in group {group!r}") + + try: + entry = entries[name] + except KeyError: + installed = ", ".join(sorted(entries)) or "none" + raise ExtensionError(f"unknown extension {name!r} in group {group!r}; installed: {installed}") from None + + if isinstance(entry, metadata.EntryPoint): + try: + loaded = entry.load() + except Exception as error: + raise ExtensionError( + f"cannot load extension {name!r} in group {group!r} from {entry.value!r}" + ) from error + if not callable(loaded): + raise ExtensionError(f"extension {name!r} in group {group!r} must be callable: {entry.value!r}") + + entry = entries[name] = loaded + + # Entry points are dynamic; this cast does not validate their signatures. + return cast(Callable[P, T], entry) + + def names(self, point: object) -> list[str]: + """Return the names of the installed and registered implementations, sorted, without importing any. + + Raises: + ExtensionError: The point is not declared. + """ + return sorted(self._entries(point)) + + def _entries(self, point: object) -> dict[str, _Entry]: + """Return the name table of a point, building it on first use.""" + entries = self._points.get(point) + if entries is not None: + return entries + + try: + group = _POINTS[point] + except KeyError: + raise ExtensionError(f"unknown extension point: {point!r}") from None + + entries = {} + for entry in self._discover().select(group=group): + if entry.name in entries: + raise ExtensionError(f"duplicate extension {entry.name!r} in group {group!r}") + entries[entry.name] = entry + + # setdefault keeps the first table if two callers race to build one. + return self._points.setdefault(point, entries) + + +extensions = Extensions() diff --git a/src/dubbo/extension/registries.py b/src/dubbo/extension/registries.py deleted file mode 100644 index cf23ae77..00000000 --- a/src/dubbo/extension/registries.py +++ /dev/null @@ -1,105 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from dataclasses import dataclass -from typing import Any - -from dubbo.cluster import LoadBalance -from dubbo.compression import Compressor, Decompressor -from dubbo.protocol import Protocol -from dubbo.registry import RegistryFactory -from dubbo.remoting import Transporter - - -@dataclass -class ExtendedRegistry: - """ - A dataclass to represent an extended registry. - - :param interface: The interface of the registry. - :type interface: Any - :param impls: The implementations of the registry. - :type impls: Dict[str, Any] - """ - - interface: Any - impls: dict[str, Any] - - -# All Extension Registries -registries = [ - "registryFactoryRegistry", - "loadBalanceRegistry", - "protocolRegistry", - "compressorRegistry", - "decompressorRegistry", - "transporterRegistry", -] - -# RegistryFactory registry -registryFactoryRegistry = ExtendedRegistry( - interface=RegistryFactory, - impls={ - "zookeeper": "dubbo.registry.zookeeper.zk_registry.ZookeeperRegistryFactory", - }, -) - -# LoadBalance registry -loadBalanceRegistry = ExtendedRegistry( - interface=LoadBalance, - impls={ - "random": "dubbo.cluster.loadbalances.RandomLoadBalance", - "cpu": "dubbo.cluster.loadbalances.CpuLoadBalance", - }, -) - -# Protocol registry -protocolRegistry = ExtendedRegistry( - interface=Protocol, - impls={ - "tri": "dubbo.protocol.triple.protocol.TripleProtocol", - }, -) - -# Compressor registry -compressorRegistry = ExtendedRegistry( - interface=Compressor, - impls={ - "identity": "dubbo.compression.Identity", - "gzip": "dubbo.compression.Gzip", - "bzip2": "dubbo.compression.Bzip2", - }, -) - - -# Decompressor registry -decompressorRegistry = ExtendedRegistry( - interface=Decompressor, - impls={ - "identity": "dubbo.compression.Identity", - "gzip": "dubbo.compression.Gzip", - "bzip2": "dubbo.compression.Bzip2", - }, -) - - -# Transporter registry -transporterRegistry = ExtendedRegistry( - interface=Transporter, - impls={ - "aio": "dubbo.remoting.aio.aio_transporter.AioTransporter", - }, -) diff --git a/src/dubbo/extension/resource.py b/src/dubbo/extension/resource.py new file mode 100644 index 00000000..ad0f6a44 --- /dev/null +++ b/src/dubbo/extension/resource.py @@ -0,0 +1,49 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from types import TracebackType +from typing import Self + +__all__ = ["Resource"] + + +class Resource(typing.Protocol): + """Something that holds resources, such as connections, until it is closed. + + It is ``anyio.abc.AsyncResource`` as a protocol, so that extension points + can extend it. + + Implementations subclass it to get ``async with``, which closes the + resource at the end of the block; one that opens on entering overrides + ``__aenter__``. + """ + + async def aclose(self) -> None: + """Release what the resource holds.""" + ... + + async def __aenter__(self) -> Self: + return self + + async def __aexit__( + self, + exc_type: type[BaseException] | None, + exc: BaseException | None, + traceback: TracebackType | None, + ) -> None: + await self.aclose() diff --git a/src/dubbo/extension/scope.py b/src/dubbo/extension/scope.py new file mode 100644 index 00000000..9a76d195 --- /dev/null +++ b/src/dubbo/extension/scope.py @@ -0,0 +1,149 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Callable, Hashable +from contextlib import AbstractAsyncContextManager +from types import TracebackType +from typing import Any, Self, TypeVar, cast + +import anyio +from anyio.abc import TaskGroup, TaskStatus + +__all__ = ["ApplicationScope"] + +T = TypeVar("T") + + +class ApplicationScope: + """What the extensions of one application share: resources opened once and closed as it stops, and plain state. + + The application enters it before anything else and exits it after + everything else; extensions reach it as ``url.scope``. It belongs to one + event loop and is not thread-safe. + + `share` enters each resource in a task of the scope, so that, once handed + to the request that opened it, the resource outlives that request's task + and is not bound by its cancel scopes. Closing refuses new requests, + waits for the resources still opening, then closes them in reverse order + of opening; a cancelled close closes those still open at once. + + Attributes: + state: Values the extensions share that open and close nothing, such + as the counts of calls under way that ``actives`` limits and + ``leastactive`` reads. An extension takes its entry on first use, + under a key that is or starts with its own class, as in + ``state.setdefault(ActiveCounts, ActiveCounts())``. Entries stay + until the scope closes, so what one holds must drop by itself + what no longer applies, as a count that falls to zero does. + """ + + def __init__(self) -> None: + self.state: dict[Hashable, Any] = {} + self._shared: dict[Hashable, object] = {} + self._closers: list[tuple[anyio.Event, anyio.Event]] = [] + # Set as each resource that is opening has been handed to its request or has failed to open. + self._opening: set[anyio.Event] = set() + # One lock per key, so that a resource may share another while it opens. + self._locks: dict[Hashable, anyio.Lock] = {} + self._task_group: TaskGroup | None = None + + async def share(self, key: Hashable, factory: Callable[[], AbstractAsyncContextManager[T]]) -> T: + """Return the resource shared under ``key``, entering ``factory()`` on the first request. + + Concurrent requests for ``key`` wait for the first; a failure to open + is raised to it, and the next request tries again. Cancelling the + request while the resource opens exits it. ``key`` is a tuple that + starts with the implementation, then what tells its instances apart, + as in ``(implementation, url)``. The caller never closes the resource. + + Raises: + RuntimeError: The scope is not open, or is closing. + """ + async with self._locks.setdefault(key, anyio.Lock()): + if self._task_group is None: + raise RuntimeError("the application scope is not open") + if key not in self._shared: + # Counted before its task runs, so that closing, which may begin meanwhile, waits for it. + opened = anyio.Event() + self._opening.add(opened) + self._shared[key] = await self._task_group.start(self._hold, factory, opened) + self._settle(opened) + + return cast(T, self._shared[key]) + + async def __aenter__(self) -> Self: + task_group = anyio.create_task_group() + await task_group.__aenter__() + self._task_group = task_group + return self + + async def __aexit__( + self, + exc_type: type[BaseException] | None, + exc: BaseException | None, + traceback: TracebackType | None, + ) -> None: + task_group, self._task_group = self._task_group, None + assert task_group is not None + self._shared.clear() + self.state.clear() + + try: + while self._opening: + await next(iter(self._opening)).wait() + for close, closed in reversed(self._closers): + close.set() + await closed.wait() + except BaseException: + task_group.cancel_scope.cancel() + for close, _ in self._closers: + close.set() + raise + finally: + await task_group.__aexit__(None, None, None) + + async def _hold( + self, + factory: Callable[[], AbstractAsyncContextManager[Any]], + opened: anyio.Event, + *, + task_status: TaskStatus[Any], + ) -> None: + # Until its request has taken the resource, a cancellation of the request exits it; then it lives until + # the scope closes it or its own cancel scopes end it, and exits under the cancellation, if any, that ends + # the scope. The guard encloses the whole lifetime, so that it never stands between the resource and the + # cancel scopes it entered. + closed = anyio.Event() + try: + with anyio.CancelScope() as guard: + async with factory() as resource: + close = anyio.Event() + self._closers.append((close, closed)) + task_status.started(resource) + await opened.wait() + guard.shield = True + try: + await close.wait() + finally: + guard.shield = False + finally: + self._settle(opened) + closed.set() + + def _settle(self, opened: anyio.Event) -> None: + self._opening.discard(opened) + opened.set() diff --git a/src/dubbo/filter/__init__.py b/src/dubbo/filter/__init__.py new file mode 100644 index 00000000..d95f960d --- /dev/null +++ b/src/dubbo/filter/__init__.py @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .base import Filter, get_filters +from .chain import chain_filters, get_attempt_filters, get_service_filters + +__all__ = ["Filter", "chain_filters", "get_attempt_filters", "get_filters", "get_service_filters"] diff --git a/src/dubbo/filter/accesslog.py b/src/dubbo/filter/accesslog.py new file mode 100644 index 00000000..9620ad08 --- /dev/null +++ b/src/dubbo/filter/accesslog.py @@ -0,0 +1,78 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +import time + +import anyio + +from dubbo.constants import GROUP_KEY, VERSION_KEY +from dubbo.exceptions import RpcError, Status +from dubbo.rpc.invocation import Invocation, Invoke, Result +from dubbo.url import URL + +from .base import Filter + +__all__ = ["AccessLogFilter"] + +_logger = logging.getLogger("dubbo.accesslog") + + +class AccessLogFilter(Filter): + """Logs each call to the service ``url`` as it ends, at INFO to the ``dubbo.accesslog`` logger, which the application configures. + + A line names the service by its ``group/interface:version`` key, then + the method, the status the call ends with and how long it took, as in + ``g/com.example.UserService:1.0 getUser OK 1.2ms``. A cancelled call + ends with ``CANCELLED``, and one that raises with ``UNKNOWN``. + + Each record also holds these values as its fields, for a formatter that + writes structured lines: ``service``, the interface; ``group`` and + ``version``, ``None`` when the service has none; ``method``; ``status``, + the name of the status; and ``duration_ms``, a float. + """ + + def __init__(self, url: URL) -> None: + self._service = url.service_key + self._fields = { + "service": url.path, + "group": url.parameters.get(GROUP_KEY), + "version": url.parameters.get(VERSION_KEY), + } + + async def invoke(self, call_next: Invoke, invocation: Invocation) -> Result: + start = time.perf_counter() + status = Status.UNKNOWN + try: + result = await call_next(invocation) + error = result.error + status = Status.OK if error is None else error.status if isinstance(error, RpcError) else Status.UNKNOWN + return result + except anyio.get_cancelled_exc_class(): + status = Status.CANCELLED + raise + finally: + if _logger.isEnabledFor(logging.INFO): + elapsed = (time.perf_counter() - start) * 1000 + _logger.info( + "%s %s %s %.1fms", + self._service, + invocation.method, + status.name, + elapsed, + extra={**self._fields, "method": invocation.method, "status": status.name, "duration_ms": elapsed}, + ) diff --git a/src/dubbo/filter/activecount.py b/src/dubbo/filter/activecount.py new file mode 100644 index 00000000..fe905125 --- /dev/null +++ b/src/dubbo/filter/activecount.py @@ -0,0 +1,112 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections import Counter +from collections.abc import Generator +from contextlib import contextmanager +from typing import cast + +import anyio + +from dubbo.rpc.invocation import Invocation, Invoke, Result +from dubbo.url import URL + +from .base import Filter + +__all__ = ["ActiveCountFilter", "ActiveCounts", "active_counts"] + +# The protocol, host, port, path and method of the calls counted together. +_Key = tuple[str, str | None, int | None, str, str] + + +class ActiveCounts: + """The calls of each method under way, by the URL they go to. + + An application keeps the calls it makes to each provider in the + ``ActiveCounts`` of its ``ApplicationScope.state``. A URL is told apart + by its protocol, host, port and path, so that the counts outlive the + invokers and filters made again for it, and the references of one + application count their calls to one provider together. + """ + + def __init__(self) -> None: + self._counts: Counter[_Key] = Counter() + # Set as a call of the key ends, for the calls that wait for room. + self._ended: dict[_Key, anyio.Event] = {} + + def get(self, url: URL, method: str) -> int: + """Return the calls of ``method`` under way to ``url``.""" + return self._counts[_key(url, method)] + + async def wait_for_room(self, url: URL, method: str, limit: int) -> None: + """Wait until fewer than ``limit`` calls of ``method`` are under way to ``url``. + + A call that counts as soon as this returns, before awaiting + anything else, stays within ``limit``. + """ + key = _key(url, method) + while self._counts[key] >= limit: + ended = self._ended.get(key) + if ended is None: + ended = self._ended[key] = anyio.Event() + await ended.wait() + + @contextmanager + def counting(self, url: URL, method: str) -> Generator[None]: + """Count a call of ``method`` to ``url`` as under way until the block exits.""" + key = _key(url, method) + self._counts[key] += 1 + try: + yield + finally: + self._counts[key] -= 1 + if not self._counts[key]: + del self._counts[key] + ended = self._ended.pop(key, None) + if ended is not None: + ended.set() + + +class ActiveCountFilter(Filter): + """Counts each call to the provider ``url`` as under way, in the ``ActiveCounts`` of its application, until it ends. + + A streaming call counts until it opens. + + Raises: + RuntimeError: No application made ``url``. + """ + + def __init__(self, url: URL) -> None: + self._counts = active_counts(url) + self._url = url + + async def invoke(self, call_next: Invoke, invocation: Invocation) -> Result: + with self._counts.counting(self._url, invocation.method): + return await call_next(invocation) + + +def active_counts(url: URL) -> ActiveCounts: + """Return the ``ActiveCounts`` of the calls the application that made ``url`` makes. + + Raises: + RuntimeError: No application made ``url``. + """ + return cast(ActiveCounts, url.scope.state.setdefault(ActiveCounts, ActiveCounts())) + + +def _key(url: URL, method: str) -> _Key: + return url.protocol, url.host, url.port, url.path, method diff --git a/src/dubbo/filter/actives.py b/src/dubbo/filter/actives.py new file mode 100644 index 00000000..7a78ac29 --- /dev/null +++ b/src/dubbo/filter/actives.py @@ -0,0 +1,72 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio + +from dubbo.constants import ACTIVES_KEY, TIMEOUT_KEY +from dubbo.exceptions import RpcError, Status +from dubbo.rpc.invocation import Invocation, Invoke, Result +from dubbo.url import URL +from dubbo.utils.converters import milliseconds + +from .activecount import active_counts +from .base import Filter + +__all__ = ["ActivesFilter"] + + +class ActivesFilter(Filter): + """Holds the calls of a method beyond those that may go to the provider ``url`` at once, until one of them ends. + + The limit of a method is ``{method}.actives``, else ``actives``; 0 or + less means no limit. A held call waits up to the timeout of its method, + ``{method}.timeout``, else ``timeout``, else without end, then fails + with ``UNAVAILABLE``. Every call counts as under way in the + ``ActiveCounts`` of the application, as ``ActiveCountFilter`` counts, so + that the limit holds across the invokers made again for the provider + and across the references of the application. A streaming call counts + until it opens. + + Raises: + RuntimeError: No application made ``url``. + """ + + def __init__(self, url: URL) -> None: + self._counts = active_counts(url) + self._url = url + self._default = url.get_parameter(ACTIVES_KEY, int, 0) + self._limits = url.get_method_parameters(ACTIVES_KEY, int) + self._timeout = url.get_parameter(TIMEOUT_KEY, milliseconds, None) + self._timeouts = url.get_method_parameters(TIMEOUT_KEY, milliseconds) + + async def invoke(self, call_next: Invoke, invocation: Invocation) -> Result: + method = invocation.method + limit = self._limits.get(method, self._default) + if limit > 0: + timeout = self._timeouts.get(method, self._timeout) + with anyio.move_on_after(timeout) as scope: + await self._counts.wait_for_room(self._url, method, limit) + if scope.cancelled_caught: + error = RpcError( + Status.UNAVAILABLE, + f"{invocation.interface}.{method} makes {limit} calls at once to {self._url.address}," + f" and none ended within {timeout} seconds", + ) + return Result(error=error) + + with self._counts.counting(self._url, method): + return await call_next(invocation) diff --git a/src/dubbo/filter/base.py b/src/dubbo/filter/base.py new file mode 100644 index 00000000..2e74f192 --- /dev/null +++ b/src/dubbo/filter/base.py @@ -0,0 +1,87 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from collections.abc import Sequence + +from dubbo.extension import extension_point, extensions +from dubbo.rpc.invocation import Invocation, Invoke, Result +from dubbo.url import URL + +__all__ = [ + "ATTEMPT_FILTER_KEY", + "Filter", + "get_filters", +] + +# The URL parameter that names, separated by commas, the filters each attempt of a call runs through. +ATTEMPT_FILTER_KEY = "reference.attempt-filter" + + +@extension_point("apache_dubbo.filter") +class Filter(typing.Protocol): + """Runs around the calls of a service or a reference. + + Implement ``__init__(url)`` and ``invoke``, and install the class under + the entry point group ``apache_dubbo.filter``; its name goes where the + filter runs: + + - ``service.filter`` (``ServiceConfig.filters``): around each call the + service serves, inside the context of the handler, so that + `dubbo.incoming` works; + - ``reference.filter`` (``ReferenceConfig.filters``): around each call + of the reference, once whatever the retries, in the caller's task; + - ``reference.attempt-filter`` (``ReferenceConfig.attempt_filters``): + around each attempt on one provider. + + One is created with the URL of each invoker it runs around, and created + again with the URL the override rules change, so it reads its settings + once and keeps nothing of its own across calls: what calls or filters + share goes in ``url.scope.state``. It holds nothing and is never + closed. ``invoke`` runs in the event loop, for many calls at once. + + A filter may change the invocation, return a result of its own without + calling ``call_next``, or change the result afterwards. It fails a call + by returning ``Result(error=RpcError(...))``; an exception it raises is + a failure of the framework, which the caller sees raised, and the + caller of a served call as ``INTERNAL``:: + + class Timing(Filter): + def __init__(self, url: URL) -> None: + self._service = url.path + + async def invoke(self, call_next: Invoke, invocation: Invocation) -> Result: + start = time.monotonic() + try: + return await call_next(invocation) + finally: + observe(self._service, invocation.method, time.monotonic() - start) + + On the calling side, a streaming call returns once it has opened; on the + serving side, once its handler has returned. + """ + + def __init__(self, url: URL) -> None: ... + + async def invoke(self, call_next: Invoke, invocation: Invocation) -> Result: + """Run around one call; ``call_next`` makes it through the rest of the chain.""" + ... + + +def get_filters(names: Sequence[str], url: URL) -> list[Filter]: + """Return the filters ``names`` names, in order, each created with ``url``.""" + return [extensions.get(Filter, name)(url) for name in names] diff --git a/src/dubbo/filter/chain.py b/src/dubbo/filter/chain.py new file mode 100644 index 00000000..b66b2c16 --- /dev/null +++ b/src/dubbo/filter/chain.py @@ -0,0 +1,138 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Building the filter chains of services and of calls to providers.""" + +import functools +from collections.abc import Callable, Sequence + +from dubbo.constants import ( + ACCESSLOG_KEY, + ACTIVES_KEY, + DEPRECATED_KEY, + EXECUTES_KEY, + LEAST_ACTIVE_LOADBALANCE, + LOADBALANCE_KEY, + SERVICE_FILTER_KEY, + TOKEN_KEY, + TPS_KEY, +) +from dubbo.rpc.invocation import Invocation, Invoke, Invoker, Result +from dubbo.url import URL +from dubbo.utils.converters import boolean, comma_separated, is_true + +from .accesslog import AccessLogFilter +from .activecount import ActiveCountFilter +from .actives import ActivesFilter +from .base import ATTEMPT_FILTER_KEY, Filter, get_filters +from .deprecated import DeprecatedFilter +from .executes import ExecutesFilter +from .token import TokenFilter +from .tps import TpsFilter + +__all__ = ["chain_filters", "get_attempt_filters", "get_service_filters"] + +# Filters that settings add, the first outermost: each with the parameter that adds it when its value, or that of +# some method, converts to a true value. +_Added = tuple[tuple[str, Callable[[str], object], Callable[[URL], Filter]], ...] + + +def get_service_filters(url: URL) -> list[Filter]: + """Return the filters each call to the service ``url`` runs through, the first outermost. + + First come those its settings add: ``accesslog`` logs each call, + ``token`` refuses those without it, and ``tps`` and ``executes`` limit + them; then those ``service.filter`` names. + """ + added = _added( + ( + (ACCESSLOG_KEY, boolean, AccessLogFilter), + (TOKEN_KEY, str, TokenFilter), + (TPS_KEY, int, TpsFilter), + (EXECUTES_KEY, int, ExecutesFilter), + ), + url, + ) + return added + get_filters(url.get_parameter(SERVICE_FILTER_KEY, comma_separated, ()), url) + + +def get_attempt_filters(url: URL) -> list[Filter]: + """Return the filters each attempt of a call on the provider ``url`` runs through, the first outermost. + + First come those its settings add: ``deprecated`` warns of the methods + the provider deprecates, ``actives`` limits the calls made to it at + once, and the ``leastactive`` load balance counts those under way, + which ``actives`` counts too; then those ``reference.attempt-filter`` + names. + """ + added = _added( + ( + (DEPRECATED_KEY, is_true, DeprecatedFilter), + (ACTIVES_KEY, int, ActivesFilter), + (LOADBALANCE_KEY, lambda name: name == LEAST_ACTIVE_LOADBALANCE, ActiveCountFilter), + ), + url, + ) + # ActivesFilter counts the calls under way itself. + if any(isinstance(filter_, ActivesFilter) for filter_ in added): + added = [filter_ for filter_ in added if not isinstance(filter_, ActiveCountFilter)] + + return added + get_filters(url.get_parameter(ATTEMPT_FILTER_KEY, comma_separated, ()), url) + + +def chain_filters(invoker: Invoker, filters: Sequence[Filter]) -> Invoker: + """Return an invoker that makes the calls of ``invoker`` through ``filters``, the first outermost. + + It has the URL and the availability of ``invoker``, and closing it closes ``invoker``. + """ + if not filters: + return invoker + + return _Chained(invoker, filters) + + +class _Chained(Invoker): + """Makes the calls of an invoker through filters, and is that invoker otherwise.""" + + def __init__(self, invoker: Invoker, filters: Sequence[Filter]) -> None: + call_next: Invoke = invoker.invoke + for filter_ in reversed(filters): + call_next = functools.partial(filter_.invoke, call_next) + self._invoker = invoker + self._call = call_next + + @property + def url(self) -> URL: + return self._invoker.url + + @property + def available(self) -> bool: + return self._invoker.available + + async def invoke(self, invocation: Invocation) -> Result: + return await self._call(invocation) + + async def aclose(self) -> None: + await self._invoker.aclose() + + +def _added(table: _Added, url: URL) -> list[Filter]: + return [ + create(url) + for key, convert, create in table + if url.get_parameter(key, convert, None) or any(url.get_method_parameters(key, convert).values()) + ] diff --git a/src/dubbo/filter/deprecated.py b/src/dubbo/filter/deprecated.py new file mode 100644 index 00000000..1f73b1f0 --- /dev/null +++ b/src/dubbo/filter/deprecated.py @@ -0,0 +1,61 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +from typing import cast + +from dubbo.constants import DEPRECATED_KEY +from dubbo.rpc.invocation import Invocation, Invoke, Result +from dubbo.url import URL +from dubbo.utils.converters import is_true + +from .base import Filter + +__all__ = ["DeprecatedFilter"] + +_logger = logging.getLogger(__name__) + + +class DeprecatedFilter(Filter): + """Logs a warning the first time the application calls a method that the provider ``url`` deprecates. + + A method is deprecated when ``{method}.deprecated``, else + ``deprecated``, reads ``true``. The methods warned of are kept in the + ``ApplicationScope.state`` of the application, by service and method. + + Raises: + RuntimeError: No application made ``url``. + """ + + def __init__(self, url: URL) -> None: + self._warned = _warned(url) + self._default = url.get_parameter(DEPRECATED_KEY, is_true, False) + self._deprecated = url.get_method_parameters(DEPRECATED_KEY, is_true) + self._service = url.service_key + self._address = url.address + + async def invoke(self, call_next: Invoke, invocation: Invocation) -> Result: + method = invocation.method + if self._deprecated.get(method, self._default) and (self._service, method) not in self._warned: + self._warned.add((self._service, method)) + _logger.warning("Calling %s.%s, which its provider at %s deprecates", self._service, method, self._address) + + return await call_next(invocation) + + +def _warned(url: URL) -> set[tuple[str, str]]: + return cast(set[tuple[str, str]], url.scope.state.setdefault(DeprecatedFilter, set())) diff --git a/src/dubbo/filter/executes.py b/src/dubbo/filter/executes.py new file mode 100644 index 00000000..9428dbcb --- /dev/null +++ b/src/dubbo/filter/executes.py @@ -0,0 +1,64 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from typing import cast + +from dubbo.constants import EXECUTES_KEY +from dubbo.exceptions import RpcError, Status +from dubbo.rpc.invocation import Invocation, Invoke, Result +from dubbo.url import URL + +from .activecount import ActiveCounts +from .base import Filter + +__all__ = ["ExecutesFilter"] + + +class ExecutesFilter(Filter): + """Fails with ``UNAVAILABLE`` the calls of a method beyond those the service ``url`` may serve at once. + + The limit of a method is ``{method}.executes``, else ``executes``; 0 + or less means no limit. Every call counts as under way in the + ``ActiveCounts`` of the calls the application serves, apart from those + it makes, so that a limit the override rules lower refuses new calls + until those under way end within it. + + Raises: + RuntimeError: No application made ``url``. + """ + + def __init__(self, url: URL) -> None: + self._counts = _served_counts(url) + self._url = url + self._default = url.get_parameter(EXECUTES_KEY, int, 0) + self._limits = url.get_method_parameters(EXECUTES_KEY, int) + + async def invoke(self, call_next: Invoke, invocation: Invocation) -> Result: + method = invocation.method + limit = self._limits.get(method, self._default) + if limit > 0 and self._counts.get(self._url, method) >= limit: + error = RpcError( + Status.UNAVAILABLE, f"{invocation.interface}.{invocation.method} serves {limit} calls at once" + ) + return Result(error=error) + + with self._counts.counting(self._url, method): + return await call_next(invocation) + + +def _served_counts(url: URL) -> ActiveCounts: + return cast(ActiveCounts, url.scope.state.setdefault((ExecutesFilter, ActiveCounts), ActiveCounts())) diff --git a/src/dubbo/filter/token.py b/src/dubbo/filter/token.py new file mode 100644 index 00000000..99bd336b --- /dev/null +++ b/src/dubbo/filter/token.py @@ -0,0 +1,42 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import hmac + +from dubbo.constants import TOKEN_KEY +from dubbo.exceptions import RpcError, Status +from dubbo.rpc.invocation import Invocation, Invoke, Result +from dubbo.url import URL + +from .base import Filter + +__all__ = ["TokenFilter"] + + +class TokenFilter(Filter): + """Refuses with ``PERMISSION_DENIED`` each call that does not attach the ``token`` of the service ``url``.""" + + def __init__(self, url: URL) -> None: + self._token = url.parameters.get(TOKEN_KEY, "").encode() + + async def invoke(self, call_next: Invoke, invocation: Invocation) -> Result: + received = invocation.attachments.get(TOKEN_KEY) + if self._token and not (isinstance(received, str) and hmac.compare_digest(received.encode(), self._token)): + error = RpcError(Status.PERMISSION_DENIED, f"{invocation.interface}.{invocation.method} needs its token") + return Result(error=error) + + return await call_next(invocation) diff --git a/src/dubbo/filter/tps.py b/src/dubbo/filter/tps.py new file mode 100644 index 00000000..4ace44ea --- /dev/null +++ b/src/dubbo/filter/tps.py @@ -0,0 +1,130 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import time +from typing import cast + +from dubbo.constants import DEFAULT_TPS_INTERVAL, TPS_INTERVAL_KEY, TPS_KEY +from dubbo.exceptions import RpcError, Status +from dubbo.rpc.invocation import Invocation, Invoke, Result +from dubbo.url import URL +from dubbo.utils.converters import milliseconds + +from .base import Filter + +__all__ = ["TpsFilter"] + + +# The protocol, host, port and path of a service URL, and the method counted alone or None for the others. +_Key = tuple[str, str | None, int | None, str, str | None] + + +class TpsWindows: + """The windows in which an application counts the calls of the services it serves. + + A window is kept for each URL a service is served with, told apart by + its protocol, host, port and path, and each method counted alone or + ``None`` for the others. It outlives the filters that the override + rules create again, so that the calls a window has counted stay + counted. + """ + + def __init__(self) -> None: + self._windows: dict[_Key, _Window] = {} + + def get(self, url: URL, method: str | None) -> "_Window": + """Return the window of ``method`` of the service ``url``, a new one on first use.""" + key = url.protocol, url.host, url.port, url.path, method + window = self._windows.get(key) + if window is None: + window = self._windows[key] = _Window() + return window + + +class TpsFilter(Filter): + """Fails with ``UNAVAILABLE`` the calls beyond those the service ``url`` may serve in each window. + + The methods are counted together: ``tps`` calls in each window of + ``tps.interval``. A method that sets ``{method}.tps`` is counted on its + own instead, in windows of ``{method}.tps.interval``, else + ``tps.interval``. A rate of 0 or less means no limit. The windows are + those of the ``TpsWindows`` of the application: a changed rate applies to + the calls the current window has counted, and a changed interval from the + next window. + + Raises: + RuntimeError: No application made ``url``. + """ + + def __init__(self, url: URL) -> None: + windows = _windows(url) + interval = url.get_parameter(TPS_INTERVAL_KEY, milliseconds, DEFAULT_TPS_INTERVAL) + intervals = url.get_method_parameters(TPS_INTERVAL_KEY, milliseconds) + self._shared = _limit(windows.get(url, None), url.get_parameter(TPS_KEY, int, 0), interval) + self._limits = { + method: _limit(windows.get(url, method), rate, intervals.get(method, interval)) + for method, rate in url.get_method_parameters(TPS_KEY, int).items() + } + + async def invoke(self, call_next: Invoke, invocation: Invocation) -> Result: + limit = self._limits.get(invocation.method, self._shared) + if limit is not None and not limit.take(): + error = RpcError( + Status.UNAVAILABLE, + f"{invocation.interface}.{invocation.method} serves {limit.rate} calls in {limit.interval} seconds", + ) + return Result(error=error) + + return await call_next(invocation) + + +class _Window: + """The calls counted in a window, which ends at ``end`` on the monotonic clock.""" + + def __init__(self) -> None: + self.end = float("-inf") + self.taken = 0 + + +class _Limit: + """Admits ``rate`` calls in fixed windows of ``interval`` seconds, the first starting with the first call.""" + + def __init__(self, window: _Window, rate: int, interval: float) -> None: + self.rate = rate + self.interval = interval + self._window = window + + def take(self) -> bool: + """Count one call; return whether the window has room for it.""" + window = self._window + now = time.monotonic() + if now >= window.end: + window.end = now + self.interval + window.taken = 0 + if window.taken >= self.rate: + return False + + window.taken += 1 + return True + + +def _windows(url: URL) -> TpsWindows: + return cast(TpsWindows, url.scope.state.setdefault(TpsWindows, TpsWindows())) + + +def _limit(window: _Window, rate: int, interval: float) -> _Limit | None: + return _Limit(window, rate, interval) if rate > 0 else None diff --git a/src/dubbo/loadbalance/__init__.py b/src/dubbo/loadbalance/__init__.py deleted file mode 100644 index b1b2965b..00000000 --- a/src/dubbo/loadbalance/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from ._interfaces import AbstractLoadBalance, LoadBalance - -__all__ = ["AbstractLoadBalance", "LoadBalance"] diff --git a/src/dubbo/loadbalance/_interfaces.py b/src/dubbo/loadbalance/_interfaces.py deleted file mode 100644 index b2d7e436..00000000 --- a/src/dubbo/loadbalance/_interfaces.py +++ /dev/null @@ -1,72 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc -from typing import Optional - -from dubbo.common import URL -from dubbo.protocol import Invocation, Invoker - - -class LoadBalance(abc.ABC): - """ - The load balance interface. - """ - - @abc.abstractmethod - def select(self, invokers: list[Invoker], url: URL, invocation: Invocation) -> Optional[Invoker]: - """ - Select an invoker from the list. - :param invokers: The invokers. - :type invokers: List[Invoker] - :param url: The URL. - :type url: URL - :param invocation: The invocation. - :type invocation: Invocation - :return: The selected invoker. If no invoker is selected, return None. - :rtype: Optional[Invoker] - """ - raise NotImplementedError() - - -class AbstractLoadBalance(LoadBalance, abc.ABC): - """ - The abstract load balance. - """ - - def select(self, invokers: list[Invoker], url: URL, invocation: Invocation) -> Optional[Invoker]: - if not invokers: - return None - - if len(invokers) == 1: - return invokers[0] - - return self.do_select(invokers, url, invocation) - - @abc.abstractmethod - def do_select(self, invokers: list[Invoker], url: URL, invocation: Invocation) -> Optional[Invoker]: - """ - Do select an invoker from the list. - :param invokers: The invokers. - :type invokers: List[Invoker] - :param url: The URL. - :type url: URL - :param invocation: The invocation. - :type invocation: Invocation - :return: The selected invoker. If no invoker is selected, return None. - :rtype: Optional[Invoker] - """ - raise NotImplementedError() diff --git a/src/dubbo/loggers.py b/src/dubbo/loggers.py deleted file mode 100644 index 6b9d91cc..00000000 --- a/src/dubbo/loggers.py +++ /dev/null @@ -1,234 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import enum -import logging -import re -import threading - -from dubbo.configs import LoggerConfig - -__all__ = ["loggerFactory"] - - -class ColorFormatter(logging.Formatter): - """ - A formatter with color. - It will format the log message like this: - 2024-06-24 16:39:57 | DEBUG | test_logger_factory:test_with_config:44 - [Dubbo] debug log - """ - - @enum.unique - class Colors(enum.Enum): - """ - Colors for log messages. - """ - - END = "\033[0m" - BOLD = "\033[1m" - BLUE = "\033[34m" - GREEN = "\033[32m" - PURPLE = "\033[35m" - CYAN = "\033[36m" - RED = "\033[31m" - YELLOW = "\033[33m" - GREY = "\033[38;5;240m" - - COLOR_LEVEL_MAP = { - "DEBUG": Colors.BLUE.value, - "INFO": Colors.GREEN.value, - "WARNING": Colors.YELLOW.value, - "ERROR": Colors.RED.value, - "CRITICAL": Colors.RED.value + Colors.BOLD.value, - } - - DATE_FORMAT: str = "%Y-%m-%d %H:%M:%S" - - LOG_FORMAT: str = ( - f"{Colors.GREEN.value}%(asctime)s{Colors.END.value}" - " | " - f"%(level_color)s%(levelname)s{Colors.END.value}" - " | " - f"{Colors.CYAN.value}%(module)s:%(funcName)s:%(lineno)d{Colors.END.value}" - " - " - f"{Colors.PURPLE.value}[Dubbo]{Colors.END.value} " - f"%(suffix)s" - f"%(msg_color)s%(message)s{Colors.END.value}" - ) - - def __init__(self, suffix: str = ""): - super().__init__(self.LOG_FORMAT, self.DATE_FORMAT) - self.suffix = f"{self.Colors.PURPLE.value}[{suffix}]{self.Colors.END.value} " if suffix else "" - - def format(self, record) -> str: - levelname = record.levelname - record.level_color = record.msg_color = self.COLOR_LEVEL_MAP.get(levelname) - record.suffix = self.suffix - return super().format(record) - - -class NoColorFormatter(logging.Formatter): - """ - A formatter without color. - It will format the log message like this: - 2024-06-24 16:39:57 | DEBUG | test_logger_factory:test_with_config:44 - [Dubbo] debug log - """ - - def __init__(self, suffix: str = ""): - color_re = re.compile(r"\033\[[0-9;]*\w|%\((msg_color|level_color)\)s") - self.log_format = color_re.sub("", ColorFormatter.LOG_FORMAT) - self.suffix = f"[{suffix}] " if suffix else "" - super().__init__(self.log_format, ColorFormatter.DATE_FORMAT) - - def format(self, record) -> str: - record.message = self.suffix + record.getMessage() - return super().format(record) - - -class _LoggerFactory: - """ - The logger factory. - """ - - DEFAULT_LOGGER_NAME = "dubbo" - - _logger_lock = threading.RLock() - _config: LoggerConfig = LoggerConfig() - _loggers = {} - - @classmethod - def set_config(cls, config): - if not isinstance(config, LoggerConfig): - raise TypeError("config must be an instance of LoggerConfig") - - cls._config = config - cls._refresh_config() - - @classmethod - def _refresh_config(cls) -> None: - """ - Refresh the logger configuration. - - """ - with cls._logger_lock: - # create logger if not exists - if not cls._loggers: - cls._loggers[cls.DEFAULT_LOGGER_NAME] = logging.getLogger(cls.DEFAULT_LOGGER_NAME) - - # update all loggers - for name, logger in cls._loggers.items(): - cls._update_logger(logger, name) - - @classmethod - def _update_logger(cls, logger: logging.Logger, name: str) -> logging.Logger: - """ - Update the logger with the current configuration. - :param logger: The logger to update. - :type logger: logging.Logger - :param name: The logger name. - :type name: str - :return: The updated logger. - :rtype: logging.Logger - """ - # clean up handlers - logger.handlers.clear() - - config = cls._config - - # set logger level - logger.setLevel(config.level) - - # add console handler if enabled - if config.is_console_enabled(): - logger.addHandler(cls._get_console_handler(name)) - - # add file handler if enabled - if config.is_file_enabled(): - logger.addHandler(cls._get_file_handler(name)) - - return logger - - @classmethod - def _get_console_handler(cls, name: str) -> logging.StreamHandler: - """ - Get the console handler - - :param name: The logger name. - :type name: str - :return: The console handler. - :rtype: logging.StreamHandler - """ - console_handler = logging.StreamHandler() - if not cls._config.console_config.formatter or cls._config.global_formatter: - # set default color formatter - console_handler.setFormatter(ColorFormatter(name if name != cls.DEFAULT_LOGGER_NAME else "")) - else: - console_handler.setFormatter( - logging.Formatter(cls._config.console_config.formatter or cls._config.global_formatter) - ) - - return console_handler - - @classmethod - def _get_file_handler(cls, name: str) -> logging.FileHandler: - """ - Get the file handler - - :param name: The logger name. - :type name: str - :return: The file handler. - :rtype: logging.FileHandler - """ - file_handler = logging.FileHandler( - filename=cls._config.file_config.file_name, - mode="a", - encoding="utf-8", - ) - if not cls._config.file_config.file_formatter or cls._config.global_formatter: - # set default no color formatter - file_handler.setFormatter(NoColorFormatter(name if name != cls.DEFAULT_LOGGER_NAME else "")) - else: - file_handler.setFormatter( - logging.Formatter(cls._config.file_config.file_formatter or cls._config.global_formatter) - ) - - return file_handler - - @classmethod - def get_logger(cls, name=DEFAULT_LOGGER_NAME) -> logging.Logger: - """ - Get the logger. class method. - - :return: The logger. - :rtype: logging.Logger - """ - logger = cls._loggers.get(name) - if logger is not None: - return logger - - with cls._logger_lock: - logger = cls._loggers.get(name) - # double check - if logger is not None: - return logger - - logger = cls._update_logger(logging.getLogger(name), name) - cls._loggers[name] = logger - - return logger - - -# expose loggerFactory -loggerFactory = _LoggerFactory diff --git a/src/dubbo/metadata/__init__.py b/src/dubbo/metadata/__init__.py new file mode 100644 index 00000000..08eb5d79 --- /dev/null +++ b/src/dubbo/metadata/__init__.py @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .info import EMPTY_REVISION, MetadataInfo, ServiceInfo +from .report import MetadataReport, get_metadata_report + +__all__ = [ + "EMPTY_REVISION", + "MetadataInfo", + "MetadataReport", + "ServiceInfo", + "get_metadata_report", +] diff --git a/src/dubbo/metadata/info.py b/src/dubbo/metadata/info.py new file mode 100644 index 00000000..6ebfe95c --- /dev/null +++ b/src/dubbo/metadata/info.py @@ -0,0 +1,156 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import hashlib +import json +from collections.abc import Mapping +from typing import Any, Self + +import attrs + +from dubbo.url import service_key +from dubbo.utils import freeze_mapping + +__all__ = ["EMPTY_REVISION", "MetadataInfo", "ServiceInfo"] + +# The revision of an application that serves no service. +EMPTY_REVISION = "0" + + +@attrs.define(frozen=True, kw_only=True) +class ServiceInfo: + """One service an application serves, as its metadata describes it to consumers. + + Attributes: + name: Interface name of the service. + group: Service group, if any. + version: Service version, if any. + protocol: Protocol the service is served with, such as ``tri``. + port: Port the service is served on; 0 or less means the port of the + instance, or of its endpoint for the protocol. + path: Path the service is called by, usually its interface name. + params: Parameters of the service URL, such as ``methods``. + """ + + name: str + group: str | None = None + version: str | None = None + protocol: str + port: int + path: str + params: Mapping[str, str] = attrs.field(factory=dict, converter=freeze_mapping, hash=False) + + @property + def service_key(self) -> str: + """``group/name:version``, leaving out the parts that are not set.""" + return service_key(self.name, self.group, self.version) + + @property + def match_key(self) -> str: + """The service key and the protocol, as in ``group/name:version:tri``; metadata is keyed by it.""" + return f"{self.service_key}:{self.protocol}" + + def describe(self) -> str: + """Return the text that the revision hashes for this service.""" + # The parameters render as sorted key=value entries separated by a comma and a space. + params = ", ".join(f"{key}={value}" for key, value in sorted(self.params.items())) + return f"{self.match_key}{self.port}{self.path}{{{params}}}" + + +@attrs.define(frozen=True, kw_only=True) +class MetadataInfo: + """The services of an application, which its instances register by revision. + + Attributes: + app: Application name. + services: The services, keyed by their match key. + """ + + app: str + services: Mapping[str, ServiceInfo] = attrs.field(factory=dict, converter=freeze_mapping, hash=False) + + @classmethod + def from_services(cls, app: str, services: list[ServiceInfo]) -> Self: + """Return the metadata of ``app`` serving ``services``.""" + return cls(app=app, services={service.match_key: service for service in services}) + + @classmethod + def from_json(cls, text: str) -> Self: + """Read the JSON a registry stores for ``remote`` metadata. + + Raises: + ValueError: The text is not such JSON. + """ + try: + data = json.loads(text) + services = [_parse_service(item) for item in data.get("services", {}).values()] + return cls.from_services(str(data["app"]), services) + except (AttributeError, KeyError, TypeError, ValueError) as error: + raise ValueError(f"invalid metadata JSON: {error}") from None + + @property + def revision(self) -> str: + """The MD5 of the application and its services in hexadecimal, or ``0`` without services. + + Instances that serve the same services share one revision. Consumers + only compare revisions. + """ + if not self.services: + return EMPTY_REVISION + + text = self.app + "".join(self.services[key].describe() for key in sorted(self.services)) + return hashlib.md5(text.encode(), usedforsecurity=False).hexdigest() + + def to_json(self) -> str: + """Return the JSON a registry stores for ``remote`` metadata.""" + services = {key: _service_json(service) for key, service in self.services.items()} + return json.dumps( + {"app": self.app, "revision": self.revision, "services": services}, + ensure_ascii=False, + separators=(",", ":"), + ) + + +def _service_json(service: ServiceInfo) -> dict[str, Any]: + fields = { + "name": service.name, + "group": service.group, + "version": service.version, + "protocol": service.protocol, + "port": service.port, + "path": service.path, + "params": dict(service.params), + } + return {key: value for key, value in fields.items() if value is not None} + + +def _parse_service(data: Mapping[str, Any]) -> ServiceInfo: + params = data.get("params") or {} + return ServiceInfo( + name=str(data["name"]), + group=_optional(data.get("group")), + version=_optional(data.get("version")), + protocol=str(data["protocol"]), + port=int(data.get("port", -1)), + path=str(data.get("path") or data["name"]), + params={str(key): str(value) for key, value in params.items()}, + ) + + +def _optional(value: object) -> str | None: + # Absent, null and empty fields all mean "not set". + return str(value) if value else None diff --git a/src/dubbo/metadata/instance.py b/src/dubbo/metadata/instance.py new file mode 100644 index 00000000..d4a2b04d --- /dev/null +++ b/src/dubbo/metadata/instance.py @@ -0,0 +1,219 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The metadata an application instance registers, which locates the metadata of its services, and those services' URLs.""" + +import json +from collections.abc import Mapping +from typing import Self + +import attrs + +from dubbo.config import MetadataType +from dubbo.constants import ( + ENDPOINTS_KEY, + GROUP_KEY, + METADATA_REVISION_KEY, + METADATA_SERVICE_URL_PARAMS_KEY, + METADATA_SERVICE_VERSION_KEY, + METADATA_STORAGE_TYPE_KEY, + SERIALIZATION_KEY, + VERSION_KEY, +) +from dubbo.url import URL + +from .info import EMPTY_REVISION, MetadataInfo +from .report import MetadataReport + +__all__ = [ + "METADATA_SERVICE_V1", + "METADATA_SERVICE_V1_SERIALIZATION", + "METADATA_SERVICE_V1_VERSION", + "METADATA_SERVICE_V2", + "METADATA_SERVICE_V2_VERSION", + "InstanceMetadata", + "instance_metadata", + "read_metadata", +] + +# The interface and the version of each MetadataService an instance may serve; its group is the application name. +METADATA_SERVICE_V1 = "org.apache.dubbo.metadata.MetadataService" +METADATA_SERVICE_V1_VERSION = "1.0.0" +METADATA_SERVICE_V2 = "org.apache.dubbo.metadata.MetadataServiceV2" +METADATA_SERVICE_V2_VERSION = "2.0.0" +# The format the MetadataService 1.0.0 carries its values in, over any protocol. +METADATA_SERVICE_V1_SERIALIZATION = "hessian2" + + +def instance_metadata( + info: MetadataInfo, + storage: MetadataType, + urls: list[URL], + metadata_service: Mapping[str, str] | None, + metadata_version: str | None, +) -> dict[str, str]: + """Return the metadata an instance serving ``urls`` registers for ``info``, stored as ``storage`` says. + + ``metadata_service`` holds the URL parameters of the MetadataService the + instance publishes, among them its ``version``, ``protocol`` and + ``port``, and ``metadata_version`` the latest version it serves, which a + consumer that knows it calls instead; both are ``None`` when the + instance serves none. + """ + ports = {url.protocol: url.port for url in urls} + values = { + METADATA_REVISION_KEY: info.revision, + METADATA_STORAGE_TYPE_KEY: str(storage), + ENDPOINTS_KEY: _json([{"port": port, "protocol": protocol} for protocol, port in ports.items()]), + } + if metadata_service is not None: + values[METADATA_SERVICE_URL_PARAMS_KEY] = _json(dict(metadata_service)) + values[METADATA_SERVICE_VERSION_KEY] = metadata_version or metadata_service[VERSION_KEY] + + return values + + +@attrs.define(frozen=True, kw_only=True) +class InstanceMetadata: + """What the metadata of a registered instance tells about its services. + + Attributes: + host: Host of the instance. + port: Port of the instance. + revision: Revision of the metadata of its services. + storage: Where the metadata of its services is read. + endpoints: The port of each protocol it serves. + metadata_service: Where its MetadataService is called, with the + interface and the version of the MetadataService, if it serves + one: MetadataServiceV2 over tri when it says it serves 2.0.0, + else the MetadataService 1.0.0 in hessian2 over the protocol it + names. + """ + + host: str + port: int + revision: str + storage: MetadataType + endpoints: Mapping[str, int] + metadata_service: URL | None + + @classmethod + def from_metadata(cls, host: str, port: int, metadata: Mapping[str, str]) -> Self | None: + """Read the ``metadata`` of the instance at ``host`` and ``port``, or return ``None`` if it serves nothing. + + Raises: + ValueError: The metadata cannot be read. + """ + revision = metadata.get(METADATA_REVISION_KEY) + if not revision or revision == EMPTY_REVISION: + return None + + try: + storage = MetadataType(metadata.get(METADATA_STORAGE_TYPE_KEY) or MetadataType.LOCAL) + endpoints = _endpoints(metadata.get(ENDPOINTS_KEY)) + service = _metadata_service(host, port, metadata) if storage is MetadataType.LOCAL else None + except (KeyError, TypeError, ValueError) as error: + raise ValueError(f"the metadata of the instance {host}:{port} cannot be read: {error}") from None + + return cls( + host=host, port=port, revision=revision, storage=storage, endpoints=endpoints, metadata_service=service + ) + + def service_urls(self, info: MetadataInfo) -> list[URL]: + """Return the URL of each service ``info`` lists, at this instance.""" + urls = [] + for service in info.services.values(): + port = service.port if service.port > 0 else self.endpoints.get(service.protocol, self.port) + identity = {GROUP_KEY: service.group, VERSION_KEY: service.version} + urls.append( + URL( + protocol=service.protocol, + host=self.host, + port=port, + path=service.path, + parameters={**service.params, **{key: value for key, value in identity.items() if value}}, + ) + ) + + return urls + + +async def read_metadata( + app: str, instance: InstanceMetadata, report: MetadataReport, consumer: URL +) -> MetadataInfo | None: + """Return the metadata of ``app`` at the revision of ``instance``, from where ``instance`` says it is stored. + + Remote metadata is read from ``report``, and local metadata from the + MetadataService of ``instance``, called with the parameters and the + attributes of ``consumer``, such as those of TLS. ``None`` means the + metadata is not stored there. + + Raises: + ValueError: The metadata cannot be read, or the instance serves no MetadataService. + DubboError: The report or the call failed. + OSError: The report or the instance cannot be reached. + """ + if instance.storage is MetadataType.REMOTE: + return await report.get_app_metadata(app, instance.revision) + if instance.metadata_service is None: + raise ValueError("the instance serves no MetadataService") + + from .service.client import call_metadata_service + + service = instance.metadata_service + url = consumer.replace( + protocol=service.protocol, + host=service.host, + port=service.port, + path=service.path, + parameters={**consumer.parameters, **service.parameters, GROUP_KEY: app}, + ) + return await call_metadata_service(url, instance.revision) + + +def _json(value: object) -> str: + return json.dumps(value, ensure_ascii=False, separators=(",", ":")) + + +def _endpoints(text: str | None) -> dict[str, int]: + """Read the port of each protocol in ``text``, as in ``[{"port": 50051, "protocol": "tri"}]``.""" + items = json.loads(text or "[]") + if not isinstance(items, list): + raise TypeError(f"endpoints must be a JSON array, not {text!r}") + + return {str(item["protocol"]): int(item["port"]) for item in items} + + +def _metadata_service(host: str, port: int, metadata: Mapping[str, str]) -> URL | None: + """Return where the instance at ``host`` and ``port`` serves the MetadataService that ``metadata`` locates, if any.""" + text = metadata.get(METADATA_SERVICE_URL_PARAMS_KEY) + if not text: + return None + + params = json.loads(text) + if not isinstance(params, dict): + raise TypeError(f"the MetadataService URL parameters must be a JSON object, not {text!r}") + protocol = str(params["protocol"]) + if protocol == "tri" and metadata.get(METADATA_SERVICE_VERSION_KEY) == METADATA_SERVICE_V2_VERSION: + path, parameters = METADATA_SERVICE_V2, {VERSION_KEY: METADATA_SERVICE_V2_VERSION} + else: + path, parameters = ( + METADATA_SERVICE_V1, + {VERSION_KEY: METADATA_SERVICE_V1_VERSION, SERIALIZATION_KEY: METADATA_SERVICE_V1_SERIALIZATION}, + ) + + return URL(protocol=protocol, host=host, port=int(params.get("port", port)), path=path, parameters=parameters) diff --git a/src/dubbo/metadata/report/__init__.py b/src/dubbo/metadata/report/__init__.py new file mode 100644 index 00000000..13f1edcc --- /dev/null +++ b/src/dubbo/metadata/report/__init__.py @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Where consumers read the metadata that an instance does not serve itself: the metadata report.""" + +from .base import MetadataReport, get_metadata_report + +__all__ = ["MetadataReport", "get_metadata_report"] diff --git a/src/dubbo/metadata/report/base.py b/src/dubbo/metadata/report/base.py new file mode 100644 index 00000000..8075ebeb --- /dev/null +++ b/src/dubbo/metadata/report/base.py @@ -0,0 +1,118 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from collections.abc import AsyncIterator +from contextlib import AbstractAsyncContextManager +from typing import Self, cast + +from dubbo.extension import Resource, extension_point, extensions +from dubbo.url import METADATA_REPORT_URL, URL + +from ..info import MetadataInfo + +__all__ = ["MetadataReport", "get_metadata_report"] + + +@extension_point("apache_dubbo.metadata_report") +class MetadataReport(Resource, typing.Protocol): + """Store what consumers of application-level discovery read besides the instances. + + That is the applications that provide each interface, and the metadata of + applications whose instances do not serve it themselves. The registry + stores both unless the application sets a metadata report apart, so the + implementation is installed under the entry point group + ``apache_dubbo.metadata_report``, named by the scheme of the URL of + either, such as ``zookeeper``, and created with that URL. Entering + ``async with`` connects, and closing disconnects. The application opens + one instance per URL, through `get_metadata_report`. Clients that other + extensions of the application also use come from getters that share them + through ``url.scope``, such as `get_zookeeper_client`: take them on + entering and leave them open on closing, as the scope closes them. + + A provider calls `register_service_app_mapping` as it first registers + its instance, and `publish_app_metadata` when its metadata is + ``remote``. A consumer calls `subscribe_service_app_mapping` for the + interfaces whose applications ``provided-by`` does not name, and + `get_app_metadata` for the instances whose metadata is ``remote``. + Metadata is stored as the text of `MetadataInfo.to_json`, and read with + `MetadataInfo.from_json`. Operations raise the error of the client, + such as ``ZookeeperError``, when the store cannot be reached. + + Attributes: + url: The URL the instance was created with. + """ + + url: URL + + def __init__(self, url: URL) -> None: + self.url = url + + async def publish_app_metadata(self, metadata: MetadataInfo) -> None: + """Store ``metadata`` under its application and revision, unless it is stored already.""" + ... + + async def get_app_metadata(self, app: str, revision: str) -> MetadataInfo | None: + """Return the metadata stored for ``app`` at ``revision``, or ``None`` if there is none. + + Raises: + ValueError: The stored metadata cannot be read. + """ + ... + + async def register_service_app_mapping(self, interface: str, app: str) -> None: + """Record that ``app`` provides ``interface``, keeping the other applications recorded for it.""" + ... + + def subscribe_service_app_mapping( + self, interface: str + ) -> AbstractAsyncContextManager[AsyncIterator[frozenset[str]]]: + """Watch the applications that provide ``interface`` until the context exits. + + The iterator yields the current names first, then the names after + each change. Changes made while the consumer is busy may be skipped, + but the latest is always yielded. Only the first names can fail, and + their failure is raised as it is, not in an exception group: after + them the iterator neither raises nor ends until the context exits, + and keeps the last names while the store is unreachable. + """ + ... + + async def aclose(self) -> None: + """Disconnect from where the metadata is stored.""" + ... + + async def __aenter__(self) -> Self: + """Connect to where the metadata is stored.""" + ... + + +async def get_metadata_report(registry: URL) -> MetadataReport: + """Return the metadata report of ``registry``, the same instance for the same URL in its application. + + It is the one the attribute ``METADATA_REPORT_URL`` of ``registry`` names, + else the registry itself. The application of its scope connects it on + first use and disconnects it when it stops. + + Raises: + ExtensionError: No implementation has the scheme of its URL. + RuntimeError: Its URL belongs to no running application. + """ + url = cast(URL, registry.attributes.get(METADATA_REPORT_URL, registry)) + scope = url.scope + implementation = extensions.get(MetadataReport, url.protocol) + return await scope.share((implementation, url), lambda: implementation(url)) diff --git a/src/dubbo/metadata/report/nacos.py b/src/dubbo/metadata/report/nacos.py new file mode 100644 index 00000000..74840684 --- /dev/null +++ b/src/dubbo/metadata/report/nacos.py @@ -0,0 +1,88 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import AsyncGenerator, AsyncIterator +from contextlib import asynccontextmanager +from typing import Self + +from dubbo.transport import nacos +from dubbo.url import URL +from dubbo.utils.converters import comma_separated + +from ..info import MetadataInfo +from .base import MetadataReport + +__all__ = ["NacosMetadataReport"] + +_MAPPING_GROUP = "mapping" + + +class NacosMetadataReport(MetadataReport): + """A ``MetadataReport`` in Nacos configurations. + + The applications that provide an interface are the comma-separated + names in the configuration whose data id is the interface, in the group + ``mapping``. The metadata of an application is the JSON in the + configuration whose data id is the application, in the group named + after the revision. The client comes from ``get_nacos_config_client``, shared + with the other users of an equal connection. + """ + + def __init__(self, url: URL) -> None: + super().__init__(url) + self._client: nacos.NacosConfigClient | None = None + + async def publish_app_metadata(self, metadata: MetadataInfo) -> None: + client = self._connected() + + content = metadata.to_json() + await client.update(metadata.app, metadata.revision, lambda current: current or content) + + async def get_app_metadata(self, app: str, revision: str) -> MetadataInfo | None: + client = self._connected() + + content = await client.get(app, revision) + return MetadataInfo.from_json(content) if content else None + + async def register_service_app_mapping(self, interface: str, app: str) -> None: + client = self._connected() + + def add(current: str | None) -> str: + if not current: + return app + return current if app in comma_separated(current) else f"{current},{app}" + + await client.update(interface, _MAPPING_GROUP, add) + + @asynccontextmanager + async def subscribe_service_app_mapping(self, interface: str) -> AsyncGenerator[AsyncIterator[frozenset[str]]]: + client = self._connected() + + async with client.watch(interface, _MAPPING_GROUP) as contents: + yield (frozenset(comma_separated(content or "")) async for content in contents) + + async def aclose(self) -> None: + self._client = None + + async def __aenter__(self) -> Self: + self._client = await nacos.get_nacos_config_client(self.url) + return self + + def _connected(self) -> nacos.NacosConfigClient: + if self._client is None: + raise RuntimeError("the metadata report is not connected") + return self._client diff --git a/src/dubbo/metadata/report/zookeeper.py b/src/dubbo/metadata/report/zookeeper.py new file mode 100644 index 00000000..520e14aa --- /dev/null +++ b/src/dubbo/metadata/report/zookeeper.py @@ -0,0 +1,104 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import AsyncGenerator, AsyncIterator +from contextlib import asynccontextmanager +from typing import Self + +from dubbo.constants import DEFAULT_ROOT, GROUP_KEY +from dubbo.transport import zookeeper +from dubbo.url import URL +from dubbo.utils.converters import comma_separated + +from ..info import MetadataInfo +from .base import MetadataReport + +__all__ = ["ZookeeperMetadataReport"] + + +class ZookeeperMetadataReport(MetadataReport): + """A ``MetadataReport`` in persistent ZooKeeper nodes. + + Under ``/{group}``, where ``group`` is the URL parameter and ``dubbo`` by + default, the applications that provide an interface are the + comma-separated names in ``mapping/{interface}``, and the metadata of an + application is the JSON in ``metadata/{app}/{revision}``. Both nodes are + persistent. The client comes from ``get_zookeeper_client``, shared with + the other users of an equal connection. + """ + + def __init__(self, url: URL) -> None: + super().__init__(url) + self._root = "/" + url.parameters.get(GROUP_KEY, DEFAULT_ROOT).removeprefix("/") + self._client: zookeeper.ZookeeperClient | None = None + + async def publish_app_metadata(self, metadata: MetadataInfo) -> None: + client = self._connected() + + content = metadata.to_json().encode() + await client.update(self._metadata_path(metadata.app, metadata.revision), lambda data: data or content) + + async def get_app_metadata(self, app: str, revision: str) -> MetadataInfo | None: + client = self._connected() + + data = await client.get(self._metadata_path(app, revision)) + return MetadataInfo.from_json(data.decode()) if data else None + + async def register_service_app_mapping(self, interface: str, app: str) -> None: + client = self._connected() + + def add(data: bytes | None) -> bytes: + text = (data or b"").decode() + if app in _names(text): + return data or b"" + return f"{text},{app}".encode() if text else app.encode() + + await client.update(self._mapping_path(interface), add) + + @asynccontextmanager + async def subscribe_service_app_mapping(self, interface: str) -> AsyncGenerator[AsyncIterator[frozenset[str]]]: + client = self._connected() + + async with client.watch(self._mapping_path(interface)) as values: + yield (_readable_names(data or b"") async for data in values) + + async def aclose(self) -> None: + self._client = None + + async def __aenter__(self) -> Self: + self._client = await zookeeper.get_zookeeper_client(self.url) + return self + + def _metadata_path(self, app: str, revision: str) -> str: + return f"{self._root}/metadata/{app}/{revision}" + + def _mapping_path(self, interface: str) -> str: + return f"{self._root}/mapping/{interface}" + + def _connected(self) -> zookeeper.ZookeeperClient: + if self._client is None: + raise RuntimeError("the metadata report is not connected") + return self._client + + +def _names(text: str) -> frozenset[str]: + return frozenset(comma_separated(text)) + + +def _readable_names(data: bytes) -> frozenset[str]: + # A name that is not UTF-8 is left out; the others are still read. + return frozenset(name for name in _names(data.decode(errors="replace")) if "\ufffd" not in name) diff --git a/src/dubbo/metadata/service/__init__.py b/src/dubbo/metadata/service/__init__.py new file mode 100644 index 00000000..c28f952d --- /dev/null +++ b/src/dubbo/metadata/service/__init__.py @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The MetadataService, through which an instance serves its metadata to consumers itself.""" diff --git a/src/dubbo/metadata/service/client.py b/src/dubbo/metadata/service/client.py new file mode 100644 index 00000000..75b03575 --- /dev/null +++ b/src/dubbo/metadata/service/client.py @@ -0,0 +1,63 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""How a consumer reads the metadata an instance serves through its MetadataService.""" + +from dubbo.constants import TIMEOUT_KEY +from dubbo.protocol import get_protocol +from dubbo.rpc.definition import get_definition +from dubbo.url import URL + +from ..info import MetadataInfo +from ..instance import METADATA_SERVICE_V2 + +__all__ = ["call_metadata_service"] + +# Milliseconds a call to the MetadataService of an instance may take, connecting included. +_METADATA_TIMEOUT = "5000" + + +async def call_metadata_service(url: URL, revision: str) -> MetadataInfo | None: + """Return the metadata at ``revision`` of the MetadataService that ``url`` calls. + + The path of ``url`` selects MetadataServiceV2 or the MetadataService + 1.0.0. For a revision it does not serve, 1.0.0 gives ``None`` and + MetadataServiceV2 fails with ``NOT_FOUND``. The call may take five + seconds, connecting included. + + Raises: + ValueError: The metadata cannot be read. + DubboError: The call failed or took too long. + OSError: The instance cannot be reached. + """ + if url.path == METADATA_SERVICE_V2: + from . import v2 + + contract: type = v2.MetadataServiceV2 + read_metadata_info = v2.read_metadata_info + else: + from . import v1 + + contract = v1.MetadataServiceV1 + read_metadata_info = v1.read_metadata_info + + url = url.update_parameters({TIMEOUT_KEY: _METADATA_TIMEOUT}) + invoker = await (await get_protocol(url.protocol, url.scope)).refer(url, get_definition(contract)) + try: + return await read_metadata_info(invoker.invoke, revision) + finally: + await invoker.aclose() diff --git a/src/dubbo/metadata/service/server.py b/src/dubbo/metadata/service/server.py new file mode 100644 index 00000000..86fb225b --- /dev/null +++ b/src/dubbo/metadata/service/server.py @@ -0,0 +1,159 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""How an instance serves the metadata of its application through its MetadataService.""" + +from collections.abc import Collection, Mapping +from contextlib import AsyncExitStack + +from dubbo.config import ConfigError +from dubbo.constants import GROUP_KEY, SERIALIZATION_KEY, VERSION_KEY +from dubbo.protocol import get_protocol +from dubbo.rpc.server import ServiceInvoker +from dubbo.url import URL + +from ..info import MetadataInfo +from ..instance import ( + METADATA_SERVICE_V1, + METADATA_SERVICE_V1_SERIALIZATION, + METADATA_SERVICE_V1_VERSION, + METADATA_SERVICE_V2, + METADATA_SERVICE_V2_VERSION, +) + +__all__ = ["LocalMetadata", "MetadataStore"] + + +class MetadataStore: + """Holds the metadata of the application by revision, which each version of the MetadataService serves.""" + + def __init__(self) -> None: + self._metadata: dict[str, MetadataInfo] = {} + + def add(self, metadata: MetadataInfo) -> None: + """Serve ``metadata`` under its revision.""" + self._metadata[metadata.revision] = metadata + + def retain(self, revisions: Collection[str]) -> None: + """Stop serving the metadata of revisions other than ``revisions``.""" + self._metadata = {revision: info for revision, info in self._metadata.items() if revision in revisions} + + def get(self, revision: str) -> MetadataInfo | None: + """Return the metadata served at ``revision``, if any.""" + return self._metadata.get(revision) + + def values(self) -> tuple[MetadataInfo, ...]: + """Return the metadata of each revision served, in the order they were added.""" + return tuple(self._metadata.values()) + + +class LocalMetadata: + """Serves the metadata of the application through its MetadataService, exported when it first serves a revision. + + ``urls`` holds the URL a service of the framework is served with on each + protocol of the application, by name, and ``stack`` closes the export. + Over tri, MetadataServiceV2 is served, and also + the MetadataService 1.0.0 in it, for consumers that know only that one; + without tri, the MetadataService 1.0.0 is served over dubbo. + """ + + def __init__(self, urls: Mapping[str, URL], stack: AsyncExitStack) -> None: + self._urls = urls + self._stack = stack + self._metadata = MetadataStore() + self._served: tuple[URL, ...] = () + + @property + def urls(self) -> tuple[URL, ...]: + """The URLs the MetadataService is served with, each port the one bound, once it serves. + + The first is the one to publish; a consumer that knows the `version` + served turns to it instead. + """ + return self._served + + @property + def version(self) -> str | None: + """The latest version of the MetadataService served, once it serves.""" + if not self._served: + return None + if any(url.path == METADATA_SERVICE_V2 for url in self._served): + return METADATA_SERVICE_V2_VERSION + return METADATA_SERVICE_V1_VERSION + + async def serve(self, info: MetadataInfo) -> URL: + """Serve ``info`` and return the URL the MetadataService is served with, its port the one bound. + + Raises: + ConfigError: The application serves neither over tri nor over dubbo. + """ + if not self._served: + self._served = await self._export(info.app) + + self._metadata.add(info) + return self._served[0] + + def retain(self, revisions: Collection[str]) -> None: + """Stop serving the metadata of revisions other than ``revisions``.""" + self._metadata.retain(revisions) + + async def _export(self, app: str) -> tuple[URL, ...]: + """Export the MetadataService and return the URLs it is served with, the one to publish first.""" + if "tri" in self._urls: + from .v2 import MetadataServiceV2Server + + tri = self._urls["tri"] + v2 = await self._export_one( + tri.replace(path=METADATA_SERVICE_V2), + METADATA_SERVICE_V2_VERSION, + MetadataServiceV2Server(self._metadata), + app, + ) + from .v1 import MetadataServiceV1Server + + v1 = await self._export_one( + tri.replace(path=METADATA_SERVICE_V1).update_parameters( + {SERIALIZATION_KEY: METADATA_SERVICE_V1_SERIALIZATION} + ), + METADATA_SERVICE_V1_VERSION, + MetadataServiceV1Server(self._metadata, app), + app, + ) + return v1, v2 + + if "dubbo" in self._urls: + from .v1 import MetadataServiceV1Server + + v1 = await self._export_one( + self._urls["dubbo"].replace(path=METADATA_SERVICE_V1), + METADATA_SERVICE_V1_VERSION, + MetadataServiceV1Server(self._metadata, app), + app, + ) + return (v1,) + + raise ConfigError( + "local metadata is served over tri or dubbo, which no service uses; " + "set application.metadata_type to remote, or serve a service over tri or dubbo" + ) + + async def _export_one(self, url: URL, version: str, implementation: object, app: str) -> URL: + url = url.update_parameters({GROUP_KEY: app, VERSION_KEY: version}) + invoker = ServiceInvoker.from_implementation(implementation, url) + exporter = await (await get_protocol(url.protocol, url.scope)).export(url, invoker.service, invoker) + self._stack.push_async_callback(exporter.aclose) + return exporter.url diff --git a/src/dubbo/metadata/service/v1.py b/src/dubbo/metadata/service/v1.py new file mode 100644 index 00000000..60ea3f0d --- /dev/null +++ b/src/dubbo/metadata/service/v1.py @@ -0,0 +1,165 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""MetadataService 1.0.0, which carries the metadata of an instance as Java objects over the protocols that call Java methods.""" + +import typing + +import attrs +import hessian2 + +from dubbo.rpc.client import proxy +from dubbo.rpc.definition import method, service +from dubbo.rpc.invocation import Invoke + +from ..info import MetadataInfo, ServiceInfo +from ..instance import METADATA_SERVICE_V1, METADATA_SERVICE_V1_VERSION +from .server import MetadataStore + +__all__ = [ + "JavaMetadataInfo", + "JavaServiceInfo", + "MetadataServiceV1", + "MetadataServiceV1Server", + "read_metadata_info", +] + + +@hessian2.java_class("org.apache.dubbo.metadata.MetadataInfo$ServiceInfo") +@attrs.define(frozen=True, kw_only=True) +class JavaServiceInfo: + """A service as ``org.apache.dubbo.metadata.MetadataInfo$ServiceInfo`` carries it; see `ServiceInfo`.""" + + name: str | None = None + group: str | None = None + version: str | None = None + protocol: str | None = None + port: int = -1 + path: str | None = None + params: dict[str, str] | None = None + + +@hessian2.java_class("org.apache.dubbo.metadata.MetadataInfo") +@attrs.define(frozen=True, kw_only=True) +class JavaMetadataInfo: + """The metadata of an application as ``org.apache.dubbo.metadata.MetadataInfo`` carries it; see `MetadataInfo`.""" + + app: str | None = None + revision: str | None = None + services: dict[str, JavaServiceInfo] | None = None + + +@service(METADATA_SERVICE_V1) +class MetadataServiceV1(typing.Protocol): + """The MetadataService of version 1.0.0, without the methods about URLs or listeners.""" + + @method("serviceName") + async def service_name(self) -> str: + """Return the name of the application.""" + ... + + @method("version") + async def version(self) -> str: + """Return the version of the MetadataService, ``1.0.0``.""" + ... + + @method("getServiceDefinition") + async def get_service_definition(self, service_key: str) -> str: + """Return the definition of the service of ``service_key``, which is not served: always an empty text.""" + ... + + @method("getMetadataInfo") + async def get_metadata_info(self, revision: str) -> JavaMetadataInfo | None: + """Return the metadata at ``revision``, or ``None`` if it is not served.""" + ... + + @method("getMetadataInfos") + async def get_metadata_infos(self) -> list[JavaMetadataInfo]: + """Return the metadata of each revision served.""" + ... + + +class MetadataServiceV1Server(MetadataServiceV1): + """Serves the metadata ``metadata`` holds for the application ``app``; a revision it does not hold is answered with ``None``.""" + + def __init__(self, metadata: MetadataStore, app: str) -> None: + self._metadata = metadata + self._app = app + + async def service_name(self) -> str: + return self._app + + async def version(self) -> str: + return METADATA_SERVICE_V1_VERSION + + async def get_service_definition(self, service_key: str) -> str: + return "" + + async def get_metadata_info(self, revision: str) -> JavaMetadataInfo | None: + metadata = self._metadata.get(revision) + return None if metadata is None else _metadata_v1(metadata) + + async def get_metadata_infos(self) -> list[JavaMetadataInfo]: + return [_metadata_v1(metadata) for metadata in self._metadata.values()] + + +async def read_metadata_info(invoke: Invoke, revision: str) -> MetadataInfo | None: + """Return the metadata at ``revision`` of the MetadataService that ``invoke`` calls, or ``None`` if it serves none. + + Raises: + ValueError: The metadata names no application, or a service without + its name or protocol. + """ + message = await proxy(MetadataServiceV1, invoke).get_metadata_info(revision) + if message is None: + return None + if not message.app: + raise ValueError("the metadata names no application") + + services = [] + for java in (message.services or {}).values(): + if not java.name or not java.protocol: + raise ValueError(f"the metadata has a service without its name or protocol: {java}") + services.append( + ServiceInfo( + name=java.name, + group=java.group or None, + version=java.version or None, + protocol=java.protocol, + port=java.port, + path=java.path or java.name, + params=java.params or {}, + ) + ) + return MetadataInfo.from_services(message.app, services) + + +def _metadata_v1(metadata: MetadataInfo) -> JavaMetadataInfo: + services = {key: _service_v1(service) for key, service in metadata.services.items()} + return JavaMetadataInfo(app=metadata.app, revision=metadata.revision, services=services) + + +def _service_v1(service: ServiceInfo) -> JavaServiceInfo: + return JavaServiceInfo( + name=service.name, + group=service.group, + version=service.version, + protocol=service.protocol, + port=service.port, + path=service.path, + params=dict(service.params), + ) diff --git a/src/dubbo/metadata/service/v2.py b/src/dubbo/metadata/service/v2.py new file mode 100644 index 00000000..4c6613cf --- /dev/null +++ b/src/dubbo/metadata/service/v2.py @@ -0,0 +1,86 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""MetadataServiceV2, version 2.0.0 of the MetadataService, which Triple carries in protobuf.""" + +from dubbo._proto.org.apache.dubbo.metadata.metadata_service_v2_dubbo import ( + MetadataServiceV2, + MetadataServiceV2Servicer, +) +from dubbo._proto.org.apache.dubbo.metadata.metadata_service_v2_pb2 import ( + MetadataInfoV2, + MetadataRequest, + OpenAPIInfo, + OpenAPIRequest, + ServiceInfoV2, +) +from dubbo.exceptions import RpcError, Status +from dubbo.rpc.client import proxy +from dubbo.rpc.invocation import Invoke + +from ..info import MetadataInfo, ServiceInfo +from .server import MetadataStore + +__all__ = ["MetadataRequest", "MetadataServiceV2", "MetadataServiceV2Server", "OpenAPIRequest", "read_metadata_info"] + + +class MetadataServiceV2Server(MetadataServiceV2Servicer): + """Serves the metadata ``metadata`` holds; a revision it does not hold fails as ``NOT_FOUND``.""" + + def __init__(self, metadata: MetadataStore) -> None: + self._metadata = metadata + + async def get_metadata_info(self, request: MetadataRequest) -> MetadataInfoV2: + metadata = self._metadata.get(request.revision) + if metadata is None: + raise RpcError(Status.NOT_FOUND, f"no metadata at revision {request.revision!r}") + + services = {key: _service_v2(service) for key, service in metadata.services.items()} + return MetadataInfoV2(app=metadata.app, version=metadata.revision, services=services) + + async def get_open_api_info(self, request: OpenAPIRequest) -> OpenAPIInfo: + raise RpcError(Status.UNIMPLEMENTED, "OpenAPI documents are not served") + + +async def read_metadata_info(invoke: Invoke, revision: str) -> MetadataInfo: + """Return the metadata at ``revision`` of the MetadataServiceV2 that ``invoke`` calls.""" + message = await proxy(MetadataServiceV2, invoke).get_metadata_info(MetadataRequest(revision=revision)) + services = [ + ServiceInfo( + name=service.name, + group=service.group or None, + version=service.version or None, + protocol=service.protocol, + port=service.port, + path=service.path or service.name, + params=dict(service.params), + ) + for service in message.services.values() + ] + return MetadataInfo.from_services(message.app, services) + + +def _service_v2(service: ServiceInfo) -> ServiceInfoV2: + return ServiceInfoV2( + name=service.name, + group=service.group or "", + version=service.version or "", + protocol=service.protocol, + port=service.port, + path=service.path, + params=dict(service.params), + ) diff --git a/src/dubbo/node.py b/src/dubbo/node.py deleted file mode 100644 index f847b111..00000000 --- a/src/dubbo/node.py +++ /dev/null @@ -1,58 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc - -from dubbo.url import URL - -__all__ = ["Node"] - - -class Node(abc.ABC): - """ - Abstract base class for a Node. - """ - - @abc.abstractmethod - def get_url(self) -> URL: - """ - Get the URL of the node. - - :return: The URL of the node. - :rtype: URL - :raises NotImplementedError: If the method is not implemented. - """ - raise NotImplementedError("get_url() is not implemented.") - - @abc.abstractmethod - def is_available(self) -> bool: - """ - Check if the node is available. - - :return: True if the node is available, False otherwise. - :rtype: bool - :raises NotImplementedError: If the method is not implemented. - """ - raise NotImplementedError("is_available() is not implemented.") - - @abc.abstractmethod - def destroy(self) -> None: - """ - Destroy the node. - - :raises NotImplementedError: If the method is not implemented. - """ - raise NotImplementedError("destroy() is not implemented.") diff --git a/src/dubbo/protoc/__init__.py b/src/dubbo/protoc/__init__.py new file mode 100644 index 00000000..a982772f --- /dev/null +++ b/src/dubbo/protoc/__init__.py @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Generate Dubbo service contracts from proto files with the protoc plugin ``protoc-gen-python-dubbo``.""" + +from .plugin import generate + +__all__ = ["generate"] diff --git a/src/dubbo/protoc/plugin.py b/src/dubbo/protoc/plugin.py new file mode 100644 index 00000000..9288ec03 --- /dev/null +++ b/src/dubbo/protoc/plugin.py @@ -0,0 +1,255 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The protoc plugin ``protoc-gen-python-dubbo``, which generates the Dubbo service contracts of proto files. + +``protoc --python_out=. --pyi_out=. --python-dubbo_out=. greeter.proto``, +or ``python -m grpc_tools.protoc`` with the same options after installing +``apache-dubbo[protoc]``, writes ``greeter_dubbo.py`` beside ``greeter_pb2.py``. For each +service, named ``{package}.{Service}`` as in every language, it holds two +contracts: ``{Service}``, a ``typing.Protocol`` that callers refer to, and +``{Service}Servicer``, an abstract class that implementations subclass. +Their methods take Python names, such as ``say_hello`` for ``SayHello``, +and the message classes of the ``_pb2`` modules, imported by their +absolute names, as protoc names them. +""" + +import keyword +import re +import sys +from collections import Counter +from collections.abc import Callable, Iterable, Mapping + +from google.protobuf.compiler.plugin_pb2 import CodeGeneratorRequest, CodeGeneratorResponse +from google.protobuf.descriptor_pb2 import FileDescriptorProto, MethodDescriptorProto, ServiceDescriptorProto + +__all__ = ["generate", "main"] + +# Returns the Python expression of a message class from its full name, as in ``.pkg.Message``. +_Reference = Callable[[str], str] +# Where a lowercase letter or digit meets an uppercase one, or an acronym meets the next word, as in GetHTTPStatus. +_WORD_BOUNDARY = re.compile(r"(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])") + + +def main() -> None: + """Read a ``CodeGeneratorRequest`` from standard input and write the ``CodeGeneratorResponse`` to standard output.""" + request = CodeGeneratorRequest.FromString(sys.stdin.buffer.read()) + sys.stdout.buffer.write(generate(request).SerializeToString()) + + +def generate(request: CodeGeneratorRequest) -> CodeGeneratorResponse: + """Return the ``_dubbo.py`` module of each file of ``request`` to generate that has services. + + A file whose services cannot become contracts, such as one whose + methods share a Python name, sets the error of the response instead. + """ + response = CodeGeneratorResponse(supported_features=CodeGeneratorResponse.FEATURE_PROTO3_OPTIONAL) + files = {file.name: file for file in request.proto_file} + messages = _messages(request.proto_file) + for name in request.file_to_generate: + file = files[name] + if not file.service: + continue + try: + content = _module(file, messages) + except ValueError as error: + response.error = f"{name}: {error}" + return response + module = _pb2_module(name).removesuffix("_pb2") + response.file.add(name=module.replace(".", "/") + "_dubbo.py", content=content) + + return response + + +def _messages(files: Iterable[FileDescriptorProto]) -> dict[str, tuple[str, str]]: + """Return the file and the Python name, such as ``Outer.Inner``, of each message by its full name, as in ``.pkg.Outer.Inner``.""" + messages = {} + for file in files: + prefix = f".{file.package}." if file.package else "." + pending = [(message, message.name) for message in file.message_type] + while pending: + message, name = pending.pop() + messages[prefix + name] = (file.name, name) + pending.extend((nested, f"{name}.{nested.name}") for nested in message.nested_type) + + return messages + + +def _module(file: FileDescriptorProto, messages: Mapping[str, tuple[str, str]]) -> str: + used = { + _pb2_module(messages[name][0]) + for service in file.service + for method in service.method + for name in (method.input_type, method.output_type) + } + aliases = _aliases(used) + # The names the module imports, which a contract or a method of the same name would hide. + imported = {"abc", "typing", "dubbo", *aliases.values()} + + names = [name for service in file.service for name in (service.name, f"{service.name}Servicer")] + if len(set(names)) < len(names): + raise ValueError("the contracts of two services share a Python name") + if hidden := sorted(imported.intersection(names)): + raise ValueError(f"a contract would hide the imported name {hidden[0]!r}") + exported = ", ".join(f'"{name}"' for name in names) + + def reference(name: str) -> str: + proto, qualified = messages[name] + expression = aliases[_pb2_module(proto)] + for part in qualified.split("."): + expression = f'getattr({expression}, "{part}")' if keyword.iskeyword(part) else f"{expression}.{part}" + return expression + + comments = {tuple(location.path): location.leading_comments for location in file.source_code_info.location} + lines = [ + "# Generated by protoc-gen-python-dubbo. DO NOT EDIT!", + f"# source: {file.name}", + f'"""Dubbo service contracts of {file.name}."""', + "", + "import abc", + "import typing", + "", + "import dubbo", + "", + ] + if aliases: + lines += [*sorted(_import(module, alias) for module, alias in aliases.items()), ""] + lines.append(f"__all__ = [{exported}]") + for index, service in enumerate(file.service): + lines += ["", "", *_contracts(file, index, service, comments, reference, imported)] + + return "\n".join(lines) + "\n" + + +def _pb2_module(proto: str) -> str: + return proto.removesuffix(".proto").replace("-", "_").replace("/", ".") + "_pb2" + + +def _aliases(modules: Iterable[str]) -> dict[str, str]: + """Return the name each ``_pb2`` module is imported as: its own, unless two modules share it.""" + modules = sorted(modules) + counts = Counter(module.rpartition(".")[2] for module in modules) + aliases = {} + for module in modules: + name = module.rpartition(".")[2] + aliases[module] = name if counts[name] == 1 else module.replace("_", "__").replace(".", "_dot_") + + return aliases + + +def _import(module: str, alias: str) -> str: + package, _, name = module.rpartition(".") + statement = f"from {package} import {name}" if package else f"import {name}" + return statement if alias == name else f"{statement} as {alias}" + + +def _contracts( + file: FileDescriptorProto, + index: int, + service: ServiceDescriptorProto, + comments: Mapping[tuple[int, ...], str], + reference: _Reference, + imported: set[str], +) -> list[str]: + """Return the lines of the caller's contract of ``service``, then of its servicer.""" + path = (FileDescriptorProto.SERVICE_FIELD_NUMBER, index) + interface = f"{file.package}.{service.name}" if file.package else service.name + docstring = _docstring(comments.get(path), " ") + caller = [f'@dubbo.service("{interface}")', f"class {service.name}(typing.Protocol):", *docstring] + servicer = [f'@dubbo.service("{interface}")', f"class {service.name}Servicer(abc.ABC):", *docstring] + if not service.method and not docstring: + caller.append(" ...") + servicer.append(" ...") + + attributes: set[str] = set() + for number, method in enumerate(service.method): + attribute = _attribute(method.name) + if attribute.startswith("_"): + raise ValueError(f"method {service.name}.{method.name} would be private in Python") + if attribute in attributes: + raise ValueError(f"methods of {service.name} share the Python name {attribute!r}") + if attribute in imported: + raise ValueError(f"method {service.name}.{method.name} would hide the imported name {attribute!r}") + attributes.add(attribute) + + comment = _docstring(comments.get((*path, ServiceDescriptorProto.METHOD_FIELD_NUMBER, number)), " " * 8) + request, response = reference(method.input_type), reference(method.output_type) + caller += ["", f' @dubbo.method("{method.name}")'] + caller += _body(_signature(attribute, *_called(method, request, response)), comment) + servicer += ["", f' @dubbo.method("{method.name}")', " @abc.abstractmethod"] + servicer += _body(_signature(attribute, *_served(method, request, response)), comment) + + return [*caller, "", "", *servicer] + + +def _called(method: MethodDescriptorProto, request: str, response: str) -> tuple[str, list[str], str]: + """Return the keyword, the parameters and the return type of ``method`` as callers hold it.""" + match method.client_streaming, method.server_streaming: + case False, False: + return "async def", ["self", f"request: {request}"], response + case False, True: + return "def", ["self", f"request: {request}"], f"dubbo.ServerStream[{response}]" + case True, False: + return "def", ["self"], f"dubbo.ClientStream[{request}, {response}]" + case _: + return "def", ["self"], f"dubbo.BidiStream[{request}, {response}]" + + +def _served(method: MethodDescriptorProto, request: str, response: str) -> tuple[str, list[str], str]: + """Return the keyword, the parameters and the return type of ``method`` as implementations serve it.""" + match method.client_streaming, method.server_streaming: + case False, False: + return "async def", ["self", f"request: {request}"], response + case False, True: + return "async def", ["self", f"request: {request}", f"stream: dubbo.SendStream[{response}]"], "None" + case True, False: + return "async def", ["self", f"stream: dubbo.ReceiveStream[{request}]"], response + case _: + return "async def", ["self", f"stream: dubbo.Stream[{response}, {request}]"], "None" + + +def _signature(attribute: str, keyword: str, parameters: list[str], returns: str) -> str: + return f" {keyword} {attribute}({', '.join(parameters)}) -> {returns}:" + + +def _body(signature: str, docstring: list[str]) -> list[str]: + return [signature, *docstring] if docstring else [f"{signature} ..."] + + +def _attribute(name: str) -> str: + """Return the Python name of the method ``name``: in snake case, with ``_`` after a keyword.""" + attribute = _WORD_BOUNDARY.sub("_", name).lower() + return f"{attribute}_" if keyword.iskeyword(attribute) else attribute + + +def _docstring(comment: str | None, indent: str) -> list[str]: + """Return the lines of a docstring holding the proto comment ``comment``, if any.""" + if not comment or not comment.strip(): + return [] + + text = comment.replace("\\", "\\\\").strip("\n").rstrip() + if text.endswith('"'): + text = text[:-1] + '\\"' + text = text.replace('"""', '\\"\\"\\"') + lines = [line.removeprefix(" ").rstrip() for line in text.split("\n")] + if len(lines) == 1: + return [f'{indent}"""{lines[0].strip()}"""'] + return [ + f'{indent}"""{lines[0].strip()}', + *(f"{indent}{line}" if line else "" for line in lines[1:]), + f'{indent}"""', + ] diff --git a/src/dubbo/protocol/__init__.py b/src/dubbo/protocol/__init__.py index 965b73f6..337ab9ed 100644 --- a/src/dubbo/protocol/__init__.py +++ b/src/dubbo/protocol/__init__.py @@ -1,19 +1,20 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. -from ._interfaces import Invocation, Invoker, Protocol, Result +from .base import Exporter, Protocol, get_protocol -__all__ = ["Invocation", "Result", "Invoker", "Protocol"] +__all__ = ["Exporter", "Protocol", "get_protocol"] diff --git a/src/dubbo/protocol/_interfaces.py b/src/dubbo/protocol/_interfaces.py deleted file mode 100644 index 22f6fe3e..00000000 --- a/src/dubbo/protocol/_interfaces.py +++ /dev/null @@ -1,123 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc -from typing import Any - -from dubbo.node import Node -from dubbo.url import URL - -__all__ = ["Invocation", "Result", "Invoker", "Protocol"] - - -class Invocation(abc.ABC): - @abc.abstractmethod - def get_service_name(self) -> str: - """ - Get the service name. - """ - raise NotImplementedError() - - @abc.abstractmethod - def get_method_name(self) -> str: - """ - Get the method name. - """ - raise NotImplementedError() - - @abc.abstractmethod - def get_argument(self) -> Any: - """ - Get the method argument. - """ - raise NotImplementedError() - - -class Result(abc.ABC): - """ - Result of a call - """ - - @abc.abstractmethod - def set_value(self, value: Any) -> None: - """ - Set the value of the result - :param value: The value to set - :type value: Any - """ - raise NotImplementedError() - - @abc.abstractmethod - def value(self) -> Any: - """ - Get the value of the result - """ - raise NotImplementedError() - - @abc.abstractmethod - def set_exception(self, exception: Exception) -> None: - """ - Set the exception to the result - :param exception: The exception to set - :type exception: Exception - """ - raise NotImplementedError() - - @abc.abstractmethod - def exception(self) -> Exception: - """ - Get the exception to the result - """ - raise NotImplementedError() - - -class Invoker(Node, abc.ABC): - """ - Invoker - """ - - @abc.abstractmethod - def invoke(self, invocation: Invocation) -> Result: - """ - Invoke the service. - :param invocation: The invocation. - :type invocation: Invocation - :return: The result. - :rtype: Result - """ - raise NotImplementedError() - - -class Protocol(abc.ABC): - @abc.abstractmethod - def export(self, url: URL): - """ - Export a remote service. - :param url: The URL. - :type url: URL - """ - raise NotImplementedError() - - @abc.abstractmethod - def refer(self, url: URL) -> Invoker: - """ - Refer a remote service. - :param url: The URL. - :type url: URL - :return: The invoker. - :rtype: Invoker - """ - raise NotImplementedError() diff --git a/src/dubbo/protocol/base.py b/src/dubbo/protocol/base.py new file mode 100644 index 00000000..79d0c42b --- /dev/null +++ b/src/dubbo/protocol/base.py @@ -0,0 +1,132 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing + +from dubbo.extension import ApplicationScope, Resource, extension_point, extensions +from dubbo.rpc.definition import Service +from dubbo.rpc.invocation import Invoker +from dubbo.url import URL + +__all__ = ["Exporter", "Protocol", "get_protocol"] + + +class Exporter(Resource, typing.Protocol): + """A service that a protocol serves.""" + + @property + def url(self) -> URL: + """The URL being served, with the port actually bound.""" + ... + + async def aclose(self) -> None: + """Stop accepting calls to the service, then wait for those already running.""" + ... + + +@extension_point("apache_dubbo.protocol") +class Protocol(Resource, typing.Protocol): + """Expose services and call remote ones over one wire protocol. + + Implementations install under the entry point group + ``apache_dubbo.protocol``, named by the URL scheme, such as ``tri``. One + instance serves every address of its scheme, so URLs go to each + `export` and `refer` rather than to the constructor, which takes no + arguments. The servers and connections it opens are its own. `export` + and `refer` may run concurrently, in the event loop. + + TLS comes from the parameters of each URL, or from the `ssl.SSLContext` + its attribute `dubbo.url.SSL_CONTEXT` holds, as + `dubbo.transport.tls.get_ssl_context` reads them. + + The application opens one instance per implementation on first use, + through `get_protocol`; the application scope enters and exits it in a + task of its own, and closes it as the application stops. + """ + + async def export(self, url: URL, definition: Service, invoker: Invoker) -> Exporter: + """Serve ``invoker`` as the service ``url`` names. + + ``url`` carries the address to listen on, the service interface as its + path and the service's settings as parameters, as in + ``tri://0.0.0.0:50051/com.example.UserService?group=a&version=1.0``. + The first service on an address starts the server there; later ones + share it. A port of 0 lets the system assign one, and a missing port + means the protocol's default. + + ``definition`` tells how to read the requests of each method, which + the filter-wrapped ``invoker`` does not expose. + + Raises: + TypeError: The protocol cannot carry a method of ``definition``. + OSError: The address cannot be bound. + ValueError: A host name with port 0 would listen on several + ports, one per address. + """ + ... + + async def refer(self, url: URL, definition: Service) -> Invoker: + """Return an invoker that calls the methods of ``definition`` on the provider ``url`` names. + + ``url`` carries the provider's address, the service interface as its + path and the service's settings as parameters, in the form `export` + takes. Invokers for one address share a connection of the instance. + Closing an invoker refuses new calls and waits a while for those + running before it gives the connection back; the last one closes it. + Neither the invoker nor the connection holds a task group or cancel + scope of the tasks that call it, so that its owner, such as a + directory replacing providers, may close it from any task. + + The invoker prepares how to send each method of ``definition`` when it + is made, and finds the method of a call by `Invocation.method`. It + returns failures of the call, including failures to reach the + provider, in `Result.error` as `dubbo.RpcError`. + + The attachments that the invoker sets itself, such as ``token``, are + the protocol's: a call that carries one fails with + ``INVALID_ARGUMENT``. + + Raises: + TypeError: The protocol cannot carry a method of ``definition``. + """ + ... + + def announce_shutdown(self) -> None: + """Tell the callers of the services that the application is stopping, while they keep being served. + + The application calls it once, when it starts to stop; `aclose` + stops serving afterwards. Callers learn it as the protocol allows, + such as from a health status or a notice on their connections, so + that they turn to other providers. A protocol with no such means + does nothing, as the default does. + """ + + async def aclose(self) -> None: + """Close every server and connection the instance opened.""" + ... + + +async def get_protocol(name: str, scope: ApplicationScope) -> Protocol: + """Return the protocol ``name``, the same instance for the same name in the application of ``scope``. + + The application opens it on first use and closes it when it stops. + + Raises: + ExtensionError: No implementation has that name. + """ + implementation = extensions.get(Protocol, name) + return await scope.share((implementation,), implementation) diff --git a/src/dubbo/protocol/dubbo/__init__.py b/src/dubbo/protocol/dubbo/__init__.py new file mode 100644 index 00000000..138ea967 --- /dev/null +++ b/src/dubbo/protocol/dubbo/__init__.py @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .protocol import DubboProtocol + +__all__ = ["DubboProtocol"] diff --git a/src/dubbo/protocol/dubbo/body.py b/src/dubbo/protocol/dubbo/body.py new file mode 100644 index 00000000..a051266e --- /dev/null +++ b/src/dubbo/protocol/dubbo/body.py @@ -0,0 +1,328 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The bodies of Dubbo requests and responses: which values they hold, in which order.""" + +import enum +import functools +import logging +from collections.abc import Mapping +from typing import Any + +import attrs +from multidict import MultiDict + +from dubbo.constants import DUBBO_VERSION +from dubbo.exceptions import RemoteError, RpcError, Status +from dubbo.protocol.java import method_descriptor +from dubbo.rpc.definition import Method +from dubbo.serialization import JavaSerialization, Reader +from dubbo.utils.converters import to_text + +__all__ = [ + "MethodCodec", + "RequestHead", + "Response", + "ResponseCodec", + "ResponseStatus", + "read_request_head", + "service_version", + "status_error", + "supports_response_attachments", + "to_attachments", +] + +_logger = logging.getLogger(__name__) + +# The version a request carries for a service without one, and those that mean none. +_NO_VERSION = "0.0.0" +_NO_VERSIONS = frozenset({"", _NO_VERSION, "*"}) +# The protocol version, interface, service version, method and descriptor that start a request. +_HEAD = (str, str, str | None, str, str) +_ATTACHMENTS = dict[str, Any] +# The kinds of response bodies, as the first value of each. +_EXCEPTION, _VALUE, _NULL = 0, 1, 2 +_WITH_ATTACHMENTS = 3 # Added to a kind whose body ends with attachments. +# The consumer versions that read response attachments: 2.0.2 to 2.0.99. +_ATTACHMENT_VERSIONS = ((2, 0, 2, 0), (2, 0, 99, 0)) +# The types of the attachments kept as they are, and of those that become text. +_TEXT = (str, bytes) +_SCALARS = (bool, int, float) + + +class ResponseStatus(enum.IntEnum): + """The status byte of a response header. + + Every status but `OK` has a body of one string, the error message. + """ + + OK = 20 # The body holds the result. + SERIALIZATION_ERROR = 25 # The request or the result cannot be serialized. + CLIENT_TIMEOUT = 30 # The consumer gave up waiting. + SERVER_TIMEOUT = 31 # The provider gave up running the call. + CHANNEL_INACTIVE = 35 # The connection closed before the response arrived. + BAD_REQUEST = 40 # The request cannot be read. + BAD_RESPONSE = 50 # The response cannot be written. + SERVICE_NOT_FOUND = 60 # No exported service or method matches the request. + SERVICE_ERROR = 70 # The service failed outside its result. + SERVER_ERROR = 80 # The provider failed. + CLIENT_ERROR = 90 # The consumer failed. + SERVER_THREADPOOL_EXHAUSTED_ERROR = 100 # The provider has no room for another call. + + +_STATUS_ERRORS: dict[int, Status] = { + ResponseStatus.CLIENT_TIMEOUT: Status.DEADLINE_EXCEEDED, + ResponseStatus.SERVER_TIMEOUT: Status.DEADLINE_EXCEEDED, + ResponseStatus.CHANNEL_INACTIVE: Status.UNAVAILABLE, + ResponseStatus.BAD_REQUEST: Status.INVALID_ARGUMENT, + # The provider runs no such service, as while it goes offline; another may. + ResponseStatus.SERVICE_NOT_FOUND: Status.UNAVAILABLE, + # The provider has no room for the call; another may. + ResponseStatus.SERVER_THREADPOOL_EXHAUSTED_ERROR: Status.UNAVAILABLE, + ResponseStatus.SERIALIZATION_ERROR: Status.INTERNAL, + ResponseStatus.SERVICE_ERROR: Status.INTERNAL, + ResponseStatus.BAD_RESPONSE: Status.INTERNAL, + ResponseStatus.CLIENT_ERROR: Status.INTERNAL, +} + + +@attrs.define(frozen=True, kw_only=True) +class RequestHead: + """The values that start a request and name the method it calls. + + Attributes: + dubbo_version: Version of the protocol model the consumer speaks. + path: Interface of the service called. + version: Version of the service called; empty when it has none. + method: Name of the method called. + descriptor: Java descriptor of the parameters, such as ``J``. + """ + + dubbo_version: str + path: str + version: str + method: str + descriptor: str + + +@attrs.define(frozen=True, kw_only=True) +class Response: + """A response as a consumer reads it. + + Attributes: + value: What the method returned; ``None`` for nothing or a failure. + exception: The exception the method raised; ``None`` when it + returned. + attachments: What the provider attached. + """ + + value: Any = None + exception: RemoteError | None = None + attachments: Mapping[str, Any] = attrs.field(factory=dict) + + +class ResponseCodec: + """Writes and reads the responses of one serialization that do not depend on the method: errors, nulls and exceptions.""" + + def __init__(self, serialization: JavaSerialization) -> None: + self.serialization = serialization + self._message = serialization.codec((str,)) + self._null = serialization.codec((int,)) + self._null_attached = serialization.codec((int, _ATTACHMENTS)) + self._exception = serialization.codec((int, Exception)) + self._exception_attached = serialization.codec((int, Exception, _ATTACHMENTS)) + + def encode_message(self, message: str) -> bytes: + """Return the body of a response with a status other than OK.""" + return self._message.encode((message,)) + + def decode_message(self, data: bytes) -> str: + """Return the message of a response with a status other than OK. + + Raises: + ValueError: ``data`` holds no message. + """ + return self.serialization.reader(data).load(str) + + def encode_null(self, attachments: Mapping[str, Any] | None) -> bytes: + if attachments is None: + return self._null.encode((_NULL,)) + return self._null_attached.encode((_NULL + _WITH_ATTACHMENTS, attachments)) + + def encode_exception(self, exception: Exception, attachments: Mapping[str, Any] | None) -> bytes: + """Return the body of a response with ``exception``, a `RemoteError` or one of a class the serialization declares.""" + if attachments is None: + return self._exception.encode((_EXCEPTION, exception)) + return self._exception_attached.encode((_EXCEPTION + _WITH_ATTACHMENTS, exception, attachments)) + + def decode_response(self, data: bytes, value_type: Any = Any) -> Response: + """Return the response ``data`` holds, its value decoded as ``value_type``. + + Values after the response, such as the null some providers append, + are left unread. + + Raises: + ValueError: ``data`` holds no response. + """ + reader = self.serialization.reader(data) + kind = reader.load(int) + if not 0 <= kind <= _NULL + _WITH_ATTACHMENTS: + raise ValueError( + f"the body is not a Dubbo response, whose kind is {_EXCEPTION} to {_NULL + _WITH_ATTACHMENTS}" + ) + + attached = kind >= _WITH_ATTACHMENTS + kind -= _WITH_ATTACHMENTS if attached else 0 + value = exception = None + if kind == _VALUE: + value = reader.load(value_type) + elif kind == _EXCEPTION: + exception = reader.load(Exception) + attachments = reader.load(_ATTACHMENTS) if attached else {} + return Response(value=value, exception=exception, attachments=attachments) + + +class MethodCodec: + """Writes and reads the bodies of the calls of one method of a service, made once for each method. + + Raises: + TypeError: The serialization cannot carry the parameters or the + response of ``method``, or a parameter has no Java type. + """ + + def __init__(self, responses: ResponseCodec, path: str, version: str, method: Method) -> None: + serialization = responses.serialization + self.descriptor = method_descriptor(serialization, method) + self.parameter_types = tuple(parameter.type for parameter in method.request) + self._responses = responses + self._prefix = (DUBBO_VERSION, path, version or _NO_VERSION, method.name, self.descriptor) + self._request = serialization.codec((str, str, str, str, str, *self.parameter_types, _ATTACHMENTS)) + # A method that returns nothing answers with a null response. + self._response_type = method.response + self._null_error: str | None = None + if method.response is not None: + self._value = serialization.codec((int, method.response)) + self._value_attached = serialization.codec((int, method.response, _ATTACHMENTS)) + if not _decodes_null(serialization, method.response): + name = getattr(method.response, "__qualname__", None) or repr(method.response) + self._null_error = f"the provider returned null, which {name} does not allow; declare {name} | None" + + def encode_request(self, arguments: tuple[Any, ...], attachments: Mapping[str, Any]) -> bytes: + return self._request.encode((*self._prefix, *arguments, attachments)) + + def read_arguments(self, reader: Reader) -> tuple[tuple[Any, ...], dict[str, Any]]: + """Return the arguments and the attachments of a request, after its head. + + Raises: + ValueError: The rest of the request holds no arguments of the + parameter types and attachments. + """ + arguments = tuple(reader.load(annotation) for annotation in self.parameter_types) + return arguments, reader.load(_ATTACHMENTS) + + def encode_value(self, value: Any, attachments: Mapping[str, Any] | None) -> bytes: + """Return the body of a response with ``value``, ending with ``attachments`` unless they are ``None``.""" + if value is None or self._response_type is None: + return self._responses.encode_null(attachments) + if attachments is None: + return self._value.encode((_VALUE, value)) + return self._value_attached.encode((_VALUE + _WITH_ATTACHMENTS, value, attachments)) + + def decode_response(self, data: bytes) -> Response: + """Return the response ``data`` holds, its value of the method's return type. + + Raises: + ValueError: ``data`` holds no response of this method, or a null + value the return type does not allow, such as ``User`` + without ``| None``. + """ + response = self._responses.decode_response(data, Any if self._response_type is None else self._response_type) + if response.value is None and response.exception is None and self._null_error is not None: + raise ValueError(self._null_error) + return response + + +def read_request_head(reader: Reader) -> RequestHead: + """Return the head of a request, the values before its arguments. + + Raises: + ValueError: The request starts with no head. + """ + dubbo_version, path, version, method, descriptor = (reader.load(annotation) for annotation in _HEAD) + return RequestHead( + dubbo_version=dubbo_version, + path=path, + version=service_version(version), + method=method, + descriptor=descriptor, + ) + + +def service_version(version: str | None) -> str: + """Return the version of a service as a request names it: empty for none, as ``0.0.0`` and ``*`` say too.""" + return "" if version is None or version in _NO_VERSIONS else version + + +# Bounded, since the versions come from the peers. +@functools.lru_cache(maxsize=64) +def supports_response_attachments(dubbo_version: str) -> bool: + """Return whether a consumer of ``dubbo_version`` reads attachments at the end of a response.""" + try: + parts = tuple(int(part) for part in dubbo_version.split(".")) + except ValueError: + return False + + lowest, highest = _ATTACHMENT_VERSIONS + return lowest <= (*parts, 0, 0, 0, 0)[:4] <= highest + + +def status_error(status: int, message: str) -> RpcError: + """Return the error a consumer receives for a response with a status other than OK.""" + try: + name = ResponseStatus(status).name + except ValueError: + name = str(status) + rpc_status = _STATUS_ERRORS.get(status, Status.UNKNOWN) + return RpcError(rpc_status, f"{name}: {message}" if message else name) + + +def to_attachments(values: Mapping[str, Any]) -> MultiDict[str | bytes]: + """Return the attachments a call carries in Python for those it received. + + Text and bytes stay as they are, numbers and booleans become text, and + values of other types are left out. + """ + attachments: MultiDict[str | bytes] = MultiDict() + for key, value in values.items(): + if isinstance(value, _TEXT): + attachments[key] = value + elif isinstance(value, _SCALARS): + attachments[key] = to_text(value) + else: + _logger.debug("Cannot read the attachment %s of type %s; it is left out", key, type(value).__name__) + + return attachments + + +def _decodes_null(serialization: JavaSerialization, annotation: Any) -> bool: + """Return whether a null of ``serialization`` reads as ``annotation``.""" + null = serialization.codec((None,)).encode((None,)) + try: + serialization.reader(null).load(annotation) + except ValueError: + return False + return True diff --git a/src/dubbo/protocol/dubbo/client.py b/src/dubbo/protocol/dubbo/client.py new file mode 100644 index 00000000..cb55a58c --- /dev/null +++ b/src/dubbo/protocol/dubbo/client.py @@ -0,0 +1,179 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +from typing import Self + +import anyio + +from dubbo.exceptions import RpcError, Status +from dubbo.extension import Resource +from dubbo.serialization import JavaSerialization +from dubbo.transport.tls import get_ssl_context, server_hostname +from dubbo.url import URL +from dubbo.utils import Dialer + +from .connection import ( + FLAG_REQUEST, + FLAG_TWO_WAY, + SERIALIZATION_MASK, + ConnectionSettings, + DubboConnection, + EventBodies, + next_request_id, +) + +__all__ = ["DubboClient"] + + +class DubboClient(Resource): + """The connection to one provider address, which opens in the background once entered and again after it is lost. + + One attempt to connect runs at a time and lasts at most the + `ConnectionSettings.connect_timeout`; calls made meanwhile wait for it, + and one that stops waiting leaves it running. After an attempt fails or + the connection is lost, the client connects again in the background + after a backoff. A call waits for its response until the connection + closes; the caller bounds it. A response in another serialization than + the request fails the call. + + The client is available while a connection is established on which + the provider takes calls: not until an attempt succeeds, nor from a + failed attempt or a lost connection until the next succeeds, nor once + closed. A call still connects while it is unavailable. + """ + + def __init__(self, url: URL, serialization: JavaSerialization, serialization_id: int) -> None: + if url.host is None or url.port is None: + raise ValueError(f"a Dubbo client needs a host and a port: {url}") + + self.address = (url.host, url.port) + self._settings = ConnectionSettings.from_url(url) + self._ssl_context = get_ssl_context(url, server=False) + self._server_hostname = server_hostname(url) if self._ssl_context is not None else None + self._serialization_id = serialization_id + self._events = EventBodies.from_serialization(serialization) + self._connection: DubboConnection | None = None + self._dialer = Dialer(self._open_connection) + self._pending: dict[int, asyncio.Future[tuple[int, bytes]]] = {} + self._closed = False + + @property + def available(self) -> bool: + connection = self._connection + return not self._closed and self._dialer.connected and connection is not None and not connection.readonly + + async def call(self, body: bytes) -> tuple[int, bytes]: + """Send a two-way request with ``body`` and return the status and the body of its response. + + Raises: + RpcError: The provider cannot be reached, the connection is lost + before the response, or ``body`` is too large. + """ + connection = await self._connect() + request_id = next_request_id() + # An asyncio future, which the connection, an asyncio protocol, resolves from its callback. + future: asyncio.Future[tuple[int, bytes]] = asyncio.get_running_loop().create_future() + self._pending[request_id] = future + try: + await connection.wait_writable() + try: + connection.write_frame(FLAG_REQUEST | FLAG_TWO_WAY, 0, request_id, body) + except ValueError as error: + raise RpcError(Status.RESOURCE_EXHAUSTED, str(error)) from None + return await future + finally: + del self._pending[request_id] + + async def aclose(self) -> None: + self._closed = True + await self._dialer.aclose() + connection = self._connection + if connection is not None: + await connection.aclose() + + async def __aenter__(self) -> Self: + if self._closed: + raise RuntimeError("the Dubbo client is closed") + self._dialer.start() + return self + + async def _connect(self) -> DubboConnection: + """Return the open connection, or wait for the attempt that opens one.""" + if self._closed: + raise RpcError(Status.UNAVAILABLE, "the Dubbo client is closed") + connection = self._connection + if connection is not None and not connection.closed: + return connection + + connection = await self._dialer.connect() + if connection is None: + raise RpcError(Status.UNAVAILABLE, "the Dubbo client is closed") + return connection + + async def _open_connection(self) -> DubboConnection: + host, port = self.address + try: + with anyio.fail_after(self._settings.connect_timeout): + _, connection = await asyncio.get_running_loop().create_connection( + self._create_connection, + host, + port, + ssl=self._ssl_context, + server_hostname=self._server_hostname, + ) + except (OSError, TimeoutError) as error: + raise RpcError(Status.UNAVAILABLE, f"cannot connect to {host}:{port}: {error}") from None + + self._connection = connection + return connection + + def _create_connection(self) -> DubboConnection: + return DubboConnection( + on_frame=self._receive, + on_closed=self._lost, + serialization_id=self._serialization_id, + events=self._events, + heartbeat=self._settings.heartbeat, + idle_timeout=self._settings.idle_timeout, + max_body=self._settings.max_body, + ) + + def _receive(self, connection: DubboConnection, flags: int, status: int, request_id: int, body: bytes) -> None: + if flags & FLAG_REQUEST: + return + + future = self._pending.get(request_id) + if future is None or future.done(): + return + + received = flags & SERIALIZATION_MASK + if received != self._serialization_id: + message = f"the response is in serialization {received}, not {self._serialization_id} as the request" + future.set_exception(RpcError(Status.INTERNAL, message)) + else: + future.set_result((status, body)) + + def _lost(self, connection: DubboConnection) -> None: + if connection is not self._connection: + return + + # Each caller raises its own error, so that no traceback gathers the frames of the others. + for future in self._pending.values(): + if not future.done(): + future.set_exception(RpcError(Status.UNAVAILABLE, f"the connection to {connection.peer} closed")) + self._dialer.lost() diff --git a/src/dubbo/protocol/dubbo/connection.py b/src/dubbo/protocol/dubbo/connection.py new file mode 100644 index 00000000..63309a59 --- /dev/null +++ b/src/dubbo/protocol/dubbo/connection.py @@ -0,0 +1,397 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""A TCP connection that carries Dubbo frames. + +It is an asyncio protocol: the I/O layer that AnyIO does not cover. +""" + +import asyncio +import itertools +import logging +import struct +from collections.abc import Callable +from typing import Any, Self, cast + +import anyio +import attrs + +from dubbo.constants import ( + CONNECT_TIMEOUT_KEY, + DEFAULT_CONNECT_TIMEOUT, + DEFAULT_HEARTBEAT, + DEFAULT_PAYLOAD, + HEARTBEAT_KEY, + HEARTBEAT_TIMEOUT_KEY, + PAYLOAD_KEY, +) +from dubbo.serialization import JavaSerialization +from dubbo.transport.tls import TLS_KEYS +from dubbo.url import SSL_CONTEXT, URL +from dubbo.utils import close_then_abort +from dubbo.utils.converters import milliseconds +from dubbo.utils.net import format_address + +__all__ = [ + "FLAG_REQUEST", + "FLAG_TWO_WAY", + "SERIALIZATION_MASK", + "ConnectionSettings", + "DubboConnection", + "EventBodies", + "next_request_id", +] + +_logger = logging.getLogger(__name__) + +_MAGIC = 0xDABB +# Magic, flags with the serialization id, status, request id and body length. +_HEADER = struct.Struct(">HBBqI") +FLAG_REQUEST = 0x80 +FLAG_TWO_WAY = 0x40 +_FLAG_EVENT = 0x20 +SERIALIZATION_MASK = 0x1F # The bits of the flags that hold the serialization id. +_OK = 20 +_READONLY = "R" # The event data that tells consumers a provider stops taking calls. +_WRITABLE = "W" # The event data that tells consumers a provider takes calls again. +_READ_SIZE = 64 * 1024 # Bytes the read buffer keeps free for each read. + +# The id of each request a process sends, unique among all its connections. +next_request_id = itertools.count(1).__next__ + +# Called with the connection, the flags with the serialization id, the status, the request id and the body. +_FrameHandler = Callable[["DubboConnection", int, int, int, bytes], None] + + +@attrs.define(frozen=True, kw_only=True) +class ConnectionSettings: + """How the connections of a consumer or a provider behave, from the parameters of its URL. + + Attributes: + connect_timeout: Seconds a consumer waits for a connection, its TLS + handshake included, from ``connect-timeout`` in milliseconds; 3 + when absent. + heartbeat: Seconds of silence before a consumer sends a heartbeat, + from ``heartbeat`` in milliseconds; 60 when absent. + idle_timeout: Seconds without reading before a connection closes, + from ``heartbeat.timeout`` in milliseconds; three heartbeats when + absent. + max_body: Bytes of the largest body, from ``payload``; 8 MiB when + absent. + tls: The TLS parameters and context of the URL, as + `dubbo.transport.tls.get_ssl_context` reads them; connections of + other TLS share no client or server. + """ + + connect_timeout: float + heartbeat: float + idle_timeout: float + max_body: int + tls: tuple[Any, ...] + + @classmethod + def from_url(cls, url: URL) -> Self: + """Return the settings ``url`` gives. + + Raises: + ValueError: A setting is not a positive number, or the idle + timeout is shorter than two heartbeats. + """ + connect_timeout = url.get_parameter(CONNECT_TIMEOUT_KEY, milliseconds, DEFAULT_CONNECT_TIMEOUT) + heartbeat = url.get_parameter(HEARTBEAT_KEY, milliseconds, DEFAULT_HEARTBEAT) + idle_timeout = url.get_parameter(HEARTBEAT_TIMEOUT_KEY, milliseconds, 3 * heartbeat) + max_body = url.get_parameter(PAYLOAD_KEY, int, DEFAULT_PAYLOAD) + if connect_timeout <= 0 or heartbeat <= 0 or max_body <= 0: + raise ValueError(f"{CONNECT_TIMEOUT_KEY}, {HEARTBEAT_KEY} and {PAYLOAD_KEY} must be positive") + if idle_timeout < 2 * heartbeat: + raise ValueError(f"{HEARTBEAT_TIMEOUT_KEY} must be at least two heartbeats") + + tls = (*(url.parameters.get(key) for key in TLS_KEYS), url.attributes.get(SSL_CONTEXT)) + return cls( + connect_timeout=connect_timeout, + heartbeat=heartbeat, + idle_timeout=idle_timeout, + max_body=max_body, + tls=tls, + ) + + +@attrs.define(frozen=True, kw_only=True) +class EventBodies: + """The bodies of the events a connection sends, serialized once, and how it reads those it receives. + + Attributes: + heartbeat: A heartbeat, a serialized null. + readonly: The notice that a provider stops taking calls. + read: Returns the value an event body holds; raises `ValueError` + for a body that holds none. + """ + + heartbeat: bytes + readonly: bytes + read: Callable[[bytes], Any] + + @classmethod + def from_serialization(cls, serialization: JavaSerialization) -> Self: + """Return the bodies ``serialization`` writes and reads.""" + return cls( + heartbeat=serialization.codec((None,)).encode((None,)), + readonly=serialization.codec((str,)).encode((_READONLY,)), + read=lambda body: serialization.reader(body).load(Any), + ) + + +class DubboConnection(asyncio.BufferedProtocol): + """One connection, of a consumer or a provider, that hands each frame to ``on_frame``. + + It handles the events itself: it answers heartbeat requests, and marks + itself `readonly` while the provider says it takes no calls. It + closes once nothing has been read for ``idle_timeout`` seconds. With + ``heartbeat``, it sends a heartbeat after that many seconds without + reading or writing. A frame that does not start with the Dubbo magic, or + whose body is larger than ``max_body`` bytes, closes it. + + Args: + on_frame: Called with each request and response that is no event, + in the event loop. + on_connected: Called once the connection is made, after the TLS + handshake if any. + on_closed: Called once a made connection is lost. + serialization_id: The id each frame it writes carries. + events: The bodies of the events, in the serialization. + heartbeat: Seconds of silence before it sends a heartbeat; ``None`` + sends none. + idle_timeout: Seconds without reading before it closes. + max_body: Bytes of the largest body it reads or writes. + pause_reading: Whether it stops reading while it cannot write, so + that a peer that reads no responses cannot make it buffer more. + """ + + def __init__( + self, + *, + on_frame: _FrameHandler, + on_connected: Callable[["DubboConnection"], None] | None = None, + on_closed: Callable[["DubboConnection"], None], + serialization_id: int, + events: EventBodies, + heartbeat: float | None, + idle_timeout: float, + max_body: int, + pause_reading: bool = False, + ) -> None: + self.max_body = max_body + self.peer: str | None = None + # Set when the provider says it stops serving; a consumer then calls others. + self.readonly = False + self._on_frame = on_frame + self._on_connected = on_connected + self._on_closed = on_closed + self._serialization_id = serialization_id + self._events = events + self._heartbeat = heartbeat + self._idle_timeout = idle_timeout + self._pause_reading = pause_reading + self._transport: asyncio.Transport | None = None + self._loop: asyncio.AbstractEventLoop | None = None + self._timer: asyncio.TimerHandle | None = None + self._last_read = self._last_write = 0.0 + # Received bytes are buffer[start:end]; a partly received frame needs ``frame_size`` bytes from start. + self._buffer = bytearray(_READ_SIZE) + self._view = memoryview(self._buffer) + self._start = self._end = 0 + self._frame_size = 0 + self._closed = anyio.Event() + self._writable = anyio.Event() + self._writable.set() + + @property + def closed(self) -> bool: + return self._closed.is_set() + + def write_frame(self, flags: int, status: int, request_id: int, body: bytes) -> None: + """Send a frame; ignored once the connection is closing. + + Raises: + ValueError: The body is larger than ``max_body``. + """ + if len(body) > self.max_body: + raise ValueError(f"the body has {len(body)} bytes, more than the {self.max_body} the connection allows") + if self._transport is None or self._transport.is_closing(): + return + + header = _HEADER.pack(_MAGIC, flags | self._serialization_id, status, request_id, len(body)) + self._transport.write(header + body) + self._last_write = cast(asyncio.AbstractEventLoop, self._loop).time() + + def announce_shutdown(self) -> None: + """Tell the consumer that this provider stops taking calls.""" + self.write_frame(FLAG_REQUEST | _FLAG_EVENT, 0, next_request_id(), self._events.readonly) + + async def wait_writable(self) -> None: + """Wait while the transport buffers more than its high-water mark.""" + if not self._writable.is_set(): + await self._writable.wait() + + def close(self) -> None: + if self._transport is not None: + self._transport.close() + + def abort(self) -> None: + """Close at once, dropping the frames not yet sent.""" + if self._transport is not None: + self._transport.abort() + + async def aclose(self) -> None: + """Close once the peer has read the frames already written, waiting up to a grace period; abort after it or when cancelled.""" + transport = self._transport + if transport is None: + return + + transport.close() + await close_then_abort(self._closed.wait, lambda: self.closed, transport.abort) + + def connection_made(self, transport: asyncio.BaseTransport) -> None: + self._transport = cast(asyncio.Transport, transport) + self._loop = asyncio.get_running_loop() + self._last_read = self._last_write = self._loop.time() + peer: Any = transport.get_extra_info("peername") + if isinstance(peer, tuple): + self.peer = format_address(*peer[:2]) + self._schedule_tick() + if self._on_connected is not None: + self._on_connected(self) + + def get_buffer(self, sizehint: int) -> memoryview: + if len(self._buffer) - self._end < _READ_SIZE: + self._make_room() + return self._view[self._end :] + + def buffer_updated(self, nbytes: int) -> None: + self._end += nbytes + self._last_read = cast(asyncio.AbstractEventLoop, self._loop).time() + buffer, header_size = self._buffer, _HEADER.size + while self._end - self._start >= header_size: + magic, flags, status, request_id, length = _HEADER.unpack_from(buffer, self._start) + if magic != _MAGIC: + _logger.debug("Received bytes from %s that are not Dubbo; the connection closes", self.peer) + self.close() + return + if length > self.max_body: + _logger.warning( + "Received a body of %d bytes from %s, more than %d; the connection closes", + length, + self.peer, + self.max_body, + ) + self.close() + return + + frame_end = self._start + header_size + length + if frame_end > self._end: + self._frame_size = header_size + length + break + + body = bytes(self._view[self._start + header_size : frame_end]) + self._start, self._frame_size = frame_end, 0 + self._receive(flags, status, request_id, body) + + if self._start == self._end: + if len(self._buffer) > 4 * _READ_SIZE: + self._buffer = bytearray(_READ_SIZE) + self._view = memoryview(self._buffer) + self._start = self._end = 0 + + def pause_writing(self) -> None: + self._writable = anyio.Event() + if self._pause_reading: + cast(asyncio.Transport, self._transport).pause_reading() + + def resume_writing(self) -> None: + self._writable.set() + if self._pause_reading: + cast(asyncio.Transport, self._transport).resume_reading() + + def connection_lost(self, exc: Exception | None) -> None: + if self._timer is not None: + self._timer.cancel() + self._writable.set() + self._closed.set() + self._on_closed(self) + + def _receive(self, flags: int, status: int, request_id: int, body: bytes) -> None: + if flags & _FLAG_EVENT: + if flags & FLAG_REQUEST: + self._receive_event(flags, request_id, body) + return + + try: + self._on_frame(self, flags, status, request_id, body) + except Exception: + _logger.exception("Cannot handle a frame from %s; the connection closes", self.peer) + self.close() + + def _receive_event(self, flags: int, request_id: int, body: bytes) -> None: + try: + event = self._events.read(body) + except ValueError: + _logger.debug("Cannot read an event from %s; it is ignored", self.peer) + return + + if event is None and flags & FLAG_TWO_WAY: + self.write_frame(_FLAG_EVENT, _OK, request_id, self._events.heartbeat) + elif event == _READONLY: + _logger.info("The provider at %s stops taking calls on this connection", self.peer) + self.readonly = True + elif event == _WRITABLE: + _logger.info("The provider at %s takes calls again on this connection", self.peer) + self.readonly = False + + def _make_room(self) -> None: + """Move the received bytes to the front of the buffer, growing it as they come. + + It at most doubles at a time, up to the frame being received, so that + a peer that only announces a large frame takes no memory for it. + """ + unread = self._end - self._start + size = len(self._buffer) + if unread + _READ_SIZE > size: + size = max(unread + _READ_SIZE, min(2 * size, self._frame_size + _READ_SIZE)) + if size > len(self._buffer): + buffer = bytearray(size) + buffer[:unread] = self._view[self._start : self._end] + self._view.release() + self._buffer, self._view = buffer, memoryview(buffer) + elif self._start: + self._buffer[:unread] = self._buffer[self._start : self._end] + self._start, self._end = 0, unread + + def _schedule_tick(self) -> None: + interval = self._idle_timeout if self._heartbeat is None else min(self._heartbeat, self._idle_timeout) + self._timer = cast(asyncio.AbstractEventLoop, self._loop).call_later(interval, self._tick) + + def _tick(self) -> None: + now = cast(asyncio.AbstractEventLoop, self._loop).time() + if now - self._last_read >= self._idle_timeout: + _logger.info("Read nothing from %s for %s seconds; the connection closes", self.peer, self._idle_timeout) + self.close() + return + + heartbeat = self._heartbeat + if heartbeat is not None and (now - self._last_read >= heartbeat or now - self._last_write >= heartbeat): + self.write_frame(FLAG_REQUEST | FLAG_TWO_WAY | _FLAG_EVENT, 0, next_request_id(), self._events.heartbeat) + self._schedule_tick() diff --git a/src/dubbo/protocol/dubbo/invoker.py b/src/dubbo/protocol/dubbo/invoker.py new file mode 100644 index 00000000..a5887ad8 --- /dev/null +++ b/src/dubbo/protocol/dubbo/invoker.py @@ -0,0 +1,187 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Mapping +from typing import Self + +import attrs + +from dubbo.constants import ( + DEFAULT_SHUTWAIT, + DUBBO_VERSION_KEY, + GENERIC_KEY, + GROUP_KEY, + INTERFACE_KEY, + PATH_KEY, + SHUTWAIT_KEY, + TIMEOUT_KEY, + TOKEN_KEY, + VERSION_KEY, +) +from dubbo.exceptions import RpcError, Status +from dubbo.protocol.generic import GENERIC_INVOKE, invoke_arguments +from dubbo.protocol.java import caller_error +from dubbo.protocol.served import Calls, ClientPool, call_within, method_timeout +from dubbo.rpc.definition import RpcType, Service +from dubbo.rpc.invocation import Invocation, Invoker, Result +from dubbo.serialization import JavaSerialization +from dubbo.url import URL +from dubbo.utils.converters import milliseconds, to_milliseconds + +from .body import MethodCodec, ResponseCodec, ResponseStatus, status_error, to_attachments +from .client import DubboClient + +__all__ = ["DubboInvoker", "ServiceCodecs"] + +# The attachments that route a request and bound it, which only the URL and the timeout of the invoker set. +_RESERVED = frozenset({PATH_KEY, INTERFACE_KEY, GROUP_KEY, VERSION_KEY, TOKEN_KEY, TIMEOUT_KEY, DUBBO_VERSION_KEY}) + + +@attrs.define(frozen=True, kw_only=True) +class ServiceCodecs: + """How the calls of the methods of one service and version travel in one serialization. + + Codecs keep no state between messages, so the invokers of a service share them. + """ + + responses: ResponseCodec + methods: Mapping[str, MethodCodec] + generic: MethodCodec + + @classmethod + def from_definition(cls, serialization: JavaSerialization, definition: Service, version: str) -> Self: + """Raises: + TypeError: A method is not unary, or ``serialization`` cannot carry it. + """ + responses = ResponseCodec(serialization) + methods = {} + for method in definition.methods: + if method.rpc_type is not RpcType.UNARY: + raise TypeError(f"Dubbo carries unary calls, but {method.name} is {method.rpc_type.value}") + methods[method.name] = MethodCodec(responses, definition.interface, version, method) + generic = MethodCodec(responses, definition.interface, version, GENERIC_INVOKE) + return cls(responses=responses, methods=methods, generic=generic) + + +class DubboInvoker(Invoker): + """Calls the methods of one remote service with a share in a client of ``clients``. + + Each method is prepared when the invoker is made, so a call only encodes, + sends and decodes. A call runs for at most the milliseconds of + ``{method}.timeout``, else of ``timeout``, one second when absent, and then ends with + ``DEADLINE_EXCEEDED``; the provider learns the timeout from the + ``timeout`` attachment. Each call attaches the ``token`` of ``url``; a + call whose own attachments set one of those that route or bound it, such + as ``group`` or ``timeout``, fails with ``INVALID_ARGUMENT``. An + exception the provider raises reaches the caller as a `RemoteError`. + Closing the invoker refuses new calls, waits for those running as long as + ``shutwait``, ten seconds when absent, then gives the share back. + """ + + def __init__( + self, + url: URL, + definition: Service, + client: DubboClient, + codecs: ServiceCodecs, + clients: ClientPool[DubboClient], + ) -> None: + """``codecs`` are those of ``definition`` at the version of ``url``.""" + self._url = url + self._responses = codecs.responses + self._methods = methods = codecs.methods + self._generic = codecs.generic + + attachments = {PATH_KEY: definition.interface, INTERFACE_KEY: definition.interface} + for key in (GROUP_KEY, VERSION_KEY, TOKEN_KEY): + if url.parameters.get(key): + attachments[key] = url.parameters[key] + self._attachments = attachments + self._timeouts = {name: method_timeout(url, name) for name in methods} + self._shutwait = url.get_parameter(SHUTWAIT_KEY, milliseconds, DEFAULT_SHUTWAIT) + self._client = client + self._clients = clients + self._closed = False + self._calls = Calls() + + @property + def url(self) -> URL: + return self._url + + @property + def available(self) -> bool: + return not self._closed and self._client.available + + async def invoke(self, invocation: Invocation) -> Result: + if invocation.generic is not None: + method = self._generic + arguments = invoke_arguments(self._responses.serialization, invocation.definition, invocation.arguments) + timeout = method_timeout(self._url, invocation.method) + else: + known = self._methods.get(invocation.method) + if known is None: + return Result(error=RpcError(Status.UNIMPLEMENTED, f"the service has no method {invocation.method!r}")) + method, arguments, timeout = known, invocation.arguments, self._timeouts[invocation.method] + if self._closed: + return Result(error=RpcError(Status.UNAVAILABLE, "the invoker is closed")) + + reserved = _RESERVED.intersection(invocation.attachments) + if reserved: + message = f"the attachments {', '.join(sorted(reserved))} are the protocol's to set" + return Result(error=RpcError(Status.INVALID_ARGUMENT, message)) + + attachments = {**invocation.attachments, **self._attachments, TIMEOUT_KEY: to_milliseconds(timeout)} + if invocation.generic is not None: + attachments[GENERIC_KEY] = invocation.generic + try: + body = method.encode_request(arguments, attachments) + except (TypeError, ValueError) as error: + return Result(error=RpcError(Status.INVALID_ARGUMENT, f"cannot encode the request: {error}")) + + self._calls.enter() + try: + return await call_within(timeout, invocation.method, self._call(method, body)) + finally: + self._calls.leave() + + async def aclose(self) -> None: + if self._closed: + return + + self._closed = True + try: + await self._calls.drain(self._shutwait) + finally: + await self._clients.release(self._client) + + async def _call(self, method: MethodCodec, body: bytes) -> Result: + try: + status, data = await self._client.call(body) + except RpcError as error: + return Result(error=error) + + try: + if status != ResponseStatus.OK: + return Result(error=status_error(status, self._responses.decode_message(data))) + response = method.decode_response(data) + except ValueError as error: + return Result(error=RpcError(Status.INTERNAL, f"cannot decode the response: {error}")) + + attachments = to_attachments(response.attachments) + if response.exception is not None: + return Result(error=caller_error(response.exception), attachments=attachments) + return Result(value=response.value, attachments=attachments) diff --git a/src/dubbo/protocol/dubbo/protocol.py b/src/dubbo/protocol/dubbo/protocol.py new file mode 100644 index 00000000..c97a1a13 --- /dev/null +++ b/src/dubbo/protocol/dubbo/protocol.py @@ -0,0 +1,145 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from dubbo.constants import ( + DEFAULT_DUBBO_PORT, + DEFAULT_JAVA_SERIALIZATION, + GROUP_KEY, + SERIALIZATION_IDS, + SERIALIZATION_KEY, + VERSION_KEY, +) +from dubbo.protocol.base import Protocol +from dubbo.protocol.served import ClientPool, ServedExporter, ServedService, Servers +from dubbo.rpc.definition import Service +from dubbo.rpc.invocation import Invoker +from dubbo.serialization import JavaSerialization, get_java_serialization +from dubbo.url import URL + +from .body import service_version +from .client import DubboClient +from .connection import ConnectionSettings +from .invoker import DubboInvoker, ServiceCodecs +from .server import DubboServer + +__all__ = ["DubboProtocol"] + + +class DubboProtocol(Protocol): + """Serve and call services with the Dubbo protocol over TCP. + + A request names its service by interface, group and version, and its + method by name and Java parameter descriptor. The ``serialization`` + parameter names the format, one of Java objects that has a Dubbo id, + ``hessian2`` when absent. Without a port, the address uses port 20880. + + ``heartbeat`` and ``heartbeat.timeout``, in milliseconds, and + ``payload``, in bytes, set the connections, as `ConnectionSettings` + describes, with TLS as `dubbo.transport.tls.get_ssl_context` reads it, + and ``max-concurrent-calls`` the calls a server runs at once, as + `DubboServer` describes. The services exported on one address + share a server, which listens until the protocol closes; each must ask + for the same serialization and settings. Once the exporter of a service + closes, the server answers its calls with ``SERVICE_NOT_FOUND``. + """ + + def __init__(self) -> None: + self._servers: Servers[DubboServer] = Servers() + self._clients: ClientPool[DubboClient] = ClientPool() + # The codecs of each shared serialization, definition and version, which the invokers of a service share. + self._codecs: dict[tuple[str, Service, str], ServiceCodecs] = {} + + async def export(self, url: URL, definition: Service, invoker: Invoker) -> ServedExporter: + url = _with_defaults(url) + serialization, serialization_id = _serialization(url) + service = ServedService( + interface=definition.interface, + group=url.parameters.get(GROUP_KEY, ""), + version=service_version(url.parameters.get(VERSION_KEY)), + invoker=invoker, + ) + + server = await self._servers.serve( + url, + lambda: DubboServer(url, serialization, serialization_id), + lambda server: server.add(service, definition), + ) + return ServedExporter(server=server, service=service, url=url.replace(port=server.address[1])) + + async def refer(self, url: URL, definition: Service) -> Invoker: + url = _with_defaults(url) + serialization, serialization_id = _serialization(url) + codecs = self._get_codecs(url, serialization, definition) + key = (url.host, url.port, serialization_id, ConnectionSettings.from_url(url)) + client = await self._clients.acquire(key, lambda: DubboClient(url, serialization, serialization_id)) + + try: + return DubboInvoker(url, definition, client, codecs, self._clients) + except BaseException: + await self._clients.release(client) + raise + + def announce_shutdown(self) -> None: + self._servers.announce_shutdown() + + async def aclose(self) -> None: + try: + await self._servers.aclose() + finally: + await self._clients.aclose() + + def _get_codecs(self, url: URL, serialization: JavaSerialization, definition: Service) -> ServiceCodecs: + """Return the codecs of ``definition`` at the version of ``url`` in ``serialization``, which ``url`` names. + + Those of a shared serialization are made once; the others for each call. + + Raises: + TypeError: A method is not unary, or ``serialization`` cannot carry it. + """ + key = (url.parameters[SERIALIZATION_KEY], definition, url.parameters.get(VERSION_KEY, "")) + codecs = self._codecs.get(key) + if codecs is not None: + return codecs + + codecs = ServiceCodecs.from_definition(serialization, definition, key[2]) + if serialization.shared: + self._codecs[key] = codecs + return codecs + + +def _with_defaults(url: URL) -> URL: + """Return ``url`` with the default port and serialization where it has none.""" + if url.port is None: + url = url.replace(port=DEFAULT_DUBBO_PORT) + if not url.parameters.get(SERIALIZATION_KEY): + url = url.update_parameters({SERIALIZATION_KEY: DEFAULT_JAVA_SERIALIZATION}) + return url + + +def _serialization(url: URL) -> tuple[JavaSerialization, int]: + """Return the serialization the ``serialization`` parameter of ``url`` names, with its id in the frames. + + Raises: + ExtensionError: No serialization has that name. + ValueError: The serialization carries no Java objects, or has no + Dubbo id. + """ + name = url.parameters[SERIALIZATION_KEY] + serialization_id = SERIALIZATION_IDS.get(name) + if serialization_id is None: + raise ValueError(f"the serialization {name!r} has no id in the Dubbo protocol") + return get_java_serialization(url), serialization_id diff --git a/src/dubbo/protocol/dubbo/server.py b/src/dubbo/protocol/dubbo/server.py new file mode 100644 index 00000000..fee468db --- /dev/null +++ b/src/dubbo/protocol/dubbo/server.py @@ -0,0 +1,492 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import logging +import math +from typing import Any, Self + +import anyio +import attrs + +from dubbo.constants import ( + DEFAULT_MAX_CONCURRENT_CALLS, + DEFAULT_SHUTWAIT, + DUBBO_VERSION, + DUBBO_VERSION_KEY, + GROUP_KEY, + MAX_CONCURRENT_CALLS_KEY, + SERIALIZATION_IDS, + SERIALIZATION_KEY, + SHUTWAIT_KEY, + TIMEOUT_KEY, +) +from dubbo.exceptions import RemoteError, RpcError, Status +from dubbo.extension import Resource +from dubbo.protocol.generic import builtin_methods +from dubbo.protocol.java import java_exception +from dubbo.protocol.served import ServedService +from dubbo.rpc.context import serving +from dubbo.rpc.definition import Method, RpcType, Service +from dubbo.rpc.invocation import Invocation, Invoke, Result +from dubbo.serialization import JavaSerialization +from dubbo.transport.listener import abort_handshakes, create_listener +from dubbo.transport.tls import get_ssl_context, ssl_handshake_timeout +from dubbo.url import URL +from dubbo.utils import release_shield, wait_then_cancel +from dubbo.utils.converters import milliseconds + +from .body import ( + MethodCodec, + RequestHead, + ResponseCodec, + ResponseStatus, + read_request_head, + supports_response_attachments, + to_attachments, +) +from .connection import FLAG_REQUEST, FLAG_TWO_WAY, SERIALIZATION_MASK, ConnectionSettings, DubboConnection, EventBodies + +__all__ = ["DubboServer"] + +_logger = logging.getLogger(__name__) + +# A service is found by its interface, group and version. +_ServiceKey = tuple[str, str, str] +# A method is found by its interface, the version of its service, its name and its descriptor, whatever the group. +_MethodKey = tuple[str, str, str, str] + + +@attrs.define(frozen=True, kw_only=True) +class _Exported: + service: ServedService + # The definition and the codec of each method, by name, and what serves its calls. + methods: dict[str, tuple[Method, MethodCodec, Invoke]] + + +@attrs.define(frozen=True, kw_only=True) +class _Request: + """A request read to the end, for an exported service.""" + + head: RequestHead + arguments: tuple[Any, ...] + attachments: dict[str, Any] + exported: _Exported + + +class DubboServer(Resource): + """Serves the services exported on one address, finding each request's by interface, group and version. + + Entering it starts listening; closing it stops listening and serving + new calls, waits for the running ones as long as ``shutwait``, ten + seconds when absent, cancels the rest and closes the connections. A + connection that cannot write stops reading. With TLS, each handshake + may take the milliseconds of ``ssl-handshake-timeout``, 10000 when + absent. + + A two-way call runs for the milliseconds of its ``timeout`` attachment, + or until its caller leaves; then its handler is cancelled as AnyIO + cancels, so that what it shields from cancellation finishes first, and a + call past its timeout is answered with ``SERVER_TIMEOUT``. A request for no exported service or + method, or whose parameter descriptor matches none, is answered with + ``SERVICE_NOT_FOUND``; one without the two-way flag gets no response. A + request beyond the ``max-concurrent-calls`` running at once, 200 when + absent and any number for 0, is answered with + ``SERVER_THREADPOOL_EXHAUSTED_ERROR``. Each service also serves the + `dubbo.protocol.generic.builtin_methods`, such as ``$echo``. The services + of one interface and version in several groups may declare a method of one + descriptor with other Python types only if they decode alike. + + Whatever a handler raises is answered with an exception, as + `dubbo.protocol.java.java_exception` names it; the statuses other than + OK stand for failures of the server itself. A call that ends with an + `RpcError` of ``UNAVAILABLE``, as a filter refuses one beyond its limit, + is answered with ``SERVER_THREADPOOL_EXHAUSTED_ERROR`` too, which + callers retry on another provider. An invoker that raises + instead of returning a result is answered with ``SERVICE_ERROR`` and the + type and message of what it raised. + + Raises: + ValueError: The URL has no host, or a setting is invalid. + OSError: A TLS file cannot be read. + """ + + def __init__(self, url: URL, serialization: JavaSerialization, serialization_id: int) -> None: + if url.host is None: + raise ValueError(f"a Dubbo server needs a host to listen on: {url}") + + self._host = url.host + self._port = url.port or 0 + self.shutwait = url.get_parameter(SHUTWAIT_KEY, milliseconds, DEFAULT_SHUTWAIT) + self._settings = ConnectionSettings.from_url(url) + self._ssl_context = get_ssl_context(url, server=True) + self._ssl_handshake_timeout = ssl_handshake_timeout(url) + self._call_limit = _max_concurrent_calls(url) + self._serialization = serialization + self._serialization_id = serialization_id + self._responses = ResponseCodec(serialization) + self._events = EventBodies.from_serialization(serialization) + self._late = self._responses.encode_message("the call ran out of the time its caller gave it") + self._services: dict[_ServiceKey, _Exported] = {} + # The codec that reads the arguments of each method, shared by the groups that export it, as the group follows them. + self._methods: dict[_MethodKey, MethodCodec] = {} + self._connections: set[DubboConnection] = set() + self._calls: set[asyncio.Task[None]] = set() + # The scopes of the running calls that each connection waits to be answered. + self._answering: dict[DubboConnection, set[anyio.CancelScope]] = {} + self._listener: asyncio.Server | None = None + self._address: tuple[str, int] | None = None + + @property + def address(self) -> tuple[str, int]: + if self._address is None: + raise RuntimeError("the Dubbo server is not listening") + return self._address + + def add(self, service: ServedService, definition: Service) -> None: + """Start serving the methods of ``definition`` with ``service``. + + Raises: + TypeError: A method is not unary, or the serialization cannot + carry it. + ValueError: Another service is exported with the same interface, + group and version, or with the same interface and version + and a method of the same name and descriptor but other + Python parameter types. + """ + key = (definition.interface, service.group, service.version) + if key in self._services: + raise ValueError(f"{service.key} is already exported on {self._host}:{self._port}") + + methods: dict[str, tuple[Method, MethodCodec, Invoke]] = {} + for method in definition.methods: + if method.rpc_type is not RpcType.UNARY: + raise TypeError(f"Dubbo carries unary calls, but {method.name} is {method.rpc_type.value}") + codec = MethodCodec(self._responses, definition.interface, service.version, method) + shared = self._methods.get((definition.interface, service.version, method.name, codec.descriptor)) + if shared is not None and shared.parameter_types != codec.parameter_types: + raise ValueError( + f"{definition.interface}.{method.name}({codec.descriptor}) is exported in another group " + "with other parameter types" + ) + methods[method.name] = (method, codec, service.invoker.invoke) + for method, serve in builtin_methods(definition, service.invoker.invoke, self._serialization): + codec = MethodCodec(self._responses, definition.interface, service.version, method) + methods[method.name] = (method, codec, serve) + + self._services[key] = _Exported(service=service, methods=methods) + self._index() + + def remove(self, service: ServedService) -> None: + """Stop serving ``service``; its new calls are answered with ``SERVICE_NOT_FOUND``.""" + self._services = {key: exported for key, exported in self._services.items() if exported.service is not service} + self._index() + + def check(self, url: URL) -> None: + """Check that ``url`` asks for the serialization and the settings this server runs with. + + Raises: + ValueError: The serialization, a connection setting or + ``max-concurrent-calls`` differs. + """ + asked = (SERIALIZATION_IDS.get(url.parameters.get(SERIALIZATION_KEY, "")), ConnectionSettings.from_url(url)) + if (*asked, _max_concurrent_calls(url)) != (self._serialization_id, self._settings, self._call_limit): + raise ValueError( + f"the Dubbo server at {self._host}:{self.address[1]} runs with another serialization or settings" + ) + + def announce_shutdown(self) -> None: + """Tell every connected consumer that the server stops taking calls, while serving on.""" + for connection in tuple(self._connections): + connection.announce_shutdown() + + async def aclose(self) -> None: + listener, self._listener = self._listener, None + if listener is None: + return + + listener.close() + # Calls that arrive from now on find no service, so that their callers try another provider. + self._services, self._methods = {}, {} + try: + await wait_then_cancel(self._calls, self.shutwait) + async with anyio.create_task_group() as closing: + for connection in tuple(self._connections): + closing.start_soon(connection.aclose) + except BaseException: + # Cancelled: the connections still open close at once. + for connection in tuple(self._connections): + connection.abort() + raise + finally: + abort_handshakes(listener) + with release_shield(): + await listener.wait_closed() + + async def __aenter__(self) -> Self: + listener, address = await create_listener( + self._create_connection, self._host, self._port, self._ssl_context, self._ssl_handshake_timeout + ) + try: + await listener.start_serving() + except BaseException: + # No one owns the server until it has started, so a start that fails closes its listener. + listener.close() + raise + + self._listener, self._address = listener, address + return self + + def _index(self) -> None: + methods: dict[_MethodKey, MethodCodec] = {} + for (interface, _, version), exported in self._services.items(): + for name, (_, codec, _) in exported.methods.items(): + methods.setdefault((interface, version, name, codec.descriptor), codec) + self._methods = methods + + def _create_connection(self) -> DubboConnection: + return DubboConnection( + on_frame=self._receive, + on_connected=self._connections.add, + on_closed=self._connection_closed, + serialization_id=self._serialization_id, + events=self._events, + heartbeat=None, + idle_timeout=self._settings.idle_timeout, + max_body=self._settings.max_body, + pause_reading=True, + ) + + def _connection_closed(self, connection: DubboConnection) -> None: + self._connections.discard(connection) + # No one waits for the answers of a caller that left, so its calls end and free their places. + for scope in self._answering.pop(connection, ()): + scope.cancel() + + def _receive(self, connection: DubboConnection, flags: int, status: int, request_id: int, body: bytes) -> None: + if not flags & FLAG_REQUEST: + return + + two_way = bool(flags & FLAG_TWO_WAY) + received = flags & SERIALIZATION_MASK + if received != self._serialization_id: + message = ( + f"the request is in {_serialization_name(received)}, " + f"but this server reads {_serialization_name(self._serialization_id)}" + ) + self._fail(connection, two_way, request_id, ResponseStatus.SERIALIZATION_ERROR, message) + return + if self._call_limit and len(self._calls) >= self._call_limit: + message = f"the server runs {self._call_limit} calls at once, its most" + self._fail(connection, two_way, request_id, ResponseStatus.SERVER_THREADPOOL_EXHAUSTED_ERROR, message) + return + + try: + request = self._read(body) + except ValueError as error: + # At debug, as a peer that keeps sending such requests would flood a higher level. + _logger.debug("Cannot read a request from %s: %s; it is answered with BAD_REQUEST", connection.peer, error) + self._fail(connection, two_way, request_id, ResponseStatus.BAD_REQUEST, f"cannot read the request: {error}") + return + except _NotFound as error: + self._fail(connection, two_way, request_id, ResponseStatus.SERVICE_NOT_FOUND, str(error)) + return + + loop = asyncio.get_running_loop() + if two_way: + timeout = _timeout(request.attachments.get(TIMEOUT_KEY)) + deadline = math.inf if timeout is None else loop.time() + timeout + serving = self._serve(connection, request_id, request, deadline) + else: + serving = self._serve_oneway(connection, request) + # Nothing between creating the task and tracking it may raise, so that every call has an owner. + task = loop.create_task(serving) + self._calls.add(task) + # For a call cancelled before it starts; one that starts leaves the count as it ends. + task.add_done_callback(self._calls.discard) + request.exported.service.track(task) + + def _read(self, body: bytes) -> _Request: + """Return the request ``body`` holds, reading its arguments as the parameters of the method it names. + + Raises: + ValueError: The body holds no request, or no arguments of those + parameters. + _NotFound: No exported service or method matches the request. + """ + reader = self._serialization.reader(body) + head = read_request_head(reader) + codec = self._methods.get((head.path, head.version, head.method, head.descriptor)) + if codec is None: + raise _NotFound( + f"no exported method matches {head.path}.{head.method}({head.descriptor}) (version {head.version!r})" + ) + arguments, attachments = codec.read_arguments(reader) + + group = attachments.get(GROUP_KEY) or "" + if not isinstance(group, str): + raise ValueError(f"the attachment {GROUP_KEY} is no text") + exported = self._services.get((head.path, group, head.version)) + if exported is None: + raise _NotFound(f"no exported service matches {head.path} (group {group!r}, version {head.version!r})") + # The codec read the arguments for any group; the method of this group must take them too. + method = exported.methods.get(head.method) + if method is None or method[1].descriptor != head.descriptor: + raise _NotFound( + f"{head.path} (group {group!r}, version {head.version!r}) has no method " + f"{head.method}({head.descriptor})" + ) + + return _Request(head=head, arguments=arguments, attachments=attachments, exported=exported) + + async def _serve(self, connection: DubboConnection, request_id: int, request: _Request, deadline: float) -> None: + """Run ``request`` and answer it, as a two-way call that ends at ``deadline``.""" + try: + await self._answer(connection, request_id, request, deadline) + finally: + self._done() + + async def _serve_oneway(self, connection: DubboConnection, request: _Request) -> None: + """Run ``request``, a one-way call, which no one waits to be answered.""" + try: + await self._outcome(connection, request) + finally: + self._done() + + def _done(self) -> None: + # The call leaves the count at once: its done callback may run only after the next requests are read. + self._calls.discard(asyncio.current_task()) + + async def _answer(self, connection: DubboConnection, request_id: int, request: _Request, deadline: float) -> None: + # The call ends in a scope at its deadline or when its caller leaves, so that its shields hold. The scope is + # made in the task: outside one, AnyIO may not tell which event loop runs. + with anyio.CancelScope(deadline=deadline) as scope: + answering = self._answering.setdefault(connection, set()) + answering.add(scope) + try: + result = await self._outcome(connection, request) + finally: + answering.discard(scope) + if scope.cancelled_caught: + # Past its timeout, as a caller that left waits for no answer. + if connection in self._connections: + connection.write_frame(0, ResponseStatus.SERVER_TIMEOUT, request_id, self._late) + return + + status, body = self._respond(request, result) + await connection.wait_writable() + try: + connection.write_frame(0, status, request_id, body) + except ValueError as error: + message = self._responses.encode_message(str(error)) + connection.write_frame(0, ResponseStatus.BAD_RESPONSE, request_id, message) + + async def _outcome(self, connection: DubboConnection, request: _Request) -> Result | Exception: + """Return the result of running ``request``, or the exception the method raised instead.""" + try: + return await self._invoke(connection, request) + except Exception as error: + if not isinstance(error, RpcError): + _logger.exception( + "Serving %s.%s raised instead of returning a result; its caller receives the error", + request.head.path, + request.head.method, + ) + return error + + async def _invoke(self, connection: DubboConnection, request: _Request) -> Result: + """Run the method ``request`` names.""" + method, _, invoke = request.exported.methods[request.head.method] + attachments = to_attachments(request.attachments) + invocation = Invocation( + interface=request.head.path, + method=request.head.method, + arguments=request.arguments, + attachments=attachments, + definition=method, + ) + with serving(attachments, peer=connection.peer): + return await invoke(invocation) + + def _respond(self, request: _Request, result: Result | Exception) -> tuple[int, bytes]: + """Return the status and the body of the response to ``request``, which ended with ``result``.""" + if isinstance(result, Exception): + return ResponseStatus.SERVICE_ERROR, self._responses.encode_message(f"{type(result).__name__}: {result}") + + error = result.error + # Refused, as a filter refuses a call beyond its limit: the caller tries another provider. + if isinstance(error, RpcError) and not isinstance(error, RemoteError) and error.status is Status.UNAVAILABLE: + return ResponseStatus.SERVER_THREADPOOL_EXHAUSTED_ERROR, self._responses.encode_message(error.message) + + attachments = self._attachments(request.head, result.attachments) + try: + if result.error is not None: + exception = java_exception(self._serialization, result.error) + return ResponseStatus.OK, self._responses.encode_exception(exception, attachments) + _, codec, _ = request.exported.methods[request.head.method] + return ResponseStatus.OK, codec.encode_value(result.value, attachments) + except (TypeError, ValueError) as encode_error: + head = request.head + _logger.warning("Cannot encode the response of %s.%s: %s", head.path, head.method, encode_error) + return ResponseStatus.BAD_RESPONSE, self._responses.encode_message( + f"cannot encode the response: {encode_error}" + ) + + def _attachments(self, head: RequestHead, attachments: Any) -> dict[str, Any] | None: + """Return the attachments a response to ``head`` carries, or ``None`` when its consumer reads none.""" + if not supports_response_attachments(head.dubbo_version): + return None + return {**attachments, DUBBO_VERSION_KEY: DUBBO_VERSION} + + def _fail(self, connection: DubboConnection, two_way: bool, request_id: int, status: int, message: str) -> None: + if two_way: + connection.write_frame(0, status, request_id, self._responses.encode_message(message)) + + +def _max_concurrent_calls(url: URL) -> int: + """Return the calls a server of ``url`` runs at once, from ``max-concurrent-calls``; 200 when absent, 0 for any number. + + Raises: + ValueError: The parameter is negative. + """ + limit = url.get_parameter(MAX_CONCURRENT_CALLS_KEY, int, DEFAULT_MAX_CONCURRENT_CALLS) + if limit < 0: + raise ValueError(f"{MAX_CONCURRENT_CALLS_KEY} must not be negative") + return limit + + +def _timeout(value: object) -> float | None: + """Return the seconds the ``timeout`` attachment ``value`` gives a call, or ``None`` for no positive whole milliseconds.""" + if isinstance(value, int) and not isinstance(value, bool): + value = str(value) + if not isinstance(value, str): + return None + try: + seconds = milliseconds(value) + except (ValueError, OverflowError): + return None + return seconds or None + + +def _serialization_name(serialization_id: int) -> str: + """Return the name of the serialization ``serialization_id`` stands for, with the id.""" + names = [name for name, value in SERIALIZATION_IDS.items() if value == serialization_id] + return f"{names[0]} ({serialization_id})" if names else f"serialization {serialization_id}" + + +class _NotFound(Exception): + """No exported service or method matches a request.""" diff --git a/src/dubbo/protocol/exported.py b/src/dubbo/protocol/exported.py new file mode 100644 index 00000000..ad4f0051 --- /dev/null +++ b/src/dubbo/protocol/exported.py @@ -0,0 +1,138 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""How the services of an application are served on their protocols, through filters that override rules change.""" + +import logging +from collections.abc import AsyncGenerator, Callable, Mapping, Sequence +from contextlib import asynccontextmanager + +import anyio +import attrs + +from dubbo.config import DubboConfig +from dubbo.config.urls import service_registries +from dubbo.extension import ApplicationScope, ExtensionError +from dubbo.filter import chain_filters, get_service_filters +from dubbo.protocol import Exporter, get_protocol +from dubbo.rpc.definition import Service +from dubbo.rpc.invocation import Invocation, Invoker, Result +from dubbo.rpc.server import ServiceInvoker +from dubbo.url import URL + +__all__ = ["ExportedService", "export_services"] + +_logger = logging.getLogger(__name__) + + +@attrs.define(frozen=True, kw_only=True) +class ExportedService: + """A service served on one of its protocols, ready to be registered. + + Attributes: + interface: Interface name of the service. + definition: The contract of the service. + url: The URL its exporter serves, with the port actually bound. + reconfigure: What applies to how it serves the parameters that the + override rules of providers change, all of them each time. + registries: The URL of each registry to register the service with, + unless it sets ``register`` to false. + """ + + interface: str + definition: Service + url: URL + reconfigure: Callable[[Mapping[str, str]], None] + registries: Sequence[URL] + + +@asynccontextmanager +async def export_services( + config: DubboConfig, urls: Mapping[str, list[URL]], services: Mapping[str, Service], scope: ApplicationScope +) -> AsyncGenerator[list[ExportedService]]: + """Serve each of ``services`` with its ``urls`` until the context exits. + + Each serves its calls through the filters its settings add and + ``service.filter`` names, which follow the override rules that + `dubbo.registry.provider.register_services` applies. + """ + exporters: list[Exporter] = [] + try: + exported = [] + for interface, service in services.items(): + registries = service_registries(config, interface, scope) + for url in urls[interface]: + protocol = await get_protocol(url.protocol, scope) + # ty reads the attrs field `url` as leaving the property of `Invoker` abstract. + invoker = _Reconfigurable(ServiceInvoker(url=url, service=service), url) # ty: ignore[abstract-class-instantiation] + exporter = await protocol.export(url, service, invoker) + exporters.append(exporter) + exported.append( + ExportedService( + interface=interface, + definition=service, + url=exporter.url, + reconfigure=invoker.reconfigure, + registries=registries, + ) + ) + + yield exported + finally: + # The exporters close together, so that their running calls share one grace period. + async with anyio.create_task_group() as task_group: + for exporter in exporters: + task_group.start_soon(exporter.aclose) + + +class _Reconfigurable(Invoker): + """Serves the calls of a service through the filters of its URL with the parameters the override rules change.""" + + def __init__(self, service: ServiceInvoker, url: URL) -> None: + self._service = service + self._url = url + self._chain = chain_filters(service, get_service_filters(url)) + + @property + def url(self) -> URL: + return self._url + + @property + def available(self) -> bool: + return self._service.available + + def reconfigure(self, changes: Mapping[str, str]) -> None: + """Serve the calls from now on through the filters of the URL updated with ``changes``, every parameter the rules change. + + Calls already running finish through the filters they started with. + Filters that the changed URL cannot create leave those before. + """ + url = self._url.update_parameters(changes) + try: + self._chain = chain_filters(self._service, get_service_filters(url)) + except (ValueError, ExtensionError): + _logger.warning( + "Cannot apply the override rules of %s; its calls keep their filters", + self._url.service_key, + exc_info=True, + ) + + async def invoke(self, invocation: Invocation) -> Result: + return await self._chain.invoke(invocation) + + async def aclose(self) -> None: + await self._service.aclose() diff --git a/src/dubbo/protocol/generic.py b/src/dubbo/protocol/generic.py new file mode 100644 index 00000000..046aa98c --- /dev/null +++ b/src/dubbo/protocol/generic.py @@ -0,0 +1,219 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Generic calls in a format of Java objects: ``$invoke`` naming the method called, in each mode it can take.""" + +import dataclasses +import datetime +import enum +import functools +import types +import typing +from collections.abc import Collection, Mapping, Sequence +from typing import Any + +import attrs + +from dubbo.constants import DEFAULT_GENERIC, GENERIC_KEY +from dubbo.exceptions import RpcError, Status +from dubbo.rpc.definition import Method, Parameter, RpcType, Service +from dubbo.rpc.invocation import Invocation, Invoke, Result +from dubbo.serialization import JavaSerialization +from dubbo.utils.annotations import TYPE_ALIASES, UNIONS + +from .java import java_type_name + +__all__ = ["GENERIC_INVOKE", "GenericInvoker", "builtin_methods", "invoke_arguments"] + +# A generic call carries the method name, the Java parameter types or null, then the arguments or null for none. +GENERIC_INVOKE = Method( + name="$invoke", + request=( + Parameter(name="method", type=str), + Parameter(name="types", type=tuple[str, ...] | None), + Parameter(name="arguments", type=tuple[Any, ...] | None), + ), + response=Any, +) +# The method names that serve generic calls. +_GENERIC_METHODS = (GENERIC_INVOKE, attrs.evolve(GENERIC_INVOKE, name="$invokeAsync")) +# The echo method, which returns its argument. +_ECHO = Method(name="$echo", request=(Parameter(name="value", type=Any),), response=Any) + +# The annotations of the java.time values a generic call carries as text: LocalDate, LocalDateTime and LocalTime. +_TIMES = (datetime.date, datetime.datetime, datetime.time) + + +def invoke_arguments(serialization: JavaSerialization, method: Method, arguments: tuple[Any, ...]) -> tuple[Any, ...]: + """Return the arguments of `GENERIC_INVOKE` that call ``method`` with ``arguments``. + + The Java parameter types are ``None`` when the parameters are all `Any`, + which leaves the provider to find the method by its name. + """ + if all(parameter.type is Any for parameter in method.request): + return method.name, None, arguments + + return method.name, tuple(java_type_name(serialization, parameter.type) for parameter in method.request), arguments + + +def builtin_methods( + definition: Service, invoke: Invoke, serialization: JavaSerialization +) -> list[tuple[Method, Invoke]]: + """Return the methods every service serves in a format of Java objects, with what serves each, but those ``definition`` declares. + + ``$invoke`` and ``$invokeAsync`` call a unary method of ``definition`` by + name through ``invoke``, as a `GenericInvoker` serves them, and + ``$echo`` returns its argument. + """ + generic = GenericInvoker(invoke, definition, serialization) + declared = {method.name for method in definition.methods} + builtins = [*((method, generic.invoke) for method in _GENERIC_METHODS), (_ECHO, _echo)] + return [(method, serve) for method, serve in builtins if method.name not in declared] + + +class GenericInvoker: + """Serves the generic calls of the unary methods of a service, each naming the method it calls. + + It takes an invocation of `GENERIC_INVOKE` and calls ``invoke`` with one + of the method named, as a call of the contract would, with the mode of its + ``generic`` attachment, ``true`` when absent. A call of a mode it does + not serve, or of a method the service has not, fails with UNIMPLEMENTED, + and one whose arguments stand for none of the method with + INVALID_ARGUMENT. Of the modes, it serves ``true``: objects travel as maps + naming their Java class under ``"class"``, filled into the classes the + parameters declare; enums travel as their names, and the dates and times + of java.time as the text of their ``toString``. + """ + + def __init__(self, invoke: Invoke, service: Service, serialization: JavaSerialization) -> None: + self._invoke = invoke + self._interface = service.interface + self._methods = {method.name: method for method in service.methods if method.rpc_type is RpcType.UNARY} + self._serialization = serialization + self._any = serialization.codec((Any,)) + # The arguments of each method, decoded as its parameters type them, which fills a class from a map. + self._arguments = { + method.name: serialization.codec((types.GenericAlias(tuple, tuple(p.type for p in method.request)),)) + for method in self._methods.values() + } + + async def invoke(self, invocation: Invocation) -> Result: + name, _, arguments = invocation.arguments + mode = invocation.attachments.get(GENERIC_KEY) or DEFAULT_GENERIC + if mode != DEFAULT_GENERIC: + return Result(error=RpcError(Status.UNIMPLEMENTED, f"generic calls of the mode {mode!r} are not served")) + method = self._methods.get(name) + if method is None: + return Result(error=RpcError(Status.UNIMPLEMENTED, f"{self._interface} has no unary method {name!r}")) + + try: + arguments = self._realize(method, arguments or ()) + except (TypeError, ValueError) as error: + message = f"the arguments of {name} stand for none of its parameters: {error}" + return Result(error=RpcError(Status.INVALID_ARGUMENT, message)) + called = attrs.evolve(invocation, method=name, definition=method, arguments=arguments, generic=mode) + result = await self._invoke(called) + if result.error is not None: + return result + + try: + value = self._serialization.generalize(result.value, method.response) + except (TypeError, ValueError) as error: + message = f"cannot return the result of {name} generically: {error}" + return Result(error=RpcError(Status.INTERNAL, message), attachments=result.attachments) + return attrs.evolve(result, value=value) + + def _realize(self, method: Method, arguments: Sequence[Any]) -> tuple[Any, ...]: + """Return the arguments of ``method`` that ``arguments``, as the call sent them, stand for. + + Raises: + TypeError: ``arguments`` cannot be read as the parameters. + ValueError: ``arguments`` stand for no arguments of ``method``. + """ + named = tuple( + _restore(argument, parameter.type) for argument, parameter in zip(arguments, method.request, strict=True) + ) + return self._arguments[method.name].decode(self._any.encode((named,)))[0] + + +async def _echo(invocation: Invocation) -> Result: + return Result(value=invocation.arguments[0]) + + +def _restore(value: Any, annotation: Any) -> Any: + """Return ``value``, which stands for a value of ``annotation``, with the enum names and the java.time texts within it as the values they name. + + Raises: + ValueError: A name is of no member of its enum, a text is of no + date or time, or a fixed-length tuple has another length. + """ + if isinstance(annotation, TYPE_ALIASES): + return _restore(value, annotation.__value__) + origin = typing.get_origin(annotation) + args = typing.get_args(annotation) + if origin is typing.Annotated: + return _restore(value, args[0]) + if origin in UNIONS: + arms = [arm for arm in args if arm is not type(None)] + enums = [arm for arm in arms if isinstance(arm, type) and issubclass(arm, enum.Enum)] + if isinstance(value, str) and enums: + return _restore(value, enums[0]) + + return _restore(value, arms[0]) if len(arms) == 1 else value + if isinstance(value, str) and annotation in _TIMES: + # A java.time value travels as the text of its toString, which is ISO 8601. + return annotation.fromisoformat(value) + if isinstance(annotation, type) and issubclass(annotation, enum.Enum): + if not isinstance(value, str): + return value + try: + return annotation[value] + except KeyError: + raise ValueError(f"{value!r} is no member of {annotation.__name__}") from None + if isinstance(value, dict): + if _is_collection(origin, Mapping) and args: + return {_restore(k, args[0]): _restore(item, args[1]) for k, item in value.items()} + if isinstance(annotation, type) and (dataclasses.is_dataclass(annotation) or attrs.has(annotation)): + fields = _field_types(annotation) + return {key: _restore(item, fields[key]) if key in fields else item for key, item in value.items()} + return value + if isinstance(value, list | tuple | set | frozenset) and _is_collection(origin, Collection) and args: + if origin is tuple and args[-1] is not Ellipsis: + return [_restore(v, a) for v, a in zip(value, args, strict=True)] + return [_restore(v, args[0]) for v in value] + + return value + + +def _is_collection(origin: Any, kind: type) -> bool: + return isinstance(origin, type) and issubclass(origin, kind) + + +@functools.cache +def _field_types(cls: type) -> dict[str, Any]: + """Return the annotations of the fields of ``cls``, by their Python names and the camelCase names they travel under. + + The camelCase name of ``_main_color`` is ``_mainColor``. + """ + hints = typing.get_type_hints(cls, include_extras=True) + fields = {} + for name, hint in hints.items(): + fields[name] = hint + core = name.lstrip("_") + first, *rest = core.split("_") + fields[name[: len(name) - len(core)] + first + "".join(part[:1].upper() + part[1:] for part in rest)] = hint + return fields diff --git a/src/dubbo/protocol/invocation.py b/src/dubbo/protocol/invocation.py deleted file mode 100644 index 400361dc..00000000 --- a/src/dubbo/protocol/invocation.py +++ /dev/null @@ -1,81 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from typing import Any, Optional - -from ._interfaces import Invocation - - -class RpcInvocation(Invocation): - """ - The RpcInvocation class is an implementation of the Invocation interface. - """ - - __slots__ = [ - "_service_name", - "_method_name", - "_argument", - "_attachments", - "_attributes", - ] - - def __init__( - self, - service_name: str, - method_name: str, - argument: Any, - attachments: Optional[dict[str, str]] = None, - attributes: Optional[dict[str, Any]] = None, - ): - """ - Initialize a new RpcInvocation instance. - :param service_name: The service name. - :type service_name: str - :param method_name: The method name. - :type method_name: str - :param argument: The argument. - :type argument: Any - :param attachments: The attachments. - :type attachments: Optional[Dict[str, str]] - :param attributes: The attributes. - :type attributes: Optional[Dict[str, Any]] - """ - self._service_name = service_name - self._method_name = method_name - self._argument = argument - self._attachments = attachments or {} - self._attributes = attributes or {} - - def add_attachment(self, key: str, value: str) -> None: - self._attachments[key] = value - - def get_attachment(self, key: str) -> Optional[str]: - return self._attachments.get(key, None) - - def add_attribute(self, key: str, value: Any) -> None: - self._attributes[key] = value - - def get_attribute(self, key: str) -> Optional[Any]: - return self._attributes.get(key, None) - - def get_service_name(self) -> str: - return self._service_name - - def get_method_name(self) -> str: - return self._method_name - - def get_argument(self) -> Any: - return self._argument diff --git a/src/dubbo/protocol/java.py b/src/dubbo/protocol/java.py new file mode 100644 index 00000000..8629d836 --- /dev/null +++ b/src/dubbo/protocol/java.py @@ -0,0 +1,211 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""How the protocols that call Java methods name Python types and errors in Java, such as Dubbo and Triple wrapping. + +What each Python type stands for in Java comes from the serialization for the +types it declares, and from the rules here for the others. +""" + +import collections.abc +import typing +from typing import Annotated, Any + +from dubbo.exceptions import RemoteError, RpcError, Status +from dubbo.rpc.definition import JavaType, Method +from dubbo.serialization import JavaSerialization +from dubbo.utils.annotations import TYPE_ALIASES, UNIONS + +__all__ = [ + "caller_error", + "java_exception", + "java_type_name", + "method_descriptor", +] + +# The Java type each Python type stands for when the serialization names none. +_TYPES: dict[Any, str] = { + bool: "boolean", + int: "int", + float: "double", + str: "java.lang.String", + bytes: "[B", + Any: "java.lang.Object", + object: "java.lang.Object", + Exception: "java.lang.Throwable", + None: "void", +} +_COLLECTIONS: dict[Any, str] = { + **dict.fromkeys( + (list, collections.abc.Sequence, collections.abc.MutableSequence, collections.abc.Collection), + "java.util.List", + ), + **dict.fromkeys((set, frozenset, collections.abc.Set, collections.abc.MutableSet), "java.util.Set"), + **dict.fromkeys((dict, collections.abc.Mapping, collections.abc.MutableMapping), "java.util.Map"), +} +# The box of each primitive, which ``X | None`` stands for. +_BOXES = { + "boolean": "java.lang.Boolean", + "byte": "java.lang.Byte", + "char": "java.lang.Character", + "short": "java.lang.Short", + "int": "java.lang.Integer", + "long": "java.lang.Long", + "float": "java.lang.Float", + "double": "java.lang.Double", +} +# The descriptor of each primitive, from the Java Virtual Machine Specification, 4.3.2. +_PRIMITIVE_DESCRIPTORS = { + "boolean": "Z", + "byte": "B", + "char": "C", + "short": "S", + "int": "I", + "long": "J", + "float": "F", + "double": "D", +} + + +# The exception a status travels as, and the class of an exception from Python that names none. +_RPC_EXCEPTION = "org.apache.dubbo.rpc.RpcException" +_RUNTIME_EXCEPTION = "java.lang.RuntimeException" +# The code of RpcException for each status, and the status of each code, shared with every language. +_CODES: dict[Status, int] = { + Status.DEADLINE_EXCEEDED: 2, # TIMEOUT_EXCEPTION + Status.PERMISSION_DENIED: 4, # FORBIDDEN_EXCEPTION + Status.UNAVAILABLE: 1, # NETWORK_EXCEPTION + Status.UNIMPLEMENTED: 11, # METHOD_NOT_FOUND +} +_UNKNOWN_EXCEPTION = 0 +_STATUSES: dict[int, Status] = { + 2: Status.DEADLINE_EXCEEDED, # TIMEOUT_EXCEPTION + 8: Status.DEADLINE_EXCEEDED, # TIMEOUT_TERMINATE + 4: Status.PERMISSION_DENIED, # FORBIDDEN_EXCEPTION + 13: Status.UNAUTHENTICATED, # AUTHORIZATION_EXCEPTION + 7: Status.UNAVAILABLE, # LIMIT_EXCEEDED_EXCEPTION + 1: Status.UNAVAILABLE, # NETWORK_EXCEPTION + 11: Status.UNIMPLEMENTED, # METHOD_NOT_FOUND + 5: Status.INTERNAL, # SERIALIZATION_EXCEPTION +} + + +def method_descriptor(serialization: JavaSerialization, method: Method) -> str: + """Return the descriptor of the parameters of ``method``, such as ``Ljava/lang/String;J``. + + A Java provider finds the method by its name and this descriptor, so it + must match the Java declaration exactly; `java_type_name` gives the Java + type of each parameter. + + Raises: + TypeError: A parameter has a type with no Java type. + """ + try: + return "".join(_descriptor(java_type_name(serialization, parameter.type)) for parameter in method.request) + except TypeError as error: + raise TypeError(f"{method.name} has a parameter with no Java type: {error}") from None + + +def java_type_name(serialization: JavaSerialization, annotation: Any) -> str: + """Return the Java type a value of ``annotation`` stands for, named as ``Class.getName`` names it. + + The serialization names the types it declares, such as ``com.example.User`` + for a class it carries under that name. Of the others, ``int``, ``bool`` + and ``float`` stand for ``int``, ``boolean`` and ``double``, and each of + them ``| None`` for its box, such as ``java.lang.Integer``; ``str`` and + ``bytes`` for ``java.lang.String`` and ``byte[]``, ``tuple[X, ...]`` for + an array, lists, sets and dicts for ``java.util.List``, ``Set`` and + ``Map``, ``Any`` for ``java.lang.Object``, ``Exception`` for + ``java.lang.Throwable``, and ``None``, the response of a method that + returns nothing, for ``void``. A `JavaType` in the metadata of an + ``Annotated`` names the type over all of these. + + Raises: + TypeError: ``annotation`` has no Java type. + """ + if isinstance(annotation, TYPE_ALIASES): + return java_type_name(serialization, annotation.__value__) + if typing.get_origin(annotation) is Annotated: + named = [metadata for metadata in annotation.__metadata__ if isinstance(metadata, JavaType)] + if named: + return named[-1].name + name = serialization.java_type(annotation) + if name is not None: + return name + if annotation in _TYPES: + return _TYPES[annotation] + if annotation in _COLLECTIONS: + return _COLLECTIONS[annotation] + + origin = typing.get_origin(annotation) + if origin in UNIONS: + members = [member for member in typing.get_args(annotation) if member is not type(None)] + if len(members) != 1: + raise TypeError(f"{annotation!r} names several Java types") + name = java_type_name(serialization, members[0]) + return _BOXES.get(name, name) + if origin is Annotated: + return java_type_name(serialization, annotation.__origin__) + if origin is tuple: + arguments = typing.get_args(annotation) + if len(arguments) != 2 or arguments[1] is not Ellipsis: + raise TypeError(f"{annotation!r} is no Java array; write tuple[X, ...]") + component = java_type_name(serialization, arguments[0]) + return "[" + (component if component.startswith("[") else _descriptor(component).replace("/", ".")) + if origin in _COLLECTIONS: + return _COLLECTIONS[origin] + + raise TypeError(f"{annotation!r} has no Java type") + + +def java_exception(serialization: JavaSerialization, error: Exception) -> Exception: + """Return the exception a Java caller receives when a handler raises ``error``. + + A `RemoteError`, and an exception of a class the serialization declares, + travel as they are. Another `RpcError` travels as an + ``org.apache.dubbo.rpc.RpcException`` whose ``code`` stands for its + status, and any other exception as a ``java.lang.RuntimeException`` + naming its Python class. + """ + if isinstance(error, RemoteError): + return error + if isinstance(error, RpcError): + code = _CODES.get(error.status, _UNKNOWN_EXCEPTION) + return RemoteError(_RPC_EXCEPTION, error.message, fields={"code": code}, status=error.status) + if serialization.java_type(type(error)) is not None: + return error + + return RemoteError(_RUNTIME_EXCEPTION, f"{type(error).__name__}: {error}") + + +def caller_error(error: RemoteError) -> RemoteError: + """Return the error a caller receives for a Java exception: an ``RpcException`` takes the status of its code.""" + if error.class_name != _RPC_EXCEPTION: + return error + + code = error.fields.get("code") + status = _STATUSES.get(code, Status.UNKNOWN) if isinstance(code, int) else Status.UNKNOWN + return RemoteError(error.class_name, error.message, fields=error.fields, status=status) + + +def _descriptor(name: str) -> str: + """Return the descriptor of a Java type named as ``Class.getName`` names it, such as ``J`` for ``long``.""" + if name in _PRIMITIVE_DESCRIPTORS: + return _PRIMITIVE_DESCRIPTORS[name] + + internal = name.replace(".", "/") + return internal if internal.startswith("[") else f"L{internal};" diff --git a/src/dubbo/protocol/served.py b/src/dubbo/protocol/served.py new file mode 100644 index 00000000..1a79bb98 --- /dev/null +++ b/src/dubbo/protocol/served.py @@ -0,0 +1,314 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""What the Dubbo and Triple protocols share: the servers they open and the services each serves, the clients their invokers share, and the calls the invokers make.""" + +import asyncio +from collections.abc import Awaitable, Callable, Hashable +from contextlib import AsyncExitStack +from typing import Any, Generic, Protocol, TypeVar + +import anyio +import attrs + +from dubbo.constants import DEFAULT_TIMEOUT, TIMEOUT_KEY +from dubbo.exceptions import RpcError, Status +from dubbo.extension import Resource +from dubbo.rpc.invocation import Invoker, Result +from dubbo.url import URL, service_key +from dubbo.utils import wait_then_cancel +from dubbo.utils.converters import milliseconds + +from .base import Exporter + +__all__ = ["Calls", "ClientPool", "ServedExporter", "ServedService", "Servers", "call_within", "method_timeout"] + + +@attrs.define(eq=False, kw_only=True) +class ServedService: + """A service exported on a server, which tracks the tasks of its running calls so that closing can end them.""" + + interface: str + group: str + version: str + invoker: Invoker + _calls: set[asyncio.Task[Any]] = attrs.field(factory=set, init=False) + + @property + def key(self) -> str: + """The Dubbo key of the service: ``group/interface:version``, leaving out an empty group or version.""" + return service_key(self.interface, self.group, self.version) + + def track(self, task: asyncio.Task[Any]) -> None: + """Track ``task``, which serves a call, as a running call until it finishes.""" + self._calls.add(task) + task.add_done_callback(self._calls.discard) + + async def drain(self, grace: float) -> None: + """Wait up to ``grace`` seconds for the running calls, once no new ones can start, then cancel the rest.""" + await wait_then_cancel(self._calls, grace) + + +class _Server(Resource, Protocol): + """What the services exported on one address share: a server that listens there while it is open.""" + + # Seconds an unexported service waits for its running calls before they are cancelled. + shutwait: float + + @property + def address(self) -> tuple[str, int]: + """The host and the port the server listens on.""" + ... + + def check(self, url: URL) -> None: + """Check that ``url`` asks for the settings the server runs with. + + Raises: + ValueError: A setting differs. + """ + ... + + def remove(self, service: ServedService) -> None: + """Stop serving ``service``; its new calls fail so that callers retry with another provider.""" + ... + + def announce_shutdown(self) -> None: + """Tell the callers that the server stops taking calls, while serving on.""" + ... + + +@attrs.define(kw_only=True, eq=False) +class ServedExporter(Exporter): + """A service exported on a server. + + Closing it removes the service from the server, whose new calls then + fail so that callers retry with another provider, waits for its running + calls as long as the server's ``shutwait``, and then cancels the rest. + """ + + server: _Server + service: ServedService + _url: URL = attrs.field(alias="url") + _closed: bool = attrs.field(default=False, init=False) + + @property + def url(self) -> URL: + return self._url + + async def aclose(self) -> None: + if self._closed: + return + + self._closed = True + self.server.remove(self.service) + await self.service.drain(self.server.shutwait) + + +_S = TypeVar("_S", bound=_Server) + + +class Servers(Resource, Generic[_S]): + """The servers a protocol opens, one for each address; closing closes them all.""" + + def __init__(self) -> None: + self._servers: dict[tuple[str, int], _S] = {} + self._stack = AsyncExitStack() + self._lock = anyio.Lock() + + async def serve(self, url: URL, create: Callable[[], _S], add: Callable[[_S], None]) -> _S: + """Return the server for the address of ``url``, once ``add`` has added a service to it. + + The first service on an address enters the server ``create`` makes, + which closes again should ``add`` fail. A later one shares that + server, whose settings ``url`` must ask for. + + Raises: + ValueError: The URL has no host, or asks for other settings than + the server on its address runs with. + Exception: What ``create``, entering the server or ``add`` raises. + """ + host = url.host + if host is None: + raise ValueError(f"a server needs a host to listen on: {url}") + + address = (host, url.port or 0) + async with self._lock: + server = self._servers.get(address) + if server is not None: + server.check(url) + add(server) + return server + + async with AsyncExitStack() as opening: + server = await opening.enter_async_context(create()) + add(server) + self._stack.push_async_exit(opening.pop_all()) + # A server on port 0 is also found under the port it was given. + self._servers[address] = self._servers[(host, server.address[1])] = server + return server + + def announce_shutdown(self) -> None: + for server in set(self._servers.values()): + server.announce_shutdown() + + async def aclose(self) -> None: + # The lock is held only while an export opens its server, so that a cancelled close still closes. + with anyio.CancelScope(shield=True): + await self._lock.acquire() + try: + self._servers = {} + await self._stack.aclose() + finally: + self._lock.release() + + +_C = TypeVar("_C", bound=Resource) + + +class ClientPool(Resource, Generic[_C]): + """The clients that the invokers of one protocol share, one for each key. + + Each `acquire` takes a share in the client of a key, opening it on first + use, and each share goes back with `release`; the last one closes the + client. Closing the pool closes the clients still shared. Clients hold no + task's cancel scope, so any task may acquire and release them. + """ + + def __init__(self) -> None: + self._shares: dict[Hashable, _Share[_C]] = {} + # The key of each client, by the client's id. + self._keys: dict[int, Hashable] = {} + self._closed = False + + async def acquire(self, key: Hashable, create: Callable[[], _C]) -> _C: + """Take a share in the client of ``key``, which the first share creates with ``create`` and enters. + + Raises: + RuntimeError: The pool is closed. + Exception: What ``create`` or entering the client raises. + """ + if self._closed: + raise RuntimeError("the client pool is closed") + + share = self._shares.get(key) + if share is not None: + share.shares += 1 + return share.client + + client = await create().__aenter__() + if self._closed: + await client.aclose() + raise RuntimeError("the client pool is closed") + + share = self._shares.get(key) + if share is None: + self._shares[key] = _Share(client=client, shares=1) + self._keys[id(client)] = key + return client + + # Another invoker created the client meanwhile; its share is taken before this one closes. + share.shares += 1 + try: + await client.aclose() + except BaseException: + await self.release(share.client) + raise + return share.client + + async def release(self, client: _C) -> None: + """Give back a share in ``client``, closing it when no share is left. + + Releasing a client the pool no longer holds does nothing. + """ + key = self._keys.get(id(client)) + if key is None: + return + + share = self._shares[key] + share.shares -= 1 + if share.shares: + return + + del self._shares[key], self._keys[id(client)] + await client.aclose() + + async def aclose(self) -> None: + """Close every client still shared, each even if closing another raises or is cancelled.""" + self._closed = True + shares = list(self._shares.values()) + self._shares.clear() + self._keys.clear() + + async with AsyncExitStack() as stack: + for share in shares: + stack.push_async_callback(share.client.aclose) + + +class Calls: + """The number of calls an invoker is making, which closing waits for.""" + + def __init__(self) -> None: + self._count = 0 + self._idle: anyio.Event | None = None + + def enter(self) -> None: + """Count a call that starts.""" + self._count += 1 + + def leave(self) -> None: + """Count a call that ends.""" + self._count -= 1 + if not self._count and self._idle is not None: + self._idle.set() + + async def drain(self, grace: float) -> None: + """Wait up to ``grace`` seconds for the calls under way to end.""" + if self._count: + self._idle = anyio.Event() + with anyio.move_on_after(grace): + await self._idle.wait() + + +@attrs.define(kw_only=True, eq=False) +class _Share(Generic[_C]): + client: _C + shares: int + + +async def call_within(timeout: float, method: str, call: Awaitable[Result]) -> Result: + """Return the result of ``call``, a call of ``method``, or one of ``DEADLINE_EXCEEDED`` once it has run ``timeout`` seconds.""" + # An asyncio timeout: a call runs 11% faster over Dubbo and 23% over Triple than in an AnyIO cancel + # scope, measured at 64 at once. + deadline = asyncio.timeout(timeout) + try: + async with deadline: + return await call + except TimeoutError: + if not deadline.expired(): + raise + + return Result(error=RpcError(Status.DEADLINE_EXCEEDED, f"{method} did not complete within {timeout} seconds")) + + +def method_timeout(url: URL, method: str) -> float: + """Return the seconds a unary call of ``method`` may take: the milliseconds of ``{method}.timeout``, else of ``timeout``; one second when both are absent. + + Raises: + ValueError: A timeout is no whole number of milliseconds. + """ + default = url.get_parameter(TIMEOUT_KEY, milliseconds, DEFAULT_TIMEOUT) + return url.get_parameter(f"{method}.{TIMEOUT_KEY}", milliseconds, default) diff --git a/src/dubbo/protocol/triple/__init__.py b/src/dubbo/protocol/triple/__init__.py index bcba37aa..a9714930 100644 --- a/src/dubbo/protocol/triple/__init__.py +++ b/src/dubbo/protocol/triple/__init__.py @@ -1,15 +1,21 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .exceptions import ErrorDetail, TripleError +from .protocol import TripleProtocol + +__all__ = ["ErrorDetail", "TripleError", "TripleProtocol"] diff --git a/src/dubbo/protocol/triple/attachments.py b/src/dubbo/protocol/triple/attachments.py new file mode 100644 index 00000000..6d15f2a5 --- /dev/null +++ b/src/dubbo/protocol/triple/attachments.py @@ -0,0 +1,120 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The attachments of a Triple call, which travel as header fields.""" + +import binascii +import json +import re +from collections.abc import Mapping + +from multidict import MultiDict + +from dubbo.transport.h2 import H2Header, H2Headers + +from .headers import HttpHeader, TripleHeader, decode_binary, encode_binary, percent_decode, percent_encode + +__all__ = ["attachment_headers", "split_headers"] + +# Fields the call itself uses; every other field is an attachment. +_RESERVED = frozenset({*HttpHeader, *TripleHeader}) +_RESERVED_PREFIXES = (b":", b"grpc-") +_ATTACHMENT_KEY = re.compile(r"[0-9a-z_.-]+") +_BINARY_SUFFIX = "-bin" + + +def split_headers(headers: H2Headers) -> tuple[dict[bytes, bytes], MultiDict[str | bytes]]: + """Split a field section into the fields the call uses and its attachments, keeping every value of a key. + + An attachment whose key ends with ``-bin`` is bytes, decoded from base64, + with each of comma-joined values taken apart; a value that is not valid + base64 is dropped. Attachment keys regain the case that + ``tri-header-convert`` records. + """ + fields: dict[bytes, bytes] = {} + attachments: MultiDict[str | bytes] = MultiDict() + for name, value in headers: + if name in _RESERVED or name.startswith(_RESERVED_PREFIXES): + fields[name] = value + continue + + key = name.decode("latin-1") + if not key.endswith(_BINARY_SUFFIX): + attachments.add(key, value.decode("utf-8", "replace")) + continue + + for part in value.split(b","): + encoded = part.strip() + try: + attachments.add(key, decode_binary(encoded)) + except binascii.Error: + continue + + converted = fields.get(TripleHeader.HEADER_CONVERT) + if converted is not None: + _restore_case(attachments, converted) + + return fields, attachments + + +def attachment_headers(attachments: Mapping[str, str | bytes]) -> list[H2Header]: + """Return the fields that carry ``attachments``, recording upper-case keys in ``tri-header-convert``. + + Each value of a key is a field of its own. A key ending with ``-bin`` + takes bytes, sent as base64 without padding; every other key takes + printable ASCII text. + + Raises: + ValueError: A key is not a valid field name, is reserved, or differs + from another only in case, or a value does not suit its key. + """ + headers: list[H2Header] = [] + converted: dict[str, str] = {} + for key, value in attachments.items(): + name = key.lower() + encoded = name.encode("ascii", "replace") + if not _ATTACHMENT_KEY.fullmatch(name) or encoded in _RESERVED or encoded.startswith(_RESERVED_PREFIXES): + raise ValueError(f"attachment key {key!r} cannot be a gRPC metadata name") + if name.endswith(_BINARY_SUFFIX): + if not isinstance(value, bytes): + raise ValueError(f"attachment {key!r} ends with {_BINARY_SUFFIX!r} and must be bytes") + data = encode_binary(value) + elif isinstance(value, str) and value.isascii() and value.isprintable(): + data = value.encode("ascii") + else: + raise ValueError(f"attachment {key!r} must be printable ASCII text") + if name != key and (converted.setdefault(name, key) != key or name in attachments): + raise ValueError(f"attachment keys differ only in case: {key!r}") + + headers.append((encoded, data)) + + if converted: + headers.append((TripleHeader.HEADER_CONVERT, percent_encode(json.dumps(converted, separators=(",", ":"))))) + + return headers + + +def _restore_case(attachments: MultiDict[str | bytes], converted: bytes) -> None: + try: + keys = json.loads(percent_decode(converted)) + except ValueError: + return + + if isinstance(keys, dict): + for name, key in keys.items(): + if isinstance(key, str) and name in attachments: + attachments.extend((key, value) for value in attachments.popall(name)) diff --git a/src/dubbo/protocol/triple/builtin/__init__.py b/src/dubbo/protocol/triple/builtin/__init__.py new file mode 100644 index 00000000..8b8f99f3 --- /dev/null +++ b/src/dubbo/protocol/triple/builtin/__init__.py @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .health import HealthService +from .reflection import ReflectionService, ReflectionV1AlphaService + +__all__ = ["HealthService", "ReflectionService", "ReflectionV1AlphaService"] diff --git a/src/dubbo/protocol/triple/builtin/health.py b/src/dubbo/protocol/triple/builtin/health.py new file mode 100644 index 00000000..971d07f0 --- /dev/null +++ b/src/dubbo/protocol/triple/builtin/health.py @@ -0,0 +1,113 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The gRPC health service, grpc.health.v1.Health.""" + +from collections.abc import Collection + +import anyio + +from dubbo._proto.grpc.health.v1.health_dubbo import Health, HealthServicer +from dubbo._proto.grpc.health.v1.health_pb2 import ( + HealthCheckRequest, + HealthCheckResponse, + HealthListRequest, + HealthListResponse, +) +from dubbo.exceptions import RpcError, Status +from dubbo.rpc.stream import SendStream + +__all__ = ["Health", "HealthService"] + +_SERVING = HealthCheckResponse.SERVING +_NOT_SERVING = HealthCheckResponse.NOT_SERVING +_SERVICE_UNKNOWN = HealthCheckResponse.SERVICE_UNKNOWN + + +class HealthService(HealthServicer): + """Reports the health of a server: SERVING for the server as a whole, named ``""``, and for each service it serves. + + A service is known by its interface and by its service key. One that + stops being served stays known as NOT_SERVING. Once the application + announces its shutdown, everything is NOT_SERVING; once the server + closes, watches end too. + """ + + def __init__(self) -> None: + self._statuses: dict[str, HealthCheckResponse.ServingStatus] = {"": _SERVING} + self._stopping = False + self._closed = False + # Replaced after every change, so a watch never misses one. + self._changed = anyio.Event() + + def update(self, services: Collection[str]) -> None: + """Report ``services`` as serving, and the other services known before as not serving.""" + if self._stopping: + return + + statuses = dict.fromkeys(self._statuses, _NOT_SERVING) | dict.fromkeys(services, _SERVING) + statuses[""] = _SERVING + self._change(statuses) + + def announce_shutdown(self) -> None: + """Report everything as not serving from now on, while the watches go on.""" + self._stopping = True + self._change(dict.fromkeys(self._statuses, _NOT_SERVING)) + + def close(self) -> None: + """Report everything as not serving, ending the watches.""" + if self._closed: + return + + self._stopping = self._closed = True + self._statuses = dict.fromkeys(self._statuses, _NOT_SERVING) + self._wake() + + async def check(self, request: HealthCheckRequest) -> HealthCheckResponse: + status = self._statuses.get(request.service) + if status is None: + raise RpcError(Status.NOT_FOUND, f"unknown service {request.service!r}") + return HealthCheckResponse(status=status) + + async def list(self, request: HealthListRequest) -> HealthListResponse: + return HealthListResponse( + statuses={name: HealthCheckResponse(status=status) for name, status in self._statuses.items()} + ) + + async def watch(self, request: HealthCheckRequest, stream: SendStream[HealthCheckResponse]) -> None: + sent = None + while True: + changed = self._changed + status = self._statuses.get(request.service, _SERVICE_UNKNOWN) + if status != sent: + await stream.send(HealthCheckResponse(status=status)) + sent = status + + if self._closed: + return + await changed.wait() + + def _change(self, statuses: dict[str, HealthCheckResponse.ServingStatus]) -> None: + if statuses == self._statuses: + return + + self._statuses = statuses + self._wake() + + def _wake(self) -> None: + self._changed.set() + self._changed = anyio.Event() diff --git a/src/dubbo/protocol/triple/builtin/reflection.py b/src/dubbo/protocol/triple/builtin/reflection.py new file mode 100644 index 00000000..fe54b45f --- /dev/null +++ b/src/dubbo/protocol/triple/builtin/reflection.py @@ -0,0 +1,159 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The gRPC reflection services, grpc.reflection.v1.ServerReflection and its earlier grpc.reflection.v1alpha.""" + +from collections.abc import Callable, Iterable +from typing import Any, ClassVar, TypeVar + +from google.protobuf import descriptor_pool +from google.protobuf.descriptor import FileDescriptor + +from dubbo._proto.grpc.reflection.v1 import reflection_dubbo as v1_dubbo +from dubbo._proto.grpc.reflection.v1 import reflection_pb2 as v1_pb2 +from dubbo._proto.grpc.reflection.v1alpha import reflection_dubbo as v1alpha_dubbo +from dubbo._proto.grpc.reflection.v1alpha import reflection_pb2 as v1alpha_pb2 +from dubbo._proto.pool import pool +from dubbo.exceptions import Status +from dubbo.rpc.stream import Stream + +__all__ = ["ReflectionService", "ReflectionV1AlphaService"] + +T = TypeVar("T") + + +class _Reflection: + """Describes the services of a server and the protobuf files that define them. + + Files are looked up among the framework's own protos, then in protobuf's + default pool, where generated modules register theirs. + + Args: + services: Returns the interfaces the server serves. + """ + + # The response message of the version served; the requests of both versions have the same fields. + _response: ClassVar[type[Any]] + + def __init__(self, services: Callable[[], Iterable[str]]) -> None: + self._services = services + self._pools = (pool, descriptor_pool.Default()) + + async def server_reflection_info(self, stream: Stream[Any, Any]) -> None: + async for request in stream: + await stream.send(self._respond(request)) + + def _respond(self, request: Any) -> Any: + response = self._response(valid_host=request.host, original_request=request) + + try: + match request.WhichOneof("message_request"): + case "list_services": + services = response.list_services_response.service + for name in sorted(self._services()): + services.add(name=name) + case "file_by_filename": + file = self._find(lambda p: p.FindFileByName(request.file_by_filename)) + response.file_descriptor_response.file_descriptor_proto.extend(_with_dependencies(file)) + case "file_containing_symbol": + file = self._find(lambda p: _symbol_file(p, request.file_containing_symbol)) + response.file_descriptor_response.file_descriptor_proto.extend(_with_dependencies(file)) + case "file_containing_extension": + extension = request.file_containing_extension + file = self._find( + lambda p: _extension_file(p, extension.containing_type, extension.extension_number) + ) + response.file_descriptor_response.file_descriptor_proto.extend(_with_dependencies(file)) + case "all_extension_numbers_of_type": + name = request.all_extension_numbers_of_type + numbers = self._find(lambda p: _extension_numbers(p, name)) + response.all_extension_numbers_response.base_type_name = name + response.all_extension_numbers_response.extension_number.extend(sorted(numbers)) + case _: + response.error_response.error_code = Status.INVALID_ARGUMENT + response.error_response.error_message = "the request asks for nothing" + except KeyError as error: + response.error_response.error_code = Status.NOT_FOUND + response.error_response.error_message = str(error.args[0] if error.args else error) + + return response + + def _find(self, lookup: Callable[[descriptor_pool.DescriptorPool], T]) -> T: + """Return what ``lookup`` finds in the first pool that has it. + + Raises: + KeyError: No pool has it. + """ + for each in self._pools[:-1]: + try: + return lookup(each) + except KeyError: + pass + + return lookup(self._pools[-1]) + + +class ReflectionService(_Reflection, v1_dubbo.ServerReflectionServicer): + """Serves grpc.reflection.v1.ServerReflection.""" + + _response = v1_pb2.ServerReflectionResponse + + +class ReflectionV1AlphaService(_Reflection, v1alpha_dubbo.ServerReflectionServicer): + """Serves grpc.reflection.v1alpha.ServerReflection, for clients that do not know v1.""" + + _response = v1alpha_pb2.ServerReflectionResponse + + +def _symbol_file(pool: descriptor_pool.DescriptorPool, symbol: str) -> FileDescriptor: + try: + return pool.FindFileContainingSymbol(symbol) + except KeyError: + # The pool finds no methods by name; a method is found through its service. + name, _, method = symbol.rpartition(".") + try: + service = pool.FindServiceByName(name) + except KeyError: + pass + else: + if method in service.methods_by_name: + return service.file + raise + + +def _extension_file(pool: descriptor_pool.DescriptorPool, containing_type: str, number: int) -> FileDescriptor: + message = pool.FindMessageTypeByName(containing_type) + found = pool.FindExtensionByNumber(message, number) + return pool.FindFileContainingSymbol(found.full_name) + + +def _extension_numbers(pool: descriptor_pool.DescriptorPool, name: str) -> list[int]: + message = pool.FindMessageTypeByName(name) + return [extension.number for extension in pool.FindAllExtensions(message)] + + +def _with_dependencies(file: FileDescriptor) -> list[bytes]: + """Return ``file`` and every file it imports, directly or not, as serialized FileDescriptorProtos.""" + found: dict[str, bytes] = {} + pending = [file] + while pending: + current = pending.pop() + if current.name not in found: + found[current.name] = current.serialized_pb + pending.extend(current.dependencies) + + return list(found.values()) diff --git a/src/dubbo/protocol/triple/call/__init__.py b/src/dubbo/protocol/triple/call/__init__.py deleted file mode 100644 index d2749784..00000000 --- a/src/dubbo/protocol/triple/call/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from ._interfaces import ClientCall, ServerCall -from .client_call import TripleClientCall - -__all__ = ["ClientCall", "ServerCall", "TripleClientCall"] diff --git a/src/dubbo/protocol/triple/call/_interfaces.py b/src/dubbo/protocol/triple/call/_interfaces.py deleted file mode 100644 index 65c84bff..00000000 --- a/src/dubbo/protocol/triple/call/_interfaces.py +++ /dev/null @@ -1,143 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc -from typing import Any - -from dubbo.protocol.triple.metadata import RequestMetadata -from dubbo.protocol.triple.status import TriRpcStatus - -__all__ = ["ClientCall", "ServerCall"] - - -class ClientCall(abc.ABC): - """ - Interface for client call. - """ - - @abc.abstractmethod - def start(self, metadata: RequestMetadata) -> None: - """ - Start this call. - - :param metadata: call metadata - :type metadata: RequestMetadata - """ - raise NotImplementedError() - - @abc.abstractmethod - def send_message(self, message: Any, last: bool) -> None: - """ - Send message to server. - - :param message: message to send - :type message: Any - :param last: whether this message is the last one - :type last: bool - """ - raise NotImplementedError() - - @abc.abstractmethod - def cancel_by_local(self, e: Exception) -> None: - """ - Cancel this call by local. - - :param e: The exception that caused the call to be canceled - :type e: Exception - """ - raise NotImplementedError() - - class Listener(abc.ABC): - """ - Interface for client call listener. - """ - - @abc.abstractmethod - def on_message(self, message: Any) -> None: - """ - Called when a message is received from server. - - :param message: received message - :type message: Any - """ - raise NotImplementedError() - - @abc.abstractmethod - def on_close(self, status: TriRpcStatus, trailers: dict[str, Any]) -> None: - """ - Called when the call is closed. - - :param status: call status - :type status: TriRpcStatus - :param trailers: trailers - :type trailers: Dict[str, Any] - """ - raise NotImplementedError() - - -class ServerCall(abc.ABC): - """ - Interface for server call. - """ - - @abc.abstractmethod - def send_message(self, message: Any) -> None: - """ - Send message to client. - - :param message: message to send - :type message: Any - """ - raise NotImplementedError() - - @abc.abstractmethod - def complete(self, status: TriRpcStatus, attachments: dict[str, Any]) -> None: - """ - Complete this call. - - :param status: call status - :type status: TriRpcStatus - :param attachments: attachments - :type attachments: Dict[str, Any] - """ - raise NotImplementedError() - - class Listener(abc.ABC): - """ - Interface for server call listener. - """ - - @abc.abstractmethod - def on_message(self, message: Any, last: bool) -> None: - """ - Called when a message is received from client. - - :param message: received message - :type message: Any - :param last: whether this message is the last one - :type last: bool - """ - raise NotImplementedError() - - @abc.abstractmethod - def on_close(self, status: TriRpcStatus) -> None: - """ - Called when the call is closed. - - :param status: call status - :type status: TriRpcStatus - """ - raise NotImplementedError() diff --git a/src/dubbo/protocol/triple/call/client_call.py b/src/dubbo/protocol/triple/call/client_call.py deleted file mode 100644 index 676826f7..00000000 --- a/src/dubbo/protocol/triple/call/client_call.py +++ /dev/null @@ -1,197 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from typing import Any, Optional - -from dubbo.compression import Compressor, Identity -from dubbo.loggers import loggerFactory -from dubbo.protocol.triple.call import ClientCall -from dubbo.protocol.triple.constants import GRpcCode -from dubbo.protocol.triple.metadata import RequestMetadata -from dubbo.protocol.triple.status import TriRpcStatus -from dubbo.protocol.triple.stream import ClientStream -from dubbo.protocol.triple.stream.client_stream import TriClientStream -from dubbo.remoting.aio.http2.stream_handler import StreamClientMultiplexHandler -from dubbo.serialization import Deserializer, SerializationError, Serializer - -__all__ = [ - "TripleClientCall", - "FutureToClientCallListenerAdapter", - "ReadStreamToClientCallListenerAdapter", -] - -from dubbo.utils import FunctionHelper - -_LOGGER = loggerFactory.get_logger() - - -class TripleClientCall(ClientCall, ClientStream.Listener): - """ - Triple client call. - """ - - def __init__( - self, - stream_factory: StreamClientMultiplexHandler, - listener: ClientCall.Listener, - serializer: Serializer, - deserializer: Deserializer, - ): - self._stream_factory = stream_factory - self._client_stream: Optional[ClientStream] = None - self._listener = listener - self._serializer = serializer - self._deserializer = deserializer - self._compressor: Optional[Compressor] = None - - self._headers_sent = False - self._done = False - self._request_metadata: Optional[RequestMetadata] = None - - def start(self, metadata: RequestMetadata) -> None: - self._request_metadata = metadata - - # get compression from metadata - self._compressor = metadata.compressor - - # create a new stream - client_stream = TriClientStream(self, self._compressor) - h2_stream = self._stream_factory.create(client_stream.transport_listener) - client_stream.bind(h2_stream) - self._client_stream = client_stream - - def send_message(self, message: Any, last: bool) -> None: - if self._done: - _LOGGER.warning("Call is done, cannot send message") - return - - # check if headers are sent - if not self._headers_sent: - # send headers - self._headers_sent = True - self._client_stream.send_headers(self._request_metadata.to_headers()) - - # send message - try: - data = FunctionHelper.call_func(self._serializer.serialize, message) if message else b"" - compress_flag = 0 if self._compressor.get_message_encoding() == Identity.get_message_encoding() else 1 - self._client_stream.send_message(data, compress_flag, last) - except SerializationError as e: - _LOGGER.error("Failed to serialize message: %s", e) - # close the stream - self.cancel_by_local(e) - # close the listener - status = TriRpcStatus( - code=GRpcCode.INTERNAL, - description="Failed to serialize message", - ) - self._listener.on_close(status, {}) - - def cancel_by_local(self, e: Exception) -> None: - if self._done: - return - self._done = True - - if not self._client_stream or not self._headers_sent: - return - - status = TriRpcStatus( - code=GRpcCode.CANCELLED, - description=f"Call cancelled by client: {e}", - ) - self._client_stream.cancel_by_local(status) - - def on_message(self, data: bytes) -> None: - """ - Called when a message is received from server. - :param data: The message data - :type data: bytes - """ - if self._done: - _LOGGER.warning("Call is done, cannot receive message") - return - - try: - # Deserialize the message - message = self._deserializer.deserialize(data) - self._listener.on_message(message) - except SerializationError as e: - _LOGGER.error("Failed to deserialize message: %s", e) - # close the stream - self.cancel_by_local(e) - # close the listener - status = TriRpcStatus( - code=GRpcCode.INTERNAL, - description="Failed to deserialize message", - ) - self._listener.on_close(status, {}) - - def on_complete(self, status: TriRpcStatus, attachments: dict[str, Any]) -> None: - """ - Called when the call is completed. - :param status: The status - :type status: TriRpcStatus - :param attachments: The attachments - :type attachments: Dict[str, Any] - """ - if not self._done: - self._done = True - self._listener.on_close(status, attachments) - - def on_cancel_by_remote(self, status: TriRpcStatus) -> None: - """ - Called when the call is cancelled by remote. - :param status: The status - :type status: TriRpcStatus - """ - self.on_complete(status, {}) - - -class FutureToClientCallListenerAdapter(ClientCall.Listener): - """ - The future call listener. - """ - - def __init__(self, future): - self._future = future - self._message = None - - def on_message(self, message: Any) -> None: - self._message = message - - def on_close(self, status: TriRpcStatus, attachments: dict[str, Any]) -> None: - if status.code != GRpcCode.OK: - self._future.set_exception(status.as_exception()) - else: - self._future.set_result(self._message) - - -class ReadStreamToClientCallListenerAdapter(ClientCall.Listener): - """ - Adapter from stream to client call listener. - """ - - def __init__(self, read_stream): - self._read_stream = read_stream - - def on_message(self, message: Any) -> None: - self._read_stream.put(message) - - def on_close(self, status: TriRpcStatus, trailers: dict[str, Any]) -> None: - if status.code != GRpcCode.OK: - self._read_stream.put_exception(status.as_exception()) - else: - self._read_stream.put_eof() diff --git a/src/dubbo/protocol/triple/call/server_call.py b/src/dubbo/protocol/triple/call/server_call.py deleted file mode 100644 index d46947d1..00000000 --- a/src/dubbo/protocol/triple/call/server_call.py +++ /dev/null @@ -1,232 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc -from concurrent.futures import ThreadPoolExecutor -from typing import Any, Callable - -from dubbo.classes import ReadWriteStream -from dubbo.loggers import loggerFactory -from dubbo.protocol.triple.call import ServerCall -from dubbo.protocol.triple.constants import ( - GRpcCode, - TripleHeaderName, - TripleHeaderValue, -) -from dubbo.protocol.triple.status import TriRpcStatus -from dubbo.protocol.triple.stream import ServerStream -from dubbo.protocol.triple.streams import ( - TriReadStream, - TriReadWriteStream, - TriServerWriteStream, -) -from dubbo.proxy.handlers import RpcMethodHandler -from dubbo.remoting.aio.http2.headers import Http2Headers -from dubbo.remoting.aio.http2.registries import HttpStatus -from dubbo.serialization import ( - CustomDeserializer, - CustomSerializer, - DirectDeserializer, - DirectSerializer, -) -from dubbo.types import RpcType, RpcTypes -from dubbo.utils import FunctionHelper - -_LOGGER = loggerFactory.get_logger() - - -class TripleServerCall(ServerCall, ServerStream.Listener): - def __init__( - self, - server_stream: ServerStream, - method_handler: RpcMethodHandler, - executor: ThreadPoolExecutor, - ): - self._server_stream = server_stream - self._executor = executor - - # create read stream - self._read_stream = TriReadStream() - - # create write stream - write_stream = TriServerWriteStream(self) - read_write_stream = TriReadWriteStream(write_stream, self._read_stream) - - self._method_runner: MethodRunner = MethodRunnerFactory.create(method_handler, read_write_stream) - - # get method descriptor - method_descriptor = method_handler.method_descriptor - - # get arguments deserializer - arg_deserializer = method_descriptor.get_arg_deserializer() - self._deserializer = CustomDeserializer(arg_deserializer) if arg_deserializer else DirectDeserializer() - - # get return serializer - return_serializer = method_descriptor.get_return_serializer() - self._serializer = CustomSerializer(return_serializer) if return_serializer else DirectSerializer() - - self._headers_sent = False - - def send_message(self, message: Any) -> None: - if not self._headers_sent: - headers = Http2Headers() - headers.status = HttpStatus.OK.value - headers.add( - TripleHeaderName.CONTENT_TYPE.value, - TripleHeaderValue.APPLICATION_GRPC_PROTO.value, - ) - self._server_stream.send_headers(headers) - - serialized_data = FunctionHelper.call_func(self._serializer.serialize, message) - # TODO support compression - self._server_stream.send_message(serialized_data, False) - - def complete(self, status: TriRpcStatus, attachments: dict[str, Any]) -> None: - if not attachments.get(TripleHeaderName.CONTENT_TYPE.value): - attachments[TripleHeaderName.CONTENT_TYPE.value] = TripleHeaderValue.APPLICATION_GRPC_PROTO.value - self._server_stream.complete(status, attachments) - - def on_headers(self, headers: dict[str, Any]) -> None: - # start a new thread to run the method - self._executor.submit(self._method_runner.run) - - def on_message(self, data: bytes) -> None: - if data == b"": - return - deserialized_data = self._deserializer.deserialize(data) - self._read_stream.put(deserialized_data) - - def on_complete(self) -> None: - self._read_stream.put_eof() - - def on_cancel_by_remote(self, status: TriRpcStatus) -> None: - # cancel the method runner. - self._read_stream.put_exception(status.as_exception()) - - -class MethodRunner(abc.ABC): - """ - Interface for method runner. - """ - - @abc.abstractmethod - def run(self) -> None: - """ - Run the method. - """ - raise NotImplementedError() - - @abc.abstractmethod - def handle_result(self, result: Any) -> None: - """ - Handle the result. - :param result: result - :type result: Any - """ - raise NotImplementedError() - - @abc.abstractmethod - def handle_exception(self, e: Exception) -> None: - """ - Handle the exception. - :param e: exception. - :type e: Exception - """ - raise NotImplementedError() - - -class DefaultMethodRunner(MethodRunner): - """ - Abstract method runner. - """ - - def __init__( - self, - func: Callable, - read_write_stream: ReadWriteStream, - rpc_type: RpcType, - ): - self._read_write_stream = read_write_stream - self._func = func - - self._rpc_type = rpc_type - - def run(self) -> None: - try: - if self._rpc_type == RpcTypes.UNARY.value: - result = self._func(self._read_write_stream.read()) - else: - result = self._func(self._read_write_stream) - # handle the result - self.handle_result(result) - except Exception as e: - # handle the exception - self.handle_exception(e) - - def handle_result(self, result: Any) -> None: - try: - # check if the stream is completed - if not self._read_write_stream.can_write_more(): - return - - if not self._rpc_type.server_stream: - # get single result - self._read_write_stream.write(result) - else: - # get multi results - for message in result: - self._read_write_stream.write(message) - - self._read_write_stream.done_writing() - except Exception as e: - self.handle_exception(e) - - def handle_exception(self, e: Exception) -> None: - if self._read_write_stream.can_write_more(): - _LOGGER.exception("Invoke method failed: %s", e) - status = TriRpcStatus( - GRpcCode.INTERNAL, - description=f"Invoke method failed: {str(e)}", - cause=e, - ) - self._read_write_stream.done_writing(tri_rpc_status=status) - - -class MethodRunnerFactory: - """ - Factory for method runner. - """ - - @staticmethod - def create(method_handler: RpcMethodHandler, read_write_stream: ReadWriteStream) -> MethodRunner: - """ - Create a method runner. - - :param method_handler: method handler - :type method_handler: RpcMethodHandler - :param read_write_stream: read write stream - :type read_write_stream: ReadWriteStream - :return: method runner - :rtype: MethodRunner - """ - - method_descriptor = method_handler.method_descriptor - - return DefaultMethodRunner( - method_descriptor.get_method(), - read_write_stream, - method_descriptor.get_rpc_type(), - ) diff --git a/src/dubbo/protocol/triple/coders.py b/src/dubbo/protocol/triple/coders.py deleted file mode 100644 index 8eb67b8c..00000000 --- a/src/dubbo/protocol/triple/coders.py +++ /dev/null @@ -1,256 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc -import struct -from typing import Optional - -from dubbo.compression import Compressor, Decompressor -from dubbo.protocol.triple.exceptions import RpcError - -""" - gRPC Message Format Diagram (HTTP/2 Data Frame): - +----------------------+-------------------------+------------------+ - | HTTP Header | gRPC Header | Business Data | - +----------------------+-------------------------+------------------+ - | (variable length) | compressed-flag (1 byte)| data (variable) | - | | message length (4 byte) | | - +----------------------+-------------------------+------------------+ -""" - -__all__ = ["TriEncoder", "TriDecoder"] - -HEADER: str = "HEADER" -PAYLOAD: str = "PAYLOAD" - -# About HEADER -HEADER_LENGTH: int = 5 -COMPRESSED_FLAG_MASK: int = 1 -RESERVED_MASK = 0xFE -DEFAULT_MAX_MESSAGE_SIZE: int = 4194304 # 4MB - - -class TriEncoder: - """ - This class is responsible for encoding the gRPC message format, which is composed of a header and payload. - """ - - __slots__ = ["_compressor"] - - def __init__(self, compressor: Optional[Compressor]): - """ - Initialize the encoder. - :param compressor: The compression to use for compressing the payload. - :type compressor: Optional[Compressor] - """ - self._compressor = compressor - - @property - def compressor(self) -> Optional[Compressor]: - """ - Get the compressor. - :return: The compressor. - :rtype: Optional[Compressor] - """ - return self._compressor - - @compressor.setter - def compressor(self, value: Compressor) -> None: - """ - Set the compressor. - :param value: The compressor. - :type value: Compressor - """ - self._compressor = value - - def encode(self, message: bytes, compress_flag: int) -> bytes: - """ - Encode the message into the gRPC message format. - - :param message: The message to encode. - :type message: bytes - :param compress_flag: The compress flag. 0 for no compression, 1 for compression. - :type compress_flag: int - :return: The encoded message. - :rtype: bytes - """ - - # check compress_flag - if compress_flag not in [0, 1]: - raise RpcError(f"compress_flag must be 0 or 1, but got {compress_flag}") - - # check message size - if len(message) > DEFAULT_MAX_MESSAGE_SIZE: - raise RpcError(f"Message too large. Allowed maximum size is 4194304 bytes, but got {len(message)} bytes.") - - # check compress_flag and compress the payload - if compress_flag == 1: - if not self._compressor: - raise RpcError("compression is required when compress_flag is 1") - message = self._compressor.compress(message) - - # Create the gRPC header - # >: big-endian - # B: unsigned char(1 byte) -> compressed_flag - # I: unsigned int(4 bytes) -> message_length - header = struct.pack(">BI", compress_flag, len(message)) - - return header + message - - -class TriDecoder: - """ - This class is responsible for decoding the gRPC message format, which is composed of a header and payload. - """ - - __slots__ = [ - "_accumulate", - "_listener", - "_decompressor", - "_state", - "_required_length", - "_decoding", - "_compressed", - "_closing", - "_closed", - ] - - def __init__( - self, - listener: "TriDecoder.Listener", - decompressor: Optional[Decompressor], - ): - """ - Initialize the decoder. - :param decompressor: The decompressor to use for decompressing the payload. - :type decompressor: Optional[Decompressor] - :param listener: The listener to deliver the decoded payload to when a message is received. - :type listener: TriDecoder.Listener - """ - - self._listener = listener - # store data for decoding - self._accumulate = bytearray() - self._decompressor = decompressor - - self._state = HEADER - self._required_length = HEADER_LENGTH - - # decode state, if True, the decoder is currently processing a message - self._decoding = False - - # whether the message is compressed - self._compressed = False - - self._closing = False - self._closed = False - - def decode(self, data: bytes) -> None: - """ - Process the incoming bytes, decoding the gRPC message and delivering the payload to the listener. - :param data: The data to decode. - :type data: bytes - """ - self._accumulate.extend(data) - self._do_decode() - - def close(self) -> None: - """ - Close the decoder and listener. - """ - self._closing = True - self._do_decode() - - def _do_decode(self) -> None: - """ - Deliver the accumulated bytes to the listener, processing the header and payload as necessary. - """ - if self._decoding: - return - - self._decoding = True - try: - while self._has_enough_bytes(): - if self._state == HEADER: - self._process_header() - elif self._state == PAYLOAD: - self._process_payload() - if self._closing: - if not self._closed: - self._closed = True - self._accumulate = None - self._listener.close() - finally: - self._decoding = False - - def _has_enough_bytes(self) -> bool: - """ - Check if the accumulated bytes are enough to process the header or payload - :return: True if there are enough bytes, False otherwise. - :rtype: bool - """ - return len(self._accumulate) >= self._required_length - - def _process_header(self) -> None: - """ - Processes the GRPC compression header which is composed of the compression flag and the outer frame length. - """ - header_bytes = self._accumulate[: self._required_length] - self._accumulate = self._accumulate[self._required_length :] - - # Parse the header - compressed_flag = int(header_bytes[0]) - if (compressed_flag & RESERVED_MASK) != 0: - raise RpcError("gRPC frame header malformed: reserved bits not zero") - else: - self._compressed = bool(compressed_flag & COMPRESSED_FLAG_MASK) - self._required_length = int.from_bytes(header_bytes[1:], byteorder="big") - # Continue to process the payload - self._state = PAYLOAD - - def _process_payload(self) -> None: - """ - Processes the GRPC message body, which depending on frame header flags may be compressed. - """ - payload_bytes = self._accumulate[: self._required_length] - self._accumulate = self._accumulate[self._required_length :] - - if self._compressed: - # Decompress the payload - payload_bytes = self._decompressor.decompress(payload_bytes) - - self._listener.on_message(bytes(payload_bytes)) - - # Done with this frame, begin processing the next header. - self._required_length = HEADER_LENGTH - self._state = HEADER - - class Listener(abc.ABC): - @abc.abstractmethod - def on_message(self, message: bytes): - """ - Called when a message is received. - :param message: The message received. - :type message: bytes - """ - raise NotImplementedError() - - @abc.abstractmethod - def close(self): - """ - Called when the listener is closed. - """ - raise NotImplementedError() diff --git a/src/dubbo/protocol/triple/constants.py b/src/dubbo/protocol/triple/constants.py deleted file mode 100644 index d0684a66..00000000 --- a/src/dubbo/protocol/triple/constants.py +++ /dev/null @@ -1,125 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import enum - - -class GRpcCode(enum.Enum): - """ - RPC status codes. - See https://github.com/grpc/grpc/blob/master/doc/statuscodes.md - """ - - # Not an error; returned on success. - OK = 0 - - # The operation was cancelled, typically by the caller. - CANCELLED = 1 - - # Unknown error. - UNKNOWN = 2 - - # The client specified an invalid argument. - INVALID_ARGUMENT = 3 - - # The deadline expired before the operation could complete. - DEADLINE_EXCEEDED = 4 - - # Some requested entity (e.g., file or directory) was not found - NOT_FOUND = 5 - - # The entity that a client attempted to create (e.g., file or directory) already exists. - ALREADY_EXISTS = 6 - - # The caller does not have permission to execute the specified operation. - PERMISSION_DENIED = 7 - - # Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. - RESOURCE_EXHAUSTED = 8 - - # The operation was rejected because the system is not in a state required for the operation's execution. - FAILED_PRECONDITION = 9 - - # The operation was aborted, typically due to a concurrency issue - # such as a sequencer check failure or transaction abort. - ABORTED = 10 - - # The operation was attempted past the valid range. - OUT_OF_RANGE = 11 - - # The operation is not implemented or is not supported/enabled in this service. - UNIMPLEMENTED = 12 - - # Internal errors. - INTERNAL = 13 - - # The service is currently unavailable. - UNAVAILABLE = 14 - - # Unrecoverable data loss or corruption. - DATA_LOSS = 15 - - # The request does not have valid authentication credentials for the operation. - UNAUTHENTICATED = 16 - - @classmethod - def from_code(cls, code: int) -> "GRpcCode": - """ - Get the RPC status code from the given code. - :param code: The RPC status code. - :type code: int - :return: The RPC status code. - :rtype: GRpcCode - """ - for rpc_code in cls: - if rpc_code.value == code: - return rpc_code - return cls.UNKNOWN - - -class TripleHeaderName(enum.Enum): - """ - Header names used in triple protocol. - """ - - CONTENT_TYPE = "content-type" - - TE = "te" - GRPC_STATUS = "grpc-status" - GRPC_MESSAGE = "grpc-message" - GRPC_STATUS_DETAILS_BIN = "grpc-status-details-bin" - GRPC_TIMEOUT = "grpc-timeout" - GRPC_ENCODING = "grpc-encoding" - GRPC_ACCEPT_ENCODING = "grpc-accept-encoding" - - SERVICE_VERSION = "tri-service-version" - SERVICE_GROUP = "tri-service-group" - - CONSUMER_APP_NAME = "tri-consumer-appname" - - -class TripleHeaderValue(enum.Enum): - """ - Header values used in triple protocol. - """ - - TRAILERS = "trailers" - HTTP = "http" - HTTPS = "https" - APPLICATION_GRPC_PROTO = "application/grpc+data" - APPLICATION_GRPC = "application/grpc" - - TEXT_PLAIN_UTF8 = "text/plain; encoding=utf-8" diff --git a/src/dubbo/protocol/triple/exceptions.py b/src/dubbo/protocol/triple/exceptions.py index 6dbfcb9a..9363da99 100644 --- a/src/dubbo/protocol/triple/exceptions.py +++ b/src/dubbo/protocol/triple/exceptions.py @@ -1,44 +1,81 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. -__all__ = ["RpcError", "StatusRpcError"] +import typing +from collections.abc import Sequence +from typing import Self, TypeVar +import attrs -class RpcError(Exception): - """ - The RPC exception. - """ +from dubbo.exceptions import RpcError, Status - def __init__(self, message: str): - self.message = f"RPC Invocation failed: {message}" - super().__init__(self.message) +# Only for annotations: protobuf stays optional. +if typing.TYPE_CHECKING: + from google.protobuf.message import Message - def __str__(self): - return self.message +__all__ = ["ErrorDetail", "TripleError"] +M = TypeVar("M", bound="Message") -class StatusRpcError(Exception): - """ - The status RPC exception. +_TYPE_URL_PREFIX = "type.googleapis.com/" + + +@attrs.define(frozen=True, kw_only=True) +class ErrorDetail: + """A message that tells more about why a call failed, held as a ``google.protobuf.Any``. + + Attributes: + type_url: Names the type of the message, as in + ``type.googleapis.com/google.rpc.ErrorInfo``. + value: The message, serialized. """ - def __init__(self, status): - self.status = status - self.message = f"RPC Invocation failed: {status.code} {status.description}" - super().__init__(status, self.message) + type_url: str + value: bytes + + @classmethod + def from_message(cls, message: "Message") -> Self: + """Hold a protobuf message.""" + return cls(type_url=_TYPE_URL_PREFIX + message.DESCRIPTOR.full_name, value=message.SerializeToString()) + + def unpack(self, message_type: type[M]) -> M | None: + """Return the message as a ``message_type``, or ``None`` when it is of another type. + + Raises: + google.protobuf.message.DecodeError: ``value`` does not hold a + ``message_type``. + """ + if self.type_url.rpartition("/")[2] != message_type.DESCRIPTOR.full_name: + return None + return message_type.FromString(self.value) + + +class TripleError(RpcError): + """A Triple call failed with a status and details, as the rich error model of gRPC carries them. + + A handler raises it to send the details along; the caller receives an + equal error. Triple carries the details; other protocols carry the + status and message alone. + + Attributes: + details: Messages that tell programs more, such as which field of + the request is invalid. + """ - def __str__(self): - return self.message + def __init__(self, status: Status, message: str = "", *, details: Sequence[ErrorDetail] = ()) -> None: + super().__init__(status, message) + self.details = tuple(details) diff --git a/src/dubbo/protocol/triple/grpc/__init__.py b/src/dubbo/protocol/triple/grpc/__init__.py new file mode 100644 index 00000000..3ea7b849 --- /dev/null +++ b/src/dubbo/protocol/triple/grpc/__init__.py @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The gRPC format of Triple: its framing, statuses and calls over HTTP/2; the modules above it only choose the format.""" + +from .client import GrpcMethod +from .server import serve + +__all__ = ["GrpcMethod", "serve"] diff --git a/src/dubbo/protocol/triple/grpc/client.py b/src/dubbo/protocol/triple/grpc/client.py new file mode 100644 index 00000000..3a2b13f7 --- /dev/null +++ b/src/dubbo/protocol/triple/grpc/client.py @@ -0,0 +1,377 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import contextlib +import math +from collections.abc import Callable, Mapping +from types import TracebackType +from typing import Any + +import anyio +from multidict import MultiDict + +from dubbo.compression import Compressor +from dubbo.exceptions import EndOfStream, RpcError, Status +from dubbo.rpc.definition import Method, RpcType +from dubbo.rpc.invocation import Invocation, Result +from dubbo.rpc.stream import BidiStream, ClientStream, ServerStream +from dubbo.serialization import Codec +from dubbo.transport.h2 import H2Client, H2Error, H2Headers, H2Stream, H2StreamResetError + +from ..attachments import attachment_headers, split_headers +from ..headers import HttpHeader, TripleHeader +from ..messages import MethodMessages +from ..settings import TripleSettings +from .framing import frame, read_message +from .headers import GrpcHeader, content_subtype, encode_timeout +from .status import response_error, to_rpc_error, trailer_error, transport_error + +__all__ = ["GrpcMethod"] + + +# How much sooner than the caller a provider may reach the deadline of a call: a timer of asyncio fires up to the +# resolution of its clock early, and before Python 3.13 the clock of Windows moves in steps of 16 ms on both sides. +_DEADLINE_SKEW = 0.1 + + +class GrpcMethod: + """Calls one method of a service, with everything that does not change between calls made once. + + Args: + method: The method called. + headers: The request headers every call of the method starts with: + the pseudo-header fields, ``:path`` among them, then the others. + messages: How the values of the method travel. + settings: Message limits and compression of the invoker. + """ + + def __init__( + self, + method: Method, + headers: H2Headers, + messages: MethodMessages, + settings: TripleSettings, + ) -> None: + self.rpc_type = method.rpc_type + self._headers = headers + self._pseudo_count = sum(1 for name, _ in headers if name.startswith(b":")) + self._request = messages.request + self._response = messages.response + self._exception = messages.exception + self._settings = settings + + async def call(self, client: H2Client, invocation: Invocation, timeout: float) -> Result: + """Make a unary call and return how it ended. + + ``timeout`` is the seconds the call may take, which the request declares as its grpc-timeout. + A call that its provider ends as ``DEADLINE_EXCEEDED`` when its own + deadline is at most ``_DEADLINE_SKEW`` away waits for that deadline + instead, so that the caller's deadline ends it, as an AnyIO deadline + or the ``timeout``, whichever side reached it first; a caller that + shields itself from cancellation gets the error ``_DEADLINE_SKEW`` + after its deadline. + """ + # The clock of AnyIO on asyncio, read directly: asking AnyIO for the time and the deadline in each + # call took 0.5 µs of the 16 a call costs its caller, measured at 128 at once on uvloop. + now = asyncio.get_running_loop().time() + # The time left first, so that the grpc-timeout is never above timeout by a rounding of the clock. + remaining = min(anyio.current_effective_deadline() - now, timeout) + deadline = now + remaining + try: + headers = self._request_headers(invocation.attachments, remaining) + data = frame(self._request.encode(invocation.arguments), self._settings.compressor) + except (TypeError, ValueError) as error: + return Result(error=RpcError(Status.INTERNAL, str(error))) + except RpcError as error: + return Result(error=error) + + attachments: MultiDict[str | bytes] = MultiDict() + try: + stream = await client.open_stream(headers) + async with stream: + await _send(stream, data, end_stream=True) + try: + compressor, thrown = await _receive_headers(stream, self._settings, attachments) + except _TrailersOnly: + raise RpcError(Status.UNIMPLEMENTED, "the response has no message") from None + + max_size = self._settings.max_message_size + message = await read_message(stream, max_size, compressor) + if message is None: + await _receive_trailers(stream, attachments) + raise RpcError(Status.UNIMPLEMENTED, "the response has no message") + if await read_message(stream, max_size, compressor) is not None: + raise RpcError(Status.UNIMPLEMENTED, "the response has more than one message") + await _receive_trailers(stream, attachments) + except RpcError as error: + if error.status is Status.DEADLINE_EXCEEDED and deadline - anyio.current_time() <= _DEADLINE_SKEW: + # Past the deadline, so that the caller's own deadline wakes the call, and not a timer beside it. + await anyio.sleep_until(deadline + _DEADLINE_SKEW) + return Result(error=error, attachments=attachments) + except H2Error as error: + return Result(error=transport_error(error), attachments=attachments) + + # Only wrapped messages carry a thrown exception as the response; elsewhere it travels as the status. + codec = self._exception if thrown and self._exception is not None else self._response + try: + value = codec.decode(message)[0] + except ValueError as error: + return Result( + error=RpcError(Status.INTERNAL, f"cannot decode the response: {error}"), attachments=attachments + ) + if codec is self._exception: + return Result(error=value, attachments=attachments) + return Result(value=value, attachments=attachments) + + async def open(self, client: H2Client, invocation: Invocation, *, on_exit: Callable[[], None]) -> Result: + """Open a streaming call and return it as the result's value, or the error that kept it from opening. + + ``on_exit`` is called once the opened call exits. + """ + try: + headers = self._request_headers( + invocation.attachments, anyio.current_effective_deadline() - anyio.current_time() + ) + # A server-streaming call sends its one request when the first response is awaited. + request = None + if self.rpc_type is RpcType.SERVER_STREAM: + request = frame(self._request.encode(invocation.arguments), self._settings.compressor) + except (TypeError, ValueError) as error: + return Result(error=RpcError(Status.INTERNAL, str(error))) + except RpcError as error: + return Result(error=error) + + try: + stream = await client.open_stream(headers) + except H2Error as error: + return Result(error=transport_error(error)) + + single = self.rpc_type is RpcType.CLIENT_STREAM + call = GrpcClientStream(stream, self._request, self._response, self._settings, request, on_exit, single=single) + return Result(value=call) + + def _request_headers(self, attachments: Mapping[str, str | bytes], remaining: float) -> H2Headers: + """Return the headers of a call that has ``remaining`` seconds before its deadline, as its grpc-timeout. + + Raises: + RpcError: The deadline has passed. + ValueError: An attachment cannot travel as a header. + """ + budget: H2Headers = () + if not math.isinf(remaining): + if remaining <= 0: + raise RpcError(Status.DEADLINE_EXCEEDED, "the call ran out of time before it started") + budget = ((GrpcHeader.TIMEOUT, encode_timeout(remaining)),) + + if not budget and not attachments: + return self._headers + + # grpc-timeout follows the pseudo-header fields. + split = self._pseudo_count + return ( + *self._headers[:split], + *budget, + *self._headers[split:], + *(attachment_headers(attachments) if attachments else ()), + ) + + +class GrpcClientStream(BidiStream[Any, Any], ClientStream[Any, Any], ServerStream[Any]): + """The caller's side of one streaming call; leaving ``async with`` cancels the call if it still runs. + + Args: + request: The framed request of a server-streaming call, which has + only that one. + on_exit: Called once the stream exits. + single: Whether the call has exactly one response, as a + client-streaming call does. + """ + + def __init__( + self, + stream: H2Stream, + request_codec: Codec[tuple[Any, ...]], + response_codec: Codec[tuple[Any, ...]], + settings: TripleSettings, + request: bytes | None, + on_exit: Callable[[], None], + *, + single: bool = False, + ) -> None: + self._stream = stream + self._single = single + self._request_codec = request_codec + self._response_codec = response_codec + self._settings = settings + # The one request goes out when the first response is awaited: inside + # the caller's ``async with``, which closes the stream if sending fails. + self._unsent_request = request + self._on_exit: Callable[[], None] | None = on_exit + self._response_attachments: MultiDict[str | bytes] = MultiDict() + self._compressor: Compressor | None = None + self._headers_received = False + self._ended = False + self._error: RpcError | None = None + + @property + def response_attachments(self) -> MultiDict[str | bytes]: + # Filled in as the response headers and trailers arrive. + return self._response_attachments + + async def send(self, message: Any) -> None: + # A call that failed fails each send as it ended. + if self._error is not None: + raise to_rpc_error(self._error) + + data = frame(self._request_codec.encode((message,)), self._settings.compressor) + try: + await _send(self._stream, data) + except H2Error as error: + raise transport_error(error) from None + + async def end(self) -> None: + try: + await self._stream.end() + except H2StreamResetError: + # The server has ended the call; receive reports how. + pass + except H2Error as error: + raise transport_error(error) from None + + async def receive(self) -> Any: + # A finished call keeps answering as it ended. + if self._error is not None: + raise to_rpc_error(self._error) + if self._ended: + raise EndOfStream + + try: + message = await self._next_message() + except RpcError as error: + self._error = error + raise + + if message is None: + self._ended = True + raise EndOfStream + + try: + return self._response_codec.decode(message)[0] + except ValueError as error: + raise RpcError(Status.INTERNAL, f"cannot decode the response: {error}") from None + + async def __aexit__( + self, + exc_type: type[BaseException] | None, + exc: BaseException | None, + traceback: TracebackType | None, + ) -> None: + try: + await self._stream.__aexit__(exc_type, exc, traceback) + finally: + on_exit, self._on_exit = self._on_exit, None + if on_exit is not None: + on_exit() + + async def _next_message(self) -> bytes | None: + """Return the next response message, or ``None`` once the call has ended OK. + + Raises: + RpcError: The call failed. + """ + try: + if self._unsent_request is not None: + request, self._unsent_request = self._unsent_request, None + await _send(self._stream, request, end_stream=True) + + if not self._headers_received: + self._headers_received = True + self._compressor, _ = await _receive_headers(self._stream, self._settings, self._response_attachments) + + max_size = self._settings.max_message_size + message = await read_message(self._stream, max_size, self._compressor) + if message is None: + await _receive_trailers(self._stream, self._response_attachments) + elif self._single: + if await read_message(self._stream, max_size, self._compressor) is not None: + raise RpcError(Status.UNIMPLEMENTED, "the response has more than one message") + await _receive_trailers(self._stream, self._response_attachments) + self._ended = True + except H2Error as error: + raise transport_error(error) from None + except _TrailersOnly: + message = None + + if message is None and self._single: + raise RpcError(Status.UNIMPLEMENTED, "the response has no message") + return message + + +class _TrailersOnly(Exception): + """The response headers ended the call with OK, so no message follows.""" + + +async def _send(stream: H2Stream, data: bytes, *, end_stream: bool = False) -> None: + # A reset means the server has ended the call; the response reports how. + with contextlib.suppress(H2StreamResetError): + await stream.send_data(data, end_stream=end_stream) + + +async def _receive_headers( + stream: H2Stream, settings: TripleSettings, attachments: MultiDict[str | bytes] +) -> tuple[Compressor | None, bool]: + """Receive the response headers, adding their attachments; return the compressor they name and whether the message is a thrown exception. + + Raises: + RpcError: The response is not a gRPC one, or is trailers only, + reporting an error. + _TrailersOnly: The response is trailers only, reporting OK. + """ + fields, received = split_headers(await stream.receive_headers()) + attachments.extend(received) + + # The grpc-status of a gRPC response decides the call; the HTTP status counts only when there is none. + if GrpcHeader.STATUS in fields and content_subtype(fields.get(HttpHeader.CONTENT_TYPE)) is not None: + error = trailer_error(fields) + if error is not None: + raise error + raise _TrailersOnly + + error = response_error(fields) + if error is not None: + raise error + + thrown = fields.get(TripleHeader.EXCEPTION_CODE, b"0") != b"0" + try: + return settings.compressors.get(fields.get(GrpcHeader.ENCODING)), thrown + except LookupError as error: + raise RpcError(Status.INTERNAL, str(error)) from None + + +async def _receive_trailers(stream: H2Stream, attachments: MultiDict[str | bytes]) -> None: + """Receive the trailers, adding their attachments. + + Raises: + RpcError: The trailers report an error. + """ + fields, received = split_headers(await stream.receive_trailers() or ()) + attachments.extend(received) + + error = trailer_error(fields) + if error is not None: + raise error diff --git a/src/dubbo/protocol/triple/grpc/compression.py b/src/dubbo/protocol/triple/grpc/compression.py new file mode 100644 index 00000000..9bbfd6bc --- /dev/null +++ b/src/dubbo/protocol/triple/grpc/compression.py @@ -0,0 +1,69 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The compressions of gRPC messages, named by grpc-encoding.""" + +from dubbo.compression import Compressor, get_compressor +from dubbo.constants import COMPRESSOR_KEY +from dubbo.extension import extensions +from dubbo.url import URL + +__all__ = ["Compressors"] + +# The grpc-encoding of messages sent as they are. +_IDENTITY = b"identity" + + +class Compressors: + """The installed compressors, made when first used with the URL of one server or client.""" + + def __init__(self, url: URL) -> None: + names = extensions.names(Compressor) + self.accept_encoding = b",".join([_IDENTITY, *(name.encode("ascii") for name in names)]) + self._url = url + self._names = frozenset(names) + self._compressors: dict[bytes, Compressor] = {} + + def configured(self) -> tuple[bytes, Compressor | None]: + """Return the grpc-encoding that the ``compressor`` parameter of the URL names, identity when absent, and its compressor. + + Raises: + ValueError: The parameter names no installed compressor. + """ + encoding = self._url.parameters.get(COMPRESSOR_KEY, _IDENTITY.decode()).encode("ascii") + try: + return encoding, self.get(encoding) + except LookupError as error: + raise ValueError(f"URL parameter {COMPRESSOR_KEY!r}: {error}") from None + + def get(self, encoding: bytes | None) -> Compressor | None: + """Return the compressor of a grpc-encoding; ``None`` for identity. + + Raises: + LookupError: No compressor is installed for ``encoding``. + """ + if encoding is None or encoding == _IDENTITY: + return None + + compressor = self._compressors.get(encoding) + if compressor is None: + name = encoding.decode("latin-1") + if name not in self._names: + raise LookupError(f"grpc-encoding {encoding!r} is not supported, only {self.accept_encoding.decode()}") + compressor = self._compressors[encoding] = get_compressor(name, self._url) + + return compressor diff --git a/src/dubbo/protocol/triple/grpc/framing.py b/src/dubbo/protocol/triple/grpc/framing.py new file mode 100644 index 00000000..9aa4a0e3 --- /dev/null +++ b/src/dubbo/protocol/triple/grpc/framing.py @@ -0,0 +1,84 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The length-prefixed messages of a gRPC call on an HTTP/2 stream.""" + +import struct + +from dubbo.compression import Compressor +from dubbo.exceptions import RpcError, Status +from dubbo.transport.h2 import H2Stream + +__all__ = ["frame", "read_message"] + +_PREFIX = struct.Struct(">BI") +_UNCOMPRESSED = 0 +_COMPRESSED = 1 + + +def frame(message: bytes, compressor: Compressor | None = None) -> bytes: + """Prefix a message with its flag and length, compressing it first with ``compressor`` when there is one.""" + if compressor is None: + return _PREFIX.pack(_UNCOMPRESSED, len(message)) + message + + message = compressor.compress(message) + return _PREFIX.pack(_COMPRESSED, len(message)) + message + + +async def read_message(stream: H2Stream, max_size: int, compressor: Compressor | None) -> bytes | None: + """Return the next message of ``stream``, or ``None`` once the peer has sent its last. + + ``compressor`` is the one the peer's grpc-encoding names. + + Raises: + RpcError: The message is cut short, larger than ``max_size`` bytes or + wrongly compressed. + H2Error: The stream failed. + """ + prefix = await stream.receive_data_exactly(_PREFIX.size) + if len(prefix) < _PREFIX.size: + if prefix: + raise RpcError(Status.INTERNAL, "the stream ended inside a message prefix") + return None + + flag, length = _PREFIX.unpack(prefix) + if length > max_size: + raise RpcError(Status.RESOURCE_EXHAUSTED, f"message of {length} bytes is larger than {max_size}") + + message = await stream.receive_data_exactly(length) + if len(message) < length: + raise RpcError(Status.INTERNAL, "the stream ended inside a message") + + if flag == _UNCOMPRESSED: + return message + if flag == _COMPRESSED: + return _decompress(message, max_size, compressor) + raise RpcError(Status.INTERNAL, f"invalid compressed flag {flag}") + + +def _decompress(message: bytes, max_size: int, compressor: Compressor | None) -> bytes: + if compressor is None: + raise RpcError(Status.INTERNAL, "compressed message without grpc-encoding") + + try: + message = compressor.decompress(message, max_size + 1) + except ValueError as error: + raise RpcError(Status.INTERNAL, f"cannot decompress the message: {error}") from None + + if len(message) > max_size: + raise RpcError(Status.RESOURCE_EXHAUSTED, f"decompressed message is larger than {max_size}") + return message diff --git a/src/dubbo/protocol/triple/grpc/headers.py b/src/dubbo/protocol/triple/grpc/headers.py new file mode 100644 index 00000000..788d5aad --- /dev/null +++ b/src/dubbo/protocol/triple/grpc/headers.py @@ -0,0 +1,83 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The header fields of the gRPC format and the values they carry.""" + +import enum +import math +import re + +__all__ = ["CONTENT_TYPE", "GrpcHeader", "content_subtype", "content_type", "decode_timeout", "encode_timeout"] + +CONTENT_TYPE = b"application/grpc" + +_TIMEOUT = re.compile(rb"([0-9]{1,8})([HMSmun])") +_TIMEOUT_MAX = 99_999_999 +_TIMEOUT_UNITS = {b"H": 3600.0, b"M": 60.0, b"S": 1.0, b"m": 1e-3, b"u": 1e-6, b"n": 1e-9} +# Units from the finest, each with how many make a second. +_TIMEOUT_ENCODINGS = ((b"n", 1e9), (b"u", 1e6), (b"m", 1e3), (b"S", 1.0), (b"M", 1 / 60), (b"H", 1 / 3600)) + + +class GrpcHeader(bytes, enum.Enum): + """Fields of the gRPC format.""" + + TIMEOUT = b"grpc-timeout" + ENCODING = b"grpc-encoding" + ACCEPT_ENCODING = b"grpc-accept-encoding" + STATUS = b"grpc-status" + MESSAGE = b"grpc-message" + STATUS_DETAILS = b"grpc-status-details-bin" + + +def content_type(subtype: str) -> bytes: + """Return the gRPC content type of messages in the format ``subtype`` names.""" + return CONTENT_TYPE + b"+" + subtype.encode("ascii") + + +def content_subtype(value: bytes | None) -> bytes | None: + """Return the subtype of a gRPC content type, ``b""`` when it has none, or ``None`` for another type.""" + if value is None or not value.startswith(CONTENT_TYPE): + return None + + rest = value[len(CONTENT_TYPE) :] + if not rest or rest.startswith(b";"): + return b"" + if not rest.startswith(b"+"): + return None + return rest[1:].partition(b";")[0] + + +def encode_timeout(seconds: float) -> bytes: + """Encode a positive timeout in the finest unit that fits eight digits, rounding up.""" + for unit, per_second in _TIMEOUT_ENCODINGS: + value = math.ceil(seconds * per_second) + if value <= _TIMEOUT_MAX: + return b"%d%s" % (value, unit) + + return b"%dH" % _TIMEOUT_MAX + + +def decode_timeout(value: bytes) -> float: + """Return the seconds a grpc-timeout stands for. + + Raises: + ValueError: The value is malformed. + """ + match = _TIMEOUT.fullmatch(value) + if match is None: + raise ValueError(f"malformed grpc-timeout {value!r}") + return int(match[1]) * _TIMEOUT_UNITS[match[2]] diff --git a/src/dubbo/protocol/triple/grpc/server.py b/src/dubbo/protocol/triple/grpc/server.py new file mode 100644 index 00000000..716ed3a0 --- /dev/null +++ b/src/dubbo/protocol/triple/grpc/server.py @@ -0,0 +1,403 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import functools +import logging +from collections.abc import Collection, Mapping +from http import HTTPStatus +from typing import Any, cast + +import anyio +from multidict import MultiDict + +from dubbo.compression import Compressor +from dubbo.exceptions import EndOfStream, RemoteError, RpcError, Status +from dubbo.rpc.context import serving +from dubbo.rpc.definition import RpcType +from dubbo.rpc.invocation import Invocation, Result +from dubbo.rpc.stream import Stream +from dubbo.serialization import Codec +from dubbo.transport.h2 import H2Error, H2Header, H2Headers, H2Stream + +from ..attachments import attachment_headers +from ..headers import HTTP_OK, HttpHeader, TripleHeader +from ..routes import Route, RouteKey +from ..settings import TripleSettings +from .framing import frame, read_message +from .headers import CONTENT_TYPE, GrpcHeader, content_subtype, content_type, decode_timeout +from .status import status_headers, to_rpc_error, transport_error + +__all__ = ["serve"] + +_logger = logging.getLogger(__name__) + +# The trailers of a call that ends OK without attachments, the common case. +_TRAILERS_OK = tuple(status_headers(None)) +# The tri-exception-code of a response that is an exception the method threw: BIZ_EXCEPTION of RpcException. +_THROWN = b"3" + + +async def serve( + stream: H2Stream, + fields: Mapping[bytes, bytes], + attachments: MultiDict[str | bytes], + routes: Mapping[RouteKey, Route], + settings: TripleSettings, + unexported: Collection[RouteKey], +) -> None: + """Serve the gRPC call on ``stream``, whose request headers split into ``fields`` and ``attachments``. + + A request the routes cannot serve is answered with an error status: + UNAVAILABLE for a route in ``unexported``, which callers may retry with + another server, and UNIMPLEMENTED for one never served. A + grpc-timeout cancels the handler when it runs out, and the call then ends + with DEADLINE_EXCEEDED. + """ + try: + route, timeout, compressor = _accept(fields, routes, settings, unexported) + except _Rejected as rejected: + await _reject(stream, rejected.error, rejected.http_status, rejected.headers) + return + + response_compressor = _response_compressor(fields, settings) + response_headers = _response_headers( + route.subtype, + settings.compressors.accept_encoding, + settings.encoding if response_compressor is not None else None, + ) + call: _UnaryCall | _GrpcServerStream + if route.method.rpc_type is RpcType.UNARY: + call = _UnaryCall(stream, route, settings, compressor, response_headers, response_compressor) + else: + call = _GrpcServerStream(stream, route, settings, compressor, response_headers, response_compressor) + + route.service.track(cast(asyncio.Task[Any], asyncio.current_task())) + if timeout is None: + await call.run(attachments) + return + + with anyio.move_on_after(timeout) as scope: + await call.run(attachments) + if scope.cancelled_caught: + await call.finish(RpcError(Status.DEADLINE_EXCEEDED, "the call ran out of time"), {}) + + +async def _reject( + stream: H2Stream, error: RpcError, http_status: HTTPStatus = HTTPStatus.OK, headers: H2Headers = () +) -> None: + """End a call before it reaches a service, with a response of trailers only. + + A request that is not gRPC gets an HTTP error status; a gRPC one gets + HTTP 200 with the error in grpc-status, as gRPC clients expect. + """ + response = ( + (HttpHeader.STATUS, b"%d" % http_status), + (HttpHeader.CONTENT_TYPE, CONTENT_TYPE), + *headers, + *status_headers(error), + ) + await stream.send_headers(response, end_stream=True) + + +class _Rejected(Exception): + def __init__(self, error: RpcError, http_status: HTTPStatus = HTTPStatus.OK, headers: H2Headers = ()) -> None: + super().__init__(error) + self.error = error + self.http_status = http_status + self.headers = headers + + +def _accept( + fields: Mapping[bytes, bytes], + routes: Mapping[RouteKey, Route], + settings: TripleSettings, + unexported: Collection[RouteKey], +) -> tuple[Route, float | None, Compressor | None]: + """Return the route, timeout and compressor of a request. + + Raises: + _Rejected: The request is not one the routes can serve. + """ + subtype = content_subtype(fields.get(HttpHeader.CONTENT_TYPE)) + if subtype is None: + error = RpcError( + Status.INVALID_ARGUMENT, f"invalid gRPC request content-type {fields.get(HttpHeader.CONTENT_TYPE)!r}" + ) + raise _Rejected(error, HTTPStatus.UNSUPPORTED_MEDIA_TYPE) + + timeout = None + value = fields.get(GrpcHeader.TIMEOUT) + if value is not None: + try: + timeout = decode_timeout(value) + except ValueError as error: + raise _Rejected(RpcError(Status.INTERNAL, str(error)), HTTPStatus.BAD_REQUEST) from None + + value = fields.get(HttpHeader.METHOD) + if value != b"POST": + raise _Rejected(RpcError(Status.INTERNAL, f":method {value!r} should be POST"), HTTPStatus.METHOD_NOT_ALLOWED) + + key = ( + fields.get(HttpHeader.PATH, b""), + fields.get(TripleHeader.SERVICE_GROUP, b""), + fields.get(TripleHeader.SERVICE_VERSION, b""), + ) + route = routes.get(key) + if route is None: + path, group, version = key + if key in unexported: + message = f"{path!r} with group {group!r} and version {version!r} is no longer served here" + raise _Rejected(RpcError(Status.UNAVAILABLE, message)) + message = f"no service serves {path!r} with group {group!r} and version {version!r}" + raise _Rejected(RpcError(Status.UNIMPLEMENTED, message)) + + # A content type without a subtype leaves the format to the service. + if subtype and subtype != route.subtype: + raise _Rejected(RpcError(Status.INTERNAL, f"no codec for content-subtype {subtype!r}")) + + try: + compressor = settings.compressors.get(fields.get(GrpcHeader.ENCODING)) + except LookupError as error: + accept = ((GrpcHeader.ACCEPT_ENCODING, settings.compressors.accept_encoding),) + raise _Rejected(RpcError(Status.UNIMPLEMENTED, str(error)), headers=accept) from None + + return route, timeout, compressor + + +def _response_compressor(fields: Mapping[bytes, bytes], settings: TripleSettings) -> Compressor | None: + """Return the compressor of the server when the caller accepts its encoding.""" + if settings.compressor is None: + return None + + accepted = fields.get(GrpcHeader.ACCEPT_ENCODING, b"").split(b",") + return settings.compressor if settings.encoding in (name.strip() for name in accepted) else None + + +@functools.cache +def _response_headers(subtype: bytes, accept_encoding: bytes, encoding: bytes | None) -> H2Headers: + """Return the headers that start every response in the format ``subtype`` names.""" + headers: H2Headers = ( + (HttpHeader.STATUS, HTTP_OK), + (HttpHeader.CONTENT_TYPE, content_type(subtype.decode())), + (GrpcHeader.ACCEPT_ENCODING, accept_encoding), + ) + return headers if encoding is None else (*headers, (GrpcHeader.ENCODING, encoding)) + + +class _Call: + """The serving side of one gRPC call.""" + + def __init__( + self, + stream: H2Stream, + route: Route, + settings: TripleSettings, + compressor: Compressor | None, + response_headers: H2Headers, + response_compressor: Compressor | None, + ) -> None: + self._stream = stream + self._route = route + self._max_message_size = settings.max_message_size + self._compressor = compressor + self._response_headers = response_headers + self._response_compressor = response_compressor + self._headers_sent = False + + async def finish(self, error: RpcError | None, attachments: Mapping[str, str | bytes]) -> None: + """End the call with ``error``, or with OK when it is ``None``, sending ``attachments`` in the trailers.""" + try: + metadata = attachment_headers(attachments) if attachments else [] + except ValueError as invalid: + error, metadata = RpcError(Status.INTERNAL, str(invalid)), [] + + trailers: tuple[H2Header, ...] = ( + _TRAILERS_OK if error is None and not metadata else (*status_headers(error), *metadata) + ) + if self._headers_sent: + await self._stream.send_trailers(trailers) + else: + # Nothing was sent: one header section carries the status and ends the call. + self._headers_sent = True + await self._stream.send_headers((*self._response_headers, *trailers), end_stream=True) + + async def _respond( + self, + codec: Codec[tuple[Any, ...]], + value: Any, + attachments: Mapping[str, str | bytes], + headers: H2Headers | None = None, + ) -> None: + """Send ``value``, encoded with ``codec``, as the one response and end the call. + + The response starts with ``headers``, those of every response by default. + """ + try: + data = frame(codec.encode((value,)), self._response_compressor) + except TypeError as error: + await self.finish(RpcError(Status.INTERNAL, f"cannot encode the response: {error}"), attachments) + return + + # The one response is the first thing the call sends. + if not self._headers_sent: + self._headers_sent = True + await self._stream.send_headers(self._response_headers if headers is None else headers) + await self._stream.send_data(data) + await self.finish(None, attachments) + + async def _receive(self) -> tuple[Any, ...]: + """Return the next request, as the values of the method's request parameters. + + Raises: + EndOfStream: The caller has sent its last request. + RpcError: The request is broken. + H2Error: The stream failed. + """ + message = await read_message(self._stream, self._max_message_size, self._compressor) + if message is None: + raise EndOfStream + + try: + return self._route.messages.request.decode(message) + except ValueError as error: + raise RpcError(Status.INTERNAL, f"cannot decode the request: {error}") from None + + async def _receive_one(self) -> tuple[Any, ...]: + """Return the only request of a call that takes exactly one, once the caller has ended its requests. + + Raises: + RpcError: The request is broken, or there is none or more than one. + H2Error: The stream failed. + """ + try: + arguments = await self._receive() + except EndOfStream: + raise RpcError(Status.UNIMPLEMENTED, "the request has no message") from None + + if await read_message(self._stream, self._max_message_size, self._compressor) is not None: + raise RpcError(Status.UNIMPLEMENTED, "the request has more than one message") + return arguments + + async def _invoke(self, arguments: tuple[Any, ...], attachments: MultiDict[str | bytes]) -> Result: + method = self._route.method + invocation = Invocation( + interface=self._route.service.interface, + method=method.name, + arguments=arguments, + attachments=attachments, + definition=method, + ) + with serving(attachments, peer=self._stream.peer): + try: + return await self._route.invoke(invocation) + except Exception as error: + _logger.exception( + "Serving %s.%s raised instead of returning a result; its caller receives INTERNAL", + invocation.interface, + invocation.method, + ) + return Result(error=RpcError(Status.INTERNAL, f"{type(error).__name__}: {error}")) + + +class _UnaryCall(_Call): + async def run(self, attachments: MultiDict[str | bytes]) -> None: + """Receive the request, run the handler and send its response.""" + try: + arguments = await self._receive_one() + except RpcError as error: + await self.finish(error, {}) + return + + result = await self._invoke(arguments, attachments) + exception = self._route.messages.exception + if result.error is None: + await self._respond(self._route.messages.response, result.value, result.attachments) + # An exception the method threw is the response where the messages carry one; a status error ends the call. + elif exception is not None and not _is_status(result.error): + thrown = (*self._response_headers, (TripleHeader.EXCEPTION_CODE, _THROWN)) + await self._respond(exception, result.error, result.attachments, thrown) + else: + await self.finish(to_rpc_error(result.error), result.attachments) + + +class _GrpcServerStream(_Call, Stream[Any, Any]): + """The serving side of one streaming gRPC call, which its handler uses as its stream.""" + + def __init__( + self, + stream: H2Stream, + route: Route, + settings: TripleSettings, + compressor: Compressor | None, + response_headers: H2Headers, + response_compressor: Compressor | None, + ) -> None: + super().__init__(stream, route, settings, compressor, response_headers, response_compressor) + self._sending = True + + async def run(self, attachments: MultiDict[str | bytes]) -> None: + """Run the handler and end the call with how it ended.""" + # A server-streaming handler takes the request, then the response + # stream; the others only the stream. + if self._route.method.rpc_type is RpcType.SERVER_STREAM: + try: + arguments = (*await self._receive_one(), self) + except RpcError as error: + await self.finish(error, {}) + return + else: + arguments = (self,) + + result = await self._invoke(arguments, attachments) + + # A client-streaming handler returns its one response; the others + # have sent theirs on the stream. + if result.error is not None: + await self.finish(to_rpc_error(result.error), result.attachments) + elif self._route.method.rpc_type is RpcType.CLIENT_STREAM: + await self._respond(self._route.messages.response, result.value, result.attachments) + else: + await self.finish(None, result.attachments) + + async def receive(self) -> Any: + try: + return (await self._receive())[0] + except H2Error as error: + raise transport_error(error) from None + + async def send(self, message: Any) -> None: + if not self._sending: + raise RuntimeError("the responses have ended") + + data = frame(self._route.messages.response.encode((message,)), self._response_compressor) + try: + if not self._headers_sent: + self._headers_sent = True + await self._stream.send_headers(self._response_headers) + await self._stream.send_data(data) + except H2Error as error: + raise transport_error(error) from None + + async def end(self) -> None: + # The trailers that end the responses go out when the handler returns. + self._sending = False + + +def _is_status(error: Exception) -> bool: + """Return whether ``error`` stands for a status of the call rather than an exception the method threw.""" + return isinstance(error, RpcError) and not isinstance(error, RemoteError) diff --git a/src/dubbo/protocol/triple/grpc/status.py b/src/dubbo/protocol/triple/grpc/status.py new file mode 100644 index 00000000..e1d41335 --- /dev/null +++ b/src/dubbo/protocol/triple/grpc/status.py @@ -0,0 +1,157 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The statuses that end a gRPC call, and the errors of responses and transports that stand for one.""" + +from collections.abc import Mapping +from http import HTTPStatus + +from google.protobuf.message import DecodeError + +from dubbo._proto.google.rpc.status_pb2 import Status as StatusMessage +from dubbo.exceptions import RemoteError, RpcError, Status +from dubbo.transport.h2 import H2ConnectionError, H2Error, H2ErrorCode, H2Header, H2StreamResetError + +from ..exceptions import ErrorDetail, TripleError +from ..headers import HTTP_OK, HttpHeader, decode_binary, encode_binary, percent_decode, percent_encode +from .headers import GrpcHeader, content_subtype + +__all__ = ["response_error", "status_headers", "to_rpc_error", "trailer_error", "transport_error"] + +_GRPC_OK = b"%d" % Status.OK +_HTTP_STATUSES = { + HTTPStatus.BAD_REQUEST: Status.INTERNAL, + HTTPStatus.UNAUTHORIZED: Status.UNAUTHENTICATED, + HTTPStatus.FORBIDDEN: Status.PERMISSION_DENIED, + HTTPStatus.NOT_FOUND: Status.UNIMPLEMENTED, + HTTPStatus.TOO_MANY_REQUESTS: Status.UNAVAILABLE, + HTTPStatus.BAD_GATEWAY: Status.UNAVAILABLE, + HTTPStatus.SERVICE_UNAVAILABLE: Status.UNAVAILABLE, + HTTPStatus.GATEWAY_TIMEOUT: Status.UNAVAILABLE, +} +_RESET_STATUSES = { + H2ErrorCode.REFUSED_STREAM: Status.UNAVAILABLE, + H2ErrorCode.CANCEL: Status.CANCELLED, + H2ErrorCode.ENHANCE_YOUR_CALM: Status.RESOURCE_EXHAUSTED, + H2ErrorCode.INADEQUATE_SECURITY: Status.PERMISSION_DENIED, +} + + +def status_headers(error: RpcError | None) -> list[H2Header]: + """Return the grpc-status, grpc-message and grpc-status-details-bin fields that end a call.""" + if error is None: + return [(GrpcHeader.STATUS, _GRPC_OK)] + + headers = [(GrpcHeader.STATUS, b"%d" % error.status)] + if error.message: + headers.append((GrpcHeader.MESSAGE, percent_encode(error.message))) + if isinstance(error, TripleError) and error.details: + headers.append((GrpcHeader.STATUS_DETAILS, _encode_details(error))) + return headers + + +def response_error(fields: Mapping[bytes, bytes]) -> RpcError | None: + """Return why response headers are not those of a gRPC response, if they are not.""" + value = fields.get(HttpHeader.STATUS) + if value != HTTP_OK: + code = int(value) if value is not None and value.isdigit() else 0 + return RpcError(_HTTP_STATUSES.get(code, Status.UNKNOWN), f"unexpected HTTP status {code}") + + value = fields.get(HttpHeader.CONTENT_TYPE) + if content_subtype(value) is None: + return RpcError(Status.UNKNOWN, f"unexpected content-type {value!r}") + + return None + + +def trailer_error(fields: Mapping[bytes, bytes]) -> RpcError | None: + """Return the error that ending fields report; ``None`` for OK.""" + # OK comes first: almost every call ends with it. + value = fields.get(GrpcHeader.STATUS) + if value == _GRPC_OK: + return None + if value is None: + return RpcError(Status.UNKNOWN, "the server sent no grpc-status") + try: + # int() also refuses digits past the limit of its conversion. + code = int(value) if value.isdigit() else None + except ValueError: + code = None + if code is None: + return RpcError(Status.INTERNAL, f"malformed grpc-status {value!r}") + try: + status = Status(code) + except ValueError: + status = Status.UNKNOWN + + message = percent_decode(fields.get(GrpcHeader.MESSAGE, b"")) + encoded = fields.get(GrpcHeader.STATUS_DETAILS) + decoded = _decode_details(encoded) if encoded is not None else None + if decoded is None: + return RpcError(status, message) + + # PROTOCOL-HTTP2.md: the details must not contradict grpc-status, and the consumer verifies it. + if decoded.code != code: + return RpcError( + Status.INTERNAL, f"grpc-status-details-bin has code {decoded.code} but grpc-status is {code}: {message}" + ) + return TripleError(status, message, details=_details(decoded)) + + +def to_rpc_error(error: Exception) -> RpcError: + """Return a fresh `RpcError` with the status, message and details of ``error``, without its traceback. + + A `RemoteError` keeps its class in the message. + """ + if isinstance(error, TripleError): + return TripleError(error.status, error.message, details=error.details) + if isinstance(error, RemoteError): + return RpcError(error.status, str(error)) + if isinstance(error, RpcError): + return RpcError(error.status, error.message) + + return RpcError(Status.UNKNOWN, f"{type(error).__name__}: {error}") + + +def transport_error(error: H2Error) -> RpcError: + """Return the error a call ends with when its HTTP/2 stream or connection fails.""" + if isinstance(error, H2StreamResetError): + return RpcError(_RESET_STATUSES.get(error.error_code, Status.INTERNAL), str(error)) + if isinstance(error, H2ConnectionError): + return RpcError(Status.UNAVAILABLE, str(error)) + return RpcError(Status.INTERNAL, str(error)) + + +def _encode_details(error: TripleError) -> bytes: + """Encode the google.rpc.Status of ``error`` as a binary field value: base64 without padding.""" + status = StatusMessage(code=error.status, message=error.message) + for detail in error.details: + status.details.add(type_url=detail.type_url, value=detail.value) + + return encode_binary(status.SerializeToString()) + + +def _decode_details(value: bytes) -> StatusMessage | None: + """Return the google.rpc.Status a binary field value encodes; ``None`` when it is malformed.""" + try: + return StatusMessage.FromString(decode_binary(value)) + except (ValueError, DecodeError): + return None + + +def _details(status: "StatusMessage") -> tuple[ErrorDetail, ...]: + return tuple(ErrorDetail(type_url=detail.type_url, value=detail.value) for detail in status.details) diff --git a/src/dubbo/protocol/triple/headers.py b/src/dubbo/protocol/triple/headers.py new file mode 100644 index 00000000..eb13af55 --- /dev/null +++ b/src/dubbo/protocol/triple/headers.py @@ -0,0 +1,88 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The HTTP and Triple header fields of a call, and the encodings of their values.""" + +import base64 +import enum +from http import HTTPStatus +from urllib.parse import quote, unquote + +__all__ = [ + "HTTP_OK", + "HttpHeader", + "TripleHeader", + "decode_binary", + "encode_binary", + "percent_decode", + "percent_encode", +] + +# The :status of every successful response. +HTTP_OK = b"%d" % HTTPStatus.OK + +# Printable ASCII except "%", the characters percent-encoding leaves as they are. +_PERCENT_SAFE = "".join(chr(code) for code in range(0x20, 0x7F) if chr(code) != "%") + + +class HttpHeader(bytes, enum.Enum): + """HTTP fields of a call.""" + + METHOD = b":method" + SCHEME = b":scheme" + AUTHORITY = b":authority" + PATH = b":path" + STATUS = b":status" + CONTENT_TYPE = b"content-type" + CONTENT_LENGTH = b"content-length" + TE = b"te" + USER_AGENT = b"user-agent" + + +class TripleHeader(bytes, enum.Enum): + """Fields of Triple beyond gRPC: the service called, the caller, and an exception a response holds.""" + + SERVICE_GROUP = b"tri-service-group" + SERVICE_VERSION = b"tri-service-version" + CONSUMER_APPLICATION = b"tri-consumer-appname" + HEADER_CONVERT = b"tri-header-convert" + # Other than 0 when the response message is an exception the method threw. + EXCEPTION_CODE = b"tri-exception-code" + + +def percent_encode(text: str) -> bytes: + """Percent-encode every character of ``text`` that is not printable ASCII, and ``%``.""" + return quote(text, safe=_PERCENT_SAFE).encode("ascii") + + +def percent_decode(value: bytes) -> str: + """Decode a percent-encoded value, keeping malformed escapes as they are.""" + return unquote(value.decode("utf-8", "replace"), errors="replace") + + +def encode_binary(data: bytes) -> bytes: + """Return the value of a ``-bin`` field that carries ``data``: base64 without padding.""" + return base64.b64encode(data).rstrip(b"=") + + +def decode_binary(value: bytes) -> bytes: + """Return the bytes the value of a ``-bin`` field carries, padded or not. + + Raises: + binascii.Error: The value is no base64. + """ + return base64.b64decode(value + b"=" * (-len(value) % 4), validate=True) diff --git a/src/dubbo/protocol/triple/invoker.py b/src/dubbo/protocol/triple/invoker.py index 31a7c2d7..e169e329 100644 --- a/src/dubbo/protocol/triple/invoker.py +++ b/src/dubbo/protocol/triple/invoker.py @@ -1,201 +1,231 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import concurrent -from collections.abc import Iterator - -from dubbo.classes import MethodDescriptor -from dubbo.compression import Compressor, Identity -from dubbo.constants import common_constants -from dubbo.extension import ExtensionError, extensionLoader -from dubbo.loggers import loggerFactory -from dubbo.protocol import Invoker, Result -from dubbo.protocol.invocation import Invocation, RpcInvocation -from dubbo.protocol.triple.call import TripleClientCall -from dubbo.protocol.triple.call.client_call import ( - FutureToClientCallListenerAdapter, - ReadStreamToClientCallListenerAdapter, -) -from dubbo.protocol.triple.constants import TripleHeaderName, TripleHeaderValue -from dubbo.protocol.triple.metadata import RequestMetadata -from dubbo.protocol.triple.results import TriResult -from dubbo.protocol.triple.streams import ( - TriClientWriteStream, - TriReadStream, - TriReadWriteStream, -) -from dubbo.remoting import Client -from dubbo.remoting.aio.exceptions import RemotingError -from dubbo.remoting.aio.http2.stream_handler import StreamClientMultiplexHandler -from dubbo.serialization import ( - CustomDeserializer, - CustomSerializer, - DirectDeserializer, - DirectSerializer, +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import importlib.metadata +import platform +from collections.abc import Mapping + +import attrs +from multidict import MultiDict + +from dubbo.constants import ( + APPLICATION_KEY, + DEFAULT_JAVA_SERIALIZATION, + DEFAULT_SHUTWAIT, + GENERIC_KEY, + GROUP_KEY, + SERIALIZATION_KEY, + SHUTWAIT_KEY, + SSL_ENABLED_KEY, + TOKEN_KEY, + VERSION_KEY, ) +from dubbo.exceptions import RpcError, Status +from dubbo.extension import ExtensionError +from dubbo.protocol.generic import GENERIC_INVOKE, invoke_arguments +from dubbo.protocol.served import Calls, ClientPool, call_within, method_timeout +from dubbo.rpc.definition import Method, RpcType, Service +from dubbo.rpc.invocation import Invocation, Invoker, Result +from dubbo.serialization import JavaSerialization, Serialization, get_java_serialization +from dubbo.transport.h2 import H2Client, H2Headers from dubbo.url import URL -from dubbo.utils import FunctionHelper +from dubbo.utils.converters import boolean, milliseconds -__all__ = ["TripleInvoker"] +from .grpc import GrpcMethod +from .grpc.headers import GrpcHeader, content_type +from .headers import HttpHeader, TripleHeader +from .messages import MethodMessages, method_messages +from .settings import TripleSettings, transport_url +__all__ = ["TripleInvoker"] -_LOGGER = loggerFactory.get_logger() +# The headers that carry URL parameters, by parameter key. +_PARAMETER_HEADERS = ( + (TripleHeader.SERVICE_GROUP, GROUP_KEY), + (TripleHeader.SERVICE_VERSION, VERSION_KEY), + (TripleHeader.CONSUMER_APPLICATION, APPLICATION_KEY), +) +# The library, its version and the platform, in the form gRPC recommends. +_USER_AGENT = ( + f"grpc-python-dubbo/{importlib.metadata.version('apache-dubbo')} " + f"({platform.system()}; {platform.python_implementation()}/{platform.python_version()})" +).encode() class TripleInvoker(Invoker): + """Calls the methods of one remote service over a share in an HTTP/2 client of ``clients``. + + Each method's call is prepared when the invoker is made, so a call only + encodes, sends and receives. Closing the invoker refuses new calls, waits + for those running as long as ``shutwait``, ten seconds when absent, then + gives the share back. It is available while open and while the client is. + A streaming call runs until its stream exits. A unary call runs until its + result, for at most the milliseconds of ``{method}.timeout``, else of + ``timeout``, and then ends with ``DEADLINE_EXCEEDED``. + + Each call attaches the ``token`` of ``url``, which the provider + registers; one that carries a ``token`` itself fails with + ``INVALID_ARGUMENT``. + + A generic call travels as ``$invoke`` of the service, its values wrapped + in the format of ``serialization`` when that carries Java objects, else + in ``hessian2``. + + ``compressor`` names the compression of the requests, such as ``gzip``; + they are sent as they are when it is absent. ``max-receive-message-size`` + is the bytes of the largest response, 4 MiB when absent. + + Raises: + ValueError: A parameter is invalid, or names no installed compressor. """ - Triple invoker. - """ - - __slots__ = ["_url", "_client", "_stream_multiplexer", "_compression"] - def __init__(self, url: URL, client: Client, stream_multiplexer: StreamClientMultiplexHandler): + def __init__( + self, + url: URL, + definition: Service, + client: H2Client, + serialization: Serialization, + messages: Mapping[str, MethodMessages], + clients: ClientPool[H2Client], + ) -> None: + """``messages`` tells how the values of each method of ``definition`` travel in ``serialization``.""" self._url = url - self._client = client - self._stream_multiplexer = stream_multiplexer - - def invoke(self, invocation: RpcInvocation) -> Result: - """ - Invoke the invocation. - :param invocation: The invocation to invoke. - :type invocation: RpcInvocation - :return: The result of the invocation. - :rtype: Result - """ - future = concurrent.futures.Future() - result = TriResult(future) - if not self._client.is_connected(): - result.set_exception(RemotingError("The client is not connected to the server.")) - return result - - # get method descriptor - method_descriptor: MethodDescriptor = invocation.get_attribute(common_constants.METHOD_DESCRIPTOR_KEY) - - # get arg_serializer - arg_serializing_function = method_descriptor.get_arg_serializer() - arg_serializer = CustomSerializer(arg_serializing_function) if arg_serializing_function else DirectSerializer() - - # get return_deserializer - return_deserializing_function = method_descriptor.get_return_deserializer() - return_deserializer = ( - CustomDeserializer(return_deserializing_function) if return_deserializing_function else DirectDeserializer() + self._interface = definition.interface + self._serialization = serialization + self._settings = settings = TripleSettings.from_url(transport_url(url)) + scheme = b"https" if url.get_parameter(SSL_ENABLED_KEY, boolean, False) else b"http" + # Pseudo-header fields precede the others; :path follows them in each method's headers. + self._pseudo: H2Headers = ( + (HttpHeader.METHOD, b"POST"), + (HttpHeader.SCHEME, scheme), + (HttpHeader.AUTHORITY, f"{url.host}:{url.port}".encode()), ) - - write_stream = TriClientWriteStream() - read_stream = TriReadStream() - - # create listener - rpc_type = method_descriptor.get_rpc_type() - is_unary = not rpc_type.client_stream and not rpc_type.server_stream - if is_unary: - listener = FutureToClientCallListenerAdapter(future) - else: - read_stream = TriReadStream() - listener = ReadStreamToClientCallListenerAdapter(read_stream) - - # Create a new TriClientCall - tri_client_call = TripleClientCall( - self._stream_multiplexer, - listener, - arg_serializer, - return_deserializer, + # The fields after :path and content-type. + self._fields: H2Headers = ( + (HttpHeader.TE, b"trailers"), + (HttpHeader.USER_AGENT, _USER_AGENT), + (GrpcHeader.ACCEPT_ENCODING, settings.compressors.accept_encoding), + *(((GrpcHeader.ENCODING, settings.encoding),) if settings.compressor is not None else ()), + *((name, url.parameters[key].encode()) for name, key in _PARAMETER_HEADERS if url.parameters.get(key)), ) - write_stream.set_call(tri_client_call) - - if not is_unary: - write_stream = TriReadWriteStream(write_stream, read_stream) - # start the call - try: - metadata = self._create_metadata(invocation) - tri_client_call.start(metadata) - except ExtensionError as e: - result.set_exception(e) - return result - - # write the message - if not rpc_type.client_stream: - # if the client call is not a stream, we send the message directly - FunctionHelper.call_func(write_stream.write, invocation.get_argument()) - write_stream.done_writing() - else: - # try to get first argument and check if it is an iterable - args, _ = invocation.get_argument() - if args and isinstance(args[0], Iterator): - # if the argument is an iterator, we need to write the stream - for arg in args[0]: - write_stream.write(arg) - write_stream.done_writing() - - # If the call is not unary, we need to return the stream - # server_stream -> return read_stream - # client_stream or bidirectional_stream -> return write_read_stream - if not is_unary: - if rpc_type.server_stream and not rpc_type.client_stream: - result.set_value(read_stream) - else: - result.set_value(write_stream) + self._methods = {method.name: self._grpc_method(method, messages[method.name]) for method in definition.methods} + self._generic: tuple[GrpcMethod, JavaSerialization] | None = None + self._timeouts = { + method.name: method_timeout(url, method.name) + for method in definition.methods + if method.rpc_type is RpcType.UNARY + } + self._token = url.parameters.get(TOKEN_KEY) + self._shutwait = url.get_parameter(SHUTWAIT_KEY, milliseconds, DEFAULT_SHUTWAIT) + self._client = client + self._clients = clients + self._closed = False + self._calls = Calls() - return result + @property + def url(self) -> URL: + return self._url - def _create_metadata(self, invocation: Invocation) -> RequestMetadata: - """ - Create the metadata. - :param invocation: The invocation. - :type invocation: Invocation - :return: The metadata. - :rtype: RequestMetadata - :raise ExtensionError: If the compressor is not supported. - """ - metadata = RequestMetadata() - # set service and method - metadata.service = invocation.get_service_name() - metadata.method = invocation.get_method_name() - - # get scheme - metadata.scheme = ( - TripleHeaderValue.HTTPS.value - if self._url.parameters.get(common_constants.SSL_ENABLED_KEY, False) - else TripleHeaderValue.HTTP.value - ) + @property + def available(self) -> bool: + return not self._closed and self._client.available - # get compressor - compression = self._url.parameters.get(common_constants.COMPRESSION_KEY, Identity.get_message_encoding()) - if metadata.compressor.get_message_encoding() != compression: + async def invoke(self, invocation: Invocation) -> Result: + if invocation.generic is not None: try: - metadata.compressor = extensionLoader.get_extension(Compressor, compression)() - except ExtensionError as e: - _LOGGER.error("Unsupported compressor: %s", compression) - raise e + method, serialization = self._generic_method() + arguments = invoke_arguments(serialization, invocation.definition, invocation.arguments) + except (ExtensionError, TypeError, ValueError) as error: + # The cause of a plugin that cannot load tells what to install. + reason = f"{error}: {error.__cause__}" if error.__cause__ is not None else str(error) + message = f"cannot call {invocation.method} generically: {reason}" + return Result(error=RpcError(Status.UNIMPLEMENTED, message)) + timeout = method_timeout(self._url, invocation.method) + else: + known = self._methods.get(invocation.method) + if known is None: + return Result(error=RpcError(Status.UNIMPLEMENTED, f"the service has no method {invocation.method!r}")) + method, arguments, timeout = known, invocation.arguments, self._timeouts.get(invocation.method) + if self._closed: + return Result(error=RpcError(Status.UNAVAILABLE, "the invoker is closed")) + if TOKEN_KEY in invocation.attachments: + return Result(error=RpcError(Status.INVALID_ARGUMENT, "the attachment token is the protocol's to set")) + + if self._token or invocation.generic is not None: + # A copy: each attempt on another provider sends its own attachments. + attachments = MultiDict(invocation.attachments) + if self._token: + attachments[TOKEN_KEY] = self._token + if invocation.generic is not None: + attachments[GENERIC_KEY] = invocation.generic + invocation = attrs.evolve(invocation, arguments=arguments, attachments=attachments) + + self._calls.enter() + # A unary call has a timeout; a streaming one runs until its stream exits. + if timeout is not None: + try: + return await call_within(timeout, invocation.method, method.call(self._client, invocation, timeout)) + finally: + self._calls.leave() - # get address - metadata.address = self._url.location + try: + result = await method.open(self._client, invocation, on_exit=self._calls.leave) + except BaseException: + self._calls.leave() + raise - # TODO add more metadata - metadata.attachments[TripleHeaderName.TE.value] = TripleHeaderValue.TRAILERS.value + if result.error is not None: + self._calls.leave() + return result - return metadata + async def aclose(self) -> None: + if self._closed: + return - def get_url(self) -> URL: - return self._url + self._closed = True + try: + await self._calls.drain(self._shutwait) + finally: + await self._clients.release(self._client) + + def _grpc_method(self, method: Method, messages: MethodMessages) -> GrpcMethod: + """Return the call of ``method`` of the service, its values travelling as ``messages``.""" + headers = ( + *self._pseudo, + (HttpHeader.PATH, f"/{self._interface}/{method.name}".encode()), + (HttpHeader.CONTENT_TYPE, content_type(messages.content_subtype)), + *self._fields, + ) + return GrpcMethod(method, headers, messages, self._settings) - def is_available(self) -> bool: - return self._client.is_connected() + def _generic_method(self) -> tuple[GrpcMethod, JavaSerialization]: + """Return the call of ``$invoke`` and the format of Java objects of its values, made on the first generic call. - def destroy(self) -> None: - self._client.close() - self._client = None - self._stream_multiplexer = None - self._url = None + Raises: + ExtensionError: The format of Java objects it needs cannot be loaded. + ValueError: That format carries no Java objects. + """ + if self._generic is None: + java = self._serialization + if not isinstance(java, JavaSerialization): + java = get_java_serialization( + self._url.update_parameters({SERIALIZATION_KEY: DEFAULT_JAVA_SERIALIZATION}) + ) + self._generic = self._grpc_method(GENERIC_INVOKE, method_messages(java, GENERIC_INVOKE)), java + + return self._generic diff --git a/src/dubbo/protocol/triple/messages.py b/src/dubbo/protocol/triple/messages.py new file mode 100644 index 00000000..30a4c759 --- /dev/null +++ b/src/dubbo/protocol/triple/messages.py @@ -0,0 +1,110 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""How the values of a method travel as Triple messages: in the format itself, or wrapped.""" + +from collections.abc import Callable, Sequence +from typing import Any + +import attrs +from google.protobuf.message import Message + +from dubbo.rpc.definition import Method +from dubbo.serialization import Codec, JavaSerialization, Serialization +from dubbo.serialization.protobuf import ProtobufSerialization +from dubbo.url import URL + +__all__ = ["MethodMessages", "method_codecs", "method_messages"] + + +@attrs.define(frozen=True, kw_only=True) +class MethodMessages: + """How the values of one method travel as Triple messages, made once for each method. + + An error travels as the gRPC status of the call. In the wrapped messages + of a format of Java objects, an exception the method threw may instead + travel as the response message, flagged by ``tri-exception-code``. + + Attributes: + content_subtype: Names the format of the messages in their content + type, such as ``proto``. + request: Codec of a request: the values of all the parameters. + response: Codec of a response: the one value returned. + exception: Codec of a response that is an exception the method + threw, which encodes any exception and decodes as the error the + caller receives; ``None`` where exceptions travel only as + statuses. + """ + + content_subtype: str + request: Codec[tuple[Any, ...]] + response: Codec[tuple[Any, ...]] + exception: Codec[tuple[Any, ...]] | None = None + + +def method_messages(serialization: Serialization, method: Method) -> MethodMessages: + """Return how the values of ``method`` travel in ``serialization``. + + The values of a format of Java objects, such as ``hessian2``, each travel + wrapped in a protobuf message, unless the method takes and returns + protobuf messages, which travel as themselves; the values of another + format, such as protobuf, travel as its messages. + + Raises: + TypeError: ``serialization`` cannot carry the request or response of ``method``. + """ + # shortcut: only formats of Java objects travel wrapped; one wrapped without Java types needs the format to say so. + if isinstance(serialization, JavaSerialization): + if not _takes_messages(method): + # Imported here, as the wrapper builds on this module. + from .wrapper import wrapped_messages + + return wrapped_messages(serialization, method) + serialization = _PROTOBUF + + request, response = method_codecs(serialization.codec, method) + return MethodMessages(content_subtype=serialization.content_subtype, request=request, response=response) + + +_PROTOBUF = ProtobufSerialization(URL(protocol="tri")) + + +def _takes_messages(method: Method) -> bool: + """Return whether ``method`` takes one protobuf message and returns one.""" + types = [parameter.type for parameter in method.request] + return len(types) == 1 and all(isinstance(t, type) and issubclass(t, Message) for t in (*types, method.response)) + + +def method_codecs( + codec: Callable[[Sequence[Any]], Codec[tuple[Any, ...]]], method: Method +) -> tuple[Codec[tuple[Any, ...]], Codec[tuple[Any, ...]]]: + """Return the codecs ``codec`` makes of the requests and of the responses of ``method``. + + Raises: + TypeError: ``codec`` cannot carry the request or response of ``method``. + """ + try: + request = codec(tuple(parameter.type for parameter in method.request)) + except TypeError as error: + raise TypeError(f"the request of {method.name}: {error}") from None + + try: + response = codec((method.response,)) + except TypeError as error: + raise TypeError(f"the response of {method.name}: {error}") from None + + return request, response diff --git a/src/dubbo/protocol/triple/metadata.py b/src/dubbo/protocol/triple/metadata.py deleted file mode 100644 index 40692c93..00000000 --- a/src/dubbo/protocol/triple/metadata.py +++ /dev/null @@ -1,89 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from typing import Any, Optional - -from dubbo.compression import Compressor, Identity -from dubbo.protocol.triple.constants import TripleHeaderName, TripleHeaderValue -from dubbo.remoting.aio.http2.headers import Http2Headers, HttpMethod - - -class RequestMetadata: - """ - The request metadata. - """ - - def __init__(self): - self.scheme: Optional[str] = None - self.application: Optional[str] = None - self.service: Optional[str] = None - self.version: Optional[str] = None - self.group: Optional[str] = None - self.address: Optional[str] = None - self.acceptEncoding: Optional[str] = None - self.timeout: Optional[str] = None - self.compressor: Compressor = Identity() - self.method: Optional[str] = None - self.attachments: dict[str, Any] = {} - - def to_headers(self) -> Http2Headers: - """ - Convert to HTTP/2 headers. - :return: The HTTP/2 headers. - :rtype: Http2Headers - """ - headers = Http2Headers() - headers.scheme = self.scheme - headers.authority = self.address - headers.method = HttpMethod.POST.value - headers.path = f"/{self.service}/{self.method}" - headers.add( - TripleHeaderName.CONTENT_TYPE.value, - TripleHeaderValue.APPLICATION_GRPC_PROTO.value, - ) - - if self.version != "1.0.0": - set_if_not_none(headers, TripleHeaderName.SERVICE_VERSION.value, self.version) - - set_if_not_none(headers, TripleHeaderName.GRPC_TIMEOUT.value, self.timeout) - set_if_not_none(headers, TripleHeaderName.SERVICE_GROUP.value, self.group) - set_if_not_none(headers, TripleHeaderName.CONSUMER_APP_NAME.value, self.application) - set_if_not_none(headers, TripleHeaderName.GRPC_ENCODING.value, self.acceptEncoding) - - if self.compressor.get_message_encoding() != Identity.get_message_encoding(): - set_if_not_none( - headers, - TripleHeaderName.GRPC_ENCODING.value, - self.compressor.get_message_encoding(), - ) - - [headers.add(k, str(v)) for k, v in self.attachments.items()] - - return headers - - -def set_if_not_none(headers: Http2Headers, key: str, value: Optional[str]) -> None: - """ - Set the header if the value is not None. - :param headers: The headers. - :type headers: Http2Headers - :param key: The key. - :type key: str - :param value: The value. - :type value: Optional[str] - """ - if value: - headers.add(key, str(value)) diff --git a/src/dubbo/protocol/triple/protocol.py b/src/dubbo/protocol/triple/protocol.py index f4aa4d34..a3e18f19 100644 --- a/src/dubbo/protocol/triple/protocol.py +++ b/src/dubbo/protocol/triple/protocol.py @@ -1,99 +1,149 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import functools -import uuid -from collections.abc import Iterable -from concurrent.futures import ThreadPoolExecutor -from typing import Optional - -from dubbo.constants import common_constants -from dubbo.extension import extensionLoader -from dubbo.loggers import loggerFactory -from dubbo.protocol import Invoker, Protocol -from dubbo.protocol.triple.invoker import TripleInvoker -from dubbo.protocol.triple.stream.server_stream import ServerTransportListener -from dubbo.proxy.handlers import RpcServiceHandler -from dubbo.remoting import Server, Transporter -from dubbo.remoting.aio import constants as aio_constants -from dubbo.remoting.aio.http2.protocol import Http2ClientProtocol, Http2ServerProtocol -from dubbo.remoting.aio.http2.stream_handler import ( - StreamClientMultiplexHandler +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Mapping + +from dubbo.constants import ( + CLIENT_KEY, + COMPRESSOR_KEY, + DEFAULT_SERIALIZATION, + DEFAULT_TRIPLE_PORT, + GROUP_KEY, + MAX_RECEIVE_MESSAGE_SIZE_KEY, + SERIALIZATION_KEY, + SHUTWAIT_KEY, + VERSION_KEY, ) -from dubbo.url import URL - -_LOGGER = loggerFactory.get_logger() +from dubbo.extension import extensions +from dubbo.protocol.base import Protocol +from dubbo.protocol.served import ClientPool, ServedExporter, ServedService, Servers +from dubbo.rpc.definition import Service +from dubbo.rpc.invocation import Invoker +from dubbo.serialization import Serialization, get_serialization +from dubbo.transport.h2 import H2Client +from dubbo.url import SSL_CONTEXT, URL +from .invoker import TripleInvoker +from .messages import MethodMessages, method_messages +from .server import TripleServer +from .settings import transport_url -class TripleProtocol(Protocol): - """ - Triple protocol. - """ +__all__ = ["TripleProtocol"] - __slots__ = ["_url", "_transporter", "_invokers"] +# The settings of the calls and of the invokers making them rather than of their connection. +_CALL_KEYS = frozenset({COMPRESSOR_KEY, MAX_RECEIVE_MESSAGE_SIZE_KEY, SHUTWAIT_KEY}) - def __init__(self): - self._transporter: Transporter = extensionLoader.get_extension( - Transporter, common_constants.TRANSPORTER_DEFAULT_VALUE - )() - self._invokers = [] - self._server: Optional[Server] = None - self._path_resolver: dict[str, RpcServiceHandler] = {} +class TripleProtocol(Protocol): + """Serve and call services with Triple, in its gRPC format over HTTP/2. + + A method is reached at ``/{interface}/{method}``; a group and a version, + when set, travel in the ``tri-service-group`` and ``tri-service-version`` + headers and must match exactly. The ``serialization`` parameter names the + message format, ``protobuf`` when absent; the values of a format of Java + objects, such as ``hessian2``, travel wrapped in a protobuf message. + Without a port, the address uses port 50051. + + The Triple settings are the parameters after ``triple.``, as in + ``triple.compressor``. + + The services exported on one address share a server, which listens until + the protocol closes; each must ask for the settings the server was + created with. Once the exporter of a service closes, its calls fail with + ``UNAVAILABLE``. The invokers of equal connection settings and the same + TLS context share an HTTP/2 client, which the ``client`` setting names + and which is created with the URL of the first, less the settings of the + calls, such as ``compressor``. + """ - def export(self, url: URL): - """ - Export a service. + def __init__(self) -> None: + self._servers: Servers[TripleServer] = Servers() + self._clients: ClientPool[H2Client] = ClientPool() + # The shared serialization of each name, and how the methods of each definition travel in it, which the + # invokers of a service share: a codec keeps no state between messages. + self._codecs: dict[tuple[str, Service], tuple[Serialization, Mapping[str, MethodMessages]]] = {} + + async def export(self, url: URL, definition: Service, invoker: Invoker) -> ServedExporter: + url = _with_port(url) + serialization = get_serialization(url) + service = ServedService( + interface=definition.interface, + group=url.parameters.get(GROUP_KEY, ""), + version=url.parameters.get(VERSION_KEY, ""), + invoker=invoker, + ) + + server = await self._servers.serve( + url, lambda: TripleServer(url), lambda server: server.add(service, definition, serialization) + ) + return ServedExporter(server=server, service=service, url=url.replace(port=server.address[1])) + + async def refer(self, url: URL, definition: Service) -> Invoker: + url = _with_port(url) + serialization, messages = self._get_codecs(url, definition) + connection = _connection_url(url) + client = await self._clients.acquire( + (connection, connection.attributes.get(SSL_CONTEXT)), + lambda: extensions.get(H2Client, connection.parameters.get(CLIENT_KEY))(connection), + ) + + try: + return TripleInvoker(url, definition, client, serialization, messages, self._clients) + except BaseException: + await self._clients.release(client) + raise + + def announce_shutdown(self) -> None: + self._servers.announce_shutdown() + + async def aclose(self) -> None: + try: + await self._servers.aclose() + finally: + await self._clients.aclose() + + def _get_codecs(self, url: URL, definition: Service) -> tuple[Serialization, Mapping[str, MethodMessages]]: + """Return the serialization ``url`` names and how each method of ``definition`` travels in it. + + Those of a shared serialization are made once; the others for each call. + + Raises: + ExtensionError: No serialization has that name. + TypeError: The serialization cannot carry a method of ``definition``. """ - if self._server is not None: - return - - service_handler = url.attributes[common_constants.SERVICE_HANDLER_KEY] + key = (url.parameters.get(SERIALIZATION_KEY, DEFAULT_SERIALIZATION), definition) + codecs = self._codecs.get(key) + if codecs is not None: + return codecs - if isinstance(service_handler, Iterable): - for handler in service_handler: - self._path_resolver[handler.service_name] = handler - else: - self._path_resolver[service_handler.service_name] = service_handler + serialization = get_serialization(url) + codecs = (serialization, {method.name: method_messages(serialization, method) for method in definition.methods}) + if serialization.shared: + self._codecs[key] = codecs + return codecs - method_executor = ThreadPoolExecutor(thread_name_prefix=f"dubbo_tri_method_{str(uuid.uuid4())}", max_workers=10) - listener_factory = functools.partial(ServerTransportListener, self._path_resolver, method_executor) +def _with_port(url: URL) -> URL: + return url if url.port is not None else url.replace(port=DEFAULT_TRIPLE_PORT) - # set stream handler and protocol - url.attributes[aio_constants.LISTENER_FACTORY_KEY] = listener_factory - url.attributes[common_constants.PROTOCOL_KEY] = Http2ServerProtocol - # Create a server - self._server = self._transporter.bind(url) - - def refer(self, url: URL) -> Invoker: - """ - Refer a remote service. - :param url: The URL. - :type url: URL - """ - # Create a stream handler - stream_multiplexer = StreamClientMultiplexHandler() - # set stream handler and protocol - url.attributes[aio_constants.STREAM_HANDLER_KEY] = stream_multiplexer - url.attributes[common_constants.PROTOCOL_KEY] = Http2ClientProtocol - - # Create a client - client = self._transporter.connect(url) - invoker = TripleInvoker(url, client, stream_multiplexer) - self._invokers.append(invoker) - return invoker +def _connection_url(url: URL) -> URL: + """Return the URL of the HTTP/2 client that ``url`` is called over: `transport_url` of it, less the settings of the calls.""" + transport = transport_url(url) + return transport.replace( + parameters={key: value for key, value in transport.parameters.items() if key not in _CALL_KEYS} + ) diff --git a/src/dubbo/protocol/triple/results.py b/src/dubbo/protocol/triple/results.py deleted file mode 100644 index a8ced5f6..00000000 --- a/src/dubbo/protocol/triple/results.py +++ /dev/null @@ -1,54 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from typing import Any - -from dubbo.protocol import Result - - -class TriResult(Result): - """ - The triple result. - """ - - __slots__ = ["_future"] - - def __init__(self, future): - self._future = future - - def set_value(self, value: Any) -> None: - """ - Set the value. - """ - self._future.set_result(value) - - def value(self) -> Any: - """ - Get the value. - """ - return self._future.result() - - def set_exception(self, exception: Exception) -> None: - """ - Set the exception. - """ - self._future.set_exception(exception) - - def exception(self) -> Exception: - """ - Get the exception. - """ - return self._future.exception() diff --git a/src/dubbo/protocol/triple/routes.py b/src/dubbo/protocol/triple/routes.py new file mode 100644 index 00000000..15bd8355 --- /dev/null +++ b/src/dubbo/protocol/triple/routes.py @@ -0,0 +1,83 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The services a Triple server serves, and the route of each of their methods.""" + +import attrs + +from dubbo.protocol.generic import builtin_methods +from dubbo.protocol.served import ServedService +from dubbo.rpc.definition import Method, Service +from dubbo.rpc.invocation import Invoke +from dubbo.serialization import JavaSerialization, Serialization + +from .messages import MethodMessages, method_messages + +__all__ = ["Route", "RouteKey", "get_routes"] + +# A route is found by the path, group and version of a request. +RouteKey = tuple[bytes, bytes, bytes] + + +@attrs.define(frozen=True, kw_only=True) +class Route: + """How to serve one method of an exported service, made once when the service is exported. + + Attributes: + messages: How the values of the method travel. Making them checks + that the format can carry the method, so a method it cannot + carry fails the export instead of every call. + subtype: Content-subtype of the messages, compared with each request's. + invoke: Serves the calls of the method. + """ + + service: ServedService + method: Method + messages: MethodMessages + subtype: bytes + invoke: Invoke + + +def get_routes(service: ServedService, definition: Service, serialization: Serialization) -> dict[RouteKey, Route]: + """Return the routes of the methods of ``definition``, served by ``service`` in ``serialization``. + + In a format of Java objects, the service also serves the + `dubbo.protocol.generic.builtin_methods`. + + Raises: + TypeError: ``serialization`` cannot carry a method. + """ + group, version = service.group.encode(), service.version.encode() + + invoke = service.invoker.invoke + methods: list[tuple[Method, Invoke]] = [(method, invoke) for method in definition.methods] + if isinstance(serialization, JavaSerialization): + methods += builtin_methods(definition, invoke, serialization) + + routes: dict[RouteKey, Route] = {} + for method, serve in methods: + path = f"/{definition.interface}/{method.name}".encode() + messages = method_messages(serialization, method) + routes[path, group, version] = Route( + service=service, + method=method, + messages=messages, + subtype=messages.content_subtype.encode("ascii"), + invoke=serve, + ) + + return routes diff --git a/src/dubbo/protocol/triple/server.py b/src/dubbo/protocol/triple/server.py new file mode 100644 index 00000000..56ec382d --- /dev/null +++ b/src/dubbo/protocol/triple/server.py @@ -0,0 +1,176 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from typing import TYPE_CHECKING, Self + +from dubbo.constants import ( + DEFAULT_SHUTWAIT, + HEALTH_ENABLED_KEY, + REFLECTION_ENABLED_KEY, + SERVER_KEY, + SHUTWAIT_KEY, +) +from dubbo.extension import Resource, extensions +from dubbo.protocol.served import ServedService +from dubbo.rpc.definition import Service, get_definition +from dubbo.rpc.server import ServiceInvoker +from dubbo.serialization import Serialization +from dubbo.transport.h2 import H2Server, H2Stream +from dubbo.url import URL +from dubbo.utils.converters import boolean, milliseconds + +from . import grpc +from .attachments import split_headers +from .routes import Route, RouteKey, get_routes +from .settings import TripleSettings, transport_url + +if TYPE_CHECKING: + from .builtin import HealthService + +__all__ = ["TripleServer"] + + +class TripleServer(Resource): + """Serves the services exported on one address, routing each stream by path, group and version. + + Entering it starts listening; closing it stops. + ``max-receive-message-size`` is the bytes of the largest request, 4 MiB + when absent. ``compressor`` names the compression of the responses, used + for the callers whose grpc-accept-encoding lists it; responses are sent as + they are otherwise. + + ``health-enabled=true`` adds the gRPC health service, which reports each + exported service as serving under its interface and its service key. + ``reflection-enabled=true`` adds the gRPC reflection service, v1 and + v1alpha, which describes the services whose protobuf files are loaded. + Neither is registered with a registry. + + Raises: + ValueError: A parameter is invalid. + """ + + def __init__(self, url: URL) -> None: + url = transport_url(url) + self.routes: dict[RouteKey, Route] = {} + # Routes of the services removed since, whose callers are told to try another server. + self._unexported: set[RouteKey] = set() + # Seconds an unexported service waits for its running calls before they are cancelled. + self.shutwait = url.get_parameter(SHUTWAIT_KEY, milliseconds, DEFAULT_SHUTWAIT) + self._parameters = url.parameters + self._settings = TripleSettings.from_url(url) + self._server = extensions.get(H2Server, url.parameters.get(SERVER_KEY))(url, self._handle) + + self._builtins: set[ServedService] = set() + self._health: HealthService | None = None + if url.get_parameter(HEALTH_ENABLED_KEY, boolean, False): + from . import builtin + + self._health = builtin.HealthService() + self._add_builtin(url, self._health) + if url.get_parameter(REFLECTION_ENABLED_KEY, boolean, False): + from . import builtin + + self._add_builtin(url, builtin.ReflectionService(self._interfaces)) + self._add_builtin(url, builtin.ReflectionV1AlphaService(self._interfaces)) + + @property + def address(self) -> tuple[str, int]: + return self._server.address + + def add(self, service: ServedService, definition: Service, serialization: Serialization) -> None: + """Start routing the methods of ``definition`` to ``service``. + + Raises: + TypeError: ``serialization`` cannot carry a method. + ValueError: Another service already serves one of the paths with + the same group and version. + """ + routes = get_routes(service, definition, serialization) + taken = routes.keys() & self.routes.keys() + if taken: + path, group, version = next(iter(taken)) + raise ValueError(f"{path.decode()} is already exported with group {group!r} and version {version!r}") + + self.routes |= routes + self._unexported -= routes.keys() + self._report_health() + + def remove(self, service: ServedService) -> None: + """Stop routing to ``service``; its calls then fail with UNAVAILABLE, so that callers retry elsewhere.""" + self._unexported |= {key for key, route in self.routes.items() if route.service is service} + self.routes = {key: route for key, route in self.routes.items() if route.service is not service} + self._report_health() + + def check(self, url: URL) -> None: + """Check that ``url`` asks for the settings this server was created with. + + Raises: + ValueError: A setting of the server differs, such as a message + limit, the TLS files or an HTTP/2 parameter. + """ + parameters = transport_url(url).parameters + differing = sorted( + key + for key in parameters.keys() | self._parameters.keys() + if parameters.get(key) != self._parameters.get(key) + ) + if differing: + host, port = self.address + raise ValueError(f"the server at {host}:{port} runs with other {', '.join(differing)}") + + def announce_shutdown(self) -> None: + """Report every service as not serving and send the connections a GOAWAY, while serving on.""" + if self._health is not None: + self._health.announce_shutdown() + self._server.announce_shutdown() + + async def aclose(self) -> None: + # Watches of the health service would otherwise hold the server open. + if self._health is not None: + self._health.close() + await self._server.aclose() + + async def __aenter__(self) -> Self: + await self._server.__aenter__() + return self + + def _add_builtin(self, url: URL, implementation: object) -> None: + from dubbo.serialization.protobuf import ProtobufSerialization + + definition = get_definition(implementation) + service = ServedService( + interface=definition.interface, + group="", + version="", + invoker=ServiceInvoker.from_implementation(implementation, url), + ) + self._builtins.add(service) + self.add(service, definition, ProtobufSerialization(url)) + + def _interfaces(self) -> set[str]: + return {route.service.interface for route in self.routes.values()} + + def _report_health(self) -> None: + if self._health is None: + return + + services = {route.service for route in self.routes.values()} - self._builtins + self._health.update({key for service in services for key in (service.interface, service.key)}) + + async def _handle(self, stream: H2Stream) -> None: + fields, attachments = split_headers(await stream.receive_headers()) + await grpc.serve(stream, fields, attachments, self.routes, self._settings, self._unexported) diff --git a/src/dubbo/protocol/triple/settings.py b/src/dubbo/protocol/triple/settings.py new file mode 100644 index 00000000..e9519b09 --- /dev/null +++ b/src/dubbo/protocol/triple/settings.py @@ -0,0 +1,84 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""What a Triple server or invoker reads from its URL once, for every call it serves or makes.""" + +from typing import Self + +import attrs + +from dubbo.compression import Compressor +from dubbo.constants import DEFAULT_MAX_RECEIVE_MESSAGE_SIZE, MAX_RECEIVE_MESSAGE_SIZE_KEY, SHUTWAIT_KEY, TRIPLE_KEY +from dubbo.transport.tls import TLS_KEYS +from dubbo.url import URL + +from .grpc.compression import Compressors + +__all__ = ["TripleSettings", "transport_url"] + +_PREFIX = f"{TRIPLE_KEY}." +# The parameters besides the Triple settings that the HTTP/2 server or client reads. +_TRANSPORT_KEYS = frozenset({*TLS_KEYS, SHUTWAIT_KEY}) + + +def transport_url(url: URL) -> URL: + """Return the URL of the server or connection that ``url`` is served or called over. + + It keeps the protocol, address and attributes of ``url``, the TLS + parameters and ``shutwait``, and the Triple settings, the parameters + after ``triple.``, without the prefix: those the protocol reads, such as + ``compressor``, ``health-enabled`` and ``client``, and those of the + HTTP/2 implementation, such as ``max-concurrent-streams``. + """ + parameters = url.parameters + kept = {key: value for key, value in parameters.items() if key in _TRANSPORT_KEYS} + kept |= {key.removeprefix(_PREFIX): value for key, value in parameters.items() if key.startswith(_PREFIX)} + return URL(protocol=url.protocol, host=url.host, port=url.port, parameters=kept, attributes=url.attributes) + + +@attrs.define(frozen=True, kw_only=True) +class TripleSettings: + """The message limits and compression of a Triple server or invoker. + + Attributes: + max_message_size: Bytes of the largest message received, which + ``max-receive-message-size`` sets, 4 MiB when absent. + compressors: The compressors a peer's encoding may name. + encoding: The encoding the ``compressor`` parameter names, identity + when absent. + compressor: The compressor of that encoding; ``None`` for identity. + """ + + max_message_size: int + compressors: Compressors + encoding: bytes + compressor: Compressor | None + + @classmethod + def from_url(cls, url: URL) -> Self: + """Read the settings of ``url``. + + Raises: + ValueError: A parameter is invalid, or names no installed compressor. + """ + size = url.get_parameter(MAX_RECEIVE_MESSAGE_SIZE_KEY, int, DEFAULT_MAX_RECEIVE_MESSAGE_SIZE) + if size <= 0: + raise ValueError(f"URL parameter {MAX_RECEIVE_MESSAGE_SIZE_KEY!r} must be positive") + + compressors = Compressors(url) + encoding, compressor = compressors.configured() + return cls(max_message_size=size, compressors=compressors, encoding=encoding, compressor=compressor) diff --git a/src/dubbo/protocol/triple/status.py b/src/dubbo/protocol/triple/status.py deleted file mode 100644 index 6e31790c..00000000 --- a/src/dubbo/protocol/triple/status.py +++ /dev/null @@ -1,152 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from typing import Optional, Union - -from dubbo.protocol.triple.constants import GRpcCode -from dubbo.protocol.triple.exceptions import StatusRpcError -from dubbo.remoting.aio.http2.registries import HttpStatus - - -class TriRpcStatus: - """ - RPC status. - """ - - __slots__ = ["_code", "_cause", "_description"] - - def __init__( - self, - code: GRpcCode, - cause: Optional[Exception] = None, - description: Optional[str] = None, - ): - """ - Initialize the RPC status. - :param code: The RPC status code. - :type code: TriRpcCode - :param description: The description. - :type description: Optional[str] - :param cause: The exception cause. - :type cause: Optional[Exception] - """ - if isinstance(code, int): - code = GRpcCode.from_code(code) - self._code = code - self._description = description - self._cause = cause - - @property - def code(self) -> GRpcCode: - return self._code - - @property - def description(self) -> Optional[str]: - return self._description - - @property - def cause(self) -> Optional[Exception]: - return self._cause - - def with_description(self, description: str) -> "TriRpcStatus": - """ - Set the description. - :param description: The description. - :type description: str - :return: The RPC status. - :rtype: TriRpcStatus - """ - self._description = description - return self - - def with_cause(self, cause: Exception) -> "TriRpcStatus": - """ - Set the cause. - :param cause: The cause. - :type cause: Exception - :return: The RPC status. - :rtype: TriRpcStatus - """ - self._cause = cause - return self - - def append_description(self, description: str) -> None: - """ - Append the description. - :param description: The description to append. - :type description: str - """ - if self._description: - self._description += f"\n{description}" - else: - self._description = description - - def as_exception(self) -> Exception: - """ - Convert the RPC status to an exception. - :return: The exception. - :rtype: Exception - """ - return StatusRpcError(self) - - @staticmethod - def limit_desc(description: str, limit: int = 1024) -> str: - """ - Limit the description length. - :param description: The description. - :type description: str - :param limit: The limit.(default: 1024) - :type limit: int - :return: The limited description. - :rtype: str - """ - if description and len(description) > limit: - return f"{description[:limit]}..." - return description - - @classmethod - def from_rpc_code(cls, code: Union[int, GRpcCode]): - if isinstance(code, int): - code = GRpcCode.from_code(code) - return cls(code) - - @classmethod - def from_http_code(cls, code: Union[int, HttpStatus]): - http_status = HttpStatus.from_code(code) if isinstance(code, int) else code - rpc_code = GRpcCode.UNKNOWN - if HttpStatus.is_1xx(http_status) or http_status in [ - HttpStatus.BAD_REQUEST, - HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE, - ]: - rpc_code = GRpcCode.INTERNAL - elif http_status == HttpStatus.UNAUTHORIZED: - rpc_code = GRpcCode.UNAUTHENTICATED - elif http_status == HttpStatus.FORBIDDEN: - rpc_code = GRpcCode.PERMISSION_DENIED - elif http_status == HttpStatus.NOT_FOUND: - rpc_code = GRpcCode.NOT_FOUND - elif http_status in [ - HttpStatus.BAD_GATEWAY, - HttpStatus.TOO_MANY_REQUESTS, - HttpStatus.SERVICE_UNAVAILABLE, - HttpStatus.GATEWAY_TIMEOUT, - ]: - rpc_code = GRpcCode.UNAVAILABLE - - return cls(rpc_code) - - def __repr__(self): - return f"TriRpcStatus(code={self._code}, cause={self._cause}, description={self._description})" diff --git a/src/dubbo/protocol/triple/stream/__init__.py b/src/dubbo/protocol/triple/stream/__init__.py deleted file mode 100644 index 5dc8c8f0..00000000 --- a/src/dubbo/protocol/triple/stream/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from ._interfaces import ClientStream, ServerStream - -__all__ = ["ClientStream", "ServerStream"] diff --git a/src/dubbo/protocol/triple/stream/_interfaces.py b/src/dubbo/protocol/triple/stream/_interfaces.py deleted file mode 100644 index 92c04e6d..00000000 --- a/src/dubbo/protocol/triple/stream/_interfaces.py +++ /dev/null @@ -1,165 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc -from typing import Any - -from dubbo.protocol.triple.status import TriRpcStatus -from dubbo.remoting.aio.http2.headers import Http2Headers - -__all__ = ["Stream", "ClientStream", "ServerStream"] - - -class Stream(abc.ABC): - """ - Stream is a bidirectional channel that manipulates the data flow between peers. - Inbound data from remote peer is acquired by Stream.Listener. - Outbound data to remote peer is sent directly by Stream - """ - - @abc.abstractmethod - def send_headers(self, headers: Http2Headers) -> None: - """ - Send headers to remote peer - :param headers: The headers to send - :type headers: Http2Headers - """ - raise NotImplementedError() - - @abc.abstractmethod - def cancel_by_local(self, status: TriRpcStatus) -> None: - """ - Cancel the stream by local - :param status: The status - :type status: TriRpcStatus - """ - raise NotImplementedError() - - class Listener(abc.ABC): - """ - Listener is a callback interface that receives events on the stream. - """ - - @abc.abstractmethod - def on_message(self, data: bytes) -> None: - """ - Called when data is received. - :param data: The data received - :type data: bytes - """ - raise NotImplementedError() - - @abc.abstractmethod - def on_cancel_by_remote(self, status: TriRpcStatus) -> None: - """ - Called when the stream is cancelled by remote - :param status: The status - :type status: TriRpcStatus - """ - raise NotImplementedError() - - -class ClientStream(Stream, abc.ABC): - """ - ClientStream is used to send request to server and receive response from server. - """ - - @abc.abstractmethod - def send_message(self, data: bytes, compress_flag: int, last: bool) -> None: - """ - Send message to remote peer - :param data: The message data - :type data: bytes - :param compress_flag: The compress flag (0: no compress, 1: compress) - :type compress_flag: int - :param last: Whether this is the last message - :type last: bool - """ - raise NotImplementedError() - - class Listener(Stream.Listener, abc.ABC): - """ - Listener is a callback interface that receives events on the stream. - """ - - @abc.abstractmethod - def on_complete(self, status: TriRpcStatus, attachments: dict[str, Any]) -> None: - """ - Called when the stream is completed. - :param status: The status - :type status: TriRpcStatus - :param attachments: The attachments - :type attachments: Dict[str,Any] - """ - raise NotImplementedError() - - -class ServerStream(Stream, abc.ABC): - """ - ServerStream is used to receive request from client and send response to client. - """ - - @abc.abstractmethod - def set_compression(self, compression: str) -> None: - """ - Set the compression. - :param compression: The compression - :type compression: str - """ - raise NotImplementedError() - - @abc.abstractmethod - def send_message(self, data: bytes, compress_flag: bool) -> None: - """ - Send message to remote peer - :param data: The message data - :type data: bytes - :param compress_flag: The compress flag - :type compress_flag: bool - """ - raise NotImplementedError() - - @abc.abstractmethod - def complete(self, status: TriRpcStatus, attachments: dict[str, Any]) -> None: - """ - Complete the stream - :param status: The status - :type status: TriRpcStatus - :param attachments: The attachments - :type attachments: Dict[str,Any] - """ - raise NotImplementedError() - - class Listener(Stream.Listener, abc.ABC): - """ - Listener is a callback interface that receives events on the stream. - """ - - @abc.abstractmethod - def on_headers(self, headers: dict[str, Any]) -> None: - """ - Called when headers are received. - :param headers: The headers - :type headers: Http2Headers - """ - raise NotImplementedError() - - @abc.abstractmethod - def on_complete(self) -> None: - """ - Callback when no more data from client side - """ - raise NotImplementedError() diff --git a/src/dubbo/protocol/triple/stream/client_stream.py b/src/dubbo/protocol/triple/stream/client_stream.py deleted file mode 100644 index 0007acba..00000000 --- a/src/dubbo/protocol/triple/stream/client_stream.py +++ /dev/null @@ -1,300 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from typing import Optional - -from dubbo.compression import Compressor, Decompressor -from dubbo.compression.identities import Identity -from dubbo.extension import ExtensionError, extensionLoader -from dubbo.protocol.triple.coders import TriDecoder, TriEncoder -from dubbo.protocol.triple.constants import ( - GRpcCode, - TripleHeaderName, - TripleHeaderValue, -) -from dubbo.protocol.triple.status import TriRpcStatus -from dubbo.protocol.triple.stream import ClientStream -from dubbo.remoting.aio.http2.headers import Http2Headers -from dubbo.remoting.aio.http2.registries import Http2ErrorCode -from dubbo.remoting.aio.http2.stream import Http2Stream - -__all__ = ["TriClientStream"] - - -class TriClientStream(ClientStream): - """ - Triple client stream. - """ - - def __init__( - self, - listener: ClientStream.Listener, - compressor: Optional[Compressor], - ): - """ - Initialize the triple client stream. - :param listener: The listener. - :type listener: ClientStream.Listener - :param compressor: The compression. - """ - self._transport_listener = ClientTransportListener(listener) - self._encoder = TriEncoder(compressor) - - self._stream: Optional[Http2Stream] = None - - @property - def transport_listener(self) -> "ClientTransportListener": - """ - Get the transport listener. - :return: The transport listener. - :rtype: ClientTransportListener - """ - return self._transport_listener - - def bind(self, stream: Http2Stream) -> None: - """ - Bind the stream. - :param stream: The stream to bind. - :type stream: Http2Stream - """ - self._stream = stream - - def send_headers(self, headers: Http2Headers) -> None: - """ - Send headers to remote peer. - :param headers: The headers to send. - :type headers: Http2Headers - """ - self._stream.send_headers(headers) - - def send_message(self, data: bytes, compress_flag: int, last: bool) -> None: - """ - Send message to remote peer. - :param data: The message data. - :type data: bytes - :param compress_flag: The compress flag (0: no compress, 1: compress). - :type compress_flag: int - :param last: Whether this is the last message. - :type last: bool - """ - # encode the data - encoded_data = self._encoder.encode(data, compress_flag) - self._stream.send_data(encoded_data, last) - - def cancel_by_local(self, status: TriRpcStatus) -> None: - """ - Cancel the stream by local - :param status: The status - :type status: TriRpcStatus - """ - self._stream.cancel_by_local(Http2ErrorCode.CANCEL) - self._transport_listener.rst = True - - -class ClientTransportListener(Http2Stream.Listener, TriDecoder.Listener): - """ - Client transport listener. - """ - - __slots__ = [ - "_listener", - "_decoder", - "_rpc_status", - "_headers_received", - "_rst", - ] - - def __init__(self, listener: ClientStream.Listener): - """ - Initialize the client transport listener. - :param listener: The listener. - """ - super().__init__() - self._listener = listener - - self._decoder: Optional[TriDecoder] = None - self._rpc_status: Optional[TriRpcStatus] = None - - self._headers_received = False - self._rst = False - - self._trailers: Http2Headers = Http2Headers() - - @property - def rst(self) -> bool: - """ - Whether the stream is rest. - :return: True if the stream is rest, otherwise False. - :rtype: bool - """ - return self._rst - - @rst.setter - def rst(self, value: bool) -> None: - """ - Set whether the stream is rest. - :param value: True if the stream is rest, otherwise False. - :type value: bool - """ - self._rst = value - - def on_headers(self, headers: Http2Headers, end_stream: bool) -> None: - if not end_stream: - # handle headers - self._on_headers_received(headers) - else: - # handle trailers - self._on_trailers_received(headers) - - if end_stream and not self._headers_received: - self._handle_transport_error(self._rpc_status) - - def on_data(self, data: bytes, end_stream: bool) -> None: - if self._rpc_status: - self._rpc_status.append_description(f"Data: {data.decode('utf-8')}") - if len(self._rpc_status.description) > 512 or end_stream: - self._handle_transport_error(self._rpc_status) - return - - # decode the data - self._decoder.decode(data) - - def cancel_by_remote(self, error_code: Http2ErrorCode) -> None: - self.rst = True - self._rpc_status = TriRpcStatus( - GRpcCode.CANCELLED, - description=f"Cancelled by remote peer, error code: {error_code}", - ) - self._listener.on_complete(self._rpc_status, self._trailers.to_dict()) - - def _on_headers_received(self, headers: Http2Headers) -> None: - """ - Handle the headers received. - :param headers: The headers. - :type headers: Http2Headers - """ - self._headers_received = True - - # validate headers - self._validate_headers(headers) - if self._rpc_status: - return - - # get messageEncoding - decompressor: Optional[Decompressor] = None - message_encoding = headers.get(TripleHeaderName.GRPC_ENCODING.value, Identity.get_message_encoding()) - if message_encoding != Identity.get_message_encoding(): - try: - # get decompressor by messageEncoding - decompressor = extensionLoader.get_extension(Decompressor, message_encoding)() - except ExtensionError: - # unsupported - self._rpc_status = TriRpcStatus( - GRpcCode.UNIMPLEMENTED, - description="Unsupported message encoding", - ) - return - - self._decoder = TriDecoder(self, decompressor) - - def _validate_headers(self, headers: Http2Headers) -> None: - """ - Validate the headers. - :param headers: The headers. - :type headers: Http2Headers - """ - status_code = int(headers.status) if headers.status else None - if status_code: - content_type = headers.get(TripleHeaderName.CONTENT_TYPE.value, "") - if not content_type.startswith(TripleHeaderValue.APPLICATION_GRPC.value): - self._rpc_status = TriRpcStatus.from_http_code(status_code).with_description( - f"Invalid content type: {content_type}" - ) - - else: - self._rpc_status = TriRpcStatus(GRpcCode.INTERNAL, description="Missing HTTP status code") - - def _on_trailers_received(self, trailers: Http2Headers) -> None: - """ - Handle the trailers received. - :param trailers: The trailers. - :type trailers: Http2Headers - """ - if not self._rpc_status and not self._headers_received: - self._validate_headers(trailers) - - if self._rpc_status: - self._rpc_status.append_description(f"Trailers: {trailers}") - else: - self._rpc_status = self._get_status_from_trailers(trailers) - self._trailers = trailers - - if self._decoder: - self._decoder.close() - else: - self._listener.on_complete(self._rpc_status, trailers.to_dict()) - - def _get_status_from_trailers(self, trailers: Http2Headers) -> TriRpcStatus: - """ - Validate the trailers. - :param trailers: The trailers. - :type trailers: Http2Headers - :return: The RPC status. - :rtype: TriRpcStatus - """ - grpc_status_code = int(trailers.get(TripleHeaderName.GRPC_STATUS.value, "-1")) - if grpc_status_code != -1: - status = TriRpcStatus.from_rpc_code(grpc_status_code) - message = trailers.get(TripleHeaderName.GRPC_MESSAGE.value, "") - status.append_description(message) - return status - - # If the status code is not found , something is broken. Try to provide a rational error. - if self._headers_received: - return TriRpcStatus(GRpcCode.UNKNOWN, description="Missing GRPC status in response") - - # Try to get status from headers - status_code = int(trailers.status) if trailers.status else None - if status_code is not None: - status = TriRpcStatus.from_http_code(status_code) - else: - status = TriRpcStatus(GRpcCode.INTERNAL, description="Missing HTTP status code") - - status.append_description("Missing GRPC status, please infer the error from the HTTP status code") - return status - - def _handle_transport_error(self, transport_error: TriRpcStatus) -> None: - """ - Handle the transport error. - :param transport_error: The transport error. - :type transport_error: TriRpcStatus - """ - self._stream.cancel_by_local(Http2ErrorCode.NO_ERROR) - self.rst = True - self._listener.on_complete(transport_error, self._trailers.to_dict()) - - def on_message(self, message: bytes) -> None: - """ - Called when a message is received (TriDecoder.Listener callback). - :param message: The message received. - """ - self._listener.on_message(message) - - def close(self) -> None: - """ - Called when the stream is closed (TriDecoder.Listener callback). - """ - self._listener.on_complete(self._rpc_status, self._trailers.to_dict()) diff --git a/src/dubbo/protocol/triple/stream/server_stream.py b/src/dubbo/protocol/triple/stream/server_stream.py deleted file mode 100644 index 78545c91..00000000 --- a/src/dubbo/protocol/triple/stream/server_stream.py +++ /dev/null @@ -1,315 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import logging -from concurrent.futures import ThreadPoolExecutor -from typing import Any, Optional - -from dubbo.compression import Decompressor -from dubbo.compression.identities import Identity -from dubbo.extension import ExtensionError, extensionLoader -from dubbo.loggers import loggerFactory -from dubbo.protocol.triple.call.server_call import TripleServerCall -from dubbo.protocol.triple.coders import TriDecoder, TriEncoder -from dubbo.protocol.triple.constants import ( - GRpcCode, - TripleHeaderName, - TripleHeaderValue, -) -from dubbo.protocol.triple.status import TriRpcStatus -from dubbo.protocol.triple.stream import ServerStream -from dubbo.proxy.handlers import RpcMethodHandler, RpcServiceHandler -from dubbo.remoting.aio.http2.headers import Http2Headers, HttpMethod -from dubbo.remoting.aio.http2.registries import Http2ErrorCode, HttpStatus -from dubbo.remoting.aio.http2.stream import Http2Stream - -__all__ = ["ServerTransportListener", "TripleServerStream"] - -_LOGGER = loggerFactory.get_logger() - - -class TripleServerStream(ServerStream): - def __init__(self, stream: Http2Stream): - self._stream = stream - - self._tri_encoder = TriEncoder(Identity()) - - self._rst = False - self._headers_sent = False - self._trailers_sent = False - - @property - def rst(self) -> bool: - return self._rst - - @rst.setter - def rst(self, value: bool) -> None: - self._rst = value - - @property - def headers_sent(self) -> bool: - return self._headers_sent - - @property - def trailers_sent(self) -> bool: - return self._trailers_sent - - def set_compression(self, compression: str) -> None: - if compression == Identity.get_message_encoding(): - return - try: - decompressor = extensionLoader.get_extension(Decompressor, compression)() - self._tri_encoder.compressor = decompressor - except ExtensionError: - _LOGGER.warning("Unsupported compression: %s", compression) - self.cancel_by_local(TriRpcStatus(GRpcCode.INTERNAL, description="Unsupported compression")) - - def send_headers(self, headers: Http2Headers) -> None: - if not self.headers_sent: - self._stream.send_headers(headers) - self._headers_sent = True - - def send_message(self, data: bytes, compress_flag: bool) -> None: - # encode the message - encoded_data = self._tri_encoder.encode(data, compress_flag) - self._stream.send_data(encoded_data, end_stream=False) - - def complete(self, status: TriRpcStatus, attachments: dict[str, Any]) -> None: - trailers = Http2Headers() - if not self.headers_sent: - trailers.status = HttpStatus.OK.value - trailers.add( - TripleHeaderName.CONTENT_TYPE.value, - TripleHeaderValue.APPLICATION_GRPC_PROTO.value, - ) - - # add attachments - [trailers.add(k, v) for k, v in attachments.items()] - - # add status - trailers.add(TripleHeaderName.GRPC_STATUS.value, status.code.value) - if status.code is not GRpcCode.OK: - trailers.add( - TripleHeaderName.GRPC_MESSAGE.value, - TriRpcStatus.limit_desc(status.description), - ) - - # send trailers - self._headers_sent = True - self._trailers_sent = True - self._stream.send_headers(trailers, end_stream=True) - - def cancel_by_local(self, status: TriRpcStatus) -> None: - if _LOGGER.isEnabledFor(logging.DEBUG): - _LOGGER.debug("Cancel stream: %s, status: %s", self._stream.id, status) - - if not self._rst: - self._rst = True - self._stream.cancel_by_local(Http2ErrorCode.CANCEL) - - -class ServerTransportListener(Http2Stream.Listener): - """ - ServerTransportListener is a callback interface that receives events on the stream. - """ - - def __init__( - self, - service_handles: dict[str, RpcServiceHandler], - method_executor: ThreadPoolExecutor, - ): - super().__init__() - self._listener: Optional[ServerStream.Listener] = None - self._decoder: Optional[TriDecoder] = None - self._service_handles = service_handles - self._executor: Optional[ThreadPoolExecutor] = method_executor - - def on_headers(self, headers: Http2Headers, end_stream: bool) -> None: - # check http method - if headers.method != HttpMethod.POST.value: - self._response_plain_text_error( - HttpStatus.METHOD_NOT_ALLOWED.value, - TriRpcStatus( - GRpcCode.INTERNAL, - description=f"Method {headers.method} is not supported", - ), - ) - return - - # check content type - content_type = headers.get(TripleHeaderName.CONTENT_TYPE.value, "") - if not content_type.startswith(TripleHeaderValue.APPLICATION_GRPC.value): - self._response_plain_text_error( - HttpStatus.UNSUPPORTED_MEDIA_TYPE.value, - TriRpcStatus( - GRpcCode.UNIMPLEMENTED, - description=( - f"Content-Type {content_type} is not supported" - if content_type - else "Content-Type is missing from the request" - ), - ), - ) - return - - # check path - path = headers.path - if not path: - self._response_plain_text_error( - HttpStatus.NOT_FOUND.value, - TriRpcStatus( - GRpcCode.UNIMPLEMENTED, - description="Expected path but is missing", - ), - ) - return - elif not path.startswith("/"): - self._response_plain_text_error( - HttpStatus.NOT_FOUND.value, - TriRpcStatus( - GRpcCode.UNIMPLEMENTED, - description=f"Expected path to start with /: {path}", - ), - ) - return - - # split the path - parts = path.split("/") - if len(parts) != 3: - self._response_error(TriRpcStatus(GRpcCode.UNIMPLEMENTED, description=f"Bad path format: {path}")) - return - - service_name, method_name = parts[1], parts[2] - - # get method handler - handler = self._get_handler(service_name, method_name) - if not handler: - self._response_error( - TriRpcStatus( - GRpcCode.UNIMPLEMENTED, - description=f"Service {service_name} is not found", - ) - ) - return - - if end_stream: - # Invalid request, ignore it. - return - - decompressor: Decompressor = Identity() - message_encoding = headers.get(TripleHeaderName.GRPC_ENCODING.value) - if message_encoding and message_encoding != decompressor.get_message_encoding(): - # update decompressor - try: - decompressor = extensionLoader.get_extension(Decompressor, message_encoding)() - except ExtensionError: - self._response_error( - TriRpcStatus( - GRpcCode.UNIMPLEMENTED, - description=f"Grpc-encoding '{message_encoding}' is not supported", - ) - ) - return - - # create a server call - self._listener = TripleServerCall(TripleServerStream(self._stream), handler, self._executor) - - # create a decoder - self._decoder = TriDecoder(ServerTransportListener.ServerDecoderListener(self._listener), decompressor) - - # deliver the headers to the listener - self._listener.on_headers(headers.to_dict()) - - def _get_handler(self, service_name: str, method_name: str) -> Optional[RpcMethodHandler]: - """ - Get the method handler. - :param service_name: The service name - :type service_name: str - :param method_name: The method name - :type method_name: str - :return: The method handler - :rtype: Optional[RpcMethodHandler] - """ - if self._service_handles: - service_handler = self._service_handles.get(service_name) - if service_handler: - return service_handler.method_handlers.get(method_name) - return None - - def on_data(self, data: bytes, end_stream: bool) -> None: - if self._decoder: - self._decoder.decode(data) - if end_stream: - self._decoder.close() - - def cancel_by_remote(self, error_code: Http2ErrorCode) -> None: - if self._listener: - self._listener.on_cancel_by_remote( - TriRpcStatus( - GRpcCode.CANCELLED, - description=f"Canceled by client ,errorCode= {error_code.value}", - ) - ) - - def _response_plain_text_error(self, code: int, status: TriRpcStatus) -> None: - """ - Error before create server stream, http plain text will be returned. - :param code: The error code - :type code: int - :param status: The status - :type status: TriRpcStatus - """ - # create headers - headers = Http2Headers() - headers.status = code - headers.add(TripleHeaderName.GRPC_STATUS.value, status.code.value) - headers.add(TripleHeaderName.GRPC_MESSAGE.value, status.description) - headers.add(TripleHeaderName.CONTENT_TYPE.value, TripleHeaderValue.TEXT_PLAIN_UTF8.value) - - # send headers - self._stream.send_headers(headers, end_stream=True) - - def _response_error(self, status: TriRpcStatus) -> None: - """ - Error after create server stream, grpc error will be returned. - :param status: The status - :type status: TriRpcStatus - """ - # create trailers - trailers = Http2Headers() - trailers.status = HttpStatus.OK.value - trailers.add(TripleHeaderName.GRPC_STATUS.value, status.code.value) - trailers.add(TripleHeaderName.GRPC_MESSAGE.value, status.description) - trailers.add( - TripleHeaderName.CONTENT_TYPE.value, - TripleHeaderValue.APPLICATION_GRPC_PROTO.value, - ) - - # send trailers - self._stream.send_headers(trailers, end_stream=True) - - class ServerDecoderListener(TriDecoder.Listener): - """ - ServerDecoderListener is a callback interface that receives events on the decoder. - """ - - def __init__(self, listener: ServerStream.Listener): - self._listener = listener - - def on_message(self, message: bytes) -> None: - self._listener.on_message(message) - - def close(self): - self._listener.on_complete() diff --git a/src/dubbo/protocol/triple/streams.py b/src/dubbo/protocol/triple/streams.py deleted file mode 100644 index 5376ec8d..00000000 --- a/src/dubbo/protocol/triple/streams.py +++ /dev/null @@ -1,284 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import queue -import threading -from typing import Any, Optional, Union - -from dubbo.classes import EOF, ReadStream, ReadWriteStream, WriteStream -from dubbo.protocol.triple.call import ClientCall, ServerCall -from dubbo.protocol.triple.constants import GRpcCode -from dubbo.protocol.triple.exceptions import RpcError -from dubbo.protocol.triple.status import TriRpcStatus - - -class TriReadStream(ReadStream): - """ - Triple read stream. Support reading data from the stream. - """ - - __slots__ = ["_storage", "_lock", "_read_done"] - - def __init__(self): - self._read_done = False - self._storage = queue.Queue(maxsize=1000) - self._lock = threading.RLock() - - def put(self, data: Any) -> None: - """ - Put data into the stream. It is private and should not be called by the user. - :param data: The data to put into the stream. - :type data: Any - """ - if self._read_done: - return - self._storage.put_nowait(data) - - def put_eof(self) -> None: - """ - Put EOF into the stream. It is private and should not be called by the user. - """ - if self._read_done: - return - self._read_done = True - self._storage.put_nowait(EOF) - - def put_exception(self, e: Exception) -> None: - """ - Set an exception to the stream. It is private and should not be called by the user. - :param e: The exception to set. - :type e: Exception - """ - # Stop the read stream - self.put_eof() - # Raise the exception - raise e - - def read(self, timeout: Optional[int] = None) -> Any: - """ - Read the stream. - :param timeout: - The timeout in seconds. If None, it will block until the data is available. - :type timeout: Optional[int] - :return: - The data read from the stream. - If no more data, return EOF. - If no data available within the timeout, return None. - :rtype: Any - """ - # If you can't read more data, return EOF - if self._read_done and self._storage.empty(): - return EOF - - try: - data = self._storage.get(timeout=max(0, timeout) if timeout is not None else None) - return data - except queue.Empty: - return None - - def __iter__(self): - return self - - def __next__(self): - data = self.read() - if data is EOF: - raise StopIteration - return data - - -class TriClientWriteStream(WriteStream): - """ - Triple client write stream. Support writing data to the stream. - """ - - __slots__ = ["_call", "_write_done"] - - def __init__(self, call: Optional[ClientCall] = None): - self._call: Optional[ClientCall] = call - self._write_done = False - - def set_call(self, call: ClientCall): - self._call = call - - def can_write_more(self) -> bool: - """ - Check if the stream can write more data. - :return: True if the stream can write more data, False otherwise. - :rtype: bool - """ - return not self._write_done - - def write(self, *args, **kwargs) -> None: - """ - Write data to the stream. - :param args: The arguments to pass to the write method. - :param kwargs: The keyword arguments to pass to the write method. - :raises RpcError: If write after done writing. - """ - if self._write_done: - raise RpcError("Write after done writing") - self._call.send_message((args, kwargs), False) - - def done_writing(self, **kwargs) -> None: - """ - Done writing to the stream. - :raises RpcError: If done writing multiple times. - """ - if self._write_done: - raise RpcError("Done writing multiple times") - - self._call.send_message(None, True) - self._write_done = True - - -class TriServerWriteStream(WriteStream): - """ - Triple server write stream. Support writing data to the stream. - """ - - __slots__ = ["_call", "_write_done"] - - def __init__(self, call: ServerCall): - self._call = call - self._write_done = False - - def can_write_more(self) -> bool: - """ - Check if the stream can write more data. - :return: True if the stream can write more data, False otherwise. - :rtype: bool - """ - return not self._write_done - - def write(self, *args, **kwargs) -> None: - """ - Write data to the stream. - :param args: The arguments to pass to the write method. - :param kwargs: The keyword arguments to pass to the write method. - :raises RpcError: If write after done writing. - """ - if self._write_done: - raise RpcError("Write after done writing") - self._call.send_message((args, kwargs)) - - def done_writing(self, **kwargs) -> None: - """ - Done writing to the stream. - :param kwargs: The keyword arguments to pass to the done - :raises RpcError: If done writing multiple times. - """ - if self._write_done: - raise RpcError("Done writing multiple times") - - # try to get TriRpcStatus from kwargs - status = kwargs.get("tri_rpc_status") - if status is None: - status = TriRpcStatus(GRpcCode.OK) - elif not isinstance(status, TriRpcStatus): - raise RpcError("Invalid status type") - - # remove the status from kwargs - kwargs.pop("tri-rpc-status", None) - - self._call.complete(status, kwargs) - self._write_done = True - - -class TriReadWriteStream(ReadWriteStream): - """ - Triple client read write stream. Support reading and writing data from the stream. - """ - - __slots__ = ["_read_stream", "_write_stream"] - - def __init__( - self, - write_stream: Union[TriClientWriteStream, TriServerWriteStream], - read_stream: TriReadStream, - ): - """ - Initialize the read write stream. - :param write_stream: The write stream. - :type write_stream: TriClientWriteStream - :param read_stream: The read stream. - :type read_stream: TriReadStream - """ - self._read_stream = read_stream - self._write_stream = write_stream - - def can_write_more(self) -> bool: - """ - Check if the stream can write more data. - :return: True if the stream can write more data, False otherwise. - :rtype: bool - """ - if self._write_stream is None: - raise RpcError("Write stream is not set") - return self._write_stream.can_write_more() - - def can_read_more(self) -> bool: - """ - Check if there is more data to read. - :return: True if there is more data to read, False otherwise. - :rtype: bool - """ - if self._read_stream is None: - raise RpcError("Read stream is not set") - return self._read_stream.can_read_more() - - def read(self, timeout: Optional[int] = None) -> Any: - """ - Read the stream. - :param timeout: - The timeout in seconds. If None, it will block until the data is available. - :type timeout: Optional[int] - :return: - The data read from the stream. - If no more data, return EOF. - If no data available within the timeout, return None. - :rtype: Any - """ - if self._read_stream is None: - raise RpcError("Read stream is not set") - return self._read_stream.read(timeout) - - def write(self, *args, **kwargs) -> None: - """ - Write data to the stream. - :param args: The arguments to pass to the write method. - :param kwargs: The keyword arguments to pass to the write method. - :raises RpcError: If write after done writing. - """ - if self._write_stream is None: - raise RpcError("Write stream is not set") - self._write_stream.write(*args, **kwargs) - - def done_writing(self, **kwargs) -> None: - """ - Done writing to the stream. - :raises RpcError: If done writing multiple times. - """ - if self._write_stream is None: - raise RpcError("Write stream is not set") - self._write_stream.done_writing(**kwargs) - - def __iter__(self): - return self - - def __next__(self): - data = self.read() - if data is EOF: - raise StopIteration - return data diff --git a/src/dubbo/protocol/triple/wrapper.py b/src/dubbo/protocol/triple/wrapper.py new file mode 100644 index 00000000..be131657 --- /dev/null +++ b/src/dubbo/protocol/triple/wrapper.py @@ -0,0 +1,98 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The wrapped messages in which Triple carries the values of a format of Java objects.""" + +from collections.abc import Sequence +from functools import partial +from typing import Any + +from google.protobuf.message import DecodeError + +from dubbo._proto.org.apache.dubbo.triple.triple_wrapper_pb2 import TripleRequestWrapper +from dubbo.protocol.java import caller_error, java_exception, java_type_name +from dubbo.rpc.definition import Method +from dubbo.serialization import Codec, JavaSerialization + +from .messages import MethodMessages, method_codecs + +__all__ = ["wrapped_codec", "wrapped_messages"] + +# The other names peers give a format in a wrapper. +_ALIASES = {"hessian2": "hessian4"} + + +def wrapped_messages(serialization: JavaSerialization, method: Method) -> MethodMessages: + """Return how the values of ``method`` travel wrapped, each in ``serialization``. + + An exception the method throws travels as a response of one value too, + which ``tri-exception-code`` flags: as `dubbo.protocol.java.java_exception` + names it, and decoded as `dubbo.protocol.java.caller_error` takes it. + + Raises: + TypeError: ``serialization`` cannot carry the request or response of + ``method``, or one of its types has no Java type. + """ + request, response = method_codecs(partial(wrapped_codec, serialization), method) + thrown = wrapped_codec(serialization, (Exception,)) + + def encode_exception(values: tuple[Any, ...]) -> bytes: + return thrown.encode((java_exception(serialization, values[0]),)) + + def decode_exception(data: bytes) -> tuple[Any, ...]: + return (caller_error(thrown.decode(data)[0]),) + + exception = Codec(encode=encode_exception, decode=decode_exception) + return MethodMessages(content_subtype="proto", request=request, response=response, exception=exception) + + +def wrapped_codec(serialization: JavaSerialization, types: Sequence[Any]) -> Codec[tuple[Any, ...]]: + """Return the codec of one value of each of ``types``, carried in a ``TripleRequestWrapper``. + + Each value is encoded alone in ``serialization``, and travels beside the + Java type of its annotation. A wrapper of one value has the bytes of a + ``TripleResponseWrapper`` of that value, as their fields have the same + numbers and kinds, so the codec of one value is that of a response. + + Raises: + TypeError: ``serialization`` cannot carry a type, or it has no Java type. + """ + name = serialization.content_subtype + names = {name, _ALIASES.get(name, name)} + codecs = [serialization.codec((annotation,)) for annotation in types] + try: + java_types = [java_type_name(serialization, annotation) for annotation in types] + except TypeError as error: + raise TypeError(f"a wrapped value needs a Java type: {error}") from None + + def encode(values: tuple[Any, ...]) -> bytes: + arguments = [codec.encode((value,)) for codec, value in zip(codecs, values, strict=True)] + return TripleRequestWrapper(serializeType=name, args=arguments, argTypes=java_types).SerializeToString() + + def decode(data: bytes) -> tuple[Any, ...]: + try: + wrapper = TripleRequestWrapper.FromString(data) + except DecodeError as error: + raise ValueError(f"not a wrapped message: {error}") from None + if wrapper.serializeType not in names: + raise ValueError(f"the values are in {wrapper.serializeType!r}, not {name!r}") + if len(wrapper.args) != len(codecs): + raise ValueError(f"expected {len(codecs)} values, not {len(wrapper.args)}") + + return tuple(codec.decode(argument)[0] for codec, argument in zip(codecs, wrapper.args, strict=True)) + + return Codec(encode=encode, decode=decode) diff --git a/src/dubbo/proxy/__init__.py b/src/dubbo/proxy/__init__.py deleted file mode 100644 index 4c4ddd8b..00000000 --- a/src/dubbo/proxy/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from ._interfaces import RpcCallable, RpcCallableFactory - -__all__ = ["RpcCallable", "RpcCallableFactory"] diff --git a/src/dubbo/proxy/_interfaces.py b/src/dubbo/proxy/_interfaces.py deleted file mode 100644 index 4a54686b..00000000 --- a/src/dubbo/proxy/_interfaces.py +++ /dev/null @@ -1,56 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc - -from dubbo.protocol import Invoker -from dubbo.proxy.handlers import RpcServiceHandler -from dubbo.url import URL - -__all__ = ["RpcCallable", "RpcCallableFactory"] - - -class RpcCallable(abc.ABC): - @abc.abstractmethod - def __call__(self, *args, **kwargs): - """ - call the rpc service - """ - raise NotImplementedError() - - -class RpcCallableFactory(abc.ABC): - @abc.abstractmethod - def get_callable(self, invoker: Invoker, url: URL) -> RpcCallable: - """ - get the rpc proxy - :param invoker: the invoker. - :type invoker: Invoker - :param url: the url. - :type url: URL - """ - raise NotImplementedError() - - @abc.abstractmethod - def get_invoker(self, service_handler: RpcServiceHandler, url: URL) -> Invoker: - """ - get the rpc invoker - :param service_handler: the service handler. - :type service_handler: RpcServiceHandler - :param url: the url. - :type url: URL - """ - raise NotImplementedError() diff --git a/src/dubbo/proxy/callables.py b/src/dubbo/proxy/callables.py deleted file mode 100644 index 3aa2b4a3..00000000 --- a/src/dubbo/proxy/callables.py +++ /dev/null @@ -1,70 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from typing import Any - -from dubbo.classes import MethodDescriptor -from dubbo.constants import common_constants -from dubbo.protocol import Invoker -from dubbo.protocol.invocation import RpcInvocation -from dubbo.proxy import RpcCallable, RpcCallableFactory -from dubbo.url import URL - -__all__ = ["MultipleRpcCallable", "DefaultRpcCallableFactory"] - -from dubbo.proxy.handlers import RpcServiceHandler - - -class MultipleRpcCallable(RpcCallable): - """ - The RpcCallable class. - """ - - def __init__(self, invoker: Invoker, url: URL): - self._invoker = invoker - self._url = url - - self._method_model: MethodDescriptor = url.attributes[common_constants.METHOD_DESCRIPTOR_KEY] - - self._service_name = url.path - self._method_name = self._method_model.get_method_name() - - def _create_invocation(self, argument: Any) -> RpcInvocation: - return RpcInvocation( - self._service_name, - self._method_name, - argument, - attributes={common_constants.METHOD_DESCRIPTOR_KEY: self._method_model}, - ) - - def __call__(self, *args, **kwargs) -> Any: - # Create a new RpcInvocation - invocation = self._create_invocation((args, kwargs)) - # Do invoke. - result = self._invoker.invoke(invocation) - return result.value() - - -class DefaultRpcCallableFactory(RpcCallableFactory): - """ - The RpcCallableFactory class. - """ - - def get_callable(self, invoker: Invoker, url: URL) -> RpcCallable: - return MultipleRpcCallable(invoker, url) - - def get_invoker(self, service_handler: RpcServiceHandler, url: URL) -> Invoker: - pass diff --git a/src/dubbo/proxy/handlers.py b/src/dubbo/proxy/handlers.py deleted file mode 100644 index 8c896637..00000000 --- a/src/dubbo/proxy/handlers.py +++ /dev/null @@ -1,216 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from typing import Callable, Optional - -from dubbo.classes import MethodDescriptor -from dubbo.types import ( - DeserializingFunction, - RpcTypes, - SerializingFunction, -) - -__all__ = ["RpcMethodHandler", "RpcServiceHandler"] - - -class RpcMethodHandler: - """ - Rpc method handler - """ - - __slots__ = ["_method_descriptor"] - - def __init__(self, method_descriptor: MethodDescriptor): - """ - Initialize the RpcMethodHandler - :param method_descriptor: the method descriptor. - :type method_descriptor: MethodDescriptor - """ - self._method_descriptor = method_descriptor - - @property - def method_descriptor(self) -> MethodDescriptor: - """ - Get the method descriptor - :return: the method descriptor - :rtype: MethodDescriptor - """ - return self._method_descriptor - - @classmethod - def unary( - cls, - method: Callable, - method_name: Optional[str] = None, - request_deserializer: Optional[DeserializingFunction] = None, - response_serializer: Optional[SerializingFunction] = None, - ) -> "RpcMethodHandler": - """ - Create a unary method handler - :param method: the method. - :type method: Callable - :param method_name: the method name. If not provided, the method name will be used. - :type method_name: Optional[str] - :param request_deserializer: the request deserializer. - :type request_deserializer: Optional[DeserializingFunction] - :param response_serializer: the response serializer. - :type response_serializer: Optional[SerializingFunction] - :return: the unary method handler. - :rtype: RpcMethodHandler - """ - return cls( - MethodDescriptor( - callable_method=method, - method_name=method_name or method.__name__, - arg_serialization=(None, request_deserializer), - return_serialization=(response_serializer, None), - rpc_type=RpcTypes.UNARY.value, - ) - ) - - @classmethod - def client_stream( - cls, - method: Callable, - method_name: Optional[str] = None, - request_deserializer: Optional[DeserializingFunction] = None, - response_serializer: Optional[SerializingFunction] = None, - ): - """ - Create a client stream method handler - :param method: the method. - :type method: Callable - :param method_name: the method name. If not provided, the method name will be used. - :type method_name: Optional[str] - :param request_deserializer: the request deserializer. - :type request_deserializer: Optional[DeserializingFunction] - :param response_serializer: the response serializer. - :type response_serializer: Optional[SerializingFunction] - :return: the client stream method handler. - :rtype: RpcMethodHandler - """ - return cls( - MethodDescriptor( - callable_method=method, - method_name=method_name or method.__name__, - arg_serialization=(None, request_deserializer), - return_serialization=(response_serializer, None), - rpc_type=RpcTypes.CLIENT_STREAM.value, - ) - ) - - @classmethod - def server_stream( - cls, - method: Callable, - method_name: Optional[str] = None, - request_deserializer: Optional[DeserializingFunction] = None, - response_serializer: Optional[SerializingFunction] = None, - ): - """ - Create a server stream method handler - :param method: the method. - :type method: Callable - :param method_name: the method name. If not provided, the method name will be used. - :type method_name: Optional[str] - :param request_deserializer: the request deserializer. - :type request_deserializer: Optional[DeserializingFunction] - :param response_serializer: the response serializer. - :type response_serializer: Optional[SerializingFunction] - :return: the server stream method handler. - :rtype: RpcMethodHandler - """ - return cls( - MethodDescriptor( - callable_method=method, - method_name=method_name or method.__name__, - arg_serialization=(None, request_deserializer), - return_serialization=(response_serializer, None), - rpc_type=RpcTypes.SERVER_STREAM.value, - ) - ) - - @classmethod - def bi_stream( - cls, - method: Callable, - method_name: Optional[str] = None, - request_deserializer: Optional[DeserializingFunction] = None, - response_serializer: Optional[SerializingFunction] = None, - ): - """ - Create a bidi stream method handler - :param method: the method. - :type method: Callable - :param method_name: the method name. If not provided, the method name will be used. - :type method_name: Optional[str] - :param request_deserializer: the request deserializer. - :type request_deserializer: Optional[DeserializingFunction] - :param response_serializer: the response serializer. - :type response_serializer: Optional[SerializingFunction] - :return: the bidi stream method handler. - :rtype: RpcMethodHandler - """ - return cls( - MethodDescriptor( - callable_method=method, - method_name=method_name or method.__name__, - arg_serialization=(None, request_deserializer), - return_serialization=(response_serializer, None), - rpc_type=RpcTypes.BI_STREAM.value, - ) - ) - - -class RpcServiceHandler: - """ - Rpc service handler - """ - - __slots__ = ["_service_name", "_method_handlers"] - - def __init__(self, service_name: str, method_handlers: list[RpcMethodHandler]): - """ - Initialize the RpcServiceHandler - :param service_name: the name of the service. - :type service_name: str - :param method_handlers: the method handlers. - :type method_handlers: List[RpcMethodHandler] - """ - self._service_name = service_name - self._method_handlers: dict[str, RpcMethodHandler] = {} - - for method_handler in method_handlers: - method_name = method_handler.method_descriptor.get_method_name() - self._method_handlers[method_name] = method_handler - - @property - def service_name(self) -> str: - """ - Get the service name - :return: the service name - :rtype: str - """ - return self._service_name - - @property - def method_handlers(self) -> dict[str, RpcMethodHandler]: - """ - Get the method handlers - :return: the method handlers - :rtype: Dict[str, RpcMethodHandler] - """ - return self._method_handlers diff --git a/src/dubbo/py.typed b/src/dubbo/py.typed new file mode 100644 index 00000000..e69de29b diff --git a/src/dubbo/registry/__init__.py b/src/dubbo/registry/__init__.py index 1af6cc31..6436c62c 100644 --- a/src/dubbo/registry/__init__.py +++ b/src/dubbo/registry/__init__.py @@ -1,19 +1,34 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. -from ._interfaces import NotifyListener, Registry, RegistryFactory +from .base import ( + InstanceRegistry, + InterfaceRegistry, + ServiceInstance, + get_instance_registry, + get_interface_registry, + registry_mode, +) -__all__ = ["Registry", "RegistryFactory", "NotifyListener"] +__all__ = [ + "InstanceRegistry", + "InterfaceRegistry", + "ServiceInstance", + "get_instance_registry", + "get_interface_registry", + "registry_mode", +] diff --git a/src/dubbo/registry/_interfaces.py b/src/dubbo/registry/_interfaces.py deleted file mode 100644 index d41c496b..00000000 --- a/src/dubbo/registry/_interfaces.py +++ /dev/null @@ -1,105 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc - -from dubbo.node import Node -from dubbo.url import URL - -__all__ = ["Registry", "RegistryFactory", "NotifyListener"] - - -class NotifyListener(abc.ABC): - """ - The notify listener. - """ - - @abc.abstractmethod - def notify(self, urls: list[URL]) -> None: - """ - Notify the listener. - - :param urls: The list of registered information , is always not empty. - """ - raise NotImplementedError() - - -class Registry(Node, abc.ABC): - @abc.abstractmethod - def register(self, url: URL) -> None: - """ - Register a service to registry. - - :param url: The service URL. - :type url: URL - :return: None - """ - raise NotImplementedError() - - @abc.abstractmethod - def unregister(self, url: URL) -> None: - """ - Unregister a service from registry. - - :param url: The service URL. - :type url: URL - """ - raise NotImplementedError() - - @abc.abstractmethod - def subscribe(self, url: URL, listener: NotifyListener) -> None: - """ - Subscribe a service from registry. - :param url: The service URL. - :type url: URL - :param listener: The listener to notify when service changed. - :type listener: NotifyListener - """ - raise NotImplementedError() - - @abc.abstractmethod - def unsubscribe(self, url: URL, listener: NotifyListener) -> None: - """ - Unsubscribe a service from registry. - :param url: The service URL. - :type url: URL - :param listener: The listener to notify when service changed. - :type listener: NotifyListener - """ - raise NotImplementedError() - - @abc.abstractmethod - def lookup(self, url: URL) -> None: - """ - Lookup a service from registry. - :param url: The service URL. - :type url: URL - """ - raise NotImplementedError() - - -class RegistryFactory(abc.ABC): - @abc.abstractmethod - def get_registry(self, url: URL) -> Registry: - """ - Get a registry instance. - - :param url: The registry URL. - :type url: URL - :return: The registry instance. - :rtype: Registry - """ - raise NotImplementedError() diff --git a/src/dubbo/registry/base.py b/src/dubbo/registry/base.py new file mode 100644 index 00000000..2f9602a8 --- /dev/null +++ b/src/dubbo/registry/base.py @@ -0,0 +1,222 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from collections.abc import AsyncIterator, Mapping +from contextlib import AbstractAsyncContextManager +from typing import Self + +import attrs + +from dubbo.config import RegistryMode +from dubbo.constants import DEFAULT_REGISTRY_MODE, REGISTER_MODE_KEY +from dubbo.extension import Resource, extension_point, extensions +from dubbo.url import URL +from dubbo.utils import freeze_mapping + +__all__ = [ + "InstanceRegistry", + "InterfaceRegistry", + "ServiceInstance", + "get_instance_registry", + "get_interface_registry", + "registry_mode", +] + + +@extension_point("apache_dubbo.interface_registry") +class InterfaceRegistry(Resource, typing.Protocol): + """Register service URLs by interface and watch those of providers. + + The implementation is installed under the entry point group + ``apache_dubbo.interface_registry``, named by the scheme of the registry + URL, such as ``zookeeper``, and created with that URL. Entering + ``async with`` connects, and closing disconnects. The application opens + one instance per URL, through `get_interface_registry`. Clients that other + extensions of the application also use come from getters that share them + through ``url.scope``, such as `get_zookeeper_client`: take them on + entering and leave them open on closing, as the scope closes them. + + Each registration stays registered until its context exits, including + while the connection to the registry is lost and found again. + + Attributes: + url: The URL the instance was created with. + """ + + url: URL + + def __init__(self, url: URL) -> None: + self.url = url + + def register(self, url: URL) -> AbstractAsyncContextManager[None]: + """Keep ``url`` registered under its ``interface`` parameter, or its path, and its ``category`` until the context exits. + + The category is ``providers`` when the URL has none; a consumer + registers itself with ``consumers``. Entering registers the URL and + exiting removes it; entering is all or nothing, so one that fails + leaves nothing registered. + """ + ... + + def subscribe( + self, interface: str, *, group: str | None, version: str | None + ) -> AbstractAsyncContextManager[AsyncIterator[list[URL]]]: + """Watch the URLs of the providers of ``interface`` until the context exits. + + ``group`` and ``version`` are those the consumer wants: ``None`` for + none, ``*`` for any, and for the group, several separated by commas. + A registry that keeps the providers of each group and version apart + uses them to find the providers; the URLs it yields may still + include others, which the consumer leaves out. + + The iterator yields the current URLs first, then the URLs after each + change. URLs the registry holds but that cannot be read are left out. + Changes made while the consumer is busy may be skipped, but the latest + is always yielded. Only the first URLs can fail, and their failure is + raised as it is, not in an exception group: after them the + iterator neither raises nor ends until the context exits, and keeps + the last URLs while the registry is unreachable. + """ + ... + + async def aclose(self) -> None: + """Disconnect from the registry.""" + ... + + async def __aenter__(self) -> Self: + """Connect to the registry.""" + ... + + +@attrs.define(frozen=True, kw_only=True) +class ServiceInstance: + """One running instance of an application, as an ``InstanceRegistry`` registers it. + + Attributes: + app: Name of the application. + host: Address consumers reach the instance at. + port: Port of the instance's main protocol. + metadata: What consumers need besides the address, such as the + revision of the application's metadata. + """ + + app: str + host: str + port: int + metadata: Mapping[str, str] = attrs.field(factory=dict, converter=freeze_mapping, hash=False) + + @property + def id(self) -> str: + """``host:port``, which tells the instances of one application apart.""" + return f"{self.host}:{self.port}" + + +@extension_point("apache_dubbo.instance_registry") +class InstanceRegistry(Resource, typing.Protocol): + """Register the instances of applications and watch those of other applications. + + The implementation is installed under the entry point group + ``apache_dubbo.instance_registry``, named by the scheme of the registry + URL, such as ``zookeeper``, and created with that URL. Entering + ``async with`` connects, and closing disconnects. The application opens + one instance per URL, through `get_instance_registry`. Clients that other + extensions of the application also use come from getters that share them + through ``url.scope``, such as `get_zookeeper_client`: take them on + entering and leave them open on closing, as the scope closes them. + + Each registration stays registered until its context exits, including + while the connection to the registry is lost and found again. + + Attributes: + url: The URL the instance was created with. + """ + + url: URL + + def __init__(self, url: URL) -> None: + self.url = url + + def register(self, instance: ServiceInstance) -> AbstractAsyncContextManager[None]: + """Keep ``instance`` registered until the context exits. + + Entering registers the instance, replacing a registered one with the + same application and id, and exiting removes it, unless a later + registration has replaced it meanwhile. Entering is all or nothing, + so one that fails leaves nothing of its own registered. + """ + ... + + def subscribe(self, app: str) -> AbstractAsyncContextManager[AsyncIterator[list[ServiceInstance]]]: + """Watch the instances of the application ``app`` until the context exits. + + The iterator yields the current instances first, then the instances + after each change, including a change of an instance's metadata. + Changes made while the consumer is busy may be skipped, but the latest + is always yielded. Only the first instances can fail, and their failure is + raised as it is, not in an exception group: after them the + iterator neither raises nor ends until the context exits, and keeps + the last instances while the registry is unreachable. + """ + ... + + async def aclose(self) -> None: + """Disconnect from the registry.""" + ... + + async def __aenter__(self) -> Self: + """Connect to the registry.""" + ... + + +async def get_interface_registry(url: URL) -> InterfaceRegistry: + """Return the interface registry ``url`` names, the same instance for the same URL in its application. + + The application of ``url.scope`` connects it on first use and + disconnects it when it stops. + + Raises: + ExtensionError: No implementation has the scheme of ``url``. + RuntimeError: ``url`` belongs to no running application. + """ + scope = url.scope + implementation = extensions.get(InterfaceRegistry, url.protocol) + return await scope.share((implementation, url), lambda: implementation(url)) + + +async def get_instance_registry(url: URL) -> InstanceRegistry: + """Return the instance registry ``url`` names, the same instance for the same URL in its application. + + The application of ``url.scope`` connects it on first use and + disconnects it when it stops. + + Raises: + ExtensionError: No implementation has the scheme of ``url``. + RuntimeError: ``url`` belongs to no running application. + """ + scope = url.scope + implementation = extensions.get(InstanceRegistry, url.protocol) + return await scope.share((implementation, url), lambda: implementation(url)) + + +def registry_mode(url: URL) -> RegistryMode: + """Return how the registry of ``url`` registers and discovers services: its ``register-mode``, else ``all``. + + Raises: + ValueError: ``register-mode`` names no mode. + """ + return RegistryMode(url.get_parameter(REGISTER_MODE_KEY, RegistryMode, DEFAULT_REGISTRY_MODE)) diff --git a/src/dubbo/registry/consumer.py b/src/dubbo/registry/consumer.py new file mode 100644 index 00000000..bb26feeb --- /dev/null +++ b/src/dubbo/registry/consumer.py @@ -0,0 +1,252 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""How a registry gives a reference the providers it holds, selected and completed, and holds the reference as a consumer.""" + +from collections.abc import AsyncGenerator, AsyncIterator, Callable, Collection, Iterable, Mapping +from contextlib import AbstractAsyncContextManager, AsyncExitStack, asynccontextmanager + +import anyio +import attrs + +from dubbo.cluster.configurator import Overrides +from dubbo.config import RegistryMode +from dubbo.constants import ( + APPLICATION_KEY, + CATEGORY_KEY, + CHECK_KEY, + CONSUMERS_CATEGORY, + DUBBO_VERSION_KEY, + GENERIC_KEY, + GROUP_KEY, + INTERFACE_KEY, + METHODS_KEY, + PROVIDERS_CATEGORY, + RELEASE_KEY, + REMOTE_APPLICATION_KEY, + SIDE_KEY, + TAG_KEY, + TIMESTAMP_KEY, + VERSION_KEY, +) +from dubbo.extension import extensions +from dubbo.protocol import Protocol +from dubbo.rpc.definition import Service +from dubbo.url import CONFIG_CENTER_URL, PROVIDER_URL, URL +from dubbo.utils import Latest +from dubbo.utils.converters import is_true + +from .base import get_interface_registry, registry_mode +from .registration import published_parameters, registered_parameters, registers, simplified + +__all__ = ["Consumer", "register_consumer"] + +_ENABLED_KEY = "enabled" +_DISABLED_KEY = "disabled" +# What a provider says about itself, which the parameters of the calls do not replace. +_PROVIDER_FIRST = ( + GROUP_KEY, + VERSION_KEY, + TAG_KEY, + METHODS_KEY, + RELEASE_KEY, + DUBBO_VERSION_KEY, + TIMESTAMP_KEY, + _ENABLED_KEY, + _DISABLED_KEY, +) +# Parameters of the URL of a reference that its registered consumer URL publishes. +_CONSUMER_PUBLISHED_KEYS = (APPLICATION_KEY, GROUP_KEY, VERSION_KEY, TAG_KEY) +# Parameters that simplified consumer URLs keep. +_CONSUMER_KEYS = frozenset( + {APPLICATION_KEY, VERSION_KEY, GROUP_KEY, DUBBO_VERSION_KEY, RELEASE_KEY, CATEGORY_KEY, CHECK_KEY} +) + + +@attrs.define(frozen=True, kw_only=True) +class Consumer: + """The service a reference calls, which selects and completes the URLs of providers. + + Attributes: + interface: Interface name of the service. + group: Group of the service; ``*`` accepts any, and commas separate several. + version: Version of the service; ``*`` accepts any. + parameters: Parameters of the calls, which provider URLs take. + attributes: Attributes of the reference, which provider URLs take. + """ + + interface: str + group: str | None + version: str | None + parameters: Mapping[str, str] + attributes: Mapping[str, object] = attrs.field(factory=dict) + + def prepare(self, provider: URL) -> URL | None: + """Return the URL to call ``provider`` with, or ``None`` if it does not serve this service. + + The URL keeps the provider's address and path. Its parameters are the + parameters of the calls, over those that providers publish for their + consumers, such as ``timeout`` and ``token``. Where the provider says + what it is, such as its group and version, the provider's value wins; + the tag is the provider's alone. Its application becomes + ``remote.application``. The attribute ``PROVIDER_URL`` keeps + ``provider`` as it is, with every parameter. + """ + if not self._accepts(provider): + return None + + offered = provider.parameters + parameters = published_parameters(offered) + parameters |= {key: value for key, value in self.parameters.items() if key != TAG_KEY} + parameters |= {key: offered[key] for key in _PROVIDER_FIRST if key in offered} + if APPLICATION_KEY in offered: + parameters[REMOTE_APPLICATION_KEY] = offered[APPLICATION_KEY] + + return URL( + protocol=provider.protocol, + host=provider.host, + port=provider.port, + path=provider.path or self.interface, + parameters=parameters, + attributes={**self.attributes, PROVIDER_URL: provider}, + ) + + @asynccontextmanager + async def watch( + self, subscription: AbstractAsyncContextManager[AsyncIterator[list[URL]]], url: URL + ) -> AsyncGenerator[AsyncIterator[list[URL]]]: + """Watch the URLs to call the providers of this service with, among the provider URLs of ``subscription``. + + The override rules of the configuration center of ``url``, the URL of + the reference, apply to them, if it has one, and a change of the + rules gives the URLs again. A provider whose URL, after the rules, + sets ``disabled`` true, or else ``enabled`` false, is left out. + """ + prepare = self._preparing() + if CONFIG_CENTER_URL not in url.attributes: + async with subscription as snapshots: + yield ([url for url in prepare(urls) if _enabled(url)] async for urls in snapshots) + return + + latest: Latest[list[URL]] = Latest() + prepared: list[URL] | None = None + + def publish() -> None: + if prepared is not None: + latest.publish([url for url in overrides.configure(prepared) if _enabled(url)]) + + async def receive(snapshots: AsyncIterator[list[URL]]) -> None: + nonlocal prepared + try: + async for urls in snapshots: + prepared = prepare(urls) + publish() + except Exception as error: + latest.close(error) + else: + latest.close() + + overrides = Overrides(url, "consumer", publish) + async with overrides, subscription as snapshots, anyio.create_task_group() as task_group: + task_group.start_soon(receive, snapshots) + yield aiter(latest) + task_group.cancel_scope.cancel() + + def _preparing(self) -> Callable[[list[URL]], list[URL]]: + """Return what prepares the providers of each snapshot, reusing what it prepared for the snapshot before.""" + last: dict[URL, URL | None] = {} + + def prepare(urls: list[URL]) -> list[URL]: + nonlocal last + last = {url: last[url] if url in last else self.prepare(url) for url in urls} + return [prepared for url in urls if (prepared := last[url]) is not None] + + return prepare + + def _accepts(self, provider: URL) -> bool: + parameters = provider.parameters + if (parameters.get(INTERFACE_KEY) or provider.path) != self.interface: + return False + if parameters.get(CATEGORY_KEY, PROVIDERS_CATEGORY) != PROVIDERS_CATEGORY: + return False + if provider.host is None or provider.protocol not in extensions.names(Protocol): + return False + + return _group_accepts(self.group, parameters.get(GROUP_KEY)) and ( + self.version == "*" or (self.version or "") == parameters.get(VERSION_KEY, "") + ) + + +def _enabled(url: URL) -> bool: + """Return whether the provider ``url`` takes calls: by ``disabled`` if it has one, else by ``enabled``, true when absent.""" + parameters = url.parameters + if _DISABLED_KEY in parameters: + return not is_true(parameters[_DISABLED_KEY]) + return is_true(parameters.get(_ENABLED_KEY, "true")) + + +def _group_accepts(wanted: str | None, group: str | None) -> bool: + if wanted == "*": + return True + if wanted and "," in wanted: + return (group or "") in wanted.split(",") + return (wanted or "") == (group or "") + + +@asynccontextmanager +async def register_consumer( + url: URL, definition: Service, registries: Iterable[URL], *, generic: str | None +) -> AsyncGenerator[None]: + """Register the reference ``url`` as a consumer until the context exits. + + It is registered in the ``consumers`` category of those of + ``registries`` that register by interface and do not set ``register`` + to false; a registry URL with ``simplified=true`` gets only the + parameters that identify the consumer. A reference of a ``generic`` + mode, which calls methods by name without a contract, is registered + with that mode, such as ``generic=true``, and no ``methods``. + """ + consumer = _consumer_url(url, [method.name for method in definition.methods], generic=generic) + async with AsyncExitStack() as stack: + for registry in registries: + if registers(registry) and registry_mode(registry) is not RegistryMode.INSTANCE: + interface_registry = await get_interface_registry(registry) + await stack.enter_async_context( + interface_registry.register(_registered_consumer_url(consumer, registry)) + ) + + yield + + +def _consumer_url(url: URL, methods: Collection[str], *, generic: str | None) -> URL: + """Return the URL that registries publish for the reference ``url``, in the ``consumers`` category.""" + parameters = {key: value for key, value in url.parameters.items() if key in _CONSUMER_PUBLISHED_KEYS} + parameters |= registered_parameters(methods) + if generic is not None: + del parameters[METHODS_KEY] + parameters[GENERIC_KEY] = generic + parameters |= {SIDE_KEY: "consumer", CATEGORY_KEY: CONSUMERS_CATEGORY, CHECK_KEY: "false", INTERFACE_KEY: url.path} + + return URL(protocol="consumer", host=url.host, path=url.path, parameters=parameters) + + +def _registered_consumer_url(url: URL, registry: URL) -> URL: + """Return ``url`` as ``registry`` takes it: whole, or simplified to what identifies the consumer.""" + if not simplified(registry): + return url + + return url.replace(parameters={key: value for key, value in url.parameters.items() if key in _CONSUMER_KEYS}) diff --git a/src/dubbo/registry/discovery.py b/src/dubbo/registry/discovery.py new file mode 100644 index 00000000..370d13be --- /dev/null +++ b/src/dubbo/registry/discovery.py @@ -0,0 +1,394 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""How a reference finds the provider URLs a registry holds: registered by interface, or through instances.""" + +import logging +import math +from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Collection, Hashable, Mapping +from contextlib import AsyncExitStack, asynccontextmanager +from typing import Generic, Self, TypeVar, cast + +import anyio +import attrs +from anyio.abc import TaskGroup, TaskStatus + +from dubbo.exceptions import DubboError +from dubbo.extension import Resource +from dubbo.metadata import MetadataInfo, MetadataReport, get_metadata_report +from dubbo.metadata.instance import InstanceMetadata, read_metadata +from dubbo.url import APPLICATION_SCOPE, METADATA_CONSUMER_URL, URL +from dubbo.utils import Latest, backoff, create_background_task_group, follow + +from .base import InstanceRegistry, ServiceInstance, get_instance_registry, get_interface_registry + +__all__ = ["subscribe_by_instance", "subscribe_by_interface"] + +_logger = logging.getLogger(__name__) + +K = TypeVar("K", bound=Hashable) +T = TypeVar("T") + +# The URLs of the services of an application, by service path. +_Services = Mapping[str, list[URL]] + + +@asynccontextmanager +async def subscribe_by_interface( + registry: URL, interface: str, *, group: str | None, version: str | None +) -> AsyncGenerator[AsyncIterator[list[URL]]]: + """Watch the provider URLs of ``interface`` registered by interface in ``registry`` until the context exits. + + The arguments and the iterator follow the contract of ``InterfaceRegistry.subscribe``. + """ + implementation = await get_interface_registry(registry) + async with implementation.subscribe(interface, group=group, version=version) as snapshots: + yield snapshots + + +@asynccontextmanager +async def subscribe_by_instance( + registry: URL, interface: str, apps: Collection[str] | None +) -> AsyncGenerator[AsyncIterator[list[URL]]]: + """Watch the provider URLs of ``interface`` until the context exits, from the instances ``registry`` holds. + + The instances are those of ``apps``, else of the applications mapped to + ``interface``. The references of the application of ``registry`` share + one watch of each mapping and each application. + """ + instances = await get_instance_registry(registry) + report = await get_metadata_report(registry) + consumer = cast(URL | None, registry.attributes.get(METADATA_CONSUMER_URL)) or URL( + protocol="consumer", attributes={APPLICATION_SCOPE: registry.scope} + ) + resolver = await registry.scope.share( + (_InstanceResolver, registry), lambda: _InstanceResolver(instances, report, consumer) + ) + async with resolver.subscribe(interface, apps) as snapshots: + yield snapshots + + +class _InstanceResolver(Resource): + """Finds the providers of interfaces in one registry through the instances of the applications that provide them. + + The metadata report maps an interface to the applications that provide + it. Each instance of an application registers the revision of its + metadata, which lists the services of the application, and that + metadata with the address of the instance gives the URLs of its + services. The subscriptions share one watch of each mapping and each + application, which runs while some subscription follows it, so an + application is watched, and the metadata of each revision read, once + however many of its services are referenced. + """ + + def __init__(self, registry: InstanceRegistry, report: MetadataReport, consumer: URL) -> None: + """The MetadataService of instances is called with the parameters and the attributes of ``consumer``.""" + self._registry = registry + self._report = report + self._consumer = consumer + self._stack = AsyncExitStack() + self._mappings: _SharedWatches[str, frozenset[str]] | None = None + self._apps: _SharedWatches[str, _Services] | None = None + + @asynccontextmanager + async def subscribe(self, interface: str, apps: Collection[str] | None) -> AsyncGenerator[AsyncIterator[list[URL]]]: + """Watch the provider URLs of ``interface`` until the context exits, in ``apps``, else in those mapped to it. + + The iterator yields the current URLs first, then the URLs after each + change. The first URLs come once the mapping is read, which may fail, + and every application has been watched once. An application whose + watch fails has no URLs and is watched again after a delay. After the + first URLs, the iterator neither raises nor ends until the context + exits. + """ + if self._mappings is None or self._apps is None: + raise RuntimeError("the resolver is closed") + + async with create_background_task_group() as task_group: + watch = _InterfaceWatch(interface, self._apps, task_group) + if apps is not None: + await watch.follow_apps(apps) + else: + await task_group.start(watch.follow_mapping, self._mappings) + try: + yield aiter(watch.latest) + finally: + task_group.cancel_scope.cancel() + + async def aclose(self) -> None: + self._mappings = self._apps = None + await self._stack.aclose() + + async def __aenter__(self) -> Self: + async with AsyncExitStack() as stack: + task_group = await stack.enter_async_context(anyio.create_task_group()) + stack.callback(task_group.cancel_scope.cancel) + self._mappings = _SharedWatches(task_group, self._watch_mapping) + self._apps = _SharedWatches(task_group, self._watch_app) + self._stack = stack.pop_all() + + return self + + async def _watch_mapping(self, interface: str, latest: Latest[frozenset[str]]) -> None: + async with self._report.subscribe_service_app_mapping(interface) as mappings: + async for apps in mappings: + latest.publish(apps) + + async def _watch_app(self, app: str, latest: Latest[_Services]) -> None: + metadata = _AppMetadata(app=app, report=self._report, consumer=self._consumer) + changes: Latest[list[ServiceInstance]] = Latest() + + async def receive() -> None: + async for instances in snapshots: + changes.publish(instances) + changes.close(RuntimeError(f"the watch of the instances of {app} ended")) + + async with self._registry.subscribe(app) as snapshots, anyio.create_task_group() as task_group: + task_group.start_soon(receive) + reader = aiter(changes) + instances = await anext(reader) + delays = backoff() + while True: + services, complete = await metadata.resolve(instances) + latest.publish(services) + + # Metadata that could not be read is read again later. + if complete: + delays = backoff() + with anyio.move_on_after(math.inf if complete else next(delays)): + instances = await anext(reader) + + +class _InterfaceWatch: + """The provider URLs of one interface across the applications that provide it.""" + + def __init__(self, interface: str, apps: "_SharedWatches[str, _Services]", task_group: TaskGroup) -> None: + self.latest: Latest[list[URL]] = Latest() + self._interface = interface + self._apps = apps + self._task_group = task_group + self._urls: dict[str, list[URL]] = {} + self._scopes: dict[str, anyio.CancelScope] = {} + self._started = False + + async def follow_mapping( + self, mappings: "_SharedWatches[str, frozenset[str]]", *, task_status: TaskStatus[None] + ) -> None: + """Follow the applications the mapping names; the first names fail the subscription if they cannot be read.""" + await follow( + lambda: mappings.follow(self._interface), + self.follow_apps, + f"the applications that provide {self._interface}", + task_status=task_status, + ) + + async def follow_apps(self, apps: Collection[str]) -> None: + """Follow ``apps`` from now on, returning once each new one has been watched once.""" + for app in self._scopes.keys() - set(apps): + self._scopes.pop(app).cancel() + self._urls.pop(app, None) + + added = sorted(set(apps) - self._scopes.keys()) + for app in added: + self._scopes[app] = anyio.CancelScope() + async with anyio.create_task_group() as starting: + for app in added: + starting.start_soon(self._task_group.start, self._follow_app, app, self._scopes[app]) + + self._started = True + self._publish() + + async def _follow_app(self, app: str, scope: anyio.CancelScope, *, task_status: TaskStatus[None]) -> None: + async def receive(services: _Services) -> None: + # A follower replaced after its application left and came back publishes nothing. + if self._scopes.get(app) is scope: + self._urls[app] = services.get(self._interface, []) + self._publish() + + with scope: + await follow( + lambda: self._apps.follow(app), + receive, + f"the instances of {app}", + retry_first=True, + task_status=task_status, + ) + + def _publish(self) -> None: + if self._started: + self.latest.publish([url for app in sorted(self._urls) for url in self._urls[app]]) + + +@attrs.define(kw_only=True, eq=False) +class _Watch(Generic[T]): + latest: Latest[T] = attrs.field(factory=Latest) + scope: anyio.CancelScope = attrs.field(factory=anyio.CancelScope) + followers: int = 0 + + +class _SharedWatches(Generic[K, T]): + """Runs one watch per key while it has followers, who share the values it publishes. + + A watch that fails before its first value fails the followers waiting + for it. One that fails or ends after it breaks the contract of what it + watches: that is logged, and the iterations of its followers end. Either + way it is forgotten, so the next follower starts it again. + """ + + def __init__(self, task_group: TaskGroup, watch: Callable[[K, Latest[T]], Awaitable[None]]) -> None: + self._task_group = task_group + self._watch = watch + self._watches: dict[K, _Watch[T]] = {} + + @asynccontextmanager + async def follow(self, key: K) -> AsyncGenerator[AsyncIterator[T]]: + """Follow the watch of ``key``, iterating its latest value first.""" + watch = self._watches.get(key) + if watch is None: + watch = self._watches[key] = _Watch() + self._task_group.start_soon(self._run, key, watch) + + watch.followers += 1 + try: + yield aiter(watch.latest) + finally: + watch.followers -= 1 + if not watch.followers: + watch.scope.cancel() + self._forget(key, watch) + + async def _run(self, key: K, watch: _Watch[T]) -> None: + with watch.scope: + try: + await self._watch(key, watch.latest) + error: Exception = RuntimeError(f"the watch of {key!r} ended") + except Exception as failure: + error = failure + + self._forget(key, watch) + if watch.latest.empty: + watch.latest.close(error) + return + + _logger.error("The watch of %r stopped after its first value", key, exc_info=error) + watch.latest.close() + + def _forget(self, key: K, watch: _Watch[T]) -> None: + # A watch that has been replaced leaves its replacement alone. + if self._watches.get(key) is watch: + del self._watches[key] + + +@attrs.define(frozen=True, kw_only=True, eq=False) +class _Resolved: + """The URLs found for an instance, and the instance metadata and the MetadataInfo they were made from.""" + + metadata: InstanceMetadata + info: MetadataInfo + urls: list[URL] + + +@attrs.define(kw_only=True, eq=False) +class _AppMetadata: + """Turns the instances of one application into the URLs of its services, reading its metadata once per revision.""" + + app: str + report: MetadataReport + # What the MetadataService of its instances is called with. + consumer: URL + # The metadata of the revisions in use. + infos: dict[str, MetadataInfo] = attrs.field(factory=dict) + # What was last found for each instance, by id. + resolved: dict[str, _Resolved] = attrs.field(factory=dict) + + async def resolve(self, instances: list[ServiceInstance]) -> tuple[_Services, bool]: + """Return the URLs of the services, and whether the metadata of every revision could be read. + + An instance whose revision cannot be read yet keeps the URLs it had, + and one whose metadata and revision do not change keeps the same URLs. + """ + found: dict[str, InstanceMetadata] = {} + for instance in instances: + try: + metadata = InstanceMetadata.from_metadata(instance.host, instance.port, instance.metadata) + except ValueError: + _logger.warning("Ignoring an instance of %s", self.app, exc_info=True) + continue + if metadata is not None: + found[instance.id] = metadata + + by_revision: dict[str, list[InstanceMetadata]] = {} + for metadata in found.values(): + by_revision.setdefault(metadata.revision, []).append(metadata) + self.infos = {revision: info for revision, info in self.infos.items() if revision in by_revision} + async with anyio.create_task_group() as task_group: + for revision, members in by_revision.items(): + if revision not in self.infos: + task_group.start_soon(self._read, revision, members) + + resolved: dict[str, _Resolved] = {} + for instance_id, metadata in found.items(): + info = self.infos.get(metadata.revision) + kept = self.resolved.get(instance_id) + if info is None: + if kept is not None: + resolved[instance_id] = kept + elif kept is not None and kept.metadata == metadata and kept.info is info: + resolved[instance_id] = kept + else: + resolved[instance_id] = _Resolved(metadata=metadata, info=info, urls=self._service_urls(metadata, info)) + self.resolved = resolved + + services: dict[str, list[URL]] = {} + for each in resolved.values(): + for url in each.urls: + services.setdefault(url.path, []).append(url) + + return services, by_revision.keys() <= self.infos.keys() + + async def _read(self, revision: str, instances: list[InstanceMetadata]) -> None: + for instance in instances: + try: + info = await read_metadata(self.app, instance, self.report, self.consumer) + except (DubboError, OSError, ValueError): + _logger.warning( + "Cannot read the metadata of %s:%d at revision %s; trying another instance", + instance.host, + instance.port, + revision, + exc_info=True, + ) + continue + + if info is not None and info.services: + self.infos[revision] = info + return + + def _service_urls(self, metadata: InstanceMetadata, info: MetadataInfo) -> list[URL]: + try: + return metadata.service_urls(info) + except ValueError: + # Kept as no URLs, so that the other instances still have theirs and this one is logged once. + _logger.warning( + "Ignoring the instance %s:%d of %s, whose metadata at revision %s holds no valid URL", + metadata.host, + metadata.port, + self.app, + metadata.revision, + exc_info=True, + ) + return [] diff --git a/src/dubbo/registry/nacos/__init__.py b/src/dubbo/registry/nacos/__init__.py new file mode 100644 index 00000000..e58bb5c7 --- /dev/null +++ b/src/dubbo/registry/nacos/__init__.py @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .instance import NacosInstanceRegistry +from .interface import NacosInterfaceRegistry + +__all__ = ["NacosInstanceRegistry", "NacosInterfaceRegistry"] diff --git a/src/dubbo/registry/nacos/instance.py b/src/dubbo/registry/nacos/instance.py new file mode 100644 index 00000000..07f14f47 --- /dev/null +++ b/src/dubbo/registry/nacos/instance.py @@ -0,0 +1,81 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import AsyncGenerator, AsyncIterator +from contextlib import AbstractAsyncContextManager, asynccontextmanager +from typing import Self + +from dubbo.constants import GROUP_KEY +from dubbo.transport import nacos +from dubbo.url import URL + +from ..base import InstanceRegistry, ServiceInstance + +__all__ = ["NacosInstanceRegistry"] + +_NACOS_GROUP_KEY = "nacos.group" + + +class NacosInstanceRegistry(InstanceRegistry): + """An ``InstanceRegistry`` in Nacos services named after the applications. + + An instance of an application is an instance of the service named after + the application, carrying the instance's metadata, in the Nacos group + that the ``nacos.group`` URL parameter names, else ``group``, else + ``DEFAULT_GROUP``. The client comes from ``get_nacos_naming_client``, shared + with the other users of an equal connection. + """ + + def __init__(self, url: URL) -> None: + super().__init__(url) + parameters = url.parameters + self._group = parameters.get(_NACOS_GROUP_KEY) or parameters.get(GROUP_KEY, nacos.DEFAULT_GROUP) + self._client: nacos.NacosNamingClient | None = None + + def register(self, instance: ServiceInstance) -> AbstractAsyncContextManager[None]: + client = self._connected() + + return client.keep_registered(instance.app, self._group, _nacos_instance(instance)) + + @asynccontextmanager + async def subscribe(self, app: str) -> AsyncGenerator[AsyncIterator[list[ServiceInstance]]]: + client = self._connected() + + async with client.watch(app, self._group) as snapshots: + yield ( + [ + ServiceInstance(app=app, host=instance.host, port=instance.port, metadata=instance.metadata) + for instance in instances + ] + async for instances in snapshots + ) + + async def aclose(self) -> None: + self._client = None + + async def __aenter__(self) -> Self: + self._client = await nacos.get_nacos_naming_client(self.url) + return self + + def _connected(self) -> nacos.NacosNamingClient: + if self._client is None: + raise RuntimeError("the registry is not connected") + return self._client + + +def _nacos_instance(instance: ServiceInstance) -> nacos.NacosInstance: + return nacos.NacosInstance(host=instance.host, port=instance.port, metadata=instance.metadata) diff --git a/src/dubbo/registry/nacos/interface.py b/src/dubbo/registry/nacos/interface.py new file mode 100644 index 00000000..e63ba05b --- /dev/null +++ b/src/dubbo/registry/nacos/interface.py @@ -0,0 +1,161 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +from collections.abc import AsyncGenerator, AsyncIterator +from contextlib import AsyncExitStack, asynccontextmanager +from typing import Self + +from dubbo.constants import ( + CATEGORY_KEY, + CONSUMERS_CATEGORY, + GROUP_KEY, + INTERFACE_KEY, + PATH_KEY, + PROVIDERS_CATEGORY, + VERSION_KEY, +) +from dubbo.transport import nacos +from dubbo.url import URL +from dubbo.utils import Latest, create_background_task_group +from dubbo.utils.converters import boolean + +from ..base import InterfaceRegistry + +__all__ = ["NacosInterfaceRegistry"] + +_logger = logging.getLogger(__name__) + +_PROTOCOL_KEY = "protocol" +_REGISTER_CONSUMER_URL_KEY = "register-consumer-url" +_ANY = "*" + + +class NacosInterfaceRegistry(InterfaceRegistry): + """An ``InterfaceRegistry`` in Nacos services named by category, interface, version and group. + + A URL is an instance of the service + ``{category}:{interface}:{version}:{group}``, with an empty segment for a + missing version or group, in the Nacos group that the ``group`` URL + parameter names, ``DEFAULT_GROUP`` by default. The instance carries the + URL's parameters, with its ``category``, ``protocol`` and ``path``, at + port 0 when the URL has none, as a consumer URL. Consumers register + only when the ``register-consumer-url`` parameter is true. The client + comes from ``get_nacos_naming_client``, shared with the other users of + an equal connection. + """ + + def __init__(self, url: URL) -> None: + super().__init__(url) + self._group = url.parameters.get(GROUP_KEY, nacos.DEFAULT_GROUP) + self._register_consumers = url.get_parameter(_REGISTER_CONSUMER_URL_KEY, boolean, False) + self._client: nacos.NacosNamingClient | None = None + + @asynccontextmanager + async def register(self, url: URL) -> AsyncGenerator[None]: + client = self._connected() + + if not self._registers(url): + yield + return + + async with client.keep_registered(_service(url), self._group, _instance(url)): + yield + + @asynccontextmanager + async def subscribe( + self, interface: str, *, group: str | None, version: str | None + ) -> AsyncGenerator[AsyncIterator[list[URL]]]: + client = self._connected() + # shortcut: "*" would need the services of the group listed and polled; add it when someone needs it. + if group == _ANY or version == _ANY: + raise ValueError(f"a Nacos registry cannot watch any group or version of {interface}: name them") + + services = [f"{PROVIDERS_CATEGORY}:{interface}:{version or ''}:{name}" for name in (group or "").split(",")] + latest: Latest[list[URL]] = Latest() + urls: dict[str, list[URL]] = {} + + async def receive(service: str, snapshots: AsyncIterator[list[nacos.NacosInstance]]) -> None: + async for instances in snapshots: + urls[service] = _urls(instances, service) + if len(urls) == len(services): + latest.publish([url for each in services for url in urls[each]]) + + async with AsyncExitStack() as stack, create_background_task_group() as task_group: + for service in services: + snapshots = await stack.enter_async_context(client.watch(service, self._group)) + task_group.start_soon(receive, service, snapshots) + yield aiter(latest) + task_group.cancel_scope.cancel() + + async def aclose(self) -> None: + self._client = None + + async def __aenter__(self) -> Self: + self._client = await nacos.get_nacos_naming_client(self.url) + return self + + def _registers(self, url: URL) -> bool: + return url.parameters.get(CATEGORY_KEY, PROVIDERS_CATEGORY) != CONSUMERS_CATEGORY or self._register_consumers + + def _connected(self) -> nacos.NacosNamingClient: + if self._client is None: + raise RuntimeError("the registry is not connected") + return self._client + + +def _service(url: URL) -> str: + parameters = url.parameters + interface = parameters.get(INTERFACE_KEY) or url.path + category = parameters.get(CATEGORY_KEY, PROVIDERS_CATEGORY) + return f"{category}:{interface}:{parameters.get(VERSION_KEY, '')}:{parameters.get(GROUP_KEY, '')}" + + +def _instance(url: URL) -> nacos.NacosInstance: + if url.host is None: + raise ValueError(f"a URL registered in Nacos needs a host: {url}") + + metadata = { + **url.parameters, + CATEGORY_KEY: url.parameters.get(CATEGORY_KEY, PROVIDERS_CATEGORY), + _PROTOCOL_KEY: url.protocol, + PATH_KEY: url.path, + } + return nacos.NacosInstance(host=url.host, port=url.port or 0, metadata=metadata) + + +def _urls(instances: list[nacos.NacosInstance], service: str) -> list[URL]: + urls = [] + for instance in instances: + parameters = dict(instance.metadata) + protocol = parameters.pop(_PROTOCOL_KEY, None) + if not protocol: + _logger.warning( + "Ignoring the instance %s:%d of %s, which names no protocol", instance.host, instance.port, service + ) + continue + path = parameters.pop(PATH_KEY, "") + try: + url = URL(protocol=protocol, host=instance.host, port=instance.port, path=path, parameters=parameters) + except ValueError: + _logger.warning( + "Ignoring the instance %s:%d of %s, which holds no valid URL", instance.host, instance.port, service + ) + continue + urls.append(url) + + return urls diff --git a/src/dubbo/registry/protocol.py b/src/dubbo/registry/protocol.py deleted file mode 100644 index 273f4afd..00000000 --- a/src/dubbo/registry/protocol.py +++ /dev/null @@ -1,67 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from dubbo.cluster.directories import RegistryDirectory -from dubbo.cluster.failfast_cluster import FailfastCluster -from dubbo.cluster.monitor.cpu import CpuInnerRpcHandler, CpuMonitor -from dubbo.configs import RegistryConfig -from dubbo.constants import common_constants -from dubbo.extension import extensionLoader -from dubbo.protocol import Invoker, Protocol -from dubbo.registry import RegistryFactory -from dubbo.url import URL - -__all__ = ["RegistryProtocol"] - - -class RegistryProtocol(Protocol): - """ - Registry protocol. - """ - - def __init__(self, config: RegistryConfig, protocol: Protocol): - self._config = config - self._protocol = protocol - - self._factory: RegistryFactory = extensionLoader.get_extension(RegistryFactory, self._config.protocol)() - - def export(self, url: URL): - # get the server registry - registry = self._factory.get_registry(url) - - ref_url: URL = url.attributes[common_constants.EXPORT_KEY] - registry.register(ref_url) - - # add cpu handler - ref_url.attributes[common_constants.SERVICE_HANDLER_KEY] = [ - ref_url.attributes[common_constants.SERVICE_HANDLER_KEY], - CpuInnerRpcHandler.get_service_handler(), - ] - - # continue the export process - self._protocol.export(ref_url) - - def refer(self, url: URL) -> Invoker: - registry = self._factory.get_registry(url) - - # create the directory - if url.parameters.get(common_constants.LOADBALANCE_KEY) == "cpu": - directory = CpuMonitor(registry, self._protocol, url) - else: - directory = RegistryDirectory(registry, self._protocol, url) - - # continue the refer process - return FailfastCluster().join(directory) diff --git a/src/dubbo/registry/provider.py b/src/dubbo/registry/provider.py new file mode 100644 index 00000000..0640e5a7 --- /dev/null +++ b/src/dubbo/registry/provider.py @@ -0,0 +1,452 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""How the services of an application are served and registered: by interface, and through the application instance.""" + +import logging +from collections.abc import AsyncGenerator, Awaitable, Callable, Sequence +from contextlib import AbstractAsyncContextManager, AsyncExitStack, asynccontextmanager +from typing import cast + +import anyio +import attrs +from anyio.abc import TaskGroup, TaskStatus + +from dubbo.cluster.configurator import Overrides +from dubbo.config import DubboConfig, MetadataType, RegistryMode +from dubbo.config.urls import internal_service_urls +from dubbo.constants import ( + APPLICATION_KEY, + CLUSTER_KEY, + DEFAULT_METADATA_TYPE, + DEFAULT_UNREGISTER_WAIT, + DEPRECATED_KEY, + DUBBO_VERSION, + DUBBO_VERSION_KEY, + EXTRA_KEYS_KEY, + GROUP_KEY, + INTERFACE_KEY, + LOADBALANCE_KEY, + METHODS_KEY, + PATH_KEY, + PREFER_SERIALIZATION_KEY, + RELEASE_KEY, + SERIALIZATION_KEY, + SIDE_KEY, + TIMEOUT_KEY, + TIMESTAMP_KEY, + TOKEN_KEY, + VERSION_KEY, + WARMUP_KEY, + WEIGHT_KEY, +) +from dubbo.extension import ApplicationScope +from dubbo.metadata import MetadataInfo, MetadataReport, ServiceInfo, get_metadata_report +from dubbo.metadata.instance import instance_metadata +from dubbo.metadata.service.server import LocalMetadata +from dubbo.protocol.exported import ExportedService +from dubbo.url import ADVERTISED_PORT, URL +from dubbo.utils import Latest, backoff, create_background_task_group +from dubbo.utils.converters import comma_separated + +from .base import ( + InstanceRegistry, + InterfaceRegistry, + ServiceInstance, + get_instance_registry, + get_interface_registry, + registry_mode, +) +from .registration import ( + RELEASE, + published_parameters, + registered_host, + registered_parameters, + registers, + registration_time, + simplified, +) + +__all__ = ["register_services"] + +_logger = logging.getLogger(__name__) + +# Parameters that simplified provider URLs keep, besides those of their methods and the extra keys. +_PROVIDER_KEYS = frozenset({ + APPLICATION_KEY, "codec", "exchanger", SERIALIZATION_KEY, PREFER_SERIALIZATION_KEY, CLUSTER_KEY, "connections", + DEPRECATED_KEY, GROUP_KEY, LOADBALANCE_KEY, "mock", PATH_KEY, TIMEOUT_KEY, TOKEN_KEY, VERSION_KEY, WARMUP_KEY, + WEIGHT_KEY, DUBBO_VERSION_KEY, RELEASE_KEY, SIDE_KEY, "ipv6", "serialize.packable.factory", "auth", + "authenticator", "username", "password", +}) # fmt: skip + + +@asynccontextmanager +async def register_services( + config: DubboConfig, services: Sequence[ExportedService], scope: ApplicationScope +) -> AsyncGenerator[tuple[URL, ...]]: + """Register ``services`` of the application of ``scope`` with their registries until the context exits. + + It holds the URLs the MetadataService is served with, if the registering serves it. + + Registries that set ``register`` to false get nothing. In those that + register by interface, the URL of each service is registered, with the + parameters consumers take. In those that register instances, the + application registers one instance whose metadata lists those URLs, and + records that it provides each interface; with ``local`` metadata, the + first such instance starts serving the MetadataService on the server of + the services, as `dubbo.metadata.service.server.LocalMetadata` does. + The URLs carry ``application.advertised_host`` and the advertised port + of their protocol, else of the application, when set. A registry URL also gets the parameters of the services that + its ``extra-keys`` name; with ``simplified=true``, it gets only those + and the parameters consumers need. + + With a configuration center, the override rules of the providers change + the registered URLs, and each change registers them again; a failure to + register them is logged and tried again. Each change, and the rules at + the start, also reach how the services serve, through ``reconfigure``. + When the context exits without an error, it waits + ``shutdown.unregister_wait`` after unregistering, if it registered + anything. + + Raises: + ConfigError: Metadata is ``local`` but no service is served over tri or dubbo. + ValueError: A parameter of a registry is invalid. + ZookeeperError: A ZooKeeper registry cannot be reached. + """ + application = config.application + async with AsyncExitStack() as stack: + changes: Latest[None] = Latest() + published: list[_Published] = [] + for service in services: + registries = [registry for registry in service.registries if registers(registry)] + if not registries: + continue + url = _provider_url(service).replace( + host=await registered_host(application.advertised_host or service.url.host, registries), + port=_advertised_port(service.url), + ) + overrides = await stack.enter_async_context(Overrides(url, "provider", lambda: changes.publish(None))) + published.append(_Published(service=service, url=url, registries=registries, overrides=overrides)) + + def reconfigure() -> None: + for each in published: + each.reconfigure() + + metadata = LocalMetadata( + internal_service_urls(config, [service.interface for service in services], scope), stack + ) + keepers = await stack.enter_async_context(create_background_task_group()) + # Cancelled after the callbacks below have released every registration. + stack.callback(keepers.cancel_scope.cancel) + kept = _Kept(keepers) + metadata_type = MetadataType(application.metadata_type or DEFAULT_METADATA_TYPE) + registrations: list[_InterfaceRegistration | _InstanceRegistration] = [] + for registry in dict.fromkeys(registry for each in published for registry in each.registries): + mode = registry_mode(registry) + if mode is not RegistryMode.INSTANCE: + registrations.append( + _InterfaceRegistration(registry=registry, client=await get_interface_registry(registry), kept=kept) + ) + if mode is not RegistryMode.INTERFACE: + registrations.append( + _InstanceRegistration( + registry=registry, + client=await get_instance_registry(registry), + report=await get_metadata_report(registry), + metadata_type=metadata_type, + metadata=metadata, + kept=kept, + ) + ) + + async def register() -> None: + for registration in registrations: + registry = registration.registry + await registration.register( + [each.registered_url(registry) for each in published if registry in each.registries] + ) + # Only the revisions of registered instances stay served. + metadata.retain( + { + registration.revision + for registration in registrations + if isinstance(registration, _InstanceRegistration) and registration.revision is not None + } + ) + + for registration in registrations: + stack.push_async_callback(registration.unregister) + reconfigure() + await register() + + task_group = await stack.enter_async_context(create_background_task_group()) + stack.callback(task_group.cancel_scope.cancel) + task_group.start_soon(_register_on_change, changes, reconfigure, register) + + yield metadata.urls + + # Consumers stop calling once they notice, while the services still serve. + if published: + wait = config.shutdown.unregister_wait + await anyio.sleep(DEFAULT_UNREGISTER_WAIT if wait is None else wait) + + +@attrs.define(frozen=True, kw_only=True) +class _Published: + """The URL a service registers before the override rules, the registries it registers with, and its rules.""" + + service: ExportedService + url: URL + registries: list[URL] + overrides: Overrides + + def registered_url(self, registry: URL) -> URL: + """Return the URL to register with ``registry``, with its extra keys, after the override rules.""" + url = _with_extra_keys(self.url, self.service.url, registry) + return _registered_provider_url(self.overrides.configure([url])[0], registry) + + def reconfigure(self) -> None: + """Apply to how the service serves the parameters that the override rules change.""" + configured = self.overrides.configure([self.url])[0].parameters + self.service.reconfigure( + {key: value for key, value in configured.items() if self.url.parameters.get(key) != value} + ) + + +async def _register_on_change( + changes: Latest[None], reconfigure: Callable[[], None], register: Callable[[], Awaitable[None]] +) -> None: + """Call ``reconfigure``, then ``register`` until it succeeds, after each change of the override rules. + + A change applies at once even while ``register`` still fails for an + earlier one, whose attempts it replaces. + """ + registering = anyio.CancelScope() + async with anyio.create_task_group() as task_group: + async for _ in changes: + reconfigure() + registering.cancel() + registering = anyio.CancelScope() + task_group.start_soon(_register_until_done, register, registering) + + +async def _register_until_done(register: Callable[[], Awaitable[None]], scope: anyio.CancelScope) -> None: + with scope: + for delay in backoff(): + try: + await register() + return + except Exception: + _logger.warning( + "Cannot register the services as their override rules changed; trying again in %.1f seconds", + delay, + exc_info=True, + ) + await anyio.sleep(delay) + + +def _provider_url(service: ExportedService) -> URL: + """Return the URL that registries publish for ``service``: what its consumers take from it.""" + methods = [method.name for method in service.definition.methods] + parameters = published_parameters(service.url.parameters, methods) | registered_parameters(methods) + + return service.url.replace( + path=service.interface, + parameters=parameters | {SIDE_KEY: "provider", INTERFACE_KEY: service.interface}, + ) + + +def _with_extra_keys(url: URL, served: URL, registry: URL) -> URL: + """Return ``url`` with the parameters of ``served`` that the ``extra-keys`` of ``registry`` name.""" + extra = comma_separated(registry.parameters.get(EXTRA_KEYS_KEY, "")) + return url.update_parameters({key: served.parameters[key] for key in extra if key in served.parameters}) + + +def _registered_provider_url(url: URL, registry: URL) -> URL: + """Return ``url`` as ``registry`` takes it: whole, or simplified to what consumers need.""" + if not simplified(registry): + return url + + parameters = url.parameters + kept = _PROVIDER_KEYS | set(comma_separated(registry.parameters.get(EXTRA_KEYS_KEY, ""))) + # The interface is kept where the path differs, so that consumers still find the service by it. + if url.path != parameters.get(INTERFACE_KEY, url.path): + kept |= {INTERFACE_KEY} + prefixes = tuple(f"{method}." for method in comma_separated(parameters.get(METHODS_KEY, ""))) + + return url.replace( + parameters={ + key: value for key, value in parameters.items() if value and (key in kept or key.startswith(prefixes)) + }, + ) + + +@attrs.define(kw_only=True, eq=False) +class _InterfaceRegistration: + """The URLs of the services registered with a registry that registers by interface.""" + + registry: URL + client: InterfaceRegistry + kept: "_Kept" + # What releases each URL registered, in the order they were. + registered: dict[URL, Callable[[], Awaitable[None]]] = attrs.field(factory=dict) + + async def register(self, urls: list[URL]) -> None: + """Register ``urls`` in place of those registered: the new ones first, so that no service is ever missing.""" + for url in urls: + if url not in self.registered: + self.registered[url] = await self.kept.keep(self.client.register(url)) + for url in [url for url in self.registered if url not in urls]: + await self.registered.pop(url)() + + async def unregister(self) -> None: + while self.registered: + await self.registered.pop(next(iter(self.registered)))() + + +@attrs.define(kw_only=True, eq=False) +class _InstanceRegistration: + """The instance of the application registered with a registry that registers instances.""" + + registry: URL + client: InstanceRegistry + kept: "_Kept" + report: MetadataReport + metadata_type: MetadataType + metadata: LocalMetadata + # What releases the instance registered. + release: Callable[[], Awaitable[None]] | None = None + # The registration time of the first instance, which every later one keeps. + timestamp: str = attrs.field(factory=registration_time) + revision: str | None = None + + async def register(self, urls: list[URL]) -> None: + """Register the instance that serves ``urls``, replacing the one registered when its metadata changes.""" + # Registries hold URLs of this application only, which DubboConfig gives a name. + app = urls[0].parameters[APPLICATION_KEY] + info = MetadataInfo.from_services(app, [_service_info(url) for url in urls]) + if info.revision == self.revision: + return + + metadata_service = metadata_version = None + if self.metadata_type is MetadataType.LOCAL: + metadata_service = _metadata_service_parameters(await self.metadata.serve(info)) + metadata_version = self.metadata.version + else: + await self.report.publish_app_metadata(info) + values = instance_metadata(info, self.metadata_type, urls, metadata_service, metadata_version) | { + TIMESTAMP_KEY: self.timestamp + } + + first = urls[0] + assert first.host is not None + assert first.port is not None + if self.release is None: + for interface in sorted({url.path for url in urls}): + await self.report.register_service_app_mapping(interface, app) + instance = ServiceInstance(app=app, host=first.host, port=first.port, metadata=values) + # The new instance replaces the one before, which then leaves it on exiting. + release, replaced = await self.kept.keep(self.client.register(instance)), self.release + self.release, self.revision = release, info.revision + if replaced is not None: + await replaced() + + async def unregister(self) -> None: + release, self.release = self.release, None + if release is not None: + await release() + + +def _advertised_port(url: URL) -> int: + """Return the port to register for the server of ``url``: the one the configuration sets, else the one bound.""" + port = cast(int | None, url.attributes.get(ADVERTISED_PORT)) or url.port + assert port is not None + return port + + +def _metadata_service_parameters(url: URL) -> dict[str, str]: + """Return the URL parameters that the instance metadata publishes for the MetadataService served with ``url``.""" + return { + VERSION_KEY: url.parameters[VERSION_KEY], + DUBBO_VERSION_KEY: DUBBO_VERSION, + RELEASE_KEY: RELEASE, + SIDE_KEY: "provider", + "port": str(_advertised_port(url)), + "protocol": url.protocol, + } + + +def _service_info(url: URL) -> ServiceInfo: + assert url.port is not None + return ServiceInfo( + name=url.parameters.get(INTERFACE_KEY, url.path), + group=url.parameters.get(GROUP_KEY), + version=url.parameters.get(VERSION_KEY), + protocol=url.protocol, + port=url.port, + path=url.path, + # The registration time would give every start a new revision. + params={key: value for key, value in url.parameters.items() if key != TIMESTAMP_KEY}, + ) + + +class _Kept: + """Registrations kept each in a task of ``task_group``, which enters and exits it, until released.""" + + def __init__(self, task_group: TaskGroup) -> None: + self._task_group = task_group + + async def keep(self, registration: AbstractAsyncContextManager[None]) -> Callable[[], Awaitable[None]]: + """Enter ``registration`` in a task of its own, raising what entering raises, and return what exits it. + + The function returned exits the registration, raising what exiting + raises, and returns once it has exited. + """ + keeper = _Keeper(registration=registration) + await self._task_group.start(keeper.keep) + return keeper.release + + +@attrs.define(kw_only=True, eq=False) +class _Keeper: + """A registration that a task enters and exits: what tells the task to exit it, and how exiting went.""" + + registration: AbstractAsyncContextManager[None] + released: anyio.Event = attrs.field(factory=anyio.Event) + exited: anyio.Event = attrs.field(factory=anyio.Event) + error: Exception | None = None + + async def keep(self, *, task_status: TaskStatus[None]) -> None: + """Enter the registration, and exit it once released.""" + try: + async with self.registration: + task_status.started() + await self.released.wait() + except Exception as error: + # Before it is entered, start raises what entering does. + if not self.released.is_set(): + raise + self.error = error + finally: + self.exited.set() + + async def release(self) -> None: + """Exit the registration, raising what exiting raises, and return once it has exited.""" + self.released.set() + await self.exited.wait() + if self.error is not None: + raise self.error diff --git a/src/dubbo/registry/registration.py b/src/dubbo/registry/registration.py new file mode 100644 index 00000000..868fe33b --- /dev/null +++ b/src/dubbo/registry/registration.py @@ -0,0 +1,153 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""What the registration of services and of references shares: the host they register at and the parameters they carry.""" + +import importlib.metadata +import time +from collections.abc import Collection, Mapping + +from anyio import to_thread + +from dubbo.constants import ( + APPLICATION_KEY, + ARCHITECTURE_KEY, + DEFAULT_REGISTER, + DEPRECATED_KEY, + DUBBO_VERSION, + DUBBO_VERSION_KEY, + ENVIRONMENT_KEY, + GROUP_KEY, + METHODS_KEY, + ORGANIZATION_KEY, + OWNER_KEY, + REGISTER_KEY, + RELEASE_KEY, + SERIALIZATION_KEY, + SIMPLIFIED_KEY, + TAG_KEY, + TIMEOUT_KEY, + TIMESTAMP_KEY, + TOKEN_KEY, + VERSION_KEY, + WARMUP_KEY, + WEIGHT_KEY, +) +from dubbo.url import URL +from dubbo.utils.converters import boolean +from dubbo.utils.net import local_host + +__all__ = [ + "RELEASE", + "published_parameters", + "registered_host", + "registered_parameters", + "registers", + "registration_time", + "simplified", +] + +# Version of the framework that registered URLs carry. +RELEASE = importlib.metadata.version("apache-dubbo") + +# Hosts that listen on every interface, which consumers cannot call. +_ANY_HOSTS = frozenset({"0.0.0.0", "::"}) +# Parameters that a provider publishes and its consumers take, besides those of each method. +_PUBLISHED_KEYS = ( + APPLICATION_KEY, + OWNER_KEY, + ORGANIZATION_KEY, + ARCHITECTURE_KEY, + ENVIRONMENT_KEY, + GROUP_KEY, + VERSION_KEY, + TIMEOUT_KEY, + WEIGHT_KEY, + WARMUP_KEY, + TAG_KEY, + TOKEN_KEY, + DEPRECATED_KEY, + SERIALIZATION_KEY, +) +# Parameters of each method that a provider publishes and its consumers take. +_PUBLISHED_METHOD_KEYS = (TIMEOUT_KEY, WEIGHT_KEY, DEPRECATED_KEY) + + +async def registered_host(host: str | None, registries: Collection[URL]) -> str: + """Return the address to register for ``host``, the advertised address or the one a server listens on. + + It is ``host`` unless it is absent or listens on every interface, else + the local address that reaches the first registry, else the address of + the host name. + """ + if host and host not in _ANY_HOSTS: + return host + + targets = [(url.host, url.port) for url in registries if url.host is not None] + return await to_thread.run_sync(local_host, targets) + + +def published_parameters(parameters: Mapping[str, str], methods: Collection[str] | None = None) -> dict[str, str]: + """Return the parameters among ``parameters`` that a provider publishes and its consumers take. + + They are what the provider says to its consumers, such as ``timeout`` + and ``token``, and the ``timeout``, ``weight`` and ``deprecated`` of a + method, as in ``sayHello.timeout``: of each of ``methods``, or of any + method when it is ``None``, as for a URL that lists none. + """ + return {key: value for key, value in parameters.items() if _published(key, methods)} + + +def registered_parameters(methods: Collection[str]) -> dict[str, str]: + """Return the parameters every registered URL carries: ``methods`` sorted, the versions, and the registration time.""" + return { + METHODS_KEY: ",".join(sorted(methods)), + DUBBO_VERSION_KEY: DUBBO_VERSION, + RELEASE_KEY: RELEASE, + TIMESTAMP_KEY: registration_time(), + } + + +def registers(registry: URL) -> bool: + """Return whether ``registry`` takes registrations: its ``register``, true by default. + + Raises: + ValueError: ``register`` is not a boolean. + """ + return registry.get_parameter(REGISTER_KEY, boolean, DEFAULT_REGISTER) + + +def simplified(registry: URL) -> bool: + """Return whether ``registry`` takes URLs with only the parameters that identify them: its ``simplified``. + + Raises: + ValueError: ``simplified`` is not a boolean. + """ + return registry.get_parameter(SIMPLIFIED_KEY, boolean, False) + + +def registration_time() -> str: + """Return the time to register now, in milliseconds since the epoch.""" + return str(time.time_ns() // 1_000_000) + + +def _published(key: str, methods: Collection[str] | None) -> bool: + if key in _PUBLISHED_KEYS: + return True + + method, _, name = key.rpartition(".") + return name in _PUBLISHED_METHOD_KEYS and bool(method) and (methods is None or method in methods) diff --git a/src/dubbo/registry/zookeeper/__init__.py b/src/dubbo/registry/zookeeper/__init__.py index 8a9af4c2..5c2576bf 100644 --- a/src/dubbo/registry/zookeeper/__init__.py +++ b/src/dubbo/registry/zookeeper/__init__.py @@ -1,31 +1,21 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. -from ._interfaces import ( - ChildrenListener, - DataListener, - StateListener, - ZookeeperClient, - ZookeeperTransport, -) +from .instance import ZookeeperInstanceRegistry +from .interface import ZookeeperInterfaceRegistry -__all__ = [ - "ChildrenListener", - "DataListener", - "StateListener", - "ZookeeperClient", - "ZookeeperTransport", -] +__all__ = ["ZookeeperInstanceRegistry", "ZookeeperInterfaceRegistry"] diff --git a/src/dubbo/registry/zookeeper/_interfaces.py b/src/dubbo/registry/zookeeper/_interfaces.py deleted file mode 100644 index c104bd23..00000000 --- a/src/dubbo/registry/zookeeper/_interfaces.py +++ /dev/null @@ -1,274 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc -import enum - -from dubbo.url import URL - -__all__ = [ - "StateListener", - "DataListener", - "ChildrenListener", - "ZookeeperClient", - "ZookeeperTransport", -] - - -class StateListener(abc.ABC): - class State(enum.Enum): - """ - Zookeeper connection state. - """ - - SUSPENDED = "SUSPENDED" - CONNECTED = "CONNECTED" - LOST = "LOST" - - @abc.abstractmethod - def state_changed(self, state: "StateListener.State") -> None: - """ - Notify when connection state changed. - - :param state: The new connection state. - :type state: StateListener.State - """ - raise NotImplementedError() - - -class DataListener(abc.ABC): - class EventType(enum.Enum): - """ - Zookeeper data event type. - """ - - CREATED = "CREATED" - DELETED = "DELETED" - CHANGED = "CHANGED" - CHILD = "CHILD" - NONE = "NONE" - - @abc.abstractmethod - def data_changed(self, path: str, data: bytes, event_type: "DataListener.EventType") -> None: - """ - Notify when data changed. - - :param path: The node path. - :type path: str - :param data: The new data. - :type data: bytes - :param event_type: The event type. - :type event_type: DataListener.EventType - """ - raise NotImplementedError() - - -class ChildrenListener(abc.ABC): - @abc.abstractmethod - def children_changed(self, path: str, children: list) -> None: - """ - Notify when children changed. - - :param path: The node path. - :type path: str - :param children: The new children. - :type children: list - """ - raise NotImplementedError() - - -class ZookeeperClient(abc.ABC): - """ - Zookeeper Client interface. - """ - - __slots__ = ["_url"] - - def __init__(self, url: URL): - """ - Initialize the zookeeper client. - - :param url: The zookeeper URL. - :type url: URL - """ - self._url = url - - @abc.abstractmethod - def start(self) -> None: - """ - Start the zookeeper client. - """ - raise NotImplementedError() - - @abc.abstractmethod - def stop(self) -> None: - """ - Stop the zookeeper client. - """ - raise NotImplementedError() - - @abc.abstractmethod - def is_connected(self) -> bool: - """ - Check if the client is connected to zookeeper. - - :return: True if connected, False otherwise. - """ - raise NotImplementedError() - - @abc.abstractmethod - def create(self, path: str, data: bytes = b"", ephemeral=False) -> None: - """ - Create a node in zookeeper. - - :param path: The node path. - :type path: str - :param data: The node data. - :type data: bytes - :param ephemeral: Whether the node is ephemeral. False: persistent, True: ephemeral. - :type ephemeral: bool - """ - raise NotImplementedError() - - @abc.abstractmethod - def create_or_update(self, path: str, data: bytes, ephemeral=False) -> None: - """ - Create or update a node in zookeeper. - - :param path: The node path. - :type path: str - :param data: The node data. - :type data: bytes - :param ephemeral: Whether the node is ephemeral. False: persistent, True: ephemeral. - :type ephemeral: bool - """ - raise NotImplementedError() - - @abc.abstractmethod - def check_exist(self, path: str) -> bool: - """ - Check if a node exists in zookeeper. - - :param path: The node path. - :type path: str - :return: True if the node exists, False otherwise. - """ - raise NotImplementedError() - - @abc.abstractmethod - def get_data(self, path: str) -> bytes: - """ - Get data of a node in zookeeper. - - :param path: The node path. - :type path: str - :return: The node data. - """ - raise NotImplementedError() - - @abc.abstractmethod - def get_children(self, path: str) -> list: - """ - Get children of a node in zookeeper. - - :param path: The node path. - :type path: str - :return: The children of the node. - """ - raise NotImplementedError() - - @abc.abstractmethod - def delete(self, path: str) -> None: - """ - Delete a node in zookeeper. - - :param path: The node path. - :type path: str - """ - raise NotImplementedError() - - @abc.abstractmethod - def add_state_listener(self, listener: StateListener) -> None: - """ - Add a state listener to zookeeper. - - :param listener: The listener to notify when connection state changed. - :type listener: StateListener - """ - raise NotImplementedError() - - @abc.abstractmethod - def remove_state_listener(self, listener: StateListener) -> None: - """ - Remove a state listener from zookeeper. - - :param listener: The listener to remove. - :type listener: StateListener - """ - raise NotImplementedError() - - @abc.abstractmethod - def add_data_listener(self, path: str, listener: DataListener) -> None: - """ - Add a data listener to a node in zookeeper. - - :param path: The node path. - :type path: str - :param listener: The listener to notify when data changed. - :type listener: DataListener - """ - raise NotImplementedError() - - @abc.abstractmethod - def remove_data_listener(self, listener: DataListener) -> None: - """ - Remove a data listener from a node in zookeeper. - - :param listener: The listener to remove. - :type listener: DataListener - """ - raise NotImplementedError() - - @abc.abstractmethod - def add_children_listener(self, path: str, listener: ChildrenListener) -> None: - """ - Add a children listener to a node in zookeeper. - - :param path: The node path. - :type path: str - :param listener: The listener to notify when children changed. - :type listener: ChildrenListener - """ - raise NotImplementedError() - - @abc.abstractmethod - def remove_children_listener(self, listener: ChildrenListener) -> None: - """ - Remove a children listener from a node in zookeeper. - - :param listener: The listener to remove. - :type listener: ChildrenListener - """ - raise NotImplementedError() - - -class ZookeeperTransport(abc.ABC): - @abc.abstractmethod - def connect(self, url: URL) -> ZookeeperClient: - """ - Connect to a zookeeper. - """ - raise NotImplementedError() diff --git a/src/dubbo/registry/zookeeper/instance.py b/src/dubbo/registry/zookeeper/instance.py new file mode 100644 index 00000000..a1369426 --- /dev/null +++ b/src/dubbo/registry/zookeeper/instance.py @@ -0,0 +1,190 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import json +import logging +import time +from collections.abc import AsyncGenerator, AsyncIterator, Mapping +from contextlib import AbstractAsyncContextManager, asynccontextmanager +from typing import Any, Self + +import anyio +from anyio.abc import TaskStatus + +from dubbo.constants import GROUP_KEY +from dubbo.transport import zookeeper +from dubbo.url import URL +from dubbo.utils import Latest, create_background_task_group, follow + +from ..base import InstanceRegistry, ServiceInstance + +__all__ = ["ZookeeperInstanceRegistry"] + +_logger = logging.getLogger(__name__) + +_INSTANCES_ROOT = "/services" +_ROOT_PATH_KEY = "rootPath" +# The class name the Curator instance payload carries. +_PAYLOAD_CLASS = "org.apache.dubbo.registry.zookeeper.ZookeeperInstance" + + +class ZookeeperInstanceRegistry(InstanceRegistry): + """An ``InstanceRegistry`` in ZooKeeper nodes holding Curator service-instance JSON. + + An instance is the ephemeral node ``{root}/{application}/{host}:{port}`` + holding the JSON of an Apache Curator service instance. The root is the + ``rootPath`` URL parameter, else ``/`` and the ``group`` parameter, else + ``/services``. The client comes from ``get_zookeeper_client``, shared + with the other users of an equal connection. + """ + + def __init__(self, url: URL) -> None: + super().__init__(url) + self._root = _instances_root(url) + self._client: zookeeper.ZookeeperClient | None = None + + def register(self, instance: ServiceInstance) -> AbstractAsyncContextManager[None]: + client = self._connected() + + return client.keep_ephemeral(self._path(instance.app, instance.id), _json(instance)) + + @asynccontextmanager + async def subscribe(self, app: str) -> AsyncGenerator[AsyncIterator[list[ServiceInstance]]]: + client = self._connected() + parent = self._path(app) + latest: Latest[list[ServiceInstance]] = Latest() + instances: dict[str, ServiceInstance] = {} + watches: dict[str, anyio.CancelScope] = {} + subscribed = False + + def update(child: str, data: bytes | None) -> None: + instance = _instance(data, f"{parent}/{child}") + if instance is None: + instances.pop(child, None) + else: + instances[child] = instance + + def publish() -> None: + if subscribed: + latest.publish(list(instances.values())) + + async def watch_instance( + child: str, scope: anyio.CancelScope, *, task_status: TaskStatus[None] = anyio.TASK_STATUS_IGNORED + ) -> None: + async def receive(data: bytes | None) -> None: + # The watch of an instance that left and came back is replaced, and updates nothing. + if watches.get(child) is scope: + update(child, data) + publish() + + path = f"{parent}/{child}" + with scope: + # Only the instances of the first snapshot fail the subscription; a later one is watched again. + await follow(lambda: client.watch(path), receive, path, retry_first=subscribed, task_status=task_status) + + async def follow_children(children: list[str]) -> None: + for child in watches.keys() - set(children): + watches.pop(child).cancel() + instances.pop(child, None) + for child in sorted(set(children) - watches.keys()): + scope = watches[child] = anyio.CancelScope() + if subscribed: + task_group.start_soon(watch_instance, child, scope) + else: + await task_group.start(watch_instance, child, scope) + + publish() + + async def watch_children(*, task_status: TaskStatus[None]) -> None: + nonlocal subscribed + async with client.watch_children(parent) as snapshots: + await follow_children(await anext(snapshots)) + subscribed = True + publish() + task_status.started() + async for children in snapshots: + await follow_children(children) + + async with create_background_task_group() as task_group: + await task_group.start(watch_children) + try: + yield aiter(latest) + finally: + task_group.cancel_scope.cancel() + + async def aclose(self) -> None: + self._client = None + + async def __aenter__(self) -> Self: + self._client = await zookeeper.get_zookeeper_client(self.url) + return self + + def _path(self, *names: str) -> str: + return "/".join((self._root, *names)) + + def _connected(self) -> zookeeper.ZookeeperClient: + if self._client is None: + raise RuntimeError("the registry is not connected") + return self._client + + +def _instances_root(url: URL) -> str: + root = url.parameters.get(_ROOT_PATH_KEY, _INSTANCES_ROOT) + if root.lower() == _INSTANCES_ROOT: + root = url.parameters.get(GROUP_KEY, _INSTANCES_ROOT) + return "/" + root.strip("/") + + +def _json(instance: ServiceInstance) -> bytes: + payload = { + "@class": _PAYLOAD_CLASS, + "id": instance.id, + "name": instance.app, + "metadata": dict(instance.metadata), + } + data = { + "name": instance.app, + "id": instance.id, + "address": instance.host, + "port": instance.port, + "sslPort": None, + "payload": payload, + "registrationTimeUTC": time.time_ns() // 1_000_000, + "serviceType": "DYNAMIC", + "uriSpec": None, + } + return json.dumps(data, ensure_ascii=False, separators=(",", ":")).encode() + + +def _instance(data: bytes | None, path: str) -> ServiceInstance | None: + """Read the instance in ``data``, or return ``None`` when the node is gone or holds no instance.""" + if not data: + return None + + try: + node: Mapping[str, Any] = json.loads(data) + payload = node.get("payload") or {} + metadata = payload.get("metadata") or {} + return ServiceInstance( + app=str(node["name"]), + host=str(node["address"]), + port=int(node["port"]), + metadata={str(key): str(value) for key, value in metadata.items()}, + ) + except (AttributeError, KeyError, TypeError, ValueError): + _logger.warning("Ignoring the service instance in %s, which cannot be read", path, exc_info=True) + return None diff --git a/src/dubbo/registry/zookeeper/interface.py b/src/dubbo/registry/zookeeper/interface.py new file mode 100644 index 00000000..ba72e58f --- /dev/null +++ b/src/dubbo/registry/zookeeper/interface.py @@ -0,0 +1,135 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +from collections.abc import AsyncGenerator, AsyncIterator +from contextlib import AbstractAsyncContextManager, asynccontextmanager +from typing import Self +from urllib.parse import quote_plus, unquote_plus, urlsplit + +from dubbo.constants import CATEGORY_KEY, DEFAULT_ROOT, GROUP_KEY, INTERFACE_KEY, PROVIDERS_CATEGORY +from dubbo.transport import zookeeper +from dubbo.url import URL + +from ..base import InterfaceRegistry + +__all__ = ["ZookeeperInterfaceRegistry"] + +_logger = logging.getLogger(__name__) + + +class ZookeeperInterfaceRegistry(InterfaceRegistry): + """An ``InterfaceRegistry`` in ephemeral ZooKeeper nodes named by form-encoded URLs. + + A URL is the node ``/{group}/{interface}/{category}/{url}``, where + ``group`` is the URL parameter and ``dubbo`` by default, and the + interface and the URL, with its parameter values unescaped, are + form-encoded: letters, digits and ``.-*_`` stay as they are, a space + becomes ``+``, and every other byte of the UTF-8 text is escaped. The + client comes from ``get_zookeeper_client``, shared with the other users + of an equal connection. + """ + + def __init__(self, url: URL) -> None: + super().__init__(url) + self._root = "/" + url.parameters.get(GROUP_KEY, DEFAULT_ROOT).removeprefix("/") + self._client: zookeeper.ZookeeperClient | None = None + + def register(self, url: URL) -> AbstractAsyncContextManager[None]: + client = self._connected() + + return client.keep_ephemeral(self._path(url)) + + @asynccontextmanager + async def subscribe( + self, interface: str, *, group: str | None, version: str | None + ) -> AsyncGenerator[AsyncIterator[list[URL]]]: + client = self._connected() + parent = f"{self._root}/{_encode(interface)}/{PROVIDERS_CATEGORY}" + + async with client.watch_children(parent) as snapshots: + yield (_urls(children, parent) async for children in snapshots) + + async def aclose(self) -> None: + self._client = None + + async def __aenter__(self) -> Self: + self._client = await zookeeper.get_zookeeper_client(self.url) + return self + + def _path(self, url: URL) -> str: + interface = url.parameters.get(INTERFACE_KEY) or url.path + category = url.parameters.get(CATEGORY_KEY, PROVIDERS_CATEGORY) + return f"{self._root}/{_encode(interface)}/{category}/{_encode(_full_string(url))}" + + def _connected(self) -> zookeeper.ZookeeperClient: + if self._client is None: + raise RuntimeError("the registry is not connected") + return self._client + + +def _full_string(url: URL) -> str: + """Return ``url`` with its user, password and parameter values unescaped, parameters sorted by key, as registry nodes hold it.""" + user = f"{url.userinfo}@" if url.userinfo else "" + path = f"/{url.path}" if url.path else "" + query = "&".join(f"{key}={value}" for key, value in sorted(url.parameters.items())) + return f"{url.protocol}://{user}{url.address}{path}" + (f"?{query}" if query else "") + + +def _parse_full_string(text: str) -> URL: + """Read a URL that ``_full_string`` returns, whose parameter values are not escaped. + + Raises: + ValueError: The text is not such a URL. + """ + address, _, query = text.partition("?") + parts = urlsplit(address) + if not parts.scheme: + raise ValueError(f"URL needs a scheme: {text!r}") + + parameters = {} + for pair in query.split("&"): + key, _, value = pair.partition("=") + if key: + parameters[key] = value + + return URL( + protocol=parts.scheme, + username=parts.username, + password=parts.password, + host=parts.hostname, + port=parts.port, + path=parts.path.removeprefix("/"), + parameters=parameters, + ) + + +def _encode(text: str) -> str: + # Form encoding leaves only letters, digits and ".-*_" as they are. + return quote_plus(text, safe="*").replace("~", "%7E") + + +def _urls(children: list[str], parent: str) -> list[URL]: + urls = [] + for child in children: + try: + urls.append(_parse_full_string(unquote_plus(child, errors="strict"))) + except ValueError: + # The name is left out: it is written by others and may hold a token or password. + _logger.warning("Ignoring a node in %s, which holds no URL", parent) + + return urls diff --git a/src/dubbo/registry/zookeeper/kazoo_transport.py b/src/dubbo/registry/zookeeper/kazoo_transport.py deleted file mode 100644 index be34fc33..00000000 --- a/src/dubbo/registry/zookeeper/kazoo_transport.py +++ /dev/null @@ -1,413 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc -import threading -from typing import Union - -from kazoo.client import KazooClient -from kazoo.protocol.states import EventType, KazooState, WatchedEvent, ZnodeStat - -from dubbo.loggers import loggerFactory -from dubbo.url import URL - -from ._interfaces import ( - ChildrenListener, - DataListener, - StateListener, - ZookeeperClient, - ZookeeperTransport, -) - -__all__ = ["KazooZookeeperClient", "KazooZookeeperTransport"] - -_LOGGER = loggerFactory.get_logger("zookeeper") - -LISTENER_TYPE = Union[StateListener, DataListener, ChildrenListener] - - -class AbstractListenerAdapter(abc.ABC): - """ - Abstract listener adapter. - - This abstract class defines a template for listener adapters, providing thread-safe methods to - manage listeners. Concrete implementations should provide specific behavior for these methods. - """ - - __slots__ = ["_lock", "_listeners"] - - def __init__(self, listener: LISTENER_TYPE): - """ - Initialize the adapter with a reentrant lock to ensure thread safety and store the initial listener. - - :param listener: The listener to manage. - :type listener: StateListener or DataListener or ChildrenListener - """ - self._lock = threading.Lock() - self._listeners = {listener} - - def add(self, listener: LISTENER_TYPE) -> None: - """ - Add a listener to the adapter. - - This method adds a listener to the adapter's set of listeners in a thread-safe manner. - - :param listener: The listener to add. - :type listener: StateListener or DataListener or ChildrenListener - """ - with self._lock: - self._listeners.add(listener) - - def remove(self, listener: LISTENER_TYPE) -> None: - """ - Remove a listener from the adapter. - - This method removes a listener from the adapter's set of listeners in a thread-safe manner. - - :param listener: The listener to remove. - :type listener: StateListener or DataListener or ChildrenListener - """ - with self._lock: - self._listeners.remove(listener) - - -class AbstractListenerAdapterFactory(abc.ABC): - """ - Abstract factory for creating and managing listener adapters. - - This abstract factory class provides methods to create and manage listener adapters - in a thread-safe manner. It maintains a dictionary to track active adapters. - """ - - __slots__ = [ - "_client", - "_lock", - "_adapters", - "_listener_to_path", - ] - - def __init__(self, client: KazooClient): - """ - Initialize the factory with a KazooClient and set up the necessary locks and dictionaries. - - :param client: An instance of KazooClient to manage Zookeeper connections. - :type client: KazooClient - """ - self._client = client - self._lock = threading.Lock() - self._adapters: dict[str, AbstractListenerAdapter] = {} - self._listener_to_path: dict[LISTENER_TYPE, str] = {} - - def create(self, path: str, listener) -> None: - """ - Create a new adapter or add a listener to an existing adapter. - - This method checks if the specified path already has an adapter. If so, it adds the listener - to the existing adapter. Otherwise, it creates a new adapter using the abstract `do_create` method. - - :param path: The Znode path to watch. - :type path: str - :param listener: The listener for which to create or add to an adapter. - :type listener: Any - """ - with self._lock: - adapter = self._adapters.get(path) - if not adapter: - # Creating a new adapter - adapter = self.do_create(path, listener) - self._adapters[path] = adapter - else: - # Add the listener to the adapter - adapter.add(listener) - - def remove(self, listener) -> None: - """ - Remove a listener and its associated adapter if no listeners remain. - - This method removes the listener's adapter from the active adapters dictionary and - removes the listener from the adapter. If no listeners remain, the adapter is discarded. - - :param listener: The listener to remove. - :type listener: Any - """ - with self._lock: - path = self._listener_to_path.pop(listener, None) - if path is None: - return - adapter = self._adapters.get(path) - if adapter is not None: - adapter.remove(listener) - - @abc.abstractmethod - def do_create(self, path: str, listener) -> AbstractListenerAdapter: - """ - Define the creation of a new adapter. - - This abstract method must be implemented by subclasses to handle the actual creation logic - for a new adapter. - - :param path: The Znode path to watch. - :type path: str - :param listener: The listener for which to create a new adapter. - :type listener: Any - :return: A new instance of an AbstractListenerAdapter. - :rtype: AbstractListenerAdapter - :raises NotImplementedError: If the method is not implemented by a subclass. - """ - raise NotImplementedError() - - -class StateListenerAdapter(AbstractListenerAdapter): - """ - State listener adapter. - - This adapter inherits from `AbstractListenerAdapter` and is designed to handle state changes - in a `KazooClient`. It converts Zookeeper states to internal states and notifies listeners. - """ - - def __init__(self, listener: StateListener): - """ - Initialize the StateListenerAdapter with a given listener. - - :param listener: The listener to manage. - :type listener: StateListener - """ - super().__init__(listener) - - def __call__(self, state: KazooState): - """ - Handle state changes and notify the listener. - - This method is called with the current state of the KazooClient, converts it to an internal - state representation, and notifies all registered listeners. - - :param state: The current state of the KazooClient. - :type state: KazooState - """ - if state == KazooState.CONNECTED: - state = StateListener.State.CONNECTED - elif state == KazooState.LOST: - state = StateListener.State.LOST - elif state == KazooState.SUSPENDED: - state = StateListener.State.SUSPENDED - - # Notify all listeners - for listener in self._listeners: - listener.state_changed(state) - - -class DataListenerAdapter(AbstractListenerAdapter): - """ - Data listener adapter. - - This adapter handles data change events for a specified Znode path and notifies a `DataListener`. - """ - - __slots__ = ["_path"] - - def __init__(self, path: str, listener: DataListener): - """ - Initialize the DataListenerAdapter with a given path and listener. - - :param path: The Znode path to watch. - :type path: str - :param listener: The data listener to notify on data changes. - :type listener: DataListener - """ - super().__init__(listener) - self._path = path - - def __call__(self, data: bytes, stat: ZnodeStat, event: WatchedEvent): - """ - Handle data changes and notify the listener. - - This method is called with the current data, stat, and event of the watched Znode, - processes the event type, and notifies all registered listeners. - - :param data: The current data of the Znode. - :type data: bytes - :param stat: The status of the Znode. - :type stat: ZnodeStat - :param event: The event that triggered the callback. - :type event: WatchedEvent - """ - with self._lock: - if event is None or len(self._listeners) == 0: - return - - event_type = None - if event.type == EventType.NONE: - event_type = DataListener.EventType.NONE - elif event.type == EventType.CREATED: - event_type = DataListener.EventType.CREATED - elif event.type == EventType.DELETED: - event_type = DataListener.EventType.DELETED - elif event.type == EventType.CHANGED: - event_type = DataListener.EventType.CHANGED - elif event.type == EventType.CHILD: - event_type = DataListener.EventType.CHILD - - # Notify all listeners - for listener in self._listeners: - listener.data_changed(self._path, data, event_type) - - -class ChildrenListenerAdapter(AbstractListenerAdapter): - """ - Children listener adapter. - - This adapter handles children change events for a specified Znode path and notifies a `ChildrenListener`. - """ - - __slots__ = ["_path"] - - def __init__(self, path: str, listener: ChildrenListener): - """ - Initialize the ChildrenListenerAdapter with a given path and listener. - - :param path: The Znode path to watch. - :type path: str - :param listener: The children listener to notify on children changes. - :type listener: ChildrenListener - """ - super().__init__(listener) - self._path = path - - def __call__(self, children: list[str]): - """ - Handle children changes and notify the listener. - - This method is called with the current list of children of the watched Znode - and notifies all registered listeners. - - :param children: The current list of children of the Znode. - :type children: List[str] - """ - with self._lock: - # Notify all listeners - for listener in self._listeners: - listener.children_changed(self._path, children) - - -class DataListenerAdapterFactory(AbstractListenerAdapterFactory): - def do_create(self, path: str, listener: DataListener) -> AbstractListenerAdapter: - data_adapter = DataListenerAdapter(path, listener) - self._client.DataWatch(path, data_adapter) - return data_adapter - - -class ChildrenListenerAdapterFactory(AbstractListenerAdapterFactory): - def do_create(self, path: str, listener: ChildrenListener) -> AbstractListenerAdapter: - children_adapter = ChildrenListenerAdapter(path, listener) - self._client.ChildrenWatch(path, children_adapter) - return children_adapter - - -class KazooZookeeperClient(ZookeeperClient): - """ - Kazoo Zookeeper client. - """ - - def __init__(self, url: URL): - super().__init__(url) - self._client: KazooClient = KazooClient(hosts=url.location, logger=_LOGGER) - # TODO: Add more attributes from url - - # state listener dict - self._state_lock = threading.Lock() - self._state_listeners: dict[StateListener, StateListenerAdapter] = {} - - self._data_adapter_factory = DataListenerAdapterFactory(self._client) - - self._children_adapter_factory = ChildrenListenerAdapterFactory(self._client) - - def start(self) -> None: - # start the client - self._client.start() - - def stop(self) -> None: - # stop the client - self._client.stop() - - def is_connected(self) -> bool: - return self._client.connected - - def create(self, path: str, data: bytes = b"", ephemeral=False) -> None: - self._client.create(path, data, ephemeral=ephemeral, makepath=True) - - def create_or_update(self, path: str, data: bytes, ephemeral=False) -> None: - if self.check_exist(path): - self._client.set(path, data) - else: - self.create(path, data, ephemeral=ephemeral) - - def check_exist(self, path: str) -> bool: - return self._client.exists(path) - - def get_data(self, path: str) -> bytes: - # data: bytes, stat: ZnodeStat - data, stat = self._client.get(path) - return data - - def get_children(self, path: str) -> list: - return self._client.get_children(path) - - def delete(self, path: str) -> None: - self._client.delete(path) - - def add_state_listener(self, listener: StateListener) -> None: - with self._state_lock: - if listener in self._state_listeners: - return - state_adapter = StateListenerAdapter(listener) - self._client.add_listener(state_adapter) - self._state_listeners[listener] = state_adapter - - def remove_state_listener(self, listener: StateListener) -> None: - with self._state_lock: - state_adapter = self._state_listeners.pop(listener, None) - if state_adapter is not None: - self._client.remove_listener(state_adapter) - - def add_data_listener(self, path: str, listener: DataListener) -> None: - self._data_adapter_factory.create(path, listener) - - def remove_data_listener(self, listener: DataListener) -> None: - self._data_adapter_factory.remove(listener) - - def add_children_listener(self, path: str, listener: ChildrenListener) -> None: - self._children_adapter_factory.create(path, listener) - - def remove_children_listener(self, listener: ChildrenListener) -> None: - self._children_adapter_factory.remove(listener) - - -class KazooZookeeperTransport(ZookeeperTransport): - def __init__(self): - self._lock = threading.Lock() - # key: location, value: KazooZookeeperClient - self._zk_client_dict: dict[str, KazooZookeeperClient] = {} - - def connect(self, url: URL) -> ZookeeperClient: - with self._lock: - zk_client = self._zk_client_dict.get(url.location) - if zk_client is None or zk_client.is_connected(): - # Create new KazooZookeeperClient - zk_client = KazooZookeeperClient(url) - zk_client.start() - self._zk_client_dict[url.location] = zk_client - - return zk_client diff --git a/src/dubbo/registry/zookeeper/zk_registry.py b/src/dubbo/registry/zookeeper/zk_registry.py deleted file mode 100644 index ba46e31d..00000000 --- a/src/dubbo/registry/zookeeper/zk_registry.py +++ /dev/null @@ -1,197 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from dubbo.constants import common_constants, registry_constants -from dubbo.loggers import loggerFactory -from dubbo.registry import NotifyListener, Registry, RegistryFactory -from dubbo.registry.zookeeper import ChildrenListener, StateListener, ZookeeperTransport -from dubbo.registry.zookeeper.kazoo_transport import KazooZookeeperTransport -from dubbo.url import URL, create_url - -__all__ = ["ZookeeperRegistryFactory", "ZookeeperRegistry"] - -_LOGGER = loggerFactory.get_logger() - - -class _DefaultStateListener(StateListener): - def state_changed(self, state: "StateListener.State") -> None: - if state == StateListener.State.LOST: - _LOGGER.warning("Connection lost") - elif state == StateListener.State.CONNECTED: - _LOGGER.info("Connection established") - elif state == StateListener.State.SUSPENDED: - _LOGGER.info("Connection suspended") - - -class _DefaultChildrenListener(ChildrenListener): - def __init__(self, listener: NotifyListener): - self._listener = listener - - def children_changed(self, path: str, children: list[str]) -> None: - urls = [] - for child in children: - url = create_url(child, encoded=True) - urls.append(url) - self._listener.notify(urls) - - -class ZookeeperRegistry(Registry): - """ - Zookeeper registry implementation. - """ - - # default root is "dubbo" - DEFAULT_ROOT = common_constants.DUBBO_VALUE - - def __init__(self, url: URL, zk_transport: ZookeeperTransport): - self._url = url - self._any_services = set() - - # connect to the zookeeper server - self._zk_client = zk_transport.connect(self._url) - - # get the root path - self._root = common_constants.PATH_SEPARATOR + url.parameters.get( - common_constants.GROUP_KEY, self.DEFAULT_ROOT - ).lstrip(common_constants.PATH_SEPARATOR) - - # add the state listener - self._zk_client.add_state_listener(_DefaultStateListener()) - - @property - def root_dir(self) -> str: - """ - Get the root directory. - :return: the root directory. - :rtype: str - """ - if common_constants.PATH_SEPARATOR == self._root: - return self._root - return self._root + common_constants.PATH_SEPARATOR - - @property - def root_path(self) -> str: - """ - Get the root path. - :return: the root path. - :rtype: str - """ - return self.root_dir - - def register(self, url: URL) -> None: - self._zk_client.create_or_update( - self.to_url_path(url), - url.location.encode("utf-8"), - ephemeral=bool(url.parameters.get(registry_constants.DYNAMIC_KEY, True)), - ) - - def unregister(self, url: URL) -> None: - self._zk_client.delete(self.to_url_path(url)) - - def subscribe(self, url: URL, listener: NotifyListener) -> None: - for path in self.get_categories_path(url): - children_listener = _DefaultChildrenListener(listener) - self._zk_client.add_children_listener(path, children_listener) - - def unsubscribe(self, url: URL, listener: NotifyListener) -> None: - # TODO: implement the unsubscribe - pass - - def lookup(self, url: URL): - providers = [] - for category_path in self.get_categories_path(url): - children_list = self._zk_client.get_children(category_path) - if children_list: - providers.extend(children_list) - return providers - - def get_service_path(self, url: URL) -> str: - """ - Get the service path. - :param url: The URL. - :type url: URL - :return: The service path. - :rtype: str - """ - service_path = url.parameters.get(common_constants.SERVICE_KEY, url.path) - if service_path == common_constants.ANY_VALUE: - return self.root_path - return self.root_dir + service_path - - def get_category_path(self, url: URL) -> str: - """ - Get the category path. - :param url: The URL. - :type url: URL - :return: The category path. - :rtype: str - """ - category = url.parameters.get(registry_constants.CATEGORY_KEY, registry_constants.PROVIDERS_CATEGORY) - return self.get_service_path(url) + common_constants.PATH_SEPARATOR + category - - def get_categories_path(self, url: URL) -> list[str]: - """ - Get the categories' path. - :param url: The URL. - :type url: URL - :return: The categories' paths. - :rtype: List[str] - """ - # get the categories - if common_constants.ANY_VALUE == url.parameters.get(registry_constants.CATEGORY_KEY): - categories = [ - registry_constants.PROVIDERS_CATEGORY, - registry_constants.CONSUMERS_CATEGORY, - ] - else: - parameter = url.parameters.get(registry_constants.CATEGORY_KEY, registry_constants.PROVIDERS_CATEGORY) - categories = [s.strip() for s in parameter.split(common_constants.COMMA_SEPARATOR)] - - # get paths - return [self.get_service_path(url) + common_constants.PATH_SEPARATOR + category for category in categories] - - def to_url_path(self, url: URL) -> str: - """ - Convert the URL to the path. - :param url: The URL. - :type url: URL - :return: The path. - :rtype: str - """ - # return the path - return self.get_category_path(url) + common_constants.PATH_SEPARATOR + url.to_str(encode=True) - - def get_url(self) -> URL: - return self._url - - def is_available(self) -> bool: - return self._zk_client and self._zk_client.is_connected() - - def destroy(self) -> None: - if self._zk_client: - self._zk_client.stop() - - def check_destroy(self) -> None: - if not self._zk_client: - raise RuntimeError("registry is destroyed") - - -class ZookeeperRegistryFactory(RegistryFactory): - def __init__(self): - self._transport: ZookeeperTransport = KazooZookeeperTransport() - - def get_registry(self, url: URL) -> Registry: - return ZookeeperRegistry(url, self._transport) diff --git a/src/dubbo/remoting/__init__.py b/src/dubbo/remoting/__init__.py deleted file mode 100644 index a93961f4..00000000 --- a/src/dubbo/remoting/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from ._interfaces import Client, Server, Transporter - -__all__ = ["Client", "Server", "Transporter"] diff --git a/src/dubbo/remoting/_interfaces.py b/src/dubbo/remoting/_interfaces.py deleted file mode 100644 index 70a95d91..00000000 --- a/src/dubbo/remoting/_interfaces.py +++ /dev/null @@ -1,108 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc - -from dubbo.url import URL - -__all__ = ["Client", "Server", "Transporter"] - - -class Client(abc.ABC): - def __init__(self, url: URL): - self._url = url - - @abc.abstractmethod - def is_connected(self) -> bool: - """ - Check if the client is connected. - """ - raise NotImplementedError() - - @abc.abstractmethod - def is_closed(self) -> bool: - """ - Check if the client is closed. - """ - raise NotImplementedError() - - @abc.abstractmethod - def connect(self): - """ - Connect to the server. - """ - raise NotImplementedError() - - @abc.abstractmethod - def close(self): - """ - Close the client. - """ - raise NotImplementedError() - - -class Server: - """ - Server - """ - - @abc.abstractmethod - def is_exported(self) -> bool: - """ - Check if the server is exported. - """ - raise NotImplementedError() - - @abc.abstractmethod - def is_closed(self) -> bool: - """ - Check if the server is closed. - """ - raise NotImplementedError() - - @abc.abstractmethod - def export(self): - """ - Export the server. - """ - raise NotImplementedError() - - @abc.abstractmethod - def close(self): - """ - Close the server. - """ - raise NotImplementedError() - - -class Transporter(abc.ABC): - """ - Transporter interface - """ - - @abc.abstractmethod - def connect(self, url: URL) -> Client: - """ - Connect to a server. - """ - raise NotImplementedError() - - @abc.abstractmethod - def bind(self, url: URL) -> Server: - """ - Bind a server. - """ - raise NotImplementedError() diff --git a/src/dubbo/remoting/aio/__init__.py b/src/dubbo/remoting/aio/__init__.py deleted file mode 100644 index e07e3a5c..00000000 --- a/src/dubbo/remoting/aio/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from ._interfaces import ConnectionStateListener, EmptyConnectionStateListener - -__all__ = ["ConnectionStateListener", "EmptyConnectionStateListener"] diff --git a/src/dubbo/remoting/aio/_interfaces.py b/src/dubbo/remoting/aio/_interfaces.py deleted file mode 100644 index d871b78f..00000000 --- a/src/dubbo/remoting/aio/_interfaces.py +++ /dev/null @@ -1,50 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import abc - -__all__ = ["ConnectionStateListener", "EmptyConnectionStateListener"] - - -class ConnectionStateListener(abc.ABC): - """ - Connection state listener. It is used to listen to the connection state. - """ - - @abc.abstractmethod - async def connection_made(self): - """ - Called when the connection is first established. - """ - raise NotImplementedError() - - @abc.abstractmethod - async def connection_lost(self, exc): - """ - Called when the connection is lost. - """ - raise NotImplementedError() - - -class EmptyConnectionStateListener(ConnectionStateListener): - """ - An empty connection state listener. It does nothing. - """ - - async def connection_made(self): - pass - - async def connection_lost(self, exc): - pass diff --git a/src/dubbo/remoting/aio/aio_transporter.py b/src/dubbo/remoting/aio/aio_transporter.py deleted file mode 100644 index a47087b0..00000000 --- a/src/dubbo/remoting/aio/aio_transporter.py +++ /dev/null @@ -1,282 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import asyncio -import concurrent -import threading -from typing import Union - -from dubbo.constants import common_constants -from dubbo.loggers import loggerFactory -from dubbo.remoting._interfaces import Client, Server, Transporter -from dubbo.remoting.aio import ConnectionStateListener, constants as aio_constants -from dubbo.remoting.aio.event_loop import EventLoop -from dubbo.remoting.aio.exceptions import RemotingError -from dubbo.url import URL -from dubbo.utils import FutureHelper - -_LOGGER = loggerFactory.get_logger() - - -class AioClient(Client, ConnectionStateListener): - """ - Asyncio client. - """ - - __slots__ = [ - "_global_lock", - "_protocol", - "_connected", - "_closed", - "_active_close", - "_event_loop", - ] - - def __init__(self, url: URL): - """ - Initialize the client. - :param url: The URL. - :type url: URL - """ - super().__init__(url) - - self._global_lock = threading.Lock() - - # Set the side of the transporter to client. - self._protocol = None - - # the status of the client - self._connected = False - self._closed = False - self._active_close = False - - # event loop - self._event_loop: EventLoop = EventLoop() - - # connect to the server - self.connect() - - def is_connected(self) -> bool: - """ - Check if the client is connected. - """ - return self._connected - - def is_closed(self) -> bool: - """ - Check if the client is closed. - """ - return self._closed - - def connect(self) -> None: - """ - Connect to the server. - """ - with self._global_lock: - if self.is_connected(): - return - elif self.is_closed(): - raise RemotingError("The client is closed.") - - # Run the connection logic in the event loop. - if self._event_loop.stopped: - raise RemotingError("The event loop is stopped.") - elif not self._event_loop.started: - self._event_loop.start() - - future = concurrent.futures.Future() - asyncio.run_coroutine_threadsafe(self._do_connect(future), self._event_loop.loop) - - try: - self._protocol = future.result(timeout=3) - _LOGGER.info( - "Connected to the server. host: %s, port: %s", - self._url.host, - self._url.port, - ) - except Exception: - raise RemotingError(f"Failed to connect to the server. host: {self._url.host}, port: {self._url.port}") - - async def _do_connect(self, future: Union[concurrent.futures.Future, asyncio.Future]): - """ - Connect to the server. - """ - running_loop = asyncio.get_running_loop() - # Create the connection. - _, protocol = await running_loop.create_connection( - lambda: self._url.attributes[common_constants.PROTOCOL_KEY](self._url, self), - self._url.host, - self._url.port, - ) - # Set the protocol. - FutureHelper.set_result(future, protocol) - - def close(self) -> None: - """ - Close the client. - """ - with self._global_lock: - if self.is_closed(): - return - - self._active_close = True - self._protocol.close() - - async def connection_made(self): - # Update the connection status. - self._connected = True - - async def connection_lost(self, exc): - self._connected = False - self._closed = True - # Check if it is an active shutdown - if self._active_close: - self._event_loop.stop() - else: - # try reconnect - for _ in range(aio_constants.RECONNECT_TIMES): - try: - future = asyncio.Future() - await self._do_connect(future) - - # Update the protocol. - self._protocol = future.result() - - # Update the connection status. - self._connected = True - self._closed = False - self._active_close = False - _LOGGER.info( - "Reconnected to the server. host: %s, port: %s", - self._url.host, - self._url.port, - ) - return - except Exception as e: - exc = e - _LOGGER.error("Failed to reconnect to the server. %s", exc) - # wait for a while - await asyncio.sleep(1) - - # cannot reconnect - raise RemotingError( - f"Failed to reconnect to the server.{exc}", - ) - - -class AioServer(Server): - """ - Asyncio server. - """ - - def __init__(self, url: URL): - self._url = url - # Set the side of the transporter to server. - self._url.parameters[common_constants.SIDE_KEY] = common_constants.SERVER_VALUE - - # the event to indicate the close status of the server - self._event_loop = EventLoop() - self._event_loop.start() - - # Whether the server is exporting - self._exporting = False - # Whether the server is exported - self._exported = False - - # Whether the server is closing - self._closing = False - # Whether the server is closed - self._closed = False - - # start the server - self.export() - - def is_exported(self) -> bool: - return self._exported or self._exporting - - def is_closed(self) -> bool: - return self._closed or self._closing - - def export(self): - """ - Export the server. - """ - if self.is_exported(): - return - elif self.is_closed(): - raise RemotingError("The server is closed.") - - async def _inner_operation(_future: concurrent.futures.Future): - try: - running_loop = asyncio.get_running_loop() - server = await running_loop.create_server( - lambda: self._url.attributes[common_constants.PROTOCOL_KEY](self._url), - self._url.host, - self._url.port, - ) - - # Serve the server forever - async with server: - FutureHelper.set_result(_future, None) - await server.serve_forever() - except Exception as e: - FutureHelper.set_exception(_future, e) - - # Run the server logic in the event loop. - future = concurrent.futures.Future() - asyncio.run_coroutine_threadsafe(_inner_operation(future), self._event_loop.loop) - - try: - exc = future.exception() - if exc: - raise RemotingError("Failed to export the server") from exc - else: - self._exported = True - _LOGGER.info( - "Exported the server. host: %s, port: %s", - self._url.host, - self._url.port, - ) - finally: - self._exporting = False - - def close(self): - """ - Close the server. - """ - if self.is_closed(): - return - self._closing = True - - try: - self._event_loop.stop() - self._closed = True - except Exception as e: - raise RemotingError("Failed to close the server") from e - finally: - self._closing = False - - -class AioTransporter(Transporter): - """ - Asyncio transporter. - """ - - def connect(self, url: URL) -> Client: - return AioClient(url) - - def bind(self, url: URL) -> Server: - return AioServer(url) diff --git a/src/dubbo/remoting/aio/constants.py b/src/dubbo/remoting/aio/constants.py deleted file mode 100644 index 103c184c..00000000 --- a/src/dubbo/remoting/aio/constants.py +++ /dev/null @@ -1,28 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -__all__ = ["STREAM_HANDLER_KEY"] - -STREAM_HANDLER_KEY = "stream-handler" - -LISTENER_FACTORY_KEY = "listener-factory" - -CLOSE_FUTURE_KEY = "close-future" - -HEARTBEAT_KEY = "heartbeat" -DEFAULT_HEARTBEAT = 6 - -RECONNECT_TIMES = 3 diff --git a/src/dubbo/remoting/aio/event_loop.py b/src/dubbo/remoting/aio/event_loop.py deleted file mode 100644 index f0140a9f..00000000 --- a/src/dubbo/remoting/aio/event_loop.py +++ /dev/null @@ -1,176 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import asyncio -import threading -import uuid -from typing import Optional - -from dubbo.loggers import loggerFactory - -_LOGGER = loggerFactory.get_logger() - - -def _try_use_uvloop() -> None: - """ - Use uvloop instead of the default asyncio running_loop. - """ - import asyncio - import os - - # Check if the operating system. - if os.name == "nt": - # Windows is not supported. - _LOGGER.warning("Unable to use uvloop, because it is not supported on your operating system.") - return - - # Try import uvloop. - try: - import uvloop - except ImportError: - # uvloop is not available. - _LOGGER.warning( - "Unable to use uvloop, because it is not installed. You can install it by running `pip install uvloop`." - ) - return - - # Use uvloop instead of the default asyncio running_loop. - if not isinstance(asyncio.get_event_loop_policy(), uvloop.EventLoopPolicy): - asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) - - -# Call the function to try to use uvloop. -_try_use_uvloop() - - -class EventLoop: - def __init__(self, in_other_tread: bool = True): - self._in_other_tread = in_other_tread - # The event loop to run the asynchronous function. - self._loop = asyncio.new_event_loop() - # The thread to run the event loop. - self._thread: Optional[threading.Thread] = None if in_other_tread else threading.current_thread() - - self._started = False - self._stopped = False - - # The lock to protect the event loop. - self._lock = threading.Lock() - - @property - def loop(self): - """ - Get the event loop. - :return: The event loop. - :rtype: asyncio.AbstractEventLoop - """ - return self._loop - - @property - def thread(self) -> Optional[threading.Thread]: - """ - Get the thread of the event loop. - :return: The thread of the event loop. If not yet started, this is None. - :rtype: Optional[threading.Thread] - """ - return self._thread - - def check_thread(self) -> bool: - """ - Check if the current thread is the event loop thread. - :return: True if the current thread is the event loop thread, otherwise False. - :rtype: bool - """ - return threading.current_thread().ident == self._thread.ident - - @property - def started(self) -> bool: - """ - Check if the event loop is started. - :return: True if the event loop is started, otherwise False. - :rtype: bool - """ - return self._started - - @property - def stopped(self) -> bool: - """ - Check if the event loop is stopped. - :return: True if the event loop is stopped, otherwise False. - :rtype: bool - """ - return self._stopped - - def start(self) -> None: - """ - Start the asyncio event loop. - """ - if self._started: - return - with self._lock: - self._started = True - self._stopped = False - if self._in_other_tread: - self._start_in_thread() - else: - self._start() - - def _start(self) -> None: - """ - Real start the asyncio event loop in current thread. - """ - asyncio.set_event_loop(self._loop) - self._loop.run_forever() - - def _start_in_thread(self) -> None: - """ - Real Start the asyncio event loop in a separate thread. - """ - thread_name = f"dubbo-asyncio-loop-{str(uuid.uuid4())}" - thread = threading.Thread(target=self._start, name=thread_name, daemon=True) - thread.start() - self._thread = thread - - def stop(self, wait: bool = False) -> None: - """ - Stop the asyncio event loop. - """ - if self._stopped: - return - with self._lock: - signal = threading.Event() - asyncio.run_coroutine_threadsafe(self._stop(signal=signal), self._loop) - # Wait for the running_loop to stop - if wait: - signal.wait() - if self._in_other_tread: - self._thread.join() - self._stopped = True - self._started = False - - async def _stop(self, signal: threading.Event) -> None: - """ - Real stop the asyncio event loop. - """ - # Cancel all tasks - tasks = [task for task in asyncio.all_tasks(self._loop) if task is not asyncio.current_task()] - for task in tasks: - task.cancel() - await asyncio.gather(*tasks, return_exceptions=True) - # Stop the event running_loop - self._loop.stop() - # Set the signal - signal.set() diff --git a/src/dubbo/remoting/aio/exceptions.py b/src/dubbo/remoting/aio/exceptions.py deleted file mode 100644 index f9416157..00000000 --- a/src/dubbo/remoting/aio/exceptions.py +++ /dev/null @@ -1,46 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -class RemotingError(Exception): - """ - The base exception class for remoting. - """ - - def __init__(self, message: str): - super().__init__(message) - self.message = message - - def __str__(self): - return self.message - - -class ProtocolError(RemotingError): - """ - The exception class for protocol errors. - """ - - def __init__(self, message: str): - super().__init__(message) - - -class StreamError(RemotingError): - """ - The exception class for stream errors. - """ - - def __init__(self, message: str): - super().__init__(message) diff --git a/src/dubbo/remoting/aio/http2/__init__.py b/src/dubbo/remoting/aio/http2/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/src/dubbo/remoting/aio/http2/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/src/dubbo/remoting/aio/http2/controllers.py b/src/dubbo/remoting/aio/http2/controllers.py deleted file mode 100644 index 04ab366c..00000000 --- a/src/dubbo/remoting/aio/http2/controllers.py +++ /dev/null @@ -1,389 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc -import asyncio -import threading -from concurrent.futures import ThreadPoolExecutor -from dataclasses import dataclass -from typing import Optional - -from h2.connection import H2Connection - -from dubbo.loggers import loggerFactory -from dubbo.remoting.aio.http2.frames import ( - DataFrame, - HeadersFrame, - UserActionFrames, - WindowUpdateFrame, -) -from dubbo.remoting.aio.http2.registries import Http2FrameType -from dubbo.remoting.aio.http2.stream import DefaultHttp2Stream, Http2Stream -from dubbo.utils import EventHelper - -__all__ = ["RemoteFlowController", "FrameInboundController", "FrameOutboundController"] - -_LOGGER = loggerFactory.get_logger() - - -class Controller(abc.ABC): - def __init__(self, loop: asyncio.AbstractEventLoop): - self._loop = loop - self._lock = threading.Lock() - self._task: Optional[asyncio.Task] = None - self._started = False - self._closed = False - - def start(self) -> None: - with self._lock: - if self._started: - return - self._task = self._loop.create_task(self._run()) - self._started = True - - @abc.abstractmethod - async def _run(self) -> None: - raise NotImplementedError() - - def close(self) -> None: - with self._lock: - if self._closed or not self._task: - return - self._task.cancel() - self._task = None - - -class RemoteFlowController(Controller): - @dataclass - class Item: - stream: Http2Stream - data: bytearray - end_stream: bool - event: Optional[asyncio.Event] - - def __init__( - self, - h2_connection: H2Connection, - transport: asyncio.Transport, - loop: asyncio.AbstractEventLoop, - ): - super().__init__(loop) - self._h2_connection = h2_connection - self._transport = transport - - self._stream_dict: dict[int, RemoteFlowController.Item] = {} - - self._outbound_queue: asyncio.Queue[int] = asyncio.Queue() - self._flow_controls: set[int] = set() - - # Start the controller - self.start() - - def write_data(self, stream: Http2Stream, frame: DataFrame, event: Optional[asyncio.Event]) -> None: - if stream.local_closed: - EventHelper.set(event) - _LOGGER.warning("Stream %s is closed locally, ignoring the data frame.", stream.id) - return - - item = self._stream_dict.get(stream.id) - if item: - # Extend the data if the stream item exists - item.data.extend(frame.data) - item.end_stream = frame.end_stream - # update the event - EventHelper.set(item.event) - item.event = event - else: - # Create a new stream item - item = RemoteFlowController.Item(stream, bytearray(frame.data), frame.end_stream, event) - self._stream_dict[stream.id] = item - self._outbound_queue.put_nowait(stream.id) - - def release_flow_control(self, frame: WindowUpdateFrame) -> None: - stream_id = frame.stream_id - if stream_id is None or stream_id == 0: - # This is for the entire connection. - for i in self._flow_controls: - self._outbound_queue.put_nowait(i) - self._flow_controls.clear() - elif stream_id in self._flow_controls: - # This is specific to a single stream. - self._flow_controls.remove(stream_id) - self._outbound_queue.put_nowait(stream_id) - - async def _run(self) -> None: - while True: - # get the data to send.(async blocking) - stream_id = await self._outbound_queue.get() - - # check if the stream is closed - item = self._stream_dict[stream_id] - stream = item.stream - if stream.local_closed: - # The local side of the stream is closed, so we don't need to send any data. - EventHelper.set(item.event) - continue - - # get the flow control window size - data = item.data - window_size = self._h2_connection.local_flow_control_window(stream.id) - chunk_size = min(window_size, len(data)) - data_to_send = data[:chunk_size] - data_to_buffer = data[chunk_size:] - - # send the data - if data_to_send or item.end_stream: - max_size = self._h2_connection.max_outbound_frame_size - # Split the data into chunks and send them out - for x in range(0, len(data_to_send), max_size): - chunk = data_to_send[x : x + max_size] - end_stream_flag = item.end_stream and not data_to_buffer and (x + max_size >= len(data_to_send)) - self._h2_connection.send_data(stream.id, chunk, end_stream=end_stream_flag) - - outbound_data = self._h2_connection.data_to_send() - if not outbound_data: - # If there is no outbound data to send but the stream needs to be closed, - # send an empty headers frame with the end_stream flag set to True. - self._h2_connection.send_data(stream.id, b"", end_stream=True) - outbound_data = self._h2_connection.data_to_send() - self._transport.write(outbound_data) - - if data_to_buffer: - # Save the data that could not be sent due to flow control limits - item.data = data_to_buffer - self._flow_controls.add(stream.id) - else: - # If all data has been sent, trigger the event. - self._stream_dict.pop(stream.id) - EventHelper.set(item.event) - if item.end_stream: - stream.close_local() - - -class FrameInboundController(Controller): - """ - HTTP/2 frame inbound controller. - This class is responsible for reading frames in the correct order. - """ - - def __init__( - self, - stream: Http2Stream, - loop: asyncio.AbstractEventLoop, - protocol, - executor: Optional[ThreadPoolExecutor] = None, - ): - """ - Initialize the FrameInboundController. - :param stream: The stream. - :type stream: Http2Stream - :param loop: The asyncio event loop. - :type loop: asyncio.AbstractEventLoop - :param protocol: The HTTP/2 protocol. - :param executor: The thread pool executor for handling frames. - :type executor: Optional[ThreadPoolExecutor] - """ - from dubbo.remoting.aio.http2.protocol import AbstractHttp2Protocol - - super().__init__(loop) - - self._stream = stream - self._protocol: AbstractHttp2Protocol = protocol - self._executor = executor - - # The queue for receiving frames. - self._inbound_queue: asyncio.Queue[UserActionFrames] = asyncio.Queue() - - self._condition: asyncio.Condition = asyncio.Condition() - - # Start the controller - self.start() - - def write_frame(self, frame: UserActionFrames) -> None: - """ - Put the frame into the frame queue (thread-unsafe). - :param frame: The HTTP/2 frame to put into the queue. - """ - self._inbound_queue.put_nowait(frame) - - def ack_frame(self, frame: UserActionFrames) -> None: - """ - Acknowledge the frame by setting the frame event.(thread-safe) - """ - - async def _inner_operation(_frame: UserActionFrames): - async with self._condition: - if _frame.frame_type == Http2FrameType.DATA: - self._protocol.ack_received_data(_frame.stream_id, _frame.padding) - self._condition.notify_all() - - asyncio.run_coroutine_threadsafe(_inner_operation(frame), self._loop) - - async def _run(self) -> None: - """ - Coroutine that continuously reads frames from the frame queue. - """ - while True: - async with self._condition: - # get the frame from the queue - frame = await self._inbound_queue.get() - - if self._stream.remote_closed: - # The remote side of the stream is closed, so we don't need to process any more frames. - break - - # handle frame in the thread pool - self._loop.run_in_executor(self._executor, self._handle_frame, frame) - - if not frame.end_stream: - # Waiting for the previous frame to be processed - await self._condition.wait() - else: - # close the stream remotely - self._stream.close_remote() - break - - def _handle_frame(self, frame: UserActionFrames): - listener = self._stream.listener - # match the frame type - frame_type = frame.frame_type - if frame_type == Http2FrameType.HEADERS: - listener.on_headers(frame.headers, frame.end_stream) - elif frame_type == Http2FrameType.DATA: - listener.on_data(frame.data, frame.end_stream) - elif frame_type == Http2FrameType.RST_STREAM: - listener.cancel_by_remote(frame.error_code) - else: - _LOGGER.warning("unprocessed frame type: %s", frame_type) - - # acknowledge the frame - self.ack_frame(frame) - - -class FrameOutboundController(Controller): - """ - HTTP/2 frame outbound controller. - This class is responsible for writing frames in the correct order. - """ - - LAST_DATA_FRAME = DataFrame(-1, b"", 0) - - def __init__(self, stream: DefaultHttp2Stream, loop: asyncio.AbstractEventLoop, protocol): - from dubbo.remoting.aio.http2.protocol import AbstractHttp2Protocol - - super().__init__(loop) - - self._stream = stream - self._protocol: AbstractHttp2Protocol = protocol - - self._headers_put_event: asyncio.Event = asyncio.Event() - self._headers_sent_event: asyncio.Event = asyncio.Event() - self._headers: Optional[HeadersFrame] = None - - self._data_queue: asyncio.Queue[DataFrame] = asyncio.Queue() - self._data_sent_event: asyncio.Event = asyncio.Event() - - self._trailers: Optional[HeadersFrame] = None - - # Start the controller - self.start() - - def write_headers(self, frame: HeadersFrame) -> None: - """ - Write the headers frame by order.(thread-safe) - :param frame: The headers frame. - :type frame: HeadersFrame - """ - - def _inner_operation(_frame: HeadersFrame): - if not self._headers: - # send the frame directly -> the headers frame is the first frame - self._headers = _frame - EventHelper.set(self._headers_put_event) - else: - # put the frame into the queue -> the headers frame is not the first frame(trailers) - self._trailers = _frame - # Notify the data queue that the last data frame has reached. - self._data_queue.put_nowait(FrameOutboundController.LAST_DATA_FRAME) - - self._loop.call_soon_threadsafe(_inner_operation, frame) - - def write_data(self, frame: DataFrame) -> None: - """ - Write the data frame by order.(thread-safe) - :param frame: The data frame. - :type frame: DataFrame - """ - self._loop.call_soon_threadsafe(self._data_queue.put_nowait, frame) - - def write_rst(self, frame: UserActionFrames) -> None: - """ - Write the reset frame directly.(thread-safe) - :param frame: The reset frame. - :type frame: UserActionFrames - """ - - def _inner_operation(_frame: UserActionFrames): - # -1 means the stream is not created, so we don't need to send the reset frame - if self._stream.id == -1: - return - - _frame.stream_id = self._stream.id - self._protocol.send_frame(_frame, self._stream) - - self._stream.close_local() - self._stream.close_remote() - - self._loop.call_soon_threadsafe(_inner_operation, frame) - - async def _run(self) -> None: - """ - Coroutine that continuously writes frames from the frame queue. - """ - - # wait and send the headers frame - await self._headers_put_event.wait() - self._protocol.send_frame(self._headers, self._stream, self._headers_sent_event) - - # check if the headers frame is the last frame - if self._headers.end_stream: - self._stream.close_local() - return - - # wait for the headers sent event - await self._headers_sent_event.wait() - - # wait and send the data frames - while True: - frame = await self._data_queue.get() - frame.stream_id = self._stream.id - if frame is not FrameOutboundController.LAST_DATA_FRAME: - self._data_sent_event = asyncio.Event() - self._protocol.send_frame(frame, self._stream, self._data_sent_event) - if frame.end_stream: - # The last frame has been sent, so the stream is closed. - return - else: - # The last frame has been reached. - break - - # wait for the last data frame and send the trailers frame - await self._data_sent_event.wait() - self._trailers.stream_id = self._stream.id - self._protocol.send_frame(self._trailers, self._stream) - - # close the stream - self._stream.close_local() diff --git a/src/dubbo/remoting/aio/http2/frames.py b/src/dubbo/remoting/aio/http2/frames.py deleted file mode 100644 index 7576472c..00000000 --- a/src/dubbo/remoting/aio/http2/frames.py +++ /dev/null @@ -1,200 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from typing import Union - -from dubbo.remoting.aio.http2.headers import Http2Headers -from dubbo.remoting.aio.http2.registries import Http2ErrorCode, Http2FrameType - -__all__ = [ - "Http2Frame", - "HeadersFrame", - "DataFrame", - "WindowUpdateFrame", - "RstStreamFrame", - "PingFrame", - "UserActionFrames", -] - - -class Http2Frame: - """ - HTTP/2 frame class. It is used to represent an HTTP/2 frame. - """ - - __slots__ = ["stream_id", "frame_type", "end_stream", "timestamp"] - - def __init__( - self, - stream_id: int, - frame_type: Http2FrameType, - end_stream: bool = False, - ): - """ - Initialize the HTTP/2 frame. - :param stream_id: The stream identifier. 0 for connection-level frames. - :type stream_id: int - :param frame_type: The frame type. - :type frame_type: Http2FrameType - :param end_stream: Whether the stream is ended. - :type end_stream: bool - """ - self.stream_id = stream_id - self.frame_type = frame_type - self.end_stream = end_stream - - def __repr__(self) -> str: - return f"" - - -class HeadersFrame(Http2Frame): - """ - HTTP/2 headers frame. - """ - - __slots__ = ["headers"] - - def __init__( - self, - stream_id: int, - headers: Http2Headers, - end_stream: bool = False, - ): - """ - Initialize the HTTP/2 headers frame. - :param stream_id: The stream identifier. - :type stream_id: int - :param headers: The headers to send. - :type headers: Http2Headers - :param end_stream: Whether the stream is ended. - :type end_stream: bool - """ - super().__init__(stream_id, Http2FrameType.HEADERS, end_stream) - self.headers = headers - - def __repr__(self) -> str: - return ( - f"" - ) - - -class DataFrame(Http2Frame): - """ - HTTP/2 data frame. - """ - - __slots__ = ["data", "padding"] - - def __init__( - self, - stream_id: int, - data: bytes, - length: int, - end_stream: bool = False, - ): - """ - Initialize the HTTP/2 data frame. - :param stream_id: The stream identifier. - :type stream_id: int - :param data: The data to send. - :type data: bytes - :param length: The length of the data. - :type length: int - :param end_stream: Whether the stream is ended. - """ - super().__init__(stream_id, Http2FrameType.DATA, end_stream) - self.data = data - self.padding = length - - def __repr__(self) -> str: - return f"" - - -class WindowUpdateFrame(Http2Frame): - """ - HTTP/2 window update frame. - """ - - __slots__ = ["delta"] - - def __init__( - self, - stream_id: int, - delta: int, - ): - """ - Initialize the HTTP/2 window update frame. - :param stream_id: The stream identifier. - :type stream_id: int - :param delta: The delta value. - :type delta: int - """ - super().__init__(stream_id, Http2FrameType.WINDOW_UPDATE, False) - self.delta = delta - - def __repr__(self) -> str: - return f"" - - -class RstStreamFrame(Http2Frame): - """ - HTTP/2 reset stream frame. - """ - - __slots__ = ["error_code"] - - def __init__( - self, - stream_id: int, - error_code: Http2ErrorCode, - ): - """ - Initialize the HTTP/2 reset stream frame. - :param stream_id: The stream identifier. - :type stream_id: int - :param error_code: The error code. - :type error_code: Http2ErrorCode - """ - super().__init__(stream_id, Http2FrameType.RST_STREAM, True) - self.error_code = error_code - - def __repr__(self) -> str: - return f"" - - -class PingFrame(Http2Frame): - """ - HTTP/2 ping frame. - """ - - __slots__ = ["data", "ack"] - - def __init__(self, data: bytes, ack: bool = False): - """ - Initialize the HTTP/2 ping frame. - :param data: The data. - :type data: bytes - """ - super().__init__(0, Http2FrameType.PING, False) - self.data = data - self.ack = ack - - def __repr__(self) -> str: - return f"" - - -# User action frames. -UserActionFrames = Union[HeadersFrame, DataFrame, RstStreamFrame] diff --git a/src/dubbo/remoting/aio/http2/headers.py b/src/dubbo/remoting/aio/http2/headers.py deleted file mode 100644 index 1f715cc9..00000000 --- a/src/dubbo/remoting/aio/http2/headers.py +++ /dev/null @@ -1,167 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import enum -from collections import OrderedDict -from typing import Optional, Union - - -class PseudoHeaderName(enum.Enum): - """ - Pseudo-header names defined in RFC 7540 Section. - See: https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2 - """ - - SCHEME = ":scheme" - # Request pseudo-headers - METHOD = ":method" - AUTHORITY = ":authority" - PATH = ":path" - # Response pseudo-headers - STATUS = ":status" - - @classmethod - def to_list(cls) -> list[str]: - """ - Get all pseudo-header names. - Returns: - The pseudo-header names list. - """ - return [header.value for header in cls] - - -class HttpMethod(enum.Enum): - """ - HTTP method types. - """ - - GET = "GET" - POST = "POST" - PUT = "PUT" - DELETE = "DELETE" - HEAD = "HEAD" - OPTIONS = "OPTIONS" - PATCH = "PATCH" - TRACE = "TRACE" - CONNECT = "CONNECT" - - -class Http2Headers: - """ - HTTP/2 headers. - """ - - __slots__ = ["_headers"] - - def __init__(self): - self._headers: OrderedDict[str, Optional[str]] = OrderedDict() - self._init() - - def _init(self): - # keep the order of headers - self._headers = {name: "" for name in PseudoHeaderName.to_list()} - - def add(self, name: str, value: str) -> None: - self._headers[name] = str(value) - - def get(self, name: str, default: Optional[str] = None) -> Optional[str]: - return self._headers.get(name, default) - - @property - def method(self) -> Optional[str]: - return self.get(PseudoHeaderName.METHOD.value) - - @method.setter - def method(self, value: Union[HttpMethod, str]) -> None: - if isinstance(value, HttpMethod): - value = value.value - else: - value = value.upper() - self.add(PseudoHeaderName.METHOD.value, value) - - @property - def scheme(self) -> Optional[str]: - return self.get(PseudoHeaderName.SCHEME.value) - - @scheme.setter - def scheme(self, value: str) -> None: - self.add(PseudoHeaderName.SCHEME.value, value) - - @property - def authority(self) -> Optional[str]: - return self.get(PseudoHeaderName.AUTHORITY.value) - - @authority.setter - def authority(self, value: str) -> None: - self.add(PseudoHeaderName.AUTHORITY.value, value) - - @property - def path(self) -> Optional[str]: - return self.get(PseudoHeaderName.PATH.value) - - @path.setter - def path(self, value: str) -> None: - self.add(PseudoHeaderName.PATH.value, value) - - @property - def status(self) -> Optional[str]: - return self.get(PseudoHeaderName.STATUS.value) - - @status.setter - def status(self, value: str) -> None: - self.add(PseudoHeaderName.STATUS.value, value) - - def to_list(self) -> list[tuple[str, str]]: - """ - Convert the headers to a list. The list contains all non-None headers. - :return: The headers list. - :rtype: List[Tuple[str, str]] - """ - headers = [] - pseudo_headers = PseudoHeaderName.to_list() - for name, value in list(self._headers.items()): - if name in pseudo_headers and value == "": - continue - headers.append((str(name), str(value) or "")) - return headers - - def to_dict(self) -> OrderedDict[str, str]: - """ - Convert the headers to an ordered dict. - :return: The headers' dict. - :rtype: OrderedDict[str, Optional[str]] - """ - headers_dict = OrderedDict() - for key, value in self._headers.items(): - if value is not None and value != "": - headers_dict[key] = value - return headers_dict - - def __repr__(self) -> str: - return f"" - - @classmethod - def from_list(cls, headers: list[tuple[str, str]]) -> "Http2Headers": - """ - Create an Http2Headers object from a list. - :param headers: The headers list. - :type headers: List[Tuple[str, str]] - :return: The Http2Headers object. - :rtype: Http2Headers - """ - http2_headers = cls() - http2_headers._headers = dict(headers) # type: ignore - return http2_headers diff --git a/src/dubbo/remoting/aio/http2/protocol.py b/src/dubbo/remoting/aio/http2/protocol.py deleted file mode 100644 index a762d0a2..00000000 --- a/src/dubbo/remoting/aio/http2/protocol.py +++ /dev/null @@ -1,368 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import abc -import asyncio -import struct -import time -from typing import Optional - -from h2.config import H2Configuration -from h2.connection import H2Connection - -from dubbo.constants import common_constants -from dubbo.loggers import loggerFactory -from dubbo.remoting.aio import ConnectionStateListener, EmptyConnectionStateListener, constants as h2_constants -from dubbo.remoting.aio.exceptions import ProtocolError -from dubbo.remoting.aio.http2.stream_handler import StreamServerMultiplexHandler -from dubbo.remoting.aio.http2.controllers import RemoteFlowController -from dubbo.remoting.aio.http2.frames import ( - DataFrame, - HeadersFrame, - Http2Frame, - PingFrame, - RstStreamFrame, - UserActionFrames, - WindowUpdateFrame, -) -from dubbo.remoting.aio.http2.registries import Http2FrameType -from dubbo.remoting.aio.http2.stream import Http2Stream -from dubbo.remoting.aio.http2.utils import Http2EventUtils -from dubbo.url import URL -from dubbo.utils import EventHelper, FutureHelper - -__all__ = ["AbstractHttp2Protocol", "Http2ClientProtocol", "Http2ServerProtocol"] - -_LOGGER = loggerFactory.get_logger() - - -class AbstractHttp2Protocol(asyncio.Protocol, abc.ABC): - """ - HTTP/2 protocol implementation. - """ - - DEFAULT_PING_DATA = struct.pack(">Q", 0) # 8 bytes of 0 - - __slots__ = [ - "_url", - "_loop", - "_h2_connection", - "_transport", - "_flow_controller", - "_stream_handler", - "_last_read", - "_last_write", - ] - - def __init__(self, url: URL, h2_config: H2Configuration): - self._url = url - self._loop = asyncio.get_running_loop() - - # Create the H2 state machine - self._h2_connection = H2Connection(h2_config) - - # The transport instance - self._transport: Optional[asyncio.Transport] = None - - self._flow_controller: Optional[RemoteFlowController] = None - - if self._url.attributes[common_constants.PROTOCOL_KEY] == Http2ServerProtocol: - listener_factory = self._url.attributes[h2_constants.LISTENER_FACTORY_KEY] - self._stream_handler = StreamServerMultiplexHandler(listener_factory) - else: - self._stream_handler = self._url.attributes[h2_constants.STREAM_HANDLER_KEY] - - # last time of receiving data - self._last_read = time.time() - # last time of sending data - self._last_write = time.time() - - @property - def last_read(self) -> float: - """ - Get the last time of receiving data. - """ - return self._last_read - - def _update_last_read(self) -> None: - """ - Update the last time of receiving data. - """ - self._last_read = time.time() - - @property - def last_write(self) -> float: - """ - Get the last time of sending data. - """ - return self._last_write - - def _update_last_write(self) -> None: - """ - Update the last time of sending data. - """ - self._last_write = time.time() - - def connection_made(self, transport: asyncio.Transport): - """ - Called when the connection is first established. We complete the following actions: - 1. Save the transport. - 2. Initialize the H2 connection. - 3. Create and start the follow controller. - 4. Initialize the stream handler. - """ - self._transport = transport - self._h2_connection.initiate_connection() - self._flush() - - # Create and start the follow controller - self._flow_controller = RemoteFlowController(self._h2_connection, self._transport, self._loop) - - # Initialize the stream handler - self._stream_handler.do_init(self._loop, self) - - def get_next_stream_id(self, future) -> None: - """ - Create a new stream.(thread-safe) - :param future: The future to set the stream identifier. - """ - - def _inner_operation(_future): - stream_id = self._h2_connection.get_next_available_stream_id() - FutureHelper.set_result(_future, stream_id) - - self._loop.call_soon_threadsafe(_inner_operation, future) - - def send_frame( - self, - frame: UserActionFrames, - stream: Http2Stream, - event: Optional[asyncio.Event] = None, - ) -> None: - """ - Send the HTTP/2 frame.(thread-unsafe) - :param frame: The frame to send. - :type frame: UserActionFrames - :param stream: The stream. - :type stream: Http2Stream - :param event: The event to be set after sending the frame. - :type event: Optional[asyncio.Event] - """ - frame_type = frame.frame_type - if frame_type == Http2FrameType.HEADERS: - self._send_headers_frame(frame, stream, event) - elif frame_type == Http2FrameType.DATA: - self._flow_controller.write_data(stream, frame, event) - elif frame_type == Http2FrameType.RST_STREAM: - self._send_reset_frame(frame.stream_id, frame.error_code.value, event) - else: - _LOGGER.warning("Unhandled frame: %s", frame) - - def _send_headers_frame( - self, - frame: HeadersFrame, - stream: Http2Stream, - event: Optional[asyncio.Event] = None, - ) -> None: - """ - Send the HTTP/2 headers frame.(thread-unsafe) - :param frame: The frame to send. - :type frame: HeadersFrame - :param stream: The stream. - :type stream: Http2Stream - :param event: The event to be set after sending the frame. - """ - if stream.id == -1: - stream.id = self._h2_connection.get_next_available_stream_id() - self._stream_handler.put_stream(stream.id, stream) - - self._h2_connection.send_headers(stream.id, frame.headers.to_list(), end_stream=frame.end_stream) - self._flush() - EventHelper.set(event) - - def _send_reset_frame(self, stream_id: int, error_code: int, event: Optional[asyncio.Event] = None) -> None: - """ - Send the HTTP/2 reset frame.(thread-unsafe) - :param stream_id: The stream identifier. - :type stream_id: int - :param error_code: The error code. - :type error_code: int - :param event: The event to be set after sending the frame. - :type event: Optional[asyncio.Event] - """ - self._h2_connection.reset_stream(stream_id, error_code) - self._flush() - EventHelper.set(event) - - def _send_ping_frame(self, data: bytes = DEFAULT_PING_DATA) -> None: - """ - Send the HTTP/2 ping frame.(thread-unsafe) - :param data: The data to send. The length of the data must be 8 bytes. - :type data: bytes - """ - self._h2_connection.ping(data) - self._flush() - - def _flush(self) -> None: - """ - Flush the data to the transport. - """ - outbound_data = self._h2_connection.data_to_send() - if outbound_data != b"": - self._transport.write(outbound_data) - # Update the last write time - self._update_last_write() - - def data_received(self, data): - """ - Called when some data is received from the transport. - :param data: The data received. - :type data: bytes - """ - # Update the last read time - self._update_last_read() - - # Process the event - events = self._h2_connection.receive_data(data) - try: - for event in events: - frame = Http2EventUtils.convert_to_frame(event) - - # If frame is None, there are two possible cases: - # 1. Events that are handled automatically by the H2 library (e.g. RemoteSettingsChanged, PingReceived). - # -> We just need to send it. - # 2. Events that are not implemented or do not require attention. -> We'll ignore it for now. - if frame is not None: - if isinstance(frame, WindowUpdateFrame): - # Because flow control may be at the connection level, it is handled here - self._flow_controller.release_flow_control(frame) - elif isinstance(frame, (HeadersFrame, DataFrame, RstStreamFrame)): - # Handle the frame by the stream handler - self._stream_handler.handle_frame(frame) - else: - # Try handling other frames - self._do_other_frame(frame) - - # Flush the data - self._flush() - - except Exception as e: - raise ProtocolError("Failed to process the Http/2 event.") from e - - def _do_other_frame(self, frame: Http2Frame): - """ - This is a scalable approach to handle other frames. Subclasses can override this method to handle other frames. - :param frame: The frame to handle. - :type frame: Http2Frame - """ - pass - - def ack_received_data(self, stream_id: int, ack_length: int) -> None: - """ - Acknowledge the received data. - :param stream_id: The stream identifier. - :type stream_id: int - :param ack_length: The length of the data to acknowledge. - :type ack_length: int - """ - - self._h2_connection.acknowledge_received_data(ack_length, stream_id) - self._flush() - - def close(self): - """ - Close the connection. - """ - self._h2_connection.close_connection() - self._flush() - self._transport.close() - - def connection_lost(self, exc): - """ - Called when the connection is lost. - """ - self._flow_controller.close() - - -class Http2ClientProtocol(AbstractHttp2Protocol): - """ - HTTP/2 client protocol implementation. - """ - - def __init__( - self, - url: URL, - connection_listener: ConnectionStateListener = None, - ): - super().__init__(url, H2Configuration(client_side=True, header_encoding="utf-8")) - self._connection_listener = connection_listener or EmptyConnectionStateListener() - - # get heartbeat interval -> default 60s - self._heartbeat_interval = url.parameters.get(h2_constants.HEARTBEAT_KEY, h2_constants.DEFAULT_HEARTBEAT) - self._ping_ack_future: Optional[asyncio.Future] = None - self._heartbeat_task: Optional[asyncio.Task] = None - - def connection_made(self, transport: asyncio.Transport): - super().connection_made(transport) - - # Start the heartbeat task - self._heartbeat_task = asyncio.create_task(self._heartbeat_loop()) - - # Notify the connection is established - asyncio.create_task(self._connection_listener.connection_made()) - - def _do_other_frame(self, frame: Http2Frame): - # Handle the ping frame - if isinstance(frame, PingFrame) and frame.ack: - FutureHelper.set_result(self._ping_ack_future, None) - - async def _heartbeat_loop(self): - """ - Heartbeat loop. It is used to check the connection status. - """ - while True: - await asyncio.sleep(self._heartbeat_interval) - - # check last read time - now = time.time() - if now - self.last_read < self._heartbeat_interval: - # the connection is normal - continue - - # try to send ping frame to check the connection - self._ping_ack_future = asyncio.Future() - self._send_ping_frame() - try: - # wait for the ping ack - await asyncio.wait_for(self._ping_ack_future, timeout=5) - except asyncio.TimeoutError: - # close the connection - self.close() - break - - def connection_lost(self, exc): - super().connection_lost(exc) - - # Notify the connection is lost - asyncio.create_task(self._connection_listener.connection_lost(exc)) - - -class Http2ServerProtocol(AbstractHttp2Protocol): - """ - HTTP/2 server protocol implementation. - """ - - def __init__(self, url: URL): - super().__init__(url, H2Configuration(client_side=False, header_encoding="utf-8")) diff --git a/src/dubbo/remoting/aio/http2/registries.py b/src/dubbo/remoting/aio/http2/registries.py deleted file mode 100644 index e232807a..00000000 --- a/src/dubbo/remoting/aio/http2/registries.py +++ /dev/null @@ -1,298 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import enum -from typing import Optional, Union - -__all__ = ["Http2FrameType", "Http2ErrorCode", "Http2Settings", "HttpStatus"] - - -class Http2FrameType(enum.Enum): - """ - Frame types are used in the frame header to identify the type of the frame. - See: https://datatracker.ietf.org/doc/html/rfc7540#section-11.2 - """ - - # Data frame, carries HTTP message bodies. - DATA = 0x0 - - # Headers frame, carries HTTP headers. - HEADERS = 0x1 - - # Priority frame, specifies the priority of a stream. - PRIORITY = 0x2 - - # Reset Stream frame, cancels a stream. - RST_STREAM = 0x3 - - # Settings frame, exchanges configuration parameters. - SETTINGS = 0x4 - - # Push Promise frame, used by the server to push resources. - PUSH_PROMISE = 0x5 - - # Ping frame, measures round-trip time and checks connectivity. - PING = 0x6 - - # Goaway frame, signals that the connection will be closed. - GOAWAY = 0x7 - - # Window Update frame, manages flow control window size. - WINDOW_UPDATE = 0x8 - - # Continuation frame, transmits large header blocks. - CONTINUATION = 0x9 - - -class Http2ErrorCode(enum.Enum): - """ - Error codes are 32-bit fields that are used in RST_STREAM and GOAWAY frames - to convey the reasons for the stream or connection error. - - see: https://datatracker.ietf.org/doc/html/rfc7540#section-11.4 - """ - - # The associated condition is not a result of an error. - NO_ERROR = 0x0 - - # The endpoint detected an unspecific protocol error. - PROTOCOL_ERROR = 0x1 - - # The endpoint encountered an unexpected internal error. - INTERNAL_ERROR = 0x2 - - # The endpoint detected that its peer violated the flow-control protocol. - FLOW_CONTROL_ERROR = 0x3 - - # The endpoint sent a SETTINGS frame but did not receive a response in a timely manner. - SETTINGS_TIMEOUT = 0x4 - - # The endpoint received a frame after a stream was half-closed. - STREAM_CLOSED = 0x5 - - # The endpoint received a frame with an invalid size. - FRAME_SIZE_ERROR = 0x6 - - # The endpoint refused the stream prior to performing any application processing - REFUSED_STREAM = 0x7 - - # Used by the endpoint to indicate that the stream is no longer needed. - CANCEL = 0x8 - - # The endpoint is unable to maintain the header compression context for the connection. - COMPRESSION_ERROR = 0x9 - - # The connection established in response to a CONNECT request (Section 8.3) was reset or abnormally closed. - CONNECT_ERROR = 0xA - - # The endpoint detected that its peer is exhibiting a behavior that might be generating excessive load. - ENHANCE_YOUR_CALM = 0xB - - # The underlying transport has properties that do not meet minimum security requirements (see Section 9.2). - INADEQUATE_SECURITY = 0xC - - # The endpoint requires that HTTP/1.1 be used instead of HTTP/2. - HTTP_1_1_REQUIRED = 0xD - - @classmethod - def get(cls, code: int): - """ - Get the error code by code. - :param code: The error code. - :type code: int - """ - for error_code in cls: - if error_code.value == code: - return error_code - # Unknown or unsupported error codes MUST NOT trigger any special behavior. - # These MAY be treated as equivalent to INTERNAL_ERROR. - return cls.INTERNAL_ERROR - - -class Http2Settings: - """ - The settings are used to communicate configuration parameters that affect how endpoints communicate. - See: https://datatracker.ietf.org/doc/html/rfc7540#section-11.3 - """ - - class Http2Setting: - """ - HTTP/2 setting. - """ - - def __init__(self, code: int, initial_value: Optional[int] = None): - self.code = code - # If the initial value is "none", it means no limitation. - self.initial_value = initial_value - - # Allows the sender to inform the remote endpoint of the maximum size - # of the header compression table used to decode header blocks, in octets. - HEADER_TABLE_SIZE = Http2Setting(0x1, 4096) - - # This setting can be used to disable server push (Section 8.2). - ENABLE_PUSH = Http2Setting(0x2, 1) - - # Indicates the maximum number of concurrent streams that the sender will allow. - MAX_CONCURRENT_STREAMS = Http2Setting(0x3, None) - - # Indicates the sender's initial window size (in octets) for stream-level flow control. - # This setting affects the window size of all streams - INITIAL_WINDOW_SIZE = Http2Setting(0x4, 65535) - - # Indicates the size of the largest frame payload that the sender is willing to receive, in octets. - MAX_FRAME_SIZE = Http2Setting(0x5, 16384) - - # This advisory setting informs a peer of the maximum size of header list - # that the sender is prepared to accept, in octets. - MAX_HEADER_LIST_SIZE = Http2Setting(0x6, None) - - -class HttpStatus(enum.Enum): - """ - Enum for HTTP status codes as defined in RFC 7231 and related specifications. - """ - - # 1xx Informational - CONTINUE = 100 - SWITCHING_PROTOCOLS = 101 - - # 2xx Success - OK = 200 - CREATED = 201 - ACCEPTED = 202 - NON_AUTHORITATIVE_INFORMATION = 203 - NO_CONTENT = 204 - RESET_CONTENT = 205 - PARTIAL_CONTENT = 206 - - # 3xx Redirection - MULTIPLE_CHOICES = 300 - MOVED_PERMANENTLY = 301 - FOUND = 302 - SEE_OTHER = 303 - NOT_MODIFIED = 304 - USE_PROXY = 305 - TEMPORARY_REDIRECT = 307 - PERMANENT_REDIRECT = 308 - - # 4xx Client Error - BAD_REQUEST = 400 - UNAUTHORIZED = 401 - PAYMENT_REQUIRED = 402 - FORBIDDEN = 403 - NOT_FOUND = 404 - METHOD_NOT_ALLOWED = 405 - NOT_ACCEPTABLE = 406 - PROXY_AUTHENTICATION_REQUIRED = 407 - REQUEST_TIMEOUT = 408 - CONFLICT = 409 - GONE = 410 - LENGTH_REQUIRED = 411 - PRECONDITION_FAILED = 412 - PAYLOAD_TOO_LARGE = 413 - URI_TOO_LONG = 414 - UNSUPPORTED_MEDIA_TYPE = 415 - RANGE_NOT_SATISFIABLE = 416 - EXPECTATION_FAILED = 417 - I_AM_A_TEAPOT = 418 - MISDIRECTED_REQUEST = 421 - UNPROCESSABLE_ENTITY = 422 - LOCKED = 423 - FAILED_DEPENDENCY = 424 - UPGRADE_REQUIRED = 426 - PRECONDITION_REQUIRED = 428 - TOO_MANY_REQUESTS = 429 - REQUEST_HEADER_FIELDS_TOO_LARGE = 431 - UNAVAILABLE_FOR_LEGAL_REASONS = 451 - - # 5xx Server Error - INTERNAL_SERVER_ERROR = 500 - NOT_IMPLEMENTED = 501 - BAD_GATEWAY = 502 - SERVICE_UNAVAILABLE = 503 - GATEWAY_TIMEOUT = 504 - HTTP_VERSION_NOT_SUPPORTED = 505 - VARIANT_ALSO_NEGOTIATES = 506 - INSUFFICIENT_STORAGE = 507 - LOOP_DETECTED = 508 - NOT_EXTENDED = 510 - NETWORK_AUTHENTICATION_REQUIRED = 511 - - @classmethod - def from_code(cls, code: int) -> "HttpStatus": - for status in cls: - if status.value == code: - return status - - @staticmethod - def is_1xx(status: Union["HttpStatus", int]) -> bool: - """ - Check if the given status is an informational (1xx) status code. - :param status: HttpStatus to check - :type status: Union[HttpStatus, int] - :return: True if the status code is in the 1xx range, False otherwise - :rtype: bool - """ - value = status if isinstance(status, int) else status.value - return 100 <= value < 200 - - @staticmethod - def is_2xx(status: Union["HttpStatus", int]) -> bool: - """ - Check if the given status is a successful (2xx) status code. - :param status: HttpStatus to check - :type status: Union[HttpStatus, int] - :return: True if the status code is in the 2xx range, False otherwise - :rtype: bool - """ - value = status if isinstance(status, int) else status.value - return 200 <= value < 300 - - @staticmethod - def is_3xx(status: Union["HttpStatus", int]) -> bool: - """ - Check if the given status is a redirection (3xx) status code. - :param status: HttpStatus to check - :type status: Union[HttpStatus, int] - :return: True if the status code is in the 3xx range, False otherwise - :rtype: bool - """ - value = status if isinstance(status, int) else status.value - return 300 <= value < 400 - - @staticmethod - def is_4xx(status: Union["HttpStatus", int]) -> bool: - """ - Check if the given status is a client error (4xx) status code. - :param status: HttpStatus to check - :type status: Union[HttpStatus, int] - :return: True if the status code is in the 4xx range, False otherwise - :rtype: bool - """ - value = status if isinstance(status, int) else status.value - return 400 <= value < 500 - - @staticmethod - def is_5xx(status: Union["HttpStatus", int]) -> bool: - """ - Check if the given status is a server error (5xx) status code. - :param status: HttpStatus to check - :type status: Union[HttpStatus, int] - :return: True if the status code is in the 5xx range, False otherwise - :rtype: bool - """ - value = status if isinstance(status, int) else status.value - return 500 <= value < 600 diff --git a/src/dubbo/remoting/aio/http2/stream.py b/src/dubbo/remoting/aio/http2/stream.py deleted file mode 100644 index 26d6d89b..00000000 --- a/src/dubbo/remoting/aio/http2/stream.py +++ /dev/null @@ -1,277 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc -import asyncio -from concurrent.futures import ThreadPoolExecutor -from typing import Optional - -from dubbo.remoting.aio.exceptions import StreamError -from dubbo.remoting.aio.http2.frames import ( - DataFrame, - HeadersFrame, - RstStreamFrame, - UserActionFrames, -) -from dubbo.remoting.aio.http2.headers import Http2Headers -from dubbo.remoting.aio.http2.registries import Http2ErrorCode - -__all__ = ["Http2Stream", "DefaultHttp2Stream"] - - -class Http2Stream(abc.ABC): - """ - A "stream" is an independent, bidirectional sequence of frames exchanged - between the client and server within an HTTP/2 connection. - see: https://datatracker.ietf.org/doc/html/rfc7540#section-5 - """ - - __slots__ = ["_id", "_listener", "_local_closed", "_remote_closed"] - - def __init__(self, stream_id: int, listener: "Http2Stream.Listener"): - self._id = stream_id - - self._listener = listener - self._listener.bind(self) - - # Whether the stream is closed locally. -> it means the stream can't send any more frames. - self._local_closed = False - # Whether the stream is closed remotely. -> it means the stream can't receive any more frames. - self._remote_closed = False - - @property - def id(self) -> int: - """ - Get the stream identifier. - """ - return self._id - - @id.setter - def id(self, stream_id: int) -> None: - """ - Set the stream identifier. - """ - self._id = stream_id - - @property - def listener(self) -> "Http2Stream.Listener": - """ - Get the listener. - """ - return self._listener - - @property - def local_closed(self) -> bool: - """ - Check if the stream is closed locally. - """ - return self._local_closed - - @property - def remote_closed(self) -> bool: - """ - Check if the stream is closed remotely. - """ - return self._remote_closed - - def close_local(self) -> None: - """ - Close the stream locally. - """ - if self._local_closed: - return - self._local_closed = True - - def close_remote(self) -> None: - """ - Close the stream remotely. - """ - if self._remote_closed: - return - self._remote_closed = True - - @abc.abstractmethod - def send_headers(self, headers: Http2Headers, end_stream: bool = False) -> None: - """ - Send the headers. - :param headers: The HTTP/2 headers. - The second send of headers will be treated as trailers (end_stream must be True). - :type headers: Http2Headers - :param end_stream: Whether to close the stream after sending the data. - """ - raise NotImplementedError() - - @abc.abstractmethod - def send_data(self, data: bytes, end_stream: bool = False) -> None: - """ - Send the data. - :param data: The data to send. - :type data: bytes - :param end_stream: Whether to close the stream after sending the data. - """ - raise NotImplementedError() - - @abc.abstractmethod - def cancel_by_local(self, error_code: Http2ErrorCode) -> None: - """ - Cancel the stream locally. -> send RST_STREAM frame. - :param error_code: The error code. - :type error_code: Http2ErrorCode - """ - raise NotImplementedError() - - class Listener(abc.ABC): - """ - Http2StreamListener is a base class for handling events in an HTTP/2 stream. - - This class provides a set of callback methods that are called when specific - events occur on the stream, such as receiving headers, receiving data, or - resetting the stream. To use this class, create a subclass and implement the - callback methods for the events you want to handle. - """ - - __slots__ = ["_stream"] - - def __init__(self): - self._stream: Optional[Http2Stream] = None - - def bind(self, stream: "Http2Stream") -> None: - """ - Bind the stream to the listener. - :param stream: The stream to bind. - :type stream: Http2Stream - """ - self._stream = stream - - @property - def stream(self) -> "Http2Stream": - """ - Get the stream. - """ - return self._stream - - @abc.abstractmethod - def on_headers(self, headers: Http2Headers, end_stream: bool) -> None: - """ - Called when the headers are received. - :param headers: The HTTP/2 headers. - :type headers: Http2Headers - :param end_stream: Whether the stream is closed after receiving the headers. - :type end_stream: bool - """ - raise NotImplementedError() - - @abc.abstractmethod - def on_data(self, data: bytes, end_stream: bool) -> None: - """ - Called when the data is received. - :param data: The data. - :type data: bytes - :param end_stream: Whether the stream is closed after receiving the data. - """ - raise NotImplementedError() - - @abc.abstractmethod - def cancel_by_remote(self, error_code: Http2ErrorCode) -> None: - """ - Cancel the stream remotely. - :param error_code: The error code. - :type error_code: Http2ErrorCode - """ - raise NotImplementedError() - - -class DefaultHttp2Stream(Http2Stream): - """ - Default implementation of the Http2Stream. - """ - - __slots__ = [ - "_loop", - "_protocol", - "_inbound_controller", - "_outbound_controller", - "_headers_sent", - ] - - def __init__( - self, - stream_id: int, - listener: "Http2Stream.Listener", - loop: asyncio.AbstractEventLoop, - protocol, - executor: Optional[ThreadPoolExecutor] = None, - ): - # Avoid circular import - from dubbo.remoting.aio.http2.controllers import ( - FrameInboundController, - FrameOutboundController, - ) - - super().__init__(stream_id, listener) - self._loop = loop - self._protocol = protocol - - # steam inbound controller - self._inbound_controller: FrameInboundController = FrameInboundController( - self, self._loop, self._protocol, executor - ) - # steam outbound controller - self._outbound_controller: FrameOutboundController = FrameOutboundController(self, self._loop, self._protocol) - - # The flag to indicate whether the headers have been sent. - self._headers_sent = False - - def close_local(self) -> None: - super().close_local() - self._outbound_controller.close() - - def close_remote(self) -> None: - super().close_remote() - self._inbound_controller.close() - - def send_headers(self, headers: Http2Headers, end_stream: bool = False) -> None: - if self.local_closed: - raise StreamError("The stream has been closed locally.") - elif self._headers_sent and not end_stream: - raise StreamError("Trailers must be the last frame of the stream(end_stream must be True).") - - self._headers_sent = True - headers_frame = HeadersFrame(self.id, headers, end_stream=end_stream) - self._outbound_controller.write_headers(headers_frame) - - def send_data(self, data: bytes, end_stream: bool = False) -> None: - if self.local_closed: - raise StreamError("The stream has been closed locally.") - elif not self._headers_sent: - raise StreamError("Headers have not been sent.") - data_frame = DataFrame(self.id, data, len(data), end_stream=end_stream) - self._outbound_controller.write_data(data_frame) - - def cancel_by_local(self, error_code: Http2ErrorCode) -> None: - if self.local_closed: - # The stream has been closed locally. - return - rst_frame = RstStreamFrame(self.id, error_code) - self._outbound_controller.write_rst(rst_frame) - - def receive_frame(self, frame: UserActionFrames) -> None: - """ - Receive the frame. - :param frame: The frame to receive. - :type frame: UserActionFrames - """ - self._inbound_controller.write_frame(frame) diff --git a/src/dubbo/remoting/aio/http2/stream_handler.py b/src/dubbo/remoting/aio/http2/stream_handler.py deleted file mode 100644 index 4e1064ef..00000000 --- a/src/dubbo/remoting/aio/http2/stream_handler.py +++ /dev/null @@ -1,174 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import asyncio -import uuid -from concurrent.futures import ThreadPoolExecutor -from typing import Callable, Optional - -from dubbo.loggers import loggerFactory -from dubbo.remoting.aio.http2.frames import UserActionFrames -from dubbo.remoting.aio.http2.registries import Http2FrameType -from dubbo.remoting.aio.http2.stream import DefaultHttp2Stream, Http2Stream - -_all__ = [ - "StreamMultiplexHandler", - "StreamClientMultiplexHandler", - "StreamServerMultiplexHandler", -] - -_LOGGER = loggerFactory.get_logger() - - -class StreamMultiplexHandler: - """ - The StreamMultiplexHandler class is responsible for managing the HTTP/2 streams. - """ - - __slots__ = ["_loop", "_protocol", "_streams", "_executor"] - - def __init__(self): - # Import the Http2Protocol class here to avoid circular imports. - from dubbo.remoting.aio.http2.protocol import AbstractHttp2Protocol - - self._loop: Optional[asyncio.AbstractEventLoop] = None - self._protocol: Optional[AbstractHttp2Protocol] = None - - # The map of stream_id to stream. - self._streams: Optional[dict[int, DefaultHttp2Stream]] = None - - # The executor for handling received frames. - self._executor = ThreadPoolExecutor(thread_name_prefix=f"dubbo_tri_stream_{str(uuid.uuid4())}") - - def do_init(self, loop: asyncio.AbstractEventLoop, protocol) -> None: - """ - Initialize the StreamMultiplexHandler.\ - :param loop: The event loop. - :type loop: asyncio.AbstractEventLoop - :param protocol: The HTTP/2 protocol. - :type protocol: Http2Protocol - """ - self._loop = loop - self._protocol = protocol - self._streams = {} - - def put_stream(self, stream_id: int, stream: DefaultHttp2Stream) -> None: - """ - Put the stream into the stream map. - :param stream_id: The stream identifier. - :type stream_id: int - :param stream: The stream. - :type stream: DefaultHttp2Stream - """ - self._streams[stream_id] = stream - - def get_stream(self, stream_id: int) -> Optional[DefaultHttp2Stream]: - """ - Get the stream by stream identifier. - :param stream_id: The stream identifier. - :type stream_id: int - :return: The stream. - """ - return self._streams.get(stream_id) - - def remove_stream(self, stream_id: int) -> None: - """ - Remove the stream by stream identifier. - :param stream_id: The stream identifier. - :type stream_id: int - """ - self._streams.pop(stream_id, None) - - def handle_frame(self, frame: UserActionFrames) -> None: - """ - Handle the HTTP/2 frame. - :param frame: The HTTP/2 frame. - :type frame: UserActionFrames - """ - stream = self._streams.get(frame.stream_id) - if stream: - # It must be ensured that the event loop is not blocked, - # and if there is a blocking operation, the executor must be used. - stream.receive_frame(frame) - - if frame.end_stream and stream.local_closed: - self.remove_stream(frame.stream_id) - else: - _LOGGER.warning("Stream %s not found. Ignoring frame %s", frame.stream_id, frame) - - def destroy(self) -> None: - """ - Destroy the StreamMultiplexHandler. - """ - self._streams = None - self._protocol = None - self._loop = None - - -class StreamClientMultiplexHandler(StreamMultiplexHandler): - """ - The StreamClientMultiplexHandler class is responsible for managing the HTTP/2 streams on the client side. - """ - - def create(self, listener: Http2Stream.Listener) -> DefaultHttp2Stream: - """ - Create a new stream. - :param listener: The stream listener. - :type listener: Http2Stream.Listener - :return: The stream. - :rtype: DefaultHttp2Stream - """ - return DefaultHttp2Stream(-1, listener, self._loop, self._protocol, self._executor) - - -class StreamServerMultiplexHandler(StreamMultiplexHandler): - """ - The StreamServerMultiplexHandler class is responsible for managing the HTTP/2 streams on the server side. - """ - - __slots__ = ["_listener_factory"] - - def __init__( - self, - listener_factory: Callable[[], Http2Stream.Listener], - ): - super().__init__() - self._listener_factory = listener_factory - - def register(self, stream_id: int) -> DefaultHttp2Stream: - """ - Register the stream. - :param stream_id: The stream identifier. - :type stream_id: int - :return: The stream. - :rtype: DefaultHttp2Stream - """ - stream_listener = self._listener_factory() - new_stream = DefaultHttp2Stream(stream_id, stream_listener, self._loop, self._protocol, self._executor) - self.put_stream(stream_id, new_stream) - return new_stream - - def handle_frame(self, frame: UserActionFrames) -> None: - """ - Handle the HTTP/2 frame. - :param frame: The HTTP/2 frame. - """ - # Register the stream if the frame is a HEADERS frame. - if frame.frame_type == Http2FrameType.HEADERS: - self.register(frame.stream_id) - - # Handle the frame. - super().handle_frame(frame) diff --git a/src/dubbo/remoting/aio/http2/utils.py b/src/dubbo/remoting/aio/http2/utils.py deleted file mode 100644 index 965a56a7..00000000 --- a/src/dubbo/remoting/aio/http2/utils.py +++ /dev/null @@ -1,82 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from typing import Union - -import h2.events as h2_event - -from dubbo.remoting.aio.http2.frames import ( - DataFrame, - HeadersFrame, - PingFrame, - RstStreamFrame, - WindowUpdateFrame, -) -from dubbo.remoting.aio.http2.headers import Http2Headers -from dubbo.remoting.aio.http2.registries import Http2ErrorCode - -__all__ = ["Http2EventUtils"] - - -class Http2EventUtils: - """ - A utility class for converting H2 events to HTTP/2 frames. - """ - - @staticmethod - def convert_to_frame( - event: h2_event.Event, - ) -> Union[HeadersFrame, DataFrame, RstStreamFrame, WindowUpdateFrame, PingFrame, None]: - """ - Convert a h2.events.Event to HTTP/2 Frame. - :param event: The H2 event. - :type event: h2.events.Event - :return: The HTTP/2 frame. - :rtype: Union[HeadersFrame, DataFrame, RstStreamFrame, WindowUpdateFrame, PingFrame, None] - """ - if isinstance( - event, - ( - h2_event.RequestReceived, - h2_event.ResponseReceived, - h2_event.TrailersReceived, - ), - ): - # HEADERS frame. - return HeadersFrame( - event.stream_id, - Http2Headers.from_list(event.headers), - end_stream=event.stream_ended is not None, - ) - elif isinstance(event, h2_event.DataReceived): - # DATA frame. - return DataFrame( - event.stream_id, - event.data, - event.flow_controlled_length, - end_stream=event.stream_ended is not None, - ) - elif isinstance(event, h2_event.StreamReset): - # RST_STREAM frame. - return RstStreamFrame(event.stream_id, Http2ErrorCode.get(event.error_code)) - elif isinstance(event, h2_event.WindowUpdated): - # WINDOW_UPDATE frame. - return WindowUpdateFrame(event.stream_id, event.delta) - elif isinstance(event, (h2_event.PingAckReceived, h2_event.PingReceived)): - # PING frame. - return PingFrame(event.ping_data, ack=isinstance(event, h2_event.PingAckReceived)) - - return None diff --git a/src/dubbo/rpc/__init__.py b/src/dubbo/rpc/__init__.py new file mode 100644 index 00000000..c15cba66 --- /dev/null +++ b/src/dubbo/rpc/__init__.py @@ -0,0 +1,57 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The call model: service contracts, invocations, streams and call context.""" + +from .client import GenericService +from .context import IncomingCall, OutgoingCall, incoming, outgoing +from .definition import ( + Method, + Parameter, + RpcType, + Service, + get_definition, + method, + service, +) +from .invocation import Invocation, Invoke, Invoker, Result +from .stream import BidiStream, ClientStream, ReceiveStream, SendStream, ServerStream, Stream + +__all__ = [ + "BidiStream", + "ClientStream", + "GenericService", + "IncomingCall", + "Invocation", + "Invoke", + "Invoker", + "Method", + "OutgoingCall", + "Parameter", + "ReceiveStream", + "Result", + "RpcType", + "SendStream", + "ServerStream", + "Service", + "Stream", + "get_definition", + "incoming", + "method", + "outgoing", + "service", +] diff --git a/src/dubbo/rpc/client.py b/src/dubbo/rpc/client.py new file mode 100644 index 00000000..f1b87c3f --- /dev/null +++ b/src/dubbo/rpc/client.py @@ -0,0 +1,220 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import functools +import inspect +from collections.abc import AsyncGenerator, Callable, Sequence +from contextlib import asynccontextmanager +from typing import Annotated, Any, TypeVar, cast + +from dubbo.constants import DEFAULT_GENERIC + +from .context import attachments_to_send, record_response +from .definition import JavaType, Method, Parameter, RpcType, get_contract_methods, get_definition +from .invocation import Invocation, Invoke, Result + +__all__ = ["GenericService", "proxy"] + +T = TypeVar("T") + +# The forms of generic calls a caller can make in Python. +_GENERIC_MODES = frozenset({DEFAULT_GENERIC, "raw.return", "protobuf-json", "gson"}) + + +def proxy(contract: type[T], invoke: Invoke) -> T: + """Return an object of type ``contract`` whose methods make their calls with ``invoke``. + + Each method has the name, signature, type annotations and docstring of + the method of ``contract`` it calls, as `inspect` and + `typing.get_type_hints` report them. + + Raises: + TypeError: ``contract`` is not a service contract, or declares how + its streaming methods are served. + """ + return cast(T, _Proxy(contract, invoke)) + + +class GenericService: + """Calls the unary methods of a service by name, without its contract. + + Arguments and results are plain data that the serialization describes + itself, in the form ``generic`` names, which the provider follows: + + - ``"true"``: objects as dicts naming their Java class under + ``"class"``, beside lists, strings and numbers; + - ``"raw.return"``: arguments as for ``"true"``, results as the provider + returns them; + - ``"protobuf-json"``: the one argument and the result as the JSON of a + protobuf message, its type the Java class of the message; + - ``"gson"``: each argument and the result as JSON. + + Each protocol decides how a generic call travels, such as ``$invoke`` + over Dubbo:: + + users = app.refer_generic("com.example.UserService") + user = await users.call("getUser", "id", 18) + + Raises: + ValueError: ``generic`` names none of these forms. + """ + + def __init__(self, interface: str, invoke: Invoke, *, generic: str = DEFAULT_GENERIC) -> None: + if generic not in _GENERIC_MODES: + raise ValueError(f"generic must be one of {', '.join(sorted(_GENERIC_MODES))}, not {generic!r}") + + self._interface = interface + self._invoke = invoke + self._generic = generic + + @property + def interface(self) -> str: + """Interface name of the service called, such as ``"com.example.UserService"``.""" + return self._interface + + async def call(self, method: str, /, *arguments: Any, types: Sequence[str] | None = None) -> Any: + """Call ``method`` with ``arguments`` in parameter order and return its result. + + ``types`` names the Java type of each parameter, as ``Class.getName`` + names it, such as ``["java.lang.String", "long"]``; a Java provider + needs them to tell apart the methods of one name. + + Raises: + TypeError: ``types`` does not name one type for each argument. + RpcError: The call failed; a ``RemoteError`` is the exception the + method raised. + """ + if types is None: + annotations: Sequence[Any] = (Any,) * len(arguments) + elif isinstance(types, str) or len(types) != len(arguments) or not all(types): + raise TypeError(f"{method}(): types must name one Java type for each of the {len(arguments)} arguments") + else: + annotations = [Annotated[Any, JavaType(name)] for name in types] + + definition = Method( + name=method, + request=tuple( + Parameter(name=f"arg{index}", type=annotation) for index, annotation in enumerate(annotations) + ), + response=Any, + ) + invocation = Invocation( + interface=self._interface, + method=method, + definition=definition, + arguments=arguments, + attachments=attachments_to_send(), + generic=self._generic, + ) + return _unary_value(await self._invoke(invocation)) + + def __repr__(self) -> str: + return f"" + + +class _Proxy: + """Turns method calls on a contract into invocations.""" + + def __init__(self, contract: type, invoke: Invoke) -> None: + methods = get_contract_methods(contract) + self._definition = get_definition(contract) + self._invoke = invoke + self._signatures = {method.name: _signature(method) for method in methods.values()} + self._attributes = {method.name: attribute for attribute, method in methods.items()} + # Each method is bound once, so calling it skips __getattr__. + for attribute, method in methods.items(): + setattr(self, attribute, self._bind(method, getattr(contract, attribute))) + + def __repr__(self) -> str: + return f"" + + def _bind(self, method: Method, declared: Callable[..., Any]) -> Callable[..., Any]: + """Return the function that calls ``method``, with the name, signature, annotations and docstring ``declared`` has.""" + if method.rpc_type is RpcType.UNARY: + + async def call(*args: Any, **kwargs: Any) -> Any: + return _unary_value(await self._invoke(self._invocation(method, self._arguments(method, args, kwargs)))) + + else: + + def call(*args: Any, **kwargs: Any) -> Any: + # Arguments are checked now; the call opens, with the + # attachments of that moment, when the block is entered. + return self._open(method, self._arguments(method, args, kwargs)) + + functools.update_wrapper(call, declared) + signature = inspect.signature(declared) + call.__signature__ = signature.replace(parameters=tuple(signature.parameters.values())[1:]) # ty: ignore[invalid-assignment] + return call + + @asynccontextmanager + async def _open(self, method: Method, arguments: tuple[Any, ...]) -> AsyncGenerator[Any]: + result = await self._invoke(self._invocation(method, arguments)) + if result.error is not None: + record_response(result.attachments) + raise result.error + + call = result.value + try: + async with call: + yield call + finally: + record_response(call.response_attachments) + + def _arguments(self, method: Method, args: tuple[Any, ...], kwargs: dict[str, Any]) -> tuple[Any, ...]: + signature = self._signatures[method.name] + # Every parameter given by position, in parameter order. + if not kwargs and len(args) == len(signature.parameters): + return args + + try: + bound = signature.bind(*args, **kwargs) + except TypeError as error: + raise TypeError(f"{self._attributes[method.name]}(): {error}") from None + + bound.apply_defaults() + return tuple(bound.arguments.values()) + + def _invocation(self, method: Method, arguments: tuple[Any, ...]) -> Invocation: + return Invocation( + interface=self._definition.interface, + method=method.name, + definition=method, + arguments=arguments, + attachments=attachments_to_send(), + ) + + +def _unary_value(result: Result) -> Any: + """Return the value of a unary call that ended with ``result``, or raise its error, recording its attachments.""" + record_response(result.attachments) + + if result.error is not None: + raise result.error + + return result.value + + +def _signature(method: Method) -> inspect.Signature: + # Client and bidirectional streams send their requests on the stream, so + # opening them takes no arguments. + if method.rpc_type in (RpcType.CLIENT_STREAM, RpcType.BIDI_STREAM): + return inspect.Signature() + + return inspect.Signature( + [inspect.Parameter(p.name, inspect.Parameter.POSITIONAL_OR_KEYWORD, default=p.default) for p in method.request] + ) diff --git a/src/dubbo/rpc/context.py b/src/dubbo/rpc/context.py new file mode 100644 index 00000000..777b5185 --- /dev/null +++ b/src/dubbo/rpc/context.py @@ -0,0 +1,180 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Generator, Mapping +from contextlib import contextmanager +from contextvars import ContextVar +from types import TracebackType + +import attrs +from multidict import MultiDict, MultiDictProxy + +from dubbo.constants import ( + DUBBO_VERSION_KEY, + FORCE_TAG_KEY, + GROUP_KEY, + INTERFACE_KEY, + PATH_KEY, + TAG_KEY, + TIMEOUT_KEY, + TOKEN_KEY, + VERSION_KEY, +) + +__all__ = ["IncomingCall", "OutgoingCall", "attachments_to_send", "incoming", "outgoing", "record_response", "serving"] + + +@attrs.define(frozen=True, kw_only=True) +class IncomingCall: + """The call a service handler is serving. + + Attributes: + attachments: Attachments the caller sent, with every value of a + repeated key. + response_attachments: Attachments to send back to the caller; `add` + gives a key another value. + peer: ``host:port`` of the caller, an IPv6 host in brackets; ``None`` for an in-process call. + """ + + attachments: MultiDictProxy[str | bytes] + response_attachments: MultiDict[str | bytes] = attrs.field(factory=MultiDict) + peer: str | None = None + + +@attrs.define(kw_only=True) +class OutgoingCall: + """Calls made inside an `outgoing` block. + + Attributes: + attachments: Attachments each call in the block sends. + response_attachments: Attachments the last call to finish in the block + received; empty until one finishes. + """ + + attachments: MultiDictProxy[str | bytes] + response_attachments: MultiDictProxy[str | bytes] = attrs.field(factory=lambda: MultiDictProxy(MultiDict())) + + +# Attachments of one call only, which the calls its handler makes do not inherit: those of Dubbo for one provider, +# HTTP fields of one connection or request, and credentials. +_NOT_INHERITED = frozenset({ + PATH_KEY, INTERFACE_KEY, GROUP_KEY, VERSION_KEY, DUBBO_VERSION_KEY, TOKEN_KEY, TIMEOUT_KEY, "_to", "async", + TAG_KEY, FORCE_TAG_KEY, + "accept", "accept-charset", "accept-datetime", "accept-encoding", "accept-language", + "access-control-request-headers", "access-control-request-method", "authorization", "cache-control", + "connection", "content-length", "content-md5", "content-type", "cookie", "date", "dnt", "expect", "forwarded", + "from", "host", "http2-settings", "if-match", "if-modified-since", "if-none-match", "if-range", + "if-unmodified-since", "keep-alive", "max-forwards", "origin", "pragma", "proxy-authorization", + "proxy-connection", "range", "referer", "sec-fetch-dest", "sec-fetch-mode", "sec-fetch-site", "sec-fetch-user", + "te", "trailer", "transfer-encoding", "upgrade", "upgrade-insecure-requests", "user-agent", +}) # fmt: skip + +_incoming: ContextVar[IncomingCall] = ContextVar("dubbo.incoming") +_outgoing: ContextVar[OutgoingCall | None] = ContextVar("dubbo.outgoing", default=None) + + +def incoming() -> IncomingCall: + """Return the call the running service handler is serving. + + Raises: + LookupError: No service handler is running. + """ + try: + return _incoming.get() + except LookupError: + raise LookupError("dubbo.incoming() is available only while a service handler runs") from None + + +@contextmanager +def outgoing(attachments: Mapping[str, str | bytes] | None = None, *, inherit: bool = True) -> Generator[OutgoingCall]: + """Add attachments to the calls made inside the block. + + A call sends the attachments it inherits, then ``attachments``; the inner + value wins on equal keys. Keys ending in ``-bin`` carry bytes, other keys + printable ASCII text. A block inherits from the enclosing block or, at + the top, from the call the running handler serves, so attachments pass + along a chain of services. Attachments of one call only are never + inherited: ``token``, ``timeout``, ``dubbo.tag``, the identity of the + service called, and HTTP fields such as ``authorization``. + ``inherit=False`` starts from nothing. + + The last call to finish in the block, innermost block only, leaves its + response attachments on the yielded `OutgoingCall`:: + + with dubbo.outgoing({"operator": "alice"}) as call: + await users.rename(1, "b") + call.response_attachments + """ + merged = attachments_to_send() if inherit else MultiDict() + merged.update(attachments or {}) + call = OutgoingCall(attachments=MultiDictProxy(merged)) + + token = _outgoing.set(call) + try: + yield call + finally: + _outgoing.reset(token) + + +def attachments_to_send() -> MultiDict[str | bytes]: + """Return the attachments a call made now sends.""" + call = _outgoing.get() + if call is not None: + return MultiDict(call.attachments) + + try: + received = _incoming.get().attachments + except LookupError: + return MultiDict() + + return MultiDict((key, value) for key, value in received.items() if key.lower() not in _NOT_INHERITED) + + +def record_response(attachments: Mapping[str, str | bytes]) -> None: + """Leave the response attachments of a finished call on the innermost `outgoing` block.""" + call = _outgoing.get() + if call is not None: + call.response_attachments = MultiDictProxy(MultiDict(attachments)) + + +class _Serving: + __slots__ = ("_call", "_tokens") + + def __init__(self, call: IncomingCall) -> None: + self._call = call + + def __enter__(self) -> IncomingCall: + self._tokens = (_incoming.set(self._call), _outgoing.set(None)) + return self._call + + def __exit__( + self, exc_type: type[BaseException] | None, exc: BaseException | None, traceback: TracebackType | None + ) -> None: + incoming_token, outgoing_token = self._tokens + _outgoing.reset(outgoing_token) + _incoming.reset(incoming_token) + + +def serving(attachments: Mapping[str, str | bytes], *, peer: str | None) -> _Serving: + """Return a context manager that runs its block as serving a call that sent ``attachments``. + + A server runs each handler inside it, so that `incoming` returns the + call. Calls the block makes inherit from this call alone, never from the + `outgoing` blocks of whoever started the block, such as the caller of an + in-process call. + """ + return _Serving(IncomingCall(attachments=MultiDictProxy(MultiDict(attachments)), peer=peer)) diff --git a/src/dubbo/rpc/definition.py b/src/dubbo/rpc/definition.py new file mode 100644 index 00000000..72cd7768 --- /dev/null +++ b/src/dubbo/rpc/definition.py @@ -0,0 +1,595 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import enum +import functools +import inspect +import typing +from collections.abc import Awaitable, Callable, Iterator, Mapping +from types import MappingProxyType, NoneType +from typing import Any, Self, TypeVar, cast, get_args, get_origin + +import attrs + +from .stream import BidiStream, ClientStream, ReceiveStream, SendStream, ServerStream, Stream + +__all__ = [ + "Handler", + "JavaType", + "Method", + "Parameter", + "RpcType", + "Service", + "arity", + "check_handler", + "get_contract_methods", + "get_definition", + "method", + "service", +] + +C = TypeVar("C", bound=type) +F = TypeVar("F", bound=Callable[..., Any]) + +# Serves one method: the arguments in parameter order, a streaming method's stream last. +Handler = Callable[..., Awaitable[Any]] + +# The class attribute that carries what `service` declares about a contract. +_SERVICE_ATTRIBUTE = "__dubbo_service__" +# The class attribute that keeps the definition built from that declaration, and its methods by attribute. +_DEFINITION_ATTRIBUTE = "__dubbo_definition__" +# The function attribute that carries what `method` declares about a contract method. +_METHOD_ATTRIBUTE = "__dubbo_method__" + + +class RpcType(enum.Enum): + """How the requests and responses of a method flow.""" + + UNARY = "unary" + SERVER_STREAM = "server_stream" + CLIENT_STREAM = "client_stream" + BIDI_STREAM = "bidi_stream" + + +# The type a caller's method returns for each kind of streaming call. +_CALL_TYPES: dict[type, RpcType] = { + ServerStream: RpcType.SERVER_STREAM, + ClientStream: RpcType.CLIENT_STREAM, + BidiStream: RpcType.BIDI_STREAM, +} +# The type of the stream an implementation's method takes for each kind of streaming call. +_HANDLER_STREAM_TYPES: dict[type, RpcType] = { + SendStream: RpcType.SERVER_STREAM, + ReceiveStream: RpcType.CLIENT_STREAM, + Stream: RpcType.BIDI_STREAM, +} + + +class _View(enum.Enum): + """Which side a contract declares its streaming methods for.""" + + CALLER = "caller" + IMPLEMENTATION = "implementation" + + +@attrs.define(frozen=True) +class JavaType: + """Names the Java type a value travels as, in the metadata of an annotation. + + A generic call that names the Java types of its arguments types each as + ``Annotated[Any, JavaType("long")]``; the protocols that call Java + methods, such as Dubbo, take the name over what the annotation stands for. + + Attributes: + name: The Java type, named as ``Class.getName`` names it, such as + ``long``, ``java.lang.String`` or ``[Ljava.lang.String;``. + """ + + name: str + + +@attrs.define(frozen=True, kw_only=True) +class Parameter: + """A parameter of a method. + + Arguments travel in parameter order; formats that name them, such as a + JSON object, use the parameter names. + + Attributes: + name: Parameter name. + type: Type annotation, used to serialize the argument. + default: Value used when a caller leaves the argument out; + ``inspect.Parameter.empty`` when the parameter is required. + """ + + name: str + type: Any + default: Any = inspect.Parameter.empty + + +def _request(value: Any) -> tuple[Parameter, ...]: + return value if isinstance(value, tuple) else (Parameter(name="request", type=value),) + + +@attrs.define(frozen=True, kw_only=True) +class Method: + """A method of a service, and on the serving side, its handler. + + Written by hand, as in ``Method(name="SayHello", request=HelloRequest, + response=HelloReply, handler=say_hello)``, it describes a method without + a contract class. + + Attributes: + name: Method name shared with other languages, such as ``"getUser"``. + request: Parameters of each request; one type stands for one + parameter. A unary method may have any number; a streaming method + has exactly one: the request of a server stream, or each message + of a client or bidirectional stream. + response: Type annotation of each response; ``None`` when a unary + method returns nothing. + rpc_type: Whether the requests and the responses are one message or + a stream. + handler: What serves the method: an ``async def`` taking the + arguments of a unary method; the request, then the stream to + send the responses on, for a server stream; or the stream for a + client or bidirectional stream. ``None`` where the method is only + called. + """ + + name: str + request: tuple[Parameter, ...] = attrs.field(converter=_request) + response: Any + rpc_type: RpcType = RpcType.UNARY + handler: Handler | None = attrs.field(default=None, eq=False, repr=False) + + def __attrs_post_init__(self) -> None: + if self.rpc_type is not RpcType.UNARY and len(self.request) != 1: + raise ValueError( + f"{self.rpc_type.value} method {self.name!r} must have exactly one request parameter, " + f"not {len(self.request)}" + ) + + +@attrs.define(frozen=True, kw_only=True) +class Service: + """A service: what it looks like on the wire, and on the serving side, the handlers of its methods. + + A contract class declares one, which `get_definition` returns; an + implementation of it gives one with handlers through `from_implementation`. + It can also be written by hand and exported as it is. + + Attributes: + interface: Service name shared with other languages, such as + ``"com.example.UserService"``. + methods: Methods of the service, with distinct names. + """ + + interface: str + methods: tuple[Method, ...] = attrs.field(converter=tuple) + _by_name: dict[str, Method] = attrs.field( + init=False, + eq=False, + repr=False, + default=attrs.Factory(lambda self: {method.name: method for method in self.methods}, takes_self=True), + ) + + def __attrs_post_init__(self) -> None: + if len(self._by_name) == len(self.methods): + return + + names = [method.name for method in self.methods] + duplicates = sorted({name for name in names if names.count(name) > 1}) + raise ValueError(f"{self.interface} defines methods more than once: {', '.join(duplicates)}") + + @classmethod + def from_implementation(cls, implementation: object) -> Self: + """Return the service ``implementation`` implements, with its handlers. + + Raises: + TypeError: ``implementation`` does not implement a service + contract, leaves a method unimplemented, or implements one + with the wrong kind of handler. + """ + if get_contract(type(implementation)) is None: + raise TypeError(f"{type(implementation).__qualname__} does not implement a service contract") + + built = _built(implementation) + if built.view is _View.CALLER: + raise TypeError( + f"{type(implementation).__qualname__} implements {built.contract.__qualname__}, which declares " + "how callers hold its streaming methods; implement the class that declares how they are " + "served, such as the generated servicer" + ) + + methods = [ + _implemented(implementation, built.contract, attribute, method) + for attribute, method in built.methods.items() + ] + + return cls(interface=built.service.interface, methods=methods) + + def method(self, name: str) -> Method: + """Return the method called ``name``. + + Raises: + KeyError: The service has no such method. + """ + try: + return self._by_name[name] + except KeyError: + raise KeyError(f"{self.interface} has no method {name!r}") from None + + +# Declarations hold what the decorators are given. Definitions are built from +# them on first use, when the module has finished defining the names that +# annotations refer to, including the contract itself. + + +@attrs.define(frozen=True, kw_only=True) +class _ServiceDeclaration: + interface: str + + +@attrs.define(frozen=True, kw_only=True) +class _MethodDeclaration: + name: str + + +@attrs.define(frozen=True, kw_only=True) +class _Built: + """The definition built from a contract, by the attributes that declare its methods.""" + + contract: type + service: Service + methods: Mapping[str, Method] + # The side the streaming methods are declared for; None when every method is unary, so it serves both sides. + view: _View | None + + +def service(interface: str) -> Callable[[C], C]: + """Declare a class as the contract of a service called ``interface``. + + Each public method is a method of the service. A unary method is an + ``async def``, the same for callers and implementations. A streaming + method is declared for one side, so a service with streaming methods + has a contract for each. Callers hold a ``def`` returning the call: + `ServerStream`, `ClientStream` or `BidiStream`:: + + @dubbo.service("com.example.UserService") + class UserService(typing.Protocol): + async def rename(self, id: int, name: str) -> None: ... + def watch(self, query: Query) -> dubbo.ServerStream[Event]: ... + def upload(self) -> dubbo.ClientStream[Chunk, int]: ... + def chat(self) -> dubbo.BidiStream[Question, Answer]: ... + + Implementations serve an ``async def`` taking the stream last: + `SendStream` for the responses of a server stream, `ReceiveStream` for + the requests of a client stream, or `Stream` for both:: + + @dubbo.service("com.example.UserService") + class UserServiceImpl: + async def rename(self, id: int, name: str) -> None: ... + async def watch(self, query: Query, events: dubbo.SendStream[Event]) -> None: ... + async def upload(self, chunks: dubbo.ReceiveStream[Chunk]) -> int: ... + async def chat(self, stream: dubbo.Stream[Answer, Question]) -> None: ... + + Subclasses implement the contract of their class: an implementation of + a ``typing.Protocol`` or of an abstract class implements every method + the contract declares. Parameters must be passable both by position + and by name, since arguments travel in order and some formats name + them. Methods keep their Python names on the wire unless `method` gives + them another. Classes generated from IDL by `dubbo.protoc` are contracts + too: ``Greeter`` for callers and ``GreeterServicer`` for implementations. + + What types travel depends on the serialization of the service: with the + default ``protobuf``, each method takes one protobuf message and returns + one, as generated contracts do; with ``hessian2``, values of annotated + Python types travel as Java objects. + + The methods are read on first use, by `get_definition`, so annotations may + refer to the contract and to names defined after it. + """ + + def decorate(cls: C) -> C: + setattr(cls, _SERVICE_ATTRIBUTE, _ServiceDeclaration(interface=interface)) + return cls + + return decorate + + +def method(name: str) -> Callable[[F], F]: + """Give a contract method the name it has in other languages. + + Without it, a method keeps its Python name:: + + @dubbo.method("getUser") + async def get_user(self, id: int) -> User: ... + + Raises: + ValueError: ``name`` is empty. + """ + if not name: + raise ValueError("method name must not be empty") + + def decorate(function: F) -> F: + setattr(function, _METHOD_ATTRIBUTE, _MethodDeclaration(name=name)) + return function + + return decorate + + +def get_definition(contract: object) -> Service: + """Return the definition of a service contract, or of the contract an object implements. + + The definition is built on first use and kept. + + Raises: + TypeError: ``contract`` is not and does not implement a service + contract, or the contract declares a member that cannot be a + method, or leaves a type unannotated or unresolvable. + ValueError: The contract gives two methods the same name. + """ + return _built(contract).service + + +def get_contract_methods(contract: object) -> Mapping[str, Method]: + """Return the methods callers call through a service contract, by the attributes that declare them. + + The keys are the Python names, such as ``get_user``, in the order of + the methods of `get_definition`. + + Raises: + TypeError: As `get_definition` raises, or the contract declares how + its streaming methods are served rather than called. + ValueError: As `get_definition` raises. + """ + built = _built(contract) + if built.view is _View.IMPLEMENTATION: + raise TypeError( + f"{built.contract.__qualname__} declares how its streaming methods are served; " + "call the service through the contract that declares how they are called" + ) + + return built.methods + + +def get_contract(cls: type) -> type | None: + """Return the service contract ``cls`` is or implements, if any.""" + return next((k for k in cls.__mro__ if _SERVICE_ATTRIBUTE in vars(k)), None) + + +def check_handler(method: Method, handler: object, where: str) -> None: + """Check that ``handler`` can serve ``method``. + + Raises: + TypeError: It is not an ``async def`` taking the arguments of the method. + """ + function = handler.func if isinstance(handler, functools.partial) else handler + if not inspect.iscoroutinefunction(function): + raise TypeError(f"{where} must be an async def") + + try: + inspect.signature(cast(Callable[..., Any], handler)).bind(*[None] * arity(method)) + except TypeError as error: + raise TypeError(f"{where} does not take the arguments of a {method.rpc_type.value} method: {error}") from None + + +def arity(method: Method) -> int: + """Return how many arguments the handler of ``method`` takes.""" + match method.rpc_type: + case RpcType.UNARY: + return len(method.request) + case RpcType.SERVER_STREAM: + # The request, then the response stream. + return 2 + case _: + return 1 + + +def _built(contract: object) -> _Built: + cls = contract if isinstance(contract, type) else type(contract) + found = get_contract(cls) + if found is None: + raise TypeError(f"{cls.__qualname__} is not a service contract; declare it with @dubbo.service") + + built = vars(found).get(_DEFINITION_ATTRIBUTE) + if built is None: + built = _build(found) + setattr(found, _DEFINITION_ATTRIBUTE, built) + + return built + + +def _build(contract: type) -> _Built: + declaration: _ServiceDeclaration = vars(contract)[_SERVICE_ATTRIBUTE] + methods: dict[str, Method] = {} + views: set[_View] = set() + for name, (method, view) in _methods(contract): + methods[name] = method + if view is not None: + views.add(view) + + if len(views) > 1: + raise TypeError( + f"{contract.__qualname__} declares some streaming methods as called and others as served; " + "declare each side in its own class" + ) + + return _Built( + contract=contract, + service=Service(interface=declaration.interface, methods=tuple(methods.values())), + methods=MappingProxyType(methods), + view=next(iter(views), None), + ) + + +def _implemented(implementation: object, contract: type, attribute_name: str, method: Method) -> Method: + where = f"{type(implementation).__qualname__}.{attribute_name}" + + # A method of a protocol, or an abstract method, only declares the method. + attribute = inspect.getattr_static(implementation, attribute_name, None) + owner = next(base for base in contract.__mro__ if attribute_name in vars(base)) + declared = attribute is vars(owner)[attribute_name] and ( + typing.Protocol in owner.__bases__ or getattr(attribute, "__isabstractmethod__", False) + ) + if attribute is None or declared: + raise TypeError(f"{where} is not implemented") + + handler = getattr(implementation, attribute_name) + check_handler(method, handler, where) + return attrs.evolve(method, handler=handler) + + +def _methods(cls: type) -> Iterator[tuple[str, tuple[Method, _View | None]]]: + # The members of the bases first, each in the place it is first declared, a subclass's member replacing one. + members: dict[str, object] = {} + for base in reversed(cls.__mro__): + for name in inspect.get_annotations(base): + if not name.startswith("_"): + raise TypeError(f"{cls.__qualname__}.{name} must be a method") + members.update(vars(base)) + + for name, member in members.items(): + if not name.startswith("_"): + yield name, _method(cls, name, member) + + +def _method(cls: type, name: str, member: object) -> tuple[Method, _View | None]: + """Return the method ``member`` declares, and the side it declares its streams for, if any.""" + where = f"{cls.__qualname__}.{name}" + if not inspect.isfunction(member): + raise TypeError(f"{where} must be a method") + + declaration = getattr(member, _METHOD_ATTRIBUTE, None) or _MethodDeclaration(name=name) + + try: + # Resolves the names inside annotations too, as in ServerStream["Event"]. + hints = typing.get_type_hints(member, include_extras=True) + except NameError as error: + raise TypeError(f"{where} has an annotation that cannot be resolved: {error}") from None + signature = inspect.signature(member) + if not signature.parameters: + raise TypeError(f"{where} must take self") + + parameters = [ + parameter.replace(annotation=hints.get(parameter.name, parameter.empty)) + for parameter in list(signature.parameters.values())[1:] + ] + for parameter in parameters: + if parameter.kind is not parameter.POSITIONAL_OR_KEYWORD: + raise TypeError( + f"{where} cannot take {parameter.kind.description} parameter {parameter.name!r}; " + "parameters must be passable by position and by name" + ) + if parameter.annotation is parameter.empty: + raise TypeError(f"{where} must annotate the type of parameter {parameter.name!r}") + + response = hints.get("return", signature.empty) + if response is signature.empty: + raise TypeError(f"{where} must annotate its return type") + if response is NoneType: + response = None + + call_type = _stream_type(response, _CALL_TYPES) + if not inspect.iscoroutinefunction(member): + if call_type is None: + raise TypeError( + f"{where} must be an async def, or a def returning dubbo.ServerStream, dubbo.ClientStream " + "or dubbo.BidiStream" + ) + return _called(where, declaration.name, call_type, parameters, get_args(response)), _View.CALLER + + if call_type is not None: + raise TypeError(f"{where} returns a stream, so it must be a def, not an async def") + + if any(_stream_type(parameter.annotation, _HANDLER_STREAM_TYPES) for parameter in parameters): + return _served(where, declaration.name, parameters, response), _View.IMPLEMENTATION + + method = Method( + name=declaration.name, + rpc_type=RpcType.UNARY, + request=tuple(Parameter(name=p.name, type=p.annotation, default=p.default) for p in parameters), + response=response, + ) + return method, None + + +def _stream_type(annotation: Any, types: Mapping[type, RpcType]) -> RpcType | None: + return types.get(get_origin(annotation) or annotation) + + +def _called( + where: str, + name: str, + rpc_type: RpcType, + parameters: list[inspect.Parameter], + types: tuple[Any, ...], +) -> Method: + """Return the method a contract for callers declares.""" + if not types: + raise TypeError(f"{where} must give the message types of the stream it returns") + + # A server stream takes its request as a parameter; the other streams + # send their requests on the stream. + if rpc_type is RpcType.SERVER_STREAM: + if len(parameters) != 1: + raise TypeError(f"{where} must take exactly one request parameter") + + (response,) = types + request = Parameter(name=parameters[0].name, type=parameters[0].annotation, default=parameters[0].default) + else: + if parameters: + raise TypeError(f"{where} must take no parameters; its requests are sent on the stream") + + request_type, response = types + request = Parameter(name="message", type=request_type) + + return Method(name=name, rpc_type=rpc_type, request=(request,), response=response) + + +def _served(where: str, name: str, parameters: list[inspect.Parameter], returns: Any) -> Method: + """Return the method a contract for implementations declares.""" + *requests, stream = parameters + rpc_type = _stream_type(stream.annotation, _HANDLER_STREAM_TYPES) + if rpc_type is None or any(_stream_type(p.annotation, _HANDLER_STREAM_TYPES) for p in requests): + raise TypeError(f"{where} must take one stream, as its last parameter") + + types = get_args(stream.annotation) + if not types: + raise TypeError(f"{where} must give the message types of its stream {stream.name!r}") + + # A server stream takes its request, then the stream; the other streams + # receive their requests on the stream. + match rpc_type: + case RpcType.SERVER_STREAM: + if len(requests) != 1: + raise TypeError(f"{where} must take exactly one request parameter before its stream") + request = Parameter(name=requests[0].name, type=requests[0].annotation, default=requests[0].default) + (response,) = types + case RpcType.CLIENT_STREAM: + (request_type,) = types + request, response = Parameter(name="message", type=request_type), returns + case _: + response, request_type = types + request = Parameter(name="message", type=request_type) + + if rpc_type is not RpcType.SERVER_STREAM and requests: + raise TypeError(f"{where} must take only its stream; its requests are received on it") + if rpc_type is not RpcType.CLIENT_STREAM and returns is not None: + raise TypeError(f"{where} sends its responses on the stream, so it must return None") + + return Method(name=name, rpc_type=rpc_type, request=(request,), response=response) diff --git a/src/dubbo/rpc/invocation.py b/src/dubbo/rpc/invocation.py new file mode 100644 index 00000000..3689cd3b --- /dev/null +++ b/src/dubbo/rpc/invocation.py @@ -0,0 +1,128 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from collections.abc import Awaitable, Callable, MutableMapping +from typing import Any + +import attrs +from multidict import MultiDict + +from dubbo.extension import Resource +from dubbo.url import URL + +from .definition import Method + +__all__ = ["Invocation", "Invoke", "Invoker", "Result"] + + +@attrs.define(kw_only=True) +class Invocation: + """One call, as it passes from a caller through filters and clusters to a protocol, or from a server through filters to a handler. + + The same invocation goes to every attempt of a call, so what changes it + for one attempt changes a copy made by ``attrs.evolve``, with a copy of + ``attachments`` when it changes them. + + Attributes: + interface: Interface name, such as ``"com.example.UserService"``. + method: Name of the method on the wire, such as ``"getUser"``. + arguments: Arguments in parameter order. On the serving side a + streaming call carries its stream last: ``(request, stream)`` for + a server stream, ``(stream,)`` for the others. + attachments: Attachments to send, or on the serving side those + received; a key may repeat. Keys ending in ``-bin`` carry bytes. + definition: The method called. A generic call defines it from the + call: unary, with an argument of any type for each argument given, + returning any value. + generic: The mode of a generic call, such as ``"true"``: one made + without the contract of the service, its arguments and result + plain data, such as dicts and lists, as `dubbo.GenericService` + makes it. ``None`` for a call of the contract. + """ + + interface: str + method: str + definition: Method + arguments: tuple[Any, ...] = () + attachments: MutableMapping[str, str | bytes] = attrs.field(factory=MultiDict) + generic: str | None = None + + +@attrs.define(kw_only=True) +class Result: + """How a call ended. + + Attributes: + value: What the handler returned. On the calling side of a streaming + call, the call itself instead: a `ServerStream`, `ClientStream` + or `BidiStream`. + error: Why the call failed, ``None`` when it succeeded: what the + handler raised, or on the calling side what the caller will see + raised, such as an `RpcError` of ``UNAVAILABLE``. + attachments: Response attachments of a unary call, or of a streaming + call that failed to start. A started streaming call carries them + as its `response_attachments` instead. + """ + + value: Any = None + error: Exception | None = None + attachments: MutableMapping[str, str | bytes] = attrs.field(factory=MultiDict) + + +# Makes a call and returns how it ended, as `Invoker.invoke` does. +Invoke = Callable[[Invocation], Awaitable[Result]] + + +class Invoker(Resource, typing.Protocol): + """Makes the calls of one service: a handler, one provider, a cluster of providers, or filters around one of these. + + `Protocol.refer` and `create_cluster` create the invokers of callers, + `ServiceInvoker` that of a handler, and `chain_filters` wraps them; + whoever creates one closes it, and closing it closes those it wraps. + ``invoke`` runs concurrently for many calls in the event loop. + """ + + @property + def url(self) -> URL: + """The URL it calls or serves with, whose parameters configure it.""" + ... + + @property + def available(self) -> bool: + """Whether it takes calls now; an invoker that does not say otherwise always does. + + Clusters prefer the available ones but call one that is not when none is. + """ + return True + + async def invoke(self, invocation: Invocation) -> Result: + """Make the call and return how it ended. + + Every failure of the call comes back in `Result.error`: what the + handler raised, a timeout, no provider, a lost connection. ``invoke`` + raises only for a bug, or for the cancellation of the calling task, + which it lets through. + """ + ... + + async def aclose(self) -> None: + """Release what the invoker holds, including what the invokers it wraps hold. + + An invoker that holds nothing returns at once. + """ + ... diff --git a/src/dubbo/rpc/server.py b/src/dubbo/rpc/server.py new file mode 100644 index 00000000..ceca5981 --- /dev/null +++ b/src/dubbo/rpc/server.py @@ -0,0 +1,103 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +from typing import Any, Self + +import attrs + +from dubbo.exceptions import RpcError, Status +from dubbo.url import URL + +from .context import incoming +from .definition import Handler, Service, arity, check_handler +from .invocation import Invocation, Invoker, Result + +__all__ = ["ServiceInvoker"] + +_logger = logging.getLogger(__name__) + + +@attrs.define(frozen=True, kw_only=True) +class ServiceInvoker(Invoker): + """Calls the handlers of ``service``, served with ``url``. + + It runs inside the call it serves, so `incoming` is set. + + Raises: + TypeError: A method of ``service`` has no handler, or one that cannot + serve it. + """ + + url: URL + service: Service + # The handler of each method and how many arguments it takes, by method name. + _calls: dict[str, tuple[Handler, int]] = attrs.field(init=False, eq=False, repr=False) + + def __attrs_post_init__(self) -> None: + calls = {} + for method in self.service.methods: + where = f"the handler of {self.service.interface}.{method.name}" + if method.handler is None: + raise TypeError(f"{where} is missing") + check_handler(method, method.handler, where) + calls[method.name] = (method.handler, arity(method)) + + object.__setattr__(self, "_calls", calls) + + @classmethod + def from_implementation(cls, implementation: object, url: URL) -> Self: + """Return the invoker of ``implementation``, served with ``url``. + + Raises: + TypeError: As `Service.from_implementation` raises. + """ + return cls(url=url, service=Service.from_implementation(implementation)) + + async def invoke(self, invocation: Invocation) -> Result: + try: + handler, count = self._calls[invocation.method] + except KeyError: + error = RpcError(Status.UNIMPLEMENTED, f"{self.service.interface} has no method {invocation.method!r}") + return Result(error=error) + + # Arguments come from the other side, which may not share the contract. + if len(invocation.arguments) != count: + error = RpcError( + Status.INVALID_ARGUMENT, + f"{invocation.method}() takes {count} arguments, not {len(invocation.arguments)}", + ) + return Result(error=error) + + response_attachments = incoming().response_attachments + + try: + value: Any = await handler(*invocation.arguments) + except Exception as error: + # An RpcError is a status the handler chose; anything else is a failure its caller cannot locate. + if not isinstance(error, RpcError): + _logger.exception( + "The method %s of %s raised; its caller receives the error", + invocation.method, + self.service.interface, + ) + return Result(error=error, attachments=response_attachments) + + return Result(value=value, attachments=response_attachments) + + async def aclose(self) -> None: + pass diff --git a/src/dubbo/rpc/stream.py b/src/dubbo/rpc/stream.py new file mode 100644 index 00000000..af7d5fa8 --- /dev/null +++ b/src/dubbo/rpc/stream.py @@ -0,0 +1,136 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from abc import ABC, abstractmethod +from collections.abc import Mapping +from types import TracebackType +from typing import Generic, Self, TypeVar + +from dubbo.exceptions import EndOfStream + +__all__ = ["BidiStream", "ClientStream", "ReceiveStream", "SendStream", "ServerStream", "Stream"] + +T_contra = TypeVar("T_contra", contravariant=True) +T_co = TypeVar("T_co", covariant=True) + + +class SendStream(ABC, Generic[T_contra]): + """Messages one side of a call sends.""" + + @abstractmethod + async def send(self, message: T_contra) -> None: + """Send ``message``, waiting while the other side cannot take more. + + Raises: + RpcError: The call failed. + """ + + +class ReceiveStream(ABC, Generic[T_co]): + """Messages one side of a call receives; ``async for`` reads them all.""" + + @abstractmethod + async def receive(self) -> T_co: + """Return the next message. + + Raises: + EndOfStream: The other side has ended its messages. + RpcError: The call failed. + """ + + def __aiter__(self) -> Self: + return self + + async def __anext__(self) -> T_co: + try: + return await self.receive() + except EndOfStream: + raise StopAsyncIteration from None + + +class Stream(SendStream[T_contra], ReceiveStream[T_co]): + """Messages in both directions: sends ``T_contra`` and receives ``T_co``.""" + + @abstractmethod + async def end(self) -> None: + """End the messages this side sends; receiving continues.""" + + +class _Call(ABC): + """A streaming call as its caller holds it; leaving the ``async with`` block ends it. + + A streaming call has no timeout; bound it with ``anyio.fail_after``, + whose deadline travels to a ``tri`` provider as ``grpc-timeout``. + Cancelling the task that awaits a call cancels the call. + """ + + @property + @abstractmethod + def response_attachments(self) -> Mapping[str, str | bytes]: + """Attachments the server sent back, complete once the call has ended. + + Callers read them from `dubbo.outgoing`, where the call leaves them + when its block exits. + """ + + async def __aenter__(self) -> Self: + return self + + @abstractmethod + async def __aexit__( + self, + exc_type: type[BaseException] | None, + exc: BaseException | None, + traceback: TracebackType | None, + ) -> None: + """End the call, cancelling it if it still runs.""" + + +class ServerStream(ReceiveStream[T_co], _Call, ABC): + """A server-streaming call as its caller holds it. + + The caller receives the responses:: + + async with users.watch(query) as events: + async for event in events: ... + """ + + +class ClientStream(Stream[T_contra, T_co], _Call, ABC): + """A client-streaming call as its caller holds it. + + The caller sends the requests, ends them, then receives the one response:: + + async with users.upload() as stream: + await stream.send(chunk) + await stream.end() + total = await stream.receive() + + A handler normally answers after the requests end, but may answer + earlier. + """ + + +class BidiStream(Stream[T_contra, T_co], _Call, ABC): + """A bidirectional streaming call as its caller holds it. + + The caller sends requests and receives responses in any order:: + + async with users.chat() as stream: + await stream.send(question) + answer = await stream.receive() + """ diff --git a/src/dubbo/serialization/__init__.py b/src/dubbo/serialization/__init__.py index ee2ef619..eb94096a 100644 --- a/src/dubbo/serialization/__init__.py +++ b/src/dubbo/serialization/__init__.py @@ -1,30 +1,20 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. -from ._interfaces import Deserializer, SerializationError, Serializer, ensure_bytes -from .custom_serializers import CustomDeserializer, CustomSerializer -from .direct_serializers import DirectDeserializer, DirectSerializer +from .base import Codec, JavaSerialization, Reader, Serialization, get_java_serialization, get_serialization -__all__ = [ - "Serializer", - "Deserializer", - "SerializationError", - "ensure_bytes", - "DirectSerializer", - "DirectDeserializer", - "CustomSerializer", - "CustomDeserializer", -] +__all__ = ["Codec", "JavaSerialization", "Reader", "Serialization", "get_java_serialization", "get_serialization"] diff --git a/src/dubbo/serialization/_interfaces.py b/src/dubbo/serialization/_interfaces.py deleted file mode 100644 index 5793dc1a..00000000 --- a/src/dubbo/serialization/_interfaces.py +++ /dev/null @@ -1,91 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import abc -from typing import Any, Union - -__all__ = ["Serializer", "Deserializer", "SerializationError", "ensure_bytes"] - - -class SerializationError(Exception): - """ - Serialization error. - """ - - def __init__(self, message: str): - super().__init__(message) - self.message = message - - def __str__(self): - return self.message - - -def ensure_bytes(obj: Union[bytes, bytearray, memoryview]) -> bytes: - """ - Ensure that the input object is bytes or can be converted to bytes. - :param obj: The object to ensure. - :type obj: Union[bytes, bytearray, memoryview] - :return: The bytes object. - :rtype: bytes - """ - - if isinstance(obj, bytes): - return obj - elif isinstance(obj, (bytearray, memoryview)): - return bytes(obj) - else: - raise SerializationError( - f"SerializationError: The incoming object is of type '{type(obj).__name__}', " - f"which is not supported. Expected types are 'bytes', 'bytearray', or 'memoryview'.\n" - f"Current object type: '{type(obj).__name__}'.\n" - f"Please provide data of the correct type or configure the serializer to handle the current input type." - ) - - -class Serializer(abc.ABC): - """ - Interface for serializer. - """ - - @abc.abstractmethod - def serialize(self, *args, **kwargs) -> bytes: - """ - Serialize an object to bytes. - :param args: The arguments to serialize. - :param kwargs: The keyword arguments to serialize. - :return: The serialized bytes. - :rtype: bytes - :raises SerializationError: If serialization fails. - """ - raise NotImplementedError() - - -class Deserializer(abc.ABC): - """ - Interface for deserializer. - """ - - @abc.abstractmethod - def deserialize(self, data: bytes) -> Any: - """ - Deserialize bytes to an object. - :param data: The bytes to deserialize. - :type data: bytes - :return: The deserialized object. - :rtype: Any - :raises SerializationError: If deserialization fails. - """ - raise NotImplementedError() diff --git a/src/dubbo/serialization/base.py b/src/dubbo/serialization/base.py new file mode 100644 index 00000000..e641ba48 --- /dev/null +++ b/src/dubbo/serialization/base.py @@ -0,0 +1,169 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from collections.abc import Callable, Sequence +from typing import Any, Generic, TypeVar + +import attrs + +from dubbo.constants import DEFAULT_JAVA_SERIALIZATION, DEFAULT_SERIALIZATION, SERIALIZATION_KEY +from dubbo.extension import extension_point, extensions +from dubbo.url import URL + +__all__ = ["Codec", "JavaSerialization", "Reader", "Serialization", "get_java_serialization", "get_serialization"] + +T = TypeVar("T") + + +@attrs.define(frozen=True, kw_only=True) +class Codec(Generic[T]): + """Turns one kind of message into bytes and back. + + Attributes: + encode: Returns the bytes of a message; raises `TypeError` for a + value the codec cannot carry. + decode: Returns the message the bytes hold; raises `ValueError` for + bytes that hold none. + """ + + encode: Callable[[T], bytes] + decode: Callable[[bytes], T] + + +@extension_point("apache_dubbo.serialization") +class Serialization(typing.Protocol): + """A message format, such as ``protobuf``. + + It turns values into bytes and back; each protocol decides which values + a message holds. Codecs are made once for each method, when a service is + exported or a method is first called, so that a call only encodes and + decodes. Codecs run in the event loop for every message, concurrently + for many calls, so they keep no state between messages and must be quick. + + Attributes: + content_subtype: Names the format in a content type, such as + ``proto`` in ``application/grpc+proto``. + shared: Whether a protocol may make one instance for each name and + share it, with its codecs, among the services that name it, + from the URL of the first; false by default, which makes one + instance for each service from its own URL. A format that reads + settings of a service from ``url`` leaves it false. + """ + + content_subtype: typing.ClassVar[str] + shared: typing.ClassVar[bool] = False + + def __init__(self, url: URL) -> None: ... + + def codec(self, types: Sequence[Any]) -> Codec[tuple[Any, ...]]: + """Return the codec of one value of each type annotation in ``types``, in order. + + It decodes each value as its annotation types it, and raises + `ValueError` for bytes that do not hold one value of each type. An + annotation of `typing.Any` takes any value the format describes + itself. + + Raises: + TypeError: The format cannot carry values of ``types``. + """ + ... + + +class Reader(typing.Protocol): + """Reads the values of one message one at a time, so that a value can decide the types of those after it.""" + + def load(self, type: Any) -> Any: + """Return the next value, decoded as the annotation ``type`` types it. + + Raises: + ValueError: No value is left, or the next one is not of ``type``; + the reader cannot go on. + """ + ... + + +@typing.runtime_checkable +class JavaSerialization(Serialization, typing.Protocol): + """A format of Java objects, whose objects travel with the names of their Java classes, such as ``hessian2``. + + The protocols that call Java methods, such as Dubbo, carry their values + in one. It names the Java types of the annotations it declares, and reads + values one at a time. An `Exception` annotation stands for a Java + throwable: a `RemoteError` travels as an object of its class, an + exception of a class the format declares as that class, and any + throwable received decodes as a `RemoteError`. + """ + + def reader(self, data: bytes) -> Reader: + """Return a reader of the values ``data`` holds.""" + ... + + def java_type(self, annotation: Any) -> str | None: + """Return the Java type values of ``annotation`` travel as, named as ``Class.getName`` names it. + + Such as ``long`` or ``com.example.User``. It names the types the format + declares; for another, such as ``int``, which stands for several Java + types, it returns ``None``. + """ + ... + + def generalize(self, value: Any, annotation: Any) -> Any: + """Return ``value``, of the type ``annotation``, as data that names its classes instead of being of them. + + An object becomes a dict of its fields, by the names they travel + under, with the Java name of its class under ``"class"``; an enum + becomes its name. A date, a time and a datetime that travels as a + ``java.time.LocalDateTime`` become their ISO 8601 text, as + ``java.time`` writes it; another datetime stays a date. Lists, + tuples, sets and dicts become those of what their items become, a + set whose items become dicts a list; other values stay as they are. + An object held in several places is generalized once. The data + encodes with the Java types ``value`` encodes with, such as ``long`` + for a field that declares it. + + Raises: + TypeError: The format cannot carry a value within ``value``. + ValueError: An object or collection within ``value`` holds itself. + """ + ... + + +def get_serialization(url: URL) -> Serialization: + """Return the serialization that the ``serialization`` parameter of ``url`` names, ``protobuf`` when absent. + + Raises: + ExtensionError: No implementation has that name. + """ + name = url.parameters.get(SERIALIZATION_KEY, DEFAULT_SERIALIZATION) + return extensions.get(Serialization, name)(url) + + +def get_java_serialization(url: URL) -> JavaSerialization: + """Return the format of Java objects that the ``serialization`` parameter of ``url`` names, ``hessian2`` when absent. + + Raises: + ExtensionError: No implementation has that name. + ValueError: The serialization it names is no format of Java objects, + such as ``protobuf``. + """ + name = url.parameters.get(SERIALIZATION_KEY, DEFAULT_JAVA_SERIALIZATION) + serialization = extensions.get(Serialization, name)(url) + if not isinstance(serialization, JavaSerialization): + raise ValueError(f"the serialization {name!r} does not carry Java objects, as hessian2 does") + + return serialization diff --git a/src/dubbo/serialization/custom_serializers.py b/src/dubbo/serialization/custom_serializers.py deleted file mode 100644 index 83ee4946..00000000 --- a/src/dubbo/serialization/custom_serializers.py +++ /dev/null @@ -1,87 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from typing import Any - -from dubbo.serialization import ( - Deserializer, - SerializationError, - Serializer, - ensure_bytes, -) -from dubbo.types import DeserializingFunction, SerializingFunction - -__all__ = ["CustomSerializer", "CustomDeserializer"] - -from dubbo.utils import FunctionHelper - - -class CustomSerializer(Serializer): - """ - Custom serializer that uses a custom serializing function to serialize objects. - """ - - __slots__ = ["serializer"] - - def __init__(self, serializer: SerializingFunction): - self.serializer = serializer - - def serialize(self, *args, **kwargs) -> bytes: - """ - Serialize an object to bytes. - :param args: The arguments to serialize. - :param kwargs: The keyword arguments to serialize. - :return: The serialized bytes. - :rtype: bytes - :raises SerializationError: If the object is not of type bytes, bytearray, or memoryview. - """ - try: - serialized_obj = FunctionHelper.call_func(self.serializer, (args, kwargs)) - except Exception as e: - raise SerializationError( - f"SerializationError: Failed to serialize object. Please check the serializer. \nDetails: {str(e)}", - ) - - return ensure_bytes(serialized_obj) - - -class CustomDeserializer(Deserializer): - """ - Custom deserializer that uses a custom deserializing function to deserialize objects. - """ - - __slots__ = ["deserializer"] - - def __init__(self, deserializer: DeserializingFunction): - self.deserializer = deserializer - - def deserialize(self, data: bytes) -> Any: - """ - Deserialize bytes to an object. - :param data: The bytes to deserialize. - :type data: bytes - :return: The deserialized object. - :rtype: Any - :raises SerializationError: If the object is not of type bytes, bytearray, or memoryview. - """ - try: - deserialized_obj = self.deserializer(data) - except Exception as e: - raise SerializationError( - f"SerializationError: Failed to deserialize object. Please check the deserializer. \nDetails: {str(e)}", - ) - - return deserialized_obj diff --git a/src/dubbo/serialization/direct_serializers.py b/src/dubbo/serialization/direct_serializers.py deleted file mode 100644 index 0b41557e..00000000 --- a/src/dubbo/serialization/direct_serializers.py +++ /dev/null @@ -1,58 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from typing import Any - -from dubbo.classes import SingletonBase -from dubbo.serialization import Deserializer, Serializer, ensure_bytes - -__all__ = ["DirectSerializer", "DirectDeserializer"] - - -class DirectSerializer(Serializer, SingletonBase): - """ - Direct serializer that does not perform any serialization. This serializer only checks if the given object is of - type bytes, bytearray, or memoryview and ensures it is returned as a bytes object. If the object is not of the - expected types, a SerializationError is raised. This serializer is a singleton. - """ - - def serialize(self, *args, **kwargs) -> bytes: - """ - Serialize an object to bytes. we only return the first argument as bytes. - :param args: The arguments to serialize. - :param kwargs: The keyword arguments to serialize. - :return: The serialized bytes. - :rtype: bytes - :raises SerializationError: If the object is not of type bytes, bytearray, or memoryview. - """ - return ensure_bytes(args[0]) if args else b"" - - -class DirectDeserializer(Deserializer): - """ - Direct deserializer that does not perform any serialization. This deserializer only returns the given bytes object - """ - - def deserialize(self, data: bytes) -> Any: - """ - Deserialize bytes to an object. - :param data: The bytes to deserialize. - :type data: bytes - :return: The deserialized object. - :rtype: Any - :raises SerializationError: If the object is not of type bytes, bytearray, or memoryview. - """ - return data diff --git a/src/dubbo/serialization/hessian2.py b/src/dubbo/serialization/hessian2.py new file mode 100644 index 00000000..88bccaa9 --- /dev/null +++ b/src/dubbo/serialization/hessian2.py @@ -0,0 +1,223 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import contextlib +import datetime +import enum +from collections.abc import Callable, Sequence +from typing import Any + +import hessian2 + +from dubbo.exceptions import RemoteError +from dubbo.url import URL + +from .base import Codec, JavaSerialization, Reader + +__all__ = ["Hessian2Serialization"] + +# How a throwable decodes: an object, or the text some peers send instead. +_THROWABLE = hessian2.HessianObject | str +# What an object being generalized stands for until it is. +_GENERALIZING = object() + + +class Hessian2Serialization(JavaSerialization): + """Carry values in Hessian 2.0, the default Dubbo format. + + A class travels under the Java name it declares with + ``hessian2.java_class``, and ``hessian2.Long`` and the other tags of + hessian2 name the Java types of values. Values decode as their + annotations type them; where an annotation takes any value, an object + decodes as a ``hessian2.HessianObject``. + """ + + content_subtype = "hessian2" + shared = True + + def __init__(self, url: URL) -> None: + super().__init__(url) + self._codec = hessian2.Codec(unknown_class="hessian_object") + + def codec(self, types: Sequence[Any]) -> Codec[tuple[Any, ...]]: + codec = self._codec + throwables = [index for index, annotation in enumerate(types) if annotation is Exception] + encode_types = tuple(Any if annotation is Exception else annotation for annotation in types) + decode_types = tuple(_THROWABLE if annotation is Exception else annotation for annotation in types) + # Decoding nothing prepares the types, which raises TypeError for one hessian2 cannot decode. + with contextlib.suppress(hessian2.DecodeError): + codec.loads_many(b"", types=decode_types) + + if not throwables: + + def encode(values: tuple[Any, ...]) -> bytes: + return codec.dumps_many(values, types=encode_types) + + def decode(data: bytes) -> tuple[Any, ...]: + return tuple(codec.loads_many(data, types=decode_types)) + + return Codec(encode=encode, decode=decode) + + def encode_throwables(values: tuple[Any, ...]) -> bytes: + converted = list(values) + for index in throwables: + converted[index] = _throwable(converted[index]) + return codec.dumps_many(converted, types=encode_types) + + def decode_throwables(data: bytes) -> tuple[Any, ...]: + values = codec.loads_many(data, types=decode_types) + for index in throwables: + values[index] = _remote_error(values[index]) + return tuple(values) + + return Codec(encode=encode_throwables, decode=decode_throwables) + + def reader(self, data: bytes) -> Reader: + return _Reader(self._codec.reader(data)) + + def java_type(self, annotation: Any) -> str | None: + try: + return self._codec.java_name(annotation) + except TypeError: + return None + + def generalize(self, value: Any, annotation: Any) -> Any: + # A null stays one, which responses carry as no value. + if value is not None and annotation is not None and annotation is not Any: + value = hessian2.Typed(value, annotation) + return _generalize(self._codec, value, {}) + + +class _Reader: + __slots__ = ("_reader",) + + def __init__(self, reader: hessian2.Reader) -> None: + self._reader = reader + + def load(self, type: Any) -> Any: + try: + if type is Exception: + return _remote_error(self._reader.load(type=_THROWABLE)) + return self._reader.load(type=type) + except EOFError: + raise ValueError("the message ends before this value") from None + + +def _generalize(codec: hessian2.Codec, value: Any, seen: dict[int, tuple[Any, Any]]) -> Any: + """Return ``value`` generalized, or ``value`` itself when nothing within it changes. + + ``seen`` holds each object and collection reached so far, with what it + became, by its id. + """ + if isinstance(value, hessian2.Typed): + if value.type == hessian2.LocalDateTime: + return _local_date_time(value.value) + inner = _generalize(codec, value.value, seen) + if inner is value.value: + return value + # An array of objects stays an array, of maps. + return hessian2.Typed(inner, tuple[Any, ...]) if isinstance(inner, tuple) else inner + if isinstance(value, dict | list | tuple | set | frozenset): + return _once(value, seen, lambda: _generalize_items(codec, value, seen)) + # A datetime stands for a java.util.Date, which stays one. + if isinstance(value, datetime.date) and not isinstance(value, datetime.datetime): + return value.isoformat() + if isinstance(value, datetime.time): + return _local_time(value) + + obj = codec.as_object(value) + if obj is None: + return value + if isinstance(value, enum.Enum): + return obj.fields["name"] + return _once( + value, + seen, + lambda: { + "class": obj.class_name, + **{name: _generalize(codec, field, seen) for name, field in obj.fields.items()}, + }, + ) + + +def _generalize_items( + codec: hessian2.Codec, value: dict | list | tuple | set | frozenset, seen: dict[int, tuple[Any, Any]] +) -> Any: + if isinstance(value, dict): + items = {_generalize(codec, key, seen): _generalize(codec, item, seen) for key, item in value.items()} + return value if all(items.get(key) is item for key, item in value.items()) else items + + generalized = [_generalize(codec, item, seen) for item in value] + if all(new is old for new, old in zip(generalized, value, strict=True)): + return value + try: + return type(value)(generalized) + except TypeError: + # A set of what became maps, which no set holds, travels as a list. + return generalized + + +def _once(value: Any, seen: dict[int, tuple[Any, Any]], generalize: Callable[[], Any]) -> Any: + """Return what ``generalize`` returns for ``value``, computed once for each object however many hold it. + + Raises: + ValueError: ``value`` holds itself. + """ + entry = seen.get(id(value)) + if entry is not None: + if entry[1] is _GENERALIZING: + raise ValueError(f"a {type(value).__name__} holds itself") + return entry[1] + + # ``seen`` keeps ``value``, so that no other object takes its id. + seen[id(value)] = (value, _GENERALIZING) + generalized = generalize() + seen[id(value)] = (value, generalized) + return generalized + + +def _local_time(value: datetime.time) -> str: + """Return the text ``java.time.LocalTime.toString`` gives for ``value``: seconds and fractions only when not zero.""" + if value.microsecond: + return value.isoformat("milliseconds" if value.microsecond % 1000 == 0 else "microseconds") + return value.isoformat("seconds" if value.second else "minutes") + + +def _local_date_time(value: datetime.datetime) -> str: + """Return the text ``java.time.LocalDateTime.toString`` gives for ``value``.""" + return f"{value.date().isoformat()}T{_local_time(value.time())}" + + +def _throwable(error: Any) -> Any: + """Return what an exception travels as: an object of its class for a `RemoteError`, else itself.""" + if not isinstance(error, RemoteError): + return error + + fields = {**error.fields, "detailMessage": error.message or None} + fields.setdefault("cause", None) + fields.setdefault("stackTrace", []) + fields.setdefault("suppressedExceptions", []) + return hessian2.HessianObject(error.class_name, fields) + + +def _remote_error(throwable: hessian2.HessianObject | str) -> RemoteError: + if isinstance(throwable, str): + return RemoteError("java.lang.Exception", throwable) + + fields = dict(throwable.fields) + message = fields.pop("detailMessage", None) + return RemoteError(throwable.class_name, message if isinstance(message, str) else "", fields=fields) diff --git a/src/dubbo/serialization/protobuf.py b/src/dubbo/serialization/protobuf.py new file mode 100644 index 00000000..039cb9f6 --- /dev/null +++ b/src/dubbo/serialization/protobuf.py @@ -0,0 +1,75 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Sequence +from typing import Any + +from google.protobuf.message import DecodeError, Message + +from dubbo.url import URL + +from .base import Codec, Serialization + +__all__ = ["ProtobufSerialization"] + +_PYTHON_TYPES = ( + "set the serialization to hessian2, or use the dubbo protocol, to carry Python types and several parameters" +) + + +class ProtobufSerialization(Serialization): + """Carry protobuf messages: the bytes hold exactly one message of a known type.""" + + content_subtype = "proto" + shared = True + + def __init__(self, url: URL) -> None: + pass + + def codec(self, types: Sequence[Any]) -> Codec[tuple[Any, ...]]: + if len(types) != 1: + raise TypeError(f"protobuf carries one message of a known type, not {types!r}; {_PYTHON_TYPES}") + + message_type = _message_type(types[0]) + + def encode(values: tuple[Any, ...]) -> bytes: + return _encode(message_type, values[0]) + + def decode(data: bytes) -> tuple[Any, ...]: + return (_decode(message_type, data),) + + return Codec(encode=encode, decode=decode) + + +def _message_type(annotation: Any) -> type[Message]: + if not (isinstance(annotation, type) and issubclass(annotation, Message)): + raise TypeError(f"protobuf carries messages, not {annotation!r}; {_PYTHON_TYPES}") + return annotation + + +def _encode(message_type: type[Message], message: Any) -> bytes: + # SerializeToString accepts a message of any type, so check it first. + if not isinstance(message, message_type): + raise TypeError(f"expected {message_type.__qualname__}, not {type(message).__qualname__}") + return message.SerializeToString() + + +def _decode(message_type: type[Message], data: bytes) -> Message: + try: + return message_type.FromString(data) + except DecodeError as error: + raise ValueError(f"not a {message_type.__qualname__}: {error}") from None diff --git a/src/dubbo/server.py b/src/dubbo/server.py deleted file mode 100644 index b7c4deec..00000000 --- a/src/dubbo/server.py +++ /dev/null @@ -1,84 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import threading -from typing import Optional - -from dubbo.bootstrap import Dubbo -from dubbo.configs import ServiceConfig -from dubbo.constants import common_constants -from dubbo.extension import extensionLoader -from dubbo.protocol import Protocol -from dubbo.registry.protocol import RegistryProtocol -from dubbo.url import URL - - -class Server: - """ - Dubbo Server - """ - - def __init__(self, service_config: ServiceConfig, dubbo: Optional[Dubbo] = None): - self._initialized = False - self._global_lock = threading.RLock() - - self._service = service_config - self._dubbo = dubbo or Dubbo() - - self._protocol: Optional[Protocol] = None - self._url: Optional[URL] = None - self._exported = False - - # initialize the server - self._initialize() - - def _initialize(self): - """ - Initialize the server. - """ - with self._global_lock: - if self._initialized: - return - - # get the protocol - service_protocol = extensionLoader.get_extension(Protocol, self._service.protocol)() - - registry_config = self._dubbo.registry_config - - self._protocol = ( - RegistryProtocol(registry_config, service_protocol) if self._dubbo.registry_config else service_protocol - ) - - # build url - service_url = self._service.to_url() - if registry_config: - self._url = registry_config.to_url().copy() - self._url.attributes[common_constants.EXPORT_KEY] = service_url - for k, v in service_url.attributes.items(): - self._url.attributes[k] = v - else: - self._url = service_url - - def start(self): - """ - Start the server. - """ - with self._global_lock: - if self._exported: - return - - self._protocol.export(self._url) - - self._exported = True diff --git a/src/dubbo/transport/__init__.py b/src/dubbo/transport/__init__.py new file mode 100644 index 00000000..6c032d66 --- /dev/null +++ b/src/dubbo/transport/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/src/dubbo/transport/h2/__init__.py b/src/dubbo/transport/h2/__init__.py new file mode 100644 index 00000000..401fb2ba --- /dev/null +++ b/src/dubbo/transport/h2/__init__.py @@ -0,0 +1,46 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .base import ( + H2Client, + H2ErrorCode, + H2Header, + H2Headers, + H2Server, + H2Stream, + H2StreamHandler, +) +from .exceptions import ( + H2ConnectionError, + H2Error, + H2StreamError, + H2StreamResetError, +) + +__all__ = [ + "H2Client", + "H2ConnectionError", + "H2Error", + "H2ErrorCode", + "H2Header", + "H2Headers", + "H2Server", + "H2Stream", + "H2StreamError", + "H2StreamHandler", + "H2StreamResetError", +] diff --git a/src/dubbo/transport/h2/aio/__init__.py b/src/dubbo/transport/h2/aio/__init__.py new file mode 100644 index 00000000..8e8c0f3b --- /dev/null +++ b/src/dubbo/transport/h2/aio/__init__.py @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .client import AioH2Client +from .server import AioH2Server +from .stream import AioH2Stream + +__all__ = ["AioH2Client", "AioH2Server", "AioH2Stream"] diff --git a/src/dubbo/transport/h2/aio/bdp.py b/src/dubbo/transport/h2/aio/bdp.py new file mode 100644 index 00000000..45d407ad --- /dev/null +++ b/src/dubbo/transport/h2/aio/bdp.py @@ -0,0 +1,129 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import math + +__all__ = ["BDP_PING", "MAX_WINDOW", "BdpEstimator"] + +# The opaque data of a measuring PING; keep-alive PINGs count up from 1 and in practice never reach it. +BDP_PING = b"\xff" * 8 + +MAX_WINDOW = 16 * 1024 * 1024 +# libnghttp2 returns credit once half the window is consumed. A whole number of pairs of default-sized +# DATA frames keeps that half on a frame boundary, so the peer can keep the entire window in flight. +_WINDOW_STEP = 2 * 16 * 1024 +_GROWTH_THRESHOLD = 2 / 3 +_RTT_WEIGHT = 0.125 +_MAX_BACKOFF = 10 + + +class BdpEstimator: + """Grows the initial stream window to twice the credit returned in a round trip, timed with PING. + + Credit is returned in bursts paced by the round trip, and the acknowledgement + of a probe arrives just before the burst its WINDOW_UPDATE released. The + credit returned between two acknowledgements therefore spans whole bursts; + as a rate over that span times the smoothed round trip, measured from the + write of each PING, it is the sample. The window grows to twice the sample, + in whole steps of two default-sized frames and at most `MAX_WINDOW`, when + the sample fills two thirds of it and the rate is the fastest that has + grown it. + + A probe starts when credit is returned after DATA has arrived since the + previous acknowledgement, so the peer has written between any two probes. + Probes that grow nothing make the next one wait for more credit, up to ten + times half the window. An acknowledgement no written probe waits for + changes nothing. + + ``window`` is the initial stream window the connection starts with. + + Attributes: + data_received: Whether DATA has arrived since the last acknowledgement; + the connection sets it for each DATA frame. + probe_unwritten: Whether the PING of the current probe is queued and + not yet written; the connection reports the write with + `probe_written`. + """ + + def __init__(self, window: int) -> None: + self.window = window + self.data_received = False + self.probe_unwritten = False + + self._probing = False + self._sent_at: float | None = None + self._acknowledged_at: float | None = None + self._rtt = 0.0 + self._best_rate = 0.0 + self._backoff = 0 + # Credit returned since the last acknowledgement, and the part the next probe waits for. + self._returned = 0 + self._threshold = 0 + + @property + def finished(self) -> bool: + """Return whether the window has reached `MAX_WINDOW`.""" + return self.window >= MAX_WINDOW + + def credit_returned(self, amount: int) -> bool: + """Record returned credit, and return whether to queue the PING of a probe that starts now.""" + self._returned += amount + if self._probing or not self.data_received or self._returned < self._threshold: + return False + + self._probing = True + self.probe_unwritten = True + self._sent_at = None + return True + + def probe_written(self, now: float) -> None: + """Start the round trip of the current probe at ``now``, when its PING is written.""" + self.probe_unwritten = False + self._sent_at = now + + def probe_acknowledged(self, now: float) -> int | None: + """Finish the probe and return the new window, or None when it stays.""" + sent_at = self._sent_at + if not self._probing or sent_at is None: + return None + + rtt = now - sent_at + span = now - (sent_at if self._acknowledged_at is None else self._acknowledged_at) + returned = self._returned + + self._probing = False + self.data_received = False + self._acknowledged_at = now + self._returned = 0 + if rtt <= 0 or span <= 0: + return None + + self._rtt = rtt if not self._rtt else self._rtt + (rtt - self._rtt) * _RTT_WEIGHT + window = self._grow(returned / span) + self._backoff = 0 if window is not None else min(self._backoff + 1, _MAX_BACKOFF) + self._threshold = self._backoff * self.window // 2 + return window + + def _grow(self, rate: float) -> int | None: + sample = rate * self._rtt + target = min(math.ceil(2 * sample / _WINDOW_STEP) * _WINDOW_STEP, MAX_WINDOW) + if rate < self._best_rate or sample < _GROWTH_THRESHOLD * self.window or target <= self.window: + return None + + self._best_rate = rate + self.window = target + return target diff --git a/src/dubbo/transport/h2/aio/client.py b/src/dubbo/transport/h2/aio/client.py new file mode 100644 index 00000000..576ce80a --- /dev/null +++ b/src/dubbo/transport/h2/aio/client.py @@ -0,0 +1,243 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import ipaddress +from typing import Any, Self + +import anyio +import ngh2 + +from dubbo.constants import CONNECT_TIMEOUT_KEY, DEFAULT_CONNECT_TIMEOUT +from dubbo.transport.h2.base import H2Client, H2Headers +from dubbo.transport.h2.exceptions import H2ConnectionError +from dubbo.transport.tls import get_ssl_context, server_hostname +from dubbo.url import URL +from dubbo.utils import Dialer, release_shield +from dubbo.utils.converters import milliseconds + +from .connection import AioH2Connection +from .stream import AioH2Stream + +__all__ = ["AioH2Client"] + +_HAPPY_EYEBALLS_DELAY = 0.25 + + +class AioH2Client(H2Client): + """Connects to one HTTP/2 endpoint through asyncio. + + Without TLS, the client uses prior-knowledge HTTP/2 over cleartext TCP. + With TLS, it verifies that the handshake selected ``h2`` through ALPN and + never falls back to HTTP/1.1. Concurrent tasks may share the client, but + after the first connection attempt all asynchronous calls and returned + streams must remain on that asyncio event loop. The client owns one active + connection plus any predecessor draining after GOAWAY. + + Entering the client starts connecting in the background. One attempt + runs at a time and lasts at most the connect timeout; callers that open + streams meanwhile wait for it, and one that stops waiting leaves it + running. After an attempt fails or the connection is lost, the client + connects again in the background after a backoff. + + ``url`` names the server host and port, with the parameters `H2Client` + describes, plus ``stream-send-buffer-size``: bytes of a stream's body + queued for flow control or the socket before a send waits, 256 KiB when + absent. + + Raises: + ValueError: The URL has no host or port, a parameter is invalid, or + the connect timeout is not positive. + OSError: A TLS file cannot be loaded. + """ + + def __init__(self, url: URL) -> None: + super().__init__(url) + + if url.host is None or url.port is None: + raise ValueError(f"an HTTP/2 client needs a host and a port: {url}") + + connect_timeout = url.get_parameter(CONNECT_TIMEOUT_KEY, milliseconds, DEFAULT_CONNECT_TIMEOUT) + if not connect_timeout > 0: + raise ValueError(f"URL parameter {CONNECT_TIMEOUT_KEY!r} must be positive") + + self._host = url.host + self._port = url.port + self._ssl_context = get_ssl_context(url, server=False, alpn=("h2",)) + self._server_hostname = server_hostname(url) if self._ssl_context is not None else None + self._connect_timeout = connect_timeout + self._host_is_name = _is_name(url.host) + + self._active_connection: AioH2Connection | None = None + self._draining_connections: set[AioH2Connection] = set() + self._dialer = Dialer(self._open_connection) + self._closed = False + self._shutdown: asyncio.Task[None] | None = None + + @property + def available(self) -> bool: + return not self._closed and self._dialer.connected + + async def open_stream(self, headers: H2Headers, *, end_stream: bool = False) -> AioH2Stream: + replaced = False + while True: + connection = await self._get_or_open_connection() + stream = await connection.open_stream(headers, end_stream=end_stream) + if stream is not None: + return stream + if replaced: + connection.raise_if_failed() + raise H2ConnectionError("the HTTP/2 connection became unavailable before opening a stream") + replaced = True + + async def aclose(self) -> None: + """Close the client and its connections for good. + + The connections close together, each once its open streams have + finished and the server has read what was sent, or after a second. A + connection attempt under way is abandoned. A cancelled close aborts + the connections at once. Closing again waits for the close under way. + """ + if self._shutdown is None: + self._closed = True + self._shutdown = asyncio.get_running_loop().create_task(self._shut_down()) + + shutdown = self._shutdown + try: + await asyncio.wait((shutdown,)) + except BaseException: + # A cancelled close aborts at once and waits only for that. + shutdown.cancel() + self._dialer.close() + connections = self._owned() + for connection in connections: + connection.abort() + with release_shield(): + await asyncio.wait((shutdown,)) + for connection in connections: + await connection.wait_closed() + raise + + # A shutdown cancelled by an earlier close has finished at once. + if not shutdown.cancelled(): + shutdown.result() + + async def __aenter__(self) -> Self: + if self._closed: + raise RuntimeError("the HTTP/2 client is closed") + self._dialer.start() + return self + + async def _get_or_open_connection(self) -> AioH2Connection: + """Reuse an accepting connection, or wait for the attempt that establishes its replacement.""" + if self._closed: + raise RuntimeError("the HTTP/2 client is closed") + current = self._active_connection + if current is not None and current.accepting_streams: + return current + + connection = await self._dialer.connect() + if connection is None: + raise RuntimeError("the HTTP/2 client is closed") + return connection + + async def _open_connection(self) -> AioH2Connection: + """Establish and publish one replacement connection within the connect timeout.""" + current = self._active_connection + if current is not None and not current.closed: + self._draining_connections.add(current) + + connection = AioH2Connection( + ngh2.Role.CLIENT, + self.url, + require_h2_alpn=self._ssl_context is not None, + on_closed=self._connection_closed, + ) + # Publish before awaiting so a concurrent close owns this connection. + self._active_connection = connection + protocol_created = False + + def create_protocol() -> AioH2Connection: + """Record that asyncio now owns the protocol lifecycle.""" + nonlocal protocol_created + protocol_created = True + return connection + + loop = asyncio.get_running_loop() + # Only the standard library loops race addresses; uvloop rejects the argument. An IP address has none to + # race, and a cancelled race leaks its socket in CPython 3.11 to 3.15. + race = self._host_is_name and isinstance(loop, asyncio.BaseEventLoop) + options: dict[str, Any] = {"happy_eyeballs_delay": _HAPPY_EYEBALLS_DELAY} if race else {} + try: + # TimeoutError is an OSError. A server counts as answering once its SETTINGS arrive, not when TCP + # accepts, which a proxy in front of a gone server still does. + with anyio.fail_after(self._connect_timeout): + await loop.create_connection( + create_protocol, + self._host, + self._port, + ssl=self._ssl_context, + server_hostname=self._server_hostname, + **options, + ) + await connection.wait_established() + except BaseException as error: + # The connection carried no stream, so it is released at once, even when cancelled. Once asyncio has the + # protocol, it reports the transport closed, which may still be on its way. + if protocol_created: + connection.start_close() + connection.abort() + else: + connection.abandon() + with release_shield(): + await connection.wait_closed() + if isinstance(error, OSError): + raise H2ConnectionError(f"failed to connect to {self._host}:{self._port}") from error + raise + + return connection + + async def _shut_down(self) -> None: + for connection in self._owned(): + connection.start_close() + # An attempt under way is abandoned; a connection it completed meanwhile is among those closed below. + await self._dialer.aclose() + + async with anyio.create_task_group() as closing: + for connection in self._owned(): + closing.start_soon(connection.aclose) + + def _owned(self) -> tuple[AioH2Connection, ...]: + """Return the connections still open: the active one and those draining.""" + active = () if self._active_connection is None else (self._active_connection,) + return (*self._draining_connections, *active) + + def _connection_closed(self, connection: AioH2Connection) -> None: + """Forget a connection after asyncio reports its transport closed, and connect again if it was the active one.""" + self._draining_connections.discard(connection) + if self._active_connection is connection: + self._active_connection = None + # Ignored while the attempt that opened it is still under way, which reports the failure itself. + self._dialer.lost() + + +def _is_name(host: str) -> bool: + try: + ipaddress.ip_address(host) + except ValueError: + return True + return False diff --git a/src/dubbo/transport/h2/aio/connection.py b/src/dubbo/transport/h2/aio/connection.py new file mode 100644 index 00000000..f252f8a7 --- /dev/null +++ b/src/dubbo/transport/h2/aio/connection.py @@ -0,0 +1,819 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import ssl +import time +from collections import deque +from collections.abc import Callable +from typing import Any, cast + +import anyio +import ngh2 + +from dubbo.constants import ( + CONNECTION_INITIAL_WINDOW_SIZE_KEY, + DEFAULT_CONNECTION_INITIAL_WINDOW_SIZE, + DEFAULT_INITIAL_WINDOW_SIZE, + DEFAULT_KEEP_ALIVE_TIMEOUT, + DEFAULT_MAX_CONCURRENT_STREAMS, + DEFAULT_MAX_HEADER_LIST_SIZE, + INITIAL_WINDOW_SIZE_KEY, + KEEP_ALIVE_INTERVAL_KEY, + KEEP_ALIVE_TIMEOUT_KEY, + MAX_CONCURRENT_STREAMS_KEY, + MAX_HEADER_LIST_SIZE_KEY, +) +from dubbo.transport.h2.base import H2ErrorCode, H2Headers +from dubbo.transport.h2.exceptions import H2ConnectionError, H2Error, H2StreamError, H2StreamResetError +from dubbo.url import URL +from dubbo.utils import close_then_abort +from dubbo.utils.converters import milliseconds +from dubbo.utils.net import format_address + +from .bdp import BDP_PING, BdpEstimator +from .keep_alive import KeepAlive +from .stream import AioH2Stream + +__all__ = ["AioH2Connection"] + +_READ_BUFFER_SIZE = 64 * 1024 +_WRITE_CHUNK_SIZE = 64 * 1024 +# The connection window every HTTP/2 connection starts with. +_PROTOCOL_CONNECTION_WINDOW_SIZE = 64 * 1024 - 1 +_STREAM_SEND_BUFFER_SIZE_KEY = "stream-send-buffer-size" +_HTTP2_TLS_VERSIONS = frozenset({"TLSv1.2", "TLSv1.3"}) +_DEFAULT_STREAM_SEND_BUFFER_SIZE = 256 * 1024 + + +class AioH2Connection(asyncio.BufferedProtocol): + """Runs one ngh2 engine over an asyncio transport. + + asyncio invokes every transport callback synchronously on one event loop, + so engine state needs no mutex; events and futures only suspend tasks until that + state changes. A change wakes only the tasks it concerns: a stream's own + receiver or sender, the senders waiting for output to drain, or the tasks + waiting to open a stream. Output is batched within a loop iteration and + written in bounded chunks, with one early client flush when a request + ends. + + Streams queue frames through the stream operations below and keep their + own state; the connection hands them what arrives through their ``_on_*`` + methods. The client or server that owns the connection uses the lifecycle + methods. The HTTP/2 parameters of ``url`` configure it as `H2Client` + describes them, and ``stream-send-buffer-size`` as `AioH2Client` + describes it. + """ + + def __init__( + self, + role: ngh2.Role, + url: URL, + *, + require_h2_alpn: bool = False, + on_connected: Callable[["AioH2Connection"], None] | None = None, + on_stream: Callable[[AioH2Stream], None] | None = None, + on_closed: Callable[["AioH2Connection"], None] | None = None, + ) -> None: + self.is_server = role is ngh2.Role.SERVER + max_streams = url.get_parameter(MAX_CONCURRENT_STREAMS_KEY, int, DEFAULT_MAX_CONCURRENT_STREAMS) + max_header_list = url.get_parameter(MAX_HEADER_LIST_SIZE_KEY, int, DEFAULT_MAX_HEADER_LIST_SIZE) + fixed_stream_window = url.get_parameter(INITIAL_WINDOW_SIZE_KEY, int, None) + stream_window = DEFAULT_INITIAL_WINDOW_SIZE if fixed_stream_window is None else fixed_stream_window + connection_window = url.get_parameter( + CONNECTION_INITIAL_WINDOW_SIZE_KEY, int, DEFAULT_CONNECTION_INITIAL_WINDOW_SIZE + ) + self._keep_alive_interval = url.get_parameter(KEEP_ALIVE_INTERVAL_KEY, milliseconds, None) + self._keep_alive_timeout = url.get_parameter(KEEP_ALIVE_TIMEOUT_KEY, milliseconds, DEFAULT_KEEP_ALIVE_TIMEOUT) + self._send_buffer_size = url.get_parameter(_STREAM_SEND_BUFFER_SIZE_KEY, int, _DEFAULT_STREAM_SEND_BUFFER_SIZE) + if self._send_buffer_size <= 0: + raise ValueError(f"URL parameter {_STREAM_SEND_BUFFER_SIZE_KEY!r} must be positive") + + # ngh2 checks each value against HTTP/2 when it takes it. + self._engine = ngh2.Connection( + role, + ngh2.Configuration( + auto_window_update=False, + initial_peer_max_concurrent_streams=max_streams, + max_inbound_header_list_size=max_header_list, + ), + ) + settings = { + ngh2.Setting.MAX_CONCURRENT_STREAMS: max_streams, + ngh2.Setting.INITIAL_WINDOW_SIZE: stream_window, + ngh2.Setting.MAX_HEADER_LIST_SIZE: max_header_list, + } + if role is ngh2.Role.CLIENT: + settings[ngh2.Setting.ENABLE_PUSH] = 0 + self._engine.initiate_connection(settings) + if connection_window != _PROTOCOL_CONNECTION_WINDOW_SIZE: + self._engine.set_local_window_size(connection_window) + + self._require_h2_alpn = require_h2_alpn + self._on_connected = on_connected + self._on_stream = on_stream + self._on_closed = on_closed + + self._buffer = bytearray(_READ_BUFFER_SIZE) + self._loop: asyncio.AbstractEventLoop | None = None + self._transport: asyncio.Transport | None = None + self.peer: str | None = None + self._write_paused = False + self._flush_scheduled = False + # Whether a request has gone out ahead of the flush that ends this loop iteration. + self._wrote_ahead = False + # Whether frames were queued since output was last written. + self._queued = False + self._writing = False + self._transport_closed = False + self._transport_lost = anyio.Event() + # Set by the first SETTINGS of the peer, which ends its connection preface, or by the end of the connection. + self._preface_ended = anyio.Event() + self._keep_alive: KeepAlive | None = None + self._bdp = BdpEstimator(stream_window) if fixed_stream_window is None else None + + # On a client, which refuses server push, every tracked stream is one it opened. + self._streams_by_id: dict[int, AioH2Stream] = {} + # Assumed until the first SETTINGS of the peer, which a client waits for before opening streams. + self._peer_max_concurrent_streams = max_streams + # Streams waiting for output to drain or for asyncio to resume writing. + self._blocked_senders: set[AioH2Stream] = set() + # The tasks waiting to open a stream, in arrival order, each told whether it may; asyncio futures, as this + # is on the path of every call when the streams run out. + self._stream_waiters: deque[asyncio.Future[bool]] = deque() + # The streams set aside for waiters that have been told and not yet opened theirs. + self._granted_streams = 0 + + self._draining = False + self._goaway_error_code: int | None = None + self._goaway_last_stream_id: int | None = None + self._closing = False + self._engine_terminated = False + self._failure: H2ConnectionError | None = None + + self._event_handlers: dict[type[ngh2.Event], Callable[[Any], None]] = { + ngh2.RequestReceived: self._handle_request_received, + ngh2.ResponseReceived: self._handle_response_received, + ngh2.DataReceived: self._handle_data_received, + ngh2.TrailersReceived: self._handle_trailers_received, + ngh2.StreamReset: self._handle_stream_reset, + ngh2.StreamClosed: self._handle_stream_closed, + ngh2.SettingsReceived: self._handle_settings_received, + ngh2.PingAcknowledged: self._handle_ping_acknowledged, + ngh2.GoAwayReceived: self._handle_goaway_received, + ngh2.ConnectionClosed: self._handle_connection_closed, + } + + @property + def closed(self) -> bool: + """Return whether asyncio has reported transport closure.""" + return self._transport_closed + + @property + def accepting_streams(self) -> bool: + """Return whether this connection can still initiate a stream.""" + return ( + self._transport is not None + and not self._transport_closed + and not self._closing + and self._failure is None + and not self._draining + and self._engine.can_send_request + ) + + async def open_stream(self, headers: H2Headers, *, end_stream: bool) -> AioH2Stream | None: + """Open a local stream, or return ``None`` when the connection can no longer open one.""" + if not await self._wait_for_stream(): + return None + + try: + stream_id = self._engine.send_request(headers, end_stream=end_stream) + except ngh2.NGH2Error as error: + raise _map_ngh2_error(error) from error + + stream = AioH2Stream(self, stream_id, headers_sent=True, send_ended=end_stream) + self._streams_by_id[stream_id] = stream + self._schedule_flush(request_ended=end_stream) + + try: + await self.wait_writable(stream) + except BaseException: + stream._reset_after_cancel() + raise + + return stream + + def raise_if_failed(self) -> None: + """Raise the first connection failure, or an error if the connection is closed.""" + if self._failure is not None: + raise self._failure + if self._transport_closed: + raise H2ConnectionError("the HTTP/2 connection is closed") + + # Stream operations. Each queues frames and leaves them to the next flush. + + def send_response(self, stream_id: int, headers: H2Headers, *, end_stream: bool) -> None: + try: + self._engine.send_response(stream_id, headers, end_stream=end_stream) + except ngh2.NGH2Error as error: + raise _map_ngh2_error(error, stream_id) from error + + self._schedule_flush() + + def send_data(self, stream_id: int, data: bytes, *, end_stream: bool) -> None: + try: + self._engine.send_data(stream_id, data, end_stream=end_stream) + except ngh2.NGH2Error as error: + raise _map_ngh2_error(error, stream_id) from error + + self._schedule_flush(request_ended=end_stream) + + def send_trailers(self, stream_id: int, trailers: H2Headers) -> None: + try: + self._engine.send_trailers(stream_id, trailers) + except ngh2.NGH2Error as error: + raise _map_ngh2_error(error, stream_id) from error + + self._schedule_flush() + + def end_stream(self, stream_id: int) -> None: + try: + self._engine.end_stream(stream_id) + except ngh2.NGH2Error as error: + raise _map_ngh2_error(error, stream_id) from error + + self._schedule_flush(request_ended=True) + + def reset_stream(self, stream_id: int, error_code: int, *, after_end_stream: bool = False) -> None: + """Reset a stream; with ``after_end_stream``, once the frames queued for it are written.""" + try: + self._engine.reset_stream(stream_id, error_code, after_end_stream=after_end_stream) + except ngh2.NGH2Error as error: + raise _map_ngh2_error(error, stream_id) from error + + self._schedule_flush() + + def consume(self, stream_id: int, amount: int) -> None: + """Return receive-window credit for bytes the application read or dropped.""" + if not amount or self._transport_closed or self._engine_terminated: + return + + try: + self._return_credit(stream_id, amount) + except ngh2.NGH2Error as error: + failure = _connection_error(error) + self._fail_connection(failure) + raise failure from error + + self._schedule_flush() + + async def wait_writable(self, stream: AioH2Stream) -> None: + """Wait until asyncio accepts writes and at most a send buffer of the stream's body is queued.""" + while True: + stream._raise_if_send_failed() + if not self._write_paused and self._engine.queued_body_size(stream.stream_id) <= self._send_buffer_size: + return + + self._blocked_senders.add(stream) + try: + await stream._wait_to_send() + finally: + self._blocked_senders.discard(stream) + + def announce_shutdown(self) -> None: + """Ask the peer to open no more streams, the first step of a graceful close.""" + if self._transport is None or self._closing or self._transport_closed or self._engine_terminated: + return + + try: + self._engine.send_shutdown_notice() + except ngh2.NGH2Error as error: + self._fail_connection(_connection_error(error)) + self.abort() + return + + self._schedule_flush() + + async def aclose(self) -> None: + """Close once the open streams finish and the peer has read the output, waiting up to a grace period; abort after it or when cancelled.""" + self.start_close() + if self._transport is None: + self.abandon() + return + + await close_then_abort(self.wait_closed, lambda: self._transport_closed, self.abort) + + def start_close(self) -> None: + """Send the final GOAWAY, without waiting for the socket to close. + + Open streams keep sending what they queued; once they finish, the + engine reports ConnectionClosed and the flush closes the socket. + """ + if self._transport_closed or self._closing: + return + + self._closing = True + self._stop_keep_alive() + self._bdp = None + self._notify_capacity() + + if not self._engine_terminated: + try: + self._engine.send_goaway() + except ngh2.NGH2Error as error: + self._fail_connection(_connection_error(error)) + else: + self._write_outbound() + return + + if self._transport is not None and not self._transport.is_closing(): + self._transport.close() + + def abort(self) -> None: + """Abort the socket, as when graceful shutdown takes too long.""" + self._closing = True + self._stop_keep_alive() + if self._transport is None: + self.connection_lost(None) + return + + self._transport.abort() + + def abandon(self) -> None: + """Finish a connection whose transport was never created.""" + self.start_close() + if self._transport is None: + self.connection_lost(None) + + async def wait_established(self) -> None: + """Wait for the first SETTINGS of the peer, which shows that an HTTP/2 endpoint answers. + + Raises: + H2ConnectionError: The connection failed or closed first. + """ + await self._preface_ended.wait() + self.raise_if_failed() + + async def wait_closed(self) -> None: + """Wait until asyncio reports that the socket transport is lost.""" + if not self._transport_closed: + await self._transport_lost.wait() + + def connection_made(self, transport: asyncio.BaseTransport) -> None: + """Attach the socket transport and send the pending connection preface.""" + socket_transport = cast(asyncio.Transport, transport) + self._loop = asyncio.get_running_loop() + self._transport = socket_transport + self.peer = _address(socket_transport.get_extra_info("peername")) + if self._transport_closed or self._closing: + socket_transport.close() + return + + if self._require_h2_alpn: + problem = _tls_problem(socket_transport.get_extra_info("ssl_object")) + if problem is not None: + self._fail_connection(H2ConnectionError(problem)) + self.abort() + return + + if self._on_connected is not None: + self._on_connected(self) + if self._closing or self._transport_closed: + return + + self._write_outbound() + if self._keep_alive_interval is not None: + self._keep_alive = KeepAlive( + self._loop, + interval=self._keep_alive_interval, + timeout=self._keep_alive_timeout, + ping=self._send_ping, + expire=self._keep_alive_expired, + ) + + def get_buffer(self, sizehint: int) -> memoryview: + """Return the reusable buffer used by asyncio's buffered protocol API.""" + return memoryview(self._buffer) + + def buffer_updated(self, nbytes: int) -> None: + """Feed the newly filled receive-buffer prefix into ngh2.""" + if self._transport_closed: + return + + try: + self._engine.receive_data(memoryview(self._buffer)[:nbytes]) + if self._keep_alive is not None: + # Socket activity counts even when an extension frame emits no event. + self._keep_alive.received() + self._dispatch_events(self._engine.events()) + self._schedule_flush() + except ngh2.NGH2Error as error: + self._fail_connection(_connection_error(error)) + self.abort() + + def pause_writing(self) -> None: + """Record asyncio write backpressure.""" + self._write_paused = True + + def resume_writing(self) -> None: + """Resume engine output after asyncio releases write backpressure.""" + self._write_paused = False + self._write_outbound() + self._wake_senders() + + def connection_lost(self, exc: Exception | None) -> None: + """Finalize transport loss and fail streams that did not complete.""" + if self._transport_closed: + return + + self._stop_keep_alive() + self._transport_closed = True + self._preface_ended.set() + if any(not stream._finished for stream in self._streams_by_id.values()): + if exc is None: + failure = H2ConnectionError("the HTTP/2 connection closed before its streams completed") + else: + failure = H2ConnectionError(f"the HTTP/2 connection failed: {exc}") + self._fail_connection(failure) + + self._wake_all() + # Streams a caller still holds keep their own buffers, not their siblings. + self._streams_by_id.clear() + self._transport_lost.set() + if self._on_closed is not None: + self._on_closed(self) + + def _schedule_flush(self, *, request_ended: bool = False) -> None: + """Flush later in this loop iteration, so output from every stream shares one write. + + A client with other calls open writes at once when the first request + of an iteration ends while asyncio holds none of its output unsent, + so that the server starts on that request while the rest gathers. + """ + if self._loop is None: + return + + self._queued = True + if not self._flush_scheduled: + self._flush_scheduled = True + self._loop.call_soon(self._flush_outbound) + # One write ahead per iteration; the other output still shares the flush. + transport = self._transport + if ( + request_ended + and not self.is_server + and not self._wrote_ahead + and len(self._streams_by_id) > 1 # A lone call has nothing to overlap with. + and not self._writing + and transport is not None + and not transport.get_write_buffer_size() # Queued output would not arrive sooner. + ): + self._wrote_ahead = True + self._write_outbound() + + def _flush_outbound(self) -> None: + """End the loop iteration's batch, writing what was queued since output was last written.""" + self._flush_scheduled = self._wrote_ahead = False + if self._queued: + self._write_outbound() + + def _write_outbound(self) -> None: + """Write available engine output until empty or asyncio applies backpressure.""" + self._queued = False + transport = self._transport + # Closing an asyncio SSL transport twice detaches it, so a later abort() is lost. + if transport is None or transport.is_closing() or self._write_paused: + return + + wrote_data = False + self._writing = True + try: + while not self._write_paused: + # Bound engine allocations so asyncio can apply backpressure between writes. + outgoing = self._engine.data_to_send(_WRITE_CHUNK_SIZE) + # Producing output may itself complete streams and emit events. + self._dispatch_events(self._engine.events()) + if outgoing: + transport.write(outgoing) + wrote_data = True + bdp = self._bdp + if bdp is not None and bdp.probe_unwritten and self._loop is not None: + # The engine writes a queued PING ahead of DATA, so this write carries it. + bdp.probe_written(time.perf_counter()) + if self._engine_terminated: + transport.close() + break + if not outgoing: + break + except ngh2.NGH2Error as error: + self._fail_connection(_connection_error(error)) + self.abort() + finally: + self._writing = False + if wrote_data: + self._wake_senders() + + def _dispatch_events(self, events: list[ngh2.Event]) -> None: + """Apply engine events in order; streams wake their own waiters.""" + for event in events: + handler = self._event_handlers.get(type(event)) + if handler is not None: + handler(event) + + def _handle_request_received(self, event: ngh2.RequestReceived) -> None: + stream = AioH2Stream( + self, + event.stream_id, + headers_sent=False, + headers=event.headers, + receive_ended=event.end_stream, + ) + self._streams_by_id[event.stream_id] = stream + if self._on_stream is not None: + self._on_stream(stream) + + def _handle_response_received(self, event: ngh2.ResponseReceived) -> None: + stream = self._streams_by_id.get(event.stream_id) + if stream is not None: + stream._on_headers(event.headers, end_stream=event.end_stream) + + def _handle_data_received(self, event: ngh2.DataReceived) -> None: + if self._bdp is not None: + self._bdp.data_received = True + + stream = self._streams_by_id.get(event.stream_id) + if stream is not None and not stream._released: + stream._on_data(event.data, end_stream=event.end_stream) + return + + # DATA that nothing will read still occupies flow-control credit. + if event.data: + self._return_credit(event.stream_id, len(event.data)) + + def _handle_trailers_received(self, event: ngh2.TrailersReceived) -> None: + stream = self._streams_by_id.get(event.stream_id) + if stream is not None: + stream._on_trailers(event.headers) + + def _handle_stream_reset(self, event: ngh2.StreamReset) -> None: + stream = self._streams_by_id.get(event.stream_id) + if stream is None: + return + + error = H2StreamResetError(event.stream_id, event.error_code) + # RFC 9113 section 8.1: after a complete response, NO_ERROR only stops the request. + if event.error_code == H2ErrorCode.NO_ERROR and stream._receive_ended: + stream._stop_sending(error) + return + + self._drop_unread(stream) + stream._abort(error) + + def _handle_stream_closed(self, event: ngh2.StreamClosed) -> None: + stream = self._streams_by_id.pop(event.stream_id, None) + if stream is None: + return + + self._notify_capacity() + + if event.local_error is None and not event.error_code: + stream._on_closed() + return + + self._drop_unread(stream) + # A GOAWAY refuses the streams above its last stream ID unprocessed; RFC 9113 section 6.8. + refused = ( + event.error_code == H2ErrorCode.REFUSED_STREAM + and self._goaway_last_stream_id is not None + and event.stream_id > self._goaway_last_stream_id + ) + if refused or isinstance(event.local_error, ngh2.ConnectionClosingError): + message = str(event.local_error or "") or "the HTTP/2 connection is draining" + failure: H2Error = H2ConnectionError( + message, + error_code=self._goaway_error_code, + last_stream_id=self._goaway_last_stream_id, + ) + else: + message = ( + str(event.local_error) + if event.local_error is not None + else f"the HTTP/2 stream closed with error code {event.error_code}" + ) + failure = H2StreamError(message, stream_id=event.stream_id) + stream._fail(failure) + + def _handle_settings_received(self, event: ngh2.SettingsReceived) -> None: + self._preface_ended.set() + # The engine holds the limit in force, unlimited when the first SETTINGS leaves it out. + maximum = self._engine.remote_settings[ngh2.Setting.MAX_CONCURRENT_STREAMS] + if maximum != self._peer_max_concurrent_streams: + self._peer_max_concurrent_streams = maximum + self._notify_capacity() + + def _handle_ping_acknowledged(self, event: ngh2.PingAcknowledged) -> None: + bdp = self._bdp + if event.opaque_data == BDP_PING and bdp is not None and self._loop is not None: + # A round trip on loopback is shorter than a tick of the loop clock on Windows before Python 3.13. + window = bdp.probe_acknowledged(time.perf_counter()) + if bdp.finished: + self._bdp = None + if window is None: + return + + try: + # The peer applies it to every open stream; RFC 9113 section 6.9.2. + self._engine.update_settings({ngh2.Setting.INITIAL_WINDOW_SIZE: window}) + except ngh2.ConnectionStateError: + # A connection that is shutting down keeps the windows it has. + self._bdp = None + return + + if self._keep_alive is not None: + self._keep_alive.acknowledged(event.opaque_data) + + def _handle_goaway_received(self, event: ngh2.GoAwayReceived) -> None: + self._draining = True + self._bdp = None + self._goaway_error_code = event.error_code + self._goaway_last_stream_id = event.last_stream_id + self._notify_capacity() + + def _handle_connection_closed(self, event: ngh2.ConnectionClosed) -> None: + # The flush that produced this event writes its output first, then closes the socket. + self._engine_terminated = True + self._notify_capacity() + if event.error_code: + self._fail_connection( + H2ConnectionError( + "peer closed the HTTP/2 connection", + error_code=event.error_code, + last_stream_id=self._goaway_last_stream_id, + ) + ) + + def _drop_unread(self, stream: AioH2Stream) -> None: + """Drop a stream's unread input and return its connection credit; engine failures propagate.""" + amount = stream._drop_unread() + if amount and not self._transport_closed and not self._engine_terminated: + self._return_credit(stream.stream_id, amount) + + def _return_credit(self, stream_id: int, amount: int) -> None: + """Return receive-window credit, and start a BDP probe when the estimator asks; engine failures propagate.""" + self._engine.consume_received_data(stream_id, amount) + + bdp = self._bdp + if bdp is None or not bdp.credit_returned(amount): + return + + try: + self._engine.send_ping(BDP_PING) + except ngh2.ConnectionStateError: + # A connection that is shutting down keeps the windows it has. + self._bdp = None + + async def _wait_for_stream(self) -> bool: + """Wait in arrival order for room for one more stream; return ``False`` once the connection opens no more.""" + first = False + while self.accepting_streams: + if first: + # The waiters told after this one wake after it, so the streams set aside for them come second. + ready = self._free_streams() + self._granted_streams > 0 + else: + # Nobody passes those already waiting. + ready = not self._stream_waiters and self._free_streams() > 0 + if ready: + return True + + waiter = asyncio.get_running_loop().create_future() + if first: + self._stream_waiters.appendleft(waiter) + else: + self._stream_waiters.append(waiter) + try: + allowed = await waiter + except BaseException: + if not waiter.done() or waiter.cancelled(): + waiter.cancel() + # A cancelled waiter may already have been passed over. + if waiter in self._stream_waiters: + self._stream_waiters.remove(waiter) + elif waiter.result(): + # The stream set aside goes to the next waiter. + self._granted_streams -= 1 + self._notify_capacity() + raise + + if not allowed: + return False + self._granted_streams -= 1 + # Should the peer have lowered its limit meanwhile, it waits again ahead of the others. + first = True + + return False + + def _free_streams(self) -> int: + return self._peer_max_concurrent_streams - len(self._streams_by_id) - self._granted_streams + + def _notify_capacity(self) -> None: + """Set aside the free streams for the waiters in arrival order, or tell them all the connection opens no more.""" + waiters = self._stream_waiters + if not self.accepting_streams: + while waiters: + waiter = waiters.popleft() + if not waiter.done(): + waiter.set_result(False) + return + + free = self._free_streams() + while waiters and free > 0: + waiter = waiters.popleft() + # A cancelled waiter is passed over; it takes nothing. + if not waiter.done(): + waiter.set_result(True) + self._granted_streams += 1 + free -= 1 + + def _wake_senders(self) -> None: + for stream in self._blocked_senders: + stream._wake_sender() + + def _wake_all(self) -> None: + """Wake every waiter after a connection-wide change, such as failure or closure.""" + for stream in tuple(self._streams_by_id.values()): + stream._wake() + self._wake_senders() + self._notify_capacity() + + def _fail_connection(self, error: H2ConnectionError) -> None: + """Preserve the first failure and propagate it to active streams.""" + self._stop_keep_alive() + if self._failure is None: + self._failure = error + for stream in tuple(self._streams_by_id.values()): + stream._abort(self._failure) + self._preface_ended.set() + self._wake_all() + + def _send_ping(self, payload: bytes) -> None: + try: + self._engine.send_ping(payload) + except ngh2.NGH2Error as error: + self._fail_connection(_connection_error(error)) + self.abort() + return + + self._schedule_flush() + + def _keep_alive_expired(self) -> None: + if self._closing or self._transport_closed: + return + + self._fail_connection(H2ConnectionError("the HTTP/2 keep-alive PING acknowledgement timed out")) + self.abort() + + def _stop_keep_alive(self) -> None: + if self._keep_alive is not None: + self._keep_alive.stop() + + +def _map_ngh2_error(error: ngh2.NGH2Error, stream_id: int | None = None) -> H2Error: + """Translate engine failures into dependency-independent transport errors.""" + message = str(error) or type(error).__name__ + if stream_id is not None and isinstance(error, (ngh2.StreamStateError, ngh2.StreamProtocolError)): + return H2StreamError(message, stream_id=stream_id) + return H2ConnectionError(message) + + +def _address(peername: Any) -> str | None: + """Return a socket address as ``host:port``, with an IPv6 host in brackets.""" + return format_address(*peername[:2]) if isinstance(peername, tuple) else None + + +def _connection_error(error: ngh2.NGH2Error) -> H2ConnectionError: + return cast(H2ConnectionError, _map_ngh2_error(error)) + + +def _tls_problem(ssl_object: ssl.SSLObject | None) -> str | None: + """Say how a TLS session breaks what RFC 9113 section 9.2 requires of HTTP/2, if it does.""" + if ssl_object is None or ssl_object.selected_alpn_protocol() != "h2": + return "TLS did not negotiate the 'h2' ALPN protocol" + if ssl_object.version() not in _HTTP2_TLS_VERSIONS: + return f"TLS negotiated {ssl_object.version()}, below the TLSv1.2 that HTTP/2 requires" + if ssl_object.compression() is not None: + return "TLS negotiated compression, which HTTP/2 forbids" + return None diff --git a/src/dubbo/transport/h2/aio/keep_alive.py b/src/dubbo/transport/h2/aio/keep_alive.py new file mode 100644 index 00000000..2fc859a5 --- /dev/null +++ b/src/dubbo/transport/h2/aio/keep_alive.py @@ -0,0 +1,111 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +from collections.abc import Callable + +__all__ = ["KeepAlive"] + +_MAX_PING_ID = 0xFFFFFFFFFFFFFFFF + + +class KeepAlive: + """Probes a connection with PING after a quiet interval and expires it when no acknowledgement arrives. + + Inbound bytes of any kind count as activity. One timer runs at a time: the + idle deadline, or while a PING is outstanding, its acknowledgement deadline. + + Args: + loop: The connection's event loop. + interval: Seconds without inbound bytes before a PING is sent. + timeout: Seconds to wait for the PING's acknowledgement. + ping: Sends a PING with the given 8-byte payload. + expire: Called when the acknowledgement does not arrive in time. + """ + + def __init__( + self, + loop: asyncio.AbstractEventLoop, + *, + interval: float, + timeout: float, + ping: Callable[[bytes], None], + expire: Callable[[], None], + ) -> None: + self._loop = loop + self._interval = interval + self._timeout = timeout + self._ping = ping + self._expire = expire + + self._last_received = loop.time() + self._ping_id = 0 + self._outstanding: bytes | None = None + self._timer: asyncio.TimerHandle | None = None + self._stopped = False + + self._arm_idle() + + def received(self) -> None: + """Record inbound activity, which postpones the next PING.""" + # The hot path only stores the time; the idle timer rechecks it when it fires. + self._last_received = self._loop.time() + + def acknowledged(self, payload: bytes) -> None: + """Complete the outstanding PING if ``payload`` matches it.""" + if payload != self._outstanding: + return + + self._outstanding = None + self._arm_idle() + + def stop(self) -> None: + """Stop probing for good.""" + self._stopped = True + self._outstanding = None + self._cancel_timer() + + def _arm_idle(self) -> None: + self._cancel_timer() + if not self._stopped: + self._timer = self._loop.call_at(self._last_received + self._interval, self._on_idle) + + def _on_idle(self) -> None: + self._timer = None + if self._stopped: + return + + deadline = self._last_received + self._interval + if deadline > self._loop.time(): + self._timer = self._loop.call_at(deadline, self._on_idle) + return + + self._ping_id = (self._ping_id + 1) & _MAX_PING_ID + self._outstanding = self._ping_id.to_bytes(8, "big") + # Armed first, so a ping that fails and stops probing also cancels it. + self._timer = self._loop.call_later(self._timeout, self._on_timeout) + self._ping(self._outstanding) + + def _on_timeout(self) -> None: + self._timer = None + if self._outstanding is not None and not self._stopped: + self._expire() + + def _cancel_timer(self) -> None: + if self._timer is not None: + self._timer.cancel() + self._timer = None diff --git a/src/dubbo/transport/h2/aio/server.py b/src/dubbo/transport/h2/aio/server.py new file mode 100644 index 00000000..542a024c --- /dev/null +++ b/src/dubbo/transport/h2/aio/server.py @@ -0,0 +1,248 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import logging +from contextlib import suppress +from types import TracebackType +from typing import Self + +import anyio +import ngh2 + +from dubbo.constants import DEFAULT_SHUTWAIT, SHUTWAIT_KEY +from dubbo.transport.h2.base import H2ErrorCode, H2Server, H2StreamHandler +from dubbo.transport.h2.exceptions import H2Error +from dubbo.transport.listener import abort_handshakes, create_listener +from dubbo.transport.tls import get_ssl_context, ssl_handshake_timeout +from dubbo.url import URL +from dubbo.utils import release_shield, wait_then_cancel +from dubbo.utils.converters import milliseconds + +from .connection import AioH2Connection +from .stream import AioH2Stream +from .tasks import join_shielded + +__all__ = ["AioH2Server"] + +_logger = logging.getLogger(__name__) + + +class AioH2Server(H2Server): + """Serves HTTP/2 through asyncio. + + Without TLS, the server accepts prior-knowledge HTTP/2 over cleartext + TCP. With TLS, it requires the handshake to select ``h2`` through ALPN and + never accepts HTTP/1.1. Entering the server starts listening; it is + single-use and owns its listener, connections, stream contexts and + handler tasks, all of which must stay on the event loop it was entered on. + + ``url`` names the interface and port to bind, with the parameters + `H2Server` describes, plus ``ssl-handshake-timeout``: the whole + milliseconds a TLS handshake may take, 10000 when absent, and + ``stream-send-buffer-size`` as `AioH2Client` describes it. When the host + is a name that resolves to multiple addresses, use a fixed port so every + listener shares one discoverable endpoint. Each accepted stream runs the + coroutine function ``handler`` in its own task. An ordinary handler + failure is logged and resets only its stream. + + Raises: + ValueError: The URL has no host or port, a parameter is invalid, or + the TLS handshake timeout is not positive. + OSError: A TLS file cannot be loaded. + """ + + def __init__(self, url: URL, handler: H2StreamHandler) -> None: + super().__init__(url, handler) + + if url.host is None or url.port is None: + raise ValueError(f"an HTTP/2 server needs a host and a port: {url}") + + self._host = url.host + self._port = url.port + self._ssl_context = get_ssl_context(url, server=True, alpn=("h2",)) + self._ssl_handshake_timeout = ssl_handshake_timeout(url) + self._shutwait = url.get_parameter(SHUTWAIT_KEY, milliseconds, DEFAULT_SHUTWAIT) + + self._listener: asyncio.Server | None = None + self._address: tuple[str, int] | None = None + self._connections: set[AioH2Connection] = set() + self._handlers: set[asyncio.Task[None]] = set() + self._started = False + self._closing = False + self._shutdown: asyncio.Task[None] | None = None + # A connection checks the HTTP/2 settings as it is made, so a server with invalid ones fails here, not on each accept. + self._create_connection() + + @property + def address(self) -> tuple[str, int]: + if self._address is None or self._closing: + raise RuntimeError("the HTTP/2 server is not listening") + return self._address + + def announce_shutdown(self) -> None: + for connection in tuple(self._connections): + connection.announce_shutdown() + + async def aclose(self) -> None: + if self._shutdown is None: + self._closing = True + self._shutdown = asyncio.get_running_loop().create_task(self._shut_down()) + + shutdown = self._shutdown + try: + await asyncio.wait((shutdown,)) + except BaseException: + # A cancelled close shuts down at once and waits only for that. + shutdown.cancel() + with suppress(asyncio.CancelledError): + await join_shielded(shutdown) + raise + + # A shutdown cancelled by an earlier close has finished at once. + if not shutdown.cancelled(): + shutdown.result() + + async def __aenter__(self) -> Self: + """Start listening. + + Raises: + RuntimeError: The server has already been started or closed. + OSError: The address cannot be bound. + ValueError: A host name with port 0 would listen on several + ports, one per address. + """ + if self._started or self._closing: + raise RuntimeError("the HTTP/2 server can only be started once") + self._started = True + + # Accepting waits until the server owns the listener. + listener, address = await create_listener( + self._create_connection, self._host, self._port, self._ssl_context, self._ssl_handshake_timeout + ) + if self._closing: + listener.close() + await listener.wait_closed() + raise RuntimeError("the HTTP/2 server closed while it started") + + self._listener, self._address = listener, address + try: + await listener.start_serving() + except BaseException: + # No one owns the server until it has started, so a start that fails closes its listener. + self._closing = True + listener.close() + raise + + return self + + async def __aexit__( + self, exc_type: type[BaseException] | None, exc: BaseException | None, traceback: TracebackType | None + ) -> None: + # Leaving under a cancellation stops at once, whether or not the cancellation is still delivered. + if exc_type is not None and issubclass(exc_type, anyio.get_cancelled_exc_class()): + with anyio.CancelScope() as scope: + scope.cancel() + await self.aclose() + return + await self.aclose() + + def _create_connection(self) -> AioH2Connection: + return AioH2Connection( + ngh2.Role.SERVER, + self.url, + require_h2_alpn=self._ssl_context is not None, + on_connected=self._connection_connected, + on_stream=self._start_handler, + on_closed=self._connections.discard, + ) + + def _connection_connected(self, connection: AioH2Connection) -> None: + """Own an established connection, or abort one that arrives while the server shuts down, as it carries nothing.""" + if self._closing: + connection.start_close() + connection.abort() + else: + self._connections.add(connection) + + def _start_handler(self, stream: AioH2Stream) -> None: + if self._closing: + with suppress(H2Error): + stream._reset(H2ErrorCode.REFUSED_STREAM) + return + + task = asyncio.get_running_loop().create_task(self._run_handler(stream)) + self._handlers.add(task) + task.add_done_callback(self._handlers.discard) + + async def _run_handler(self, stream: AioH2Stream) -> None: + """Run the handler for one stream, resetting the stream if the handler leaves it unfinished.""" + try: + async with stream: + # The handler is cancelled alone when its stream is aborted, in a scope so that its shields hold. + # The scope is made in the task: outside one, AnyIO may not tell which event loop runs. + with anyio.CancelScope() as scope: + stream._on_abort = scope.cancel + await self.handler(stream) + except H2Error: + pass + except Exception: + _logger.exception("The HTTP/2 stream handler failed") + + async def _shut_down(self) -> None: + listener = self._listener + try: + async with anyio.create_task_group() as task_group: + if listener is not None: + listener_waiting = anyio.Event() + loop = asyncio.get_running_loop() + + async def wait_for_listener() -> None: + # Started before close: older asyncio versions stop tracking clients once the listener closes. + # The callback runs only after wait_closed() reaches its first suspension. + loop.call_soon(listener_waiting.set) + await listener.wait_closed() + + task_group.start_soon(wait_for_listener) + await listener_waiting.wait() + listener.close() + + for connection in tuple(self._connections): + connection.announce_shutdown() + + await wait_then_cancel(self._handlers, self._shutwait) + + # Each closes once its queued responses are written, or aborts after a grace period. + async with anyio.create_task_group() as closing: + for connection in tuple(self._connections): + closing.start_soon(connection.aclose) + + if listener is not None: + abort_handshakes(listener) + except BaseException: + # Cancelled: the listener and the connections still open close at once. + if listener is not None: + listener.close() + abort_handshakes(listener) + for connection in tuple(self._connections): + connection.abort() + with release_shield(): + if self._handlers: + await asyncio.wait(tuple(self._handlers)) + for connection in tuple(self._connections): + await connection.wait_closed() + raise diff --git a/src/dubbo/transport/h2/aio/stream.py b/src/dubbo/transport/h2/aio/stream.py new file mode 100644 index 00000000..ba05f26e --- /dev/null +++ b/src/dubbo/transport/h2/aio/stream.py @@ -0,0 +1,426 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +from collections import deque +from collections.abc import Callable +from types import TracebackType +from typing import TYPE_CHECKING, Self + +from dubbo.transport.h2.base import H2ErrorCode, H2Headers, H2Stream +from dubbo.transport.h2.exceptions import H2Error, H2StreamError + +if TYPE_CHECKING: + from .connection import AioH2Connection + +__all__ = ["AioH2Stream"] + + +class AioH2Stream(H2Stream): + """One asyncio-backed HTTP/2 stream. + + The stream keeps its own state. It queues frames through its connection, + which hands it incoming headers, data and trailers through the ``_on_*`` + methods, synchronously on the connection's event loop. Sending and + receiving may overlap, but two operations in the same direction are + rejected by the guards. Every operation must stay on that event loop. + + Cancelling an outbound operation after ngh2 accepts it resets the stream + with `H2ErrorCode.CANCEL` before propagating `asyncio.CancelledError`. + Cancelling a receive leaves the stream usable; an exact receive puts the + bytes it collected back at the front, without returning their window + credit again. Backend and engine failures are exposed through Dubbo's H2 + exception hierarchy. + + Obtained from `AioH2Client.open_stream` or a server handler. + """ + + def __init__( + self, + connection: "AioH2Connection", + stream_id: int, + *, + headers_sent: bool, + send_ended: bool = False, + headers: H2Headers | None = None, + receive_ended: bool = False, + ) -> None: + self._connection = connection + self._stream_id = stream_id + + self._headers_sent = headers_sent + self._send_ended = send_ended + self._send_guard = _StreamOperationGuard(stream_id, "sending on") + + self._inbound_headers = headers + self._inbound_trailers: H2Headers | None = None + self._inbound_chunks: deque[bytes] = deque() + self._chunk_offset = 0 + # Bytes at the front of the queue whose window credit has already been returned. + self._credited = 0 + self._receive_ended = receive_ended + self._receive_guard = _StreamOperationGuard(stream_id, "receiving from") + + self._closed = False + self._failure: H2Error | None = None + # Set when the peer stops the local direction but leaves its own readable. + self._send_failure: H2Error | None = None + # Set once the context closes; nothing reads the stream after that. + self._released = False + # Called once when the peer resets the stream or the connection fails. + self._on_abort: Callable[[], object] | None = None + + # Set by the task waiting in that direction; whoever wakes it clears it. + self._receive_waiter: asyncio.Future[None] | None = None + self._send_waiter: asyncio.Future[None] | None = None + + @property + def stream_id(self) -> int: + return self._stream_id + + @property + def peer(self) -> str | None: + return self._connection.peer + + async def send_headers(self, headers: H2Headers, *, end_stream: bool = False) -> None: + with self._send_guard: + self._raise_if_failed() + if self._headers_sent: + raise H2StreamError("initial headers were already sent", stream_id=self._stream_id) + + self._connection.send_response(self._stream_id, headers, end_stream=end_stream) + # The engine has accepted the frame; it cannot be taken back. + self._headers_sent = True + self._send_ended = end_stream + await self._wait_writable() + + async def send_data(self, data: bytes, *, end_stream: bool = False) -> None: + with self._send_guard: + self._check_sendable() + + self._connection.send_data(self._stream_id, data, end_stream=end_stream) + self._send_ended = end_stream + await self._wait_writable() + + async def send_trailers(self, trailers: H2Headers) -> None: + with self._send_guard: + self._check_sendable() + + self._connection.send_trailers(self._stream_id, trailers) + self._send_ended = True + await self._wait_writable() + + async def end(self) -> None: + with self._send_guard: + if self._send_failure is not None: + raise self._send_failure + if self._send_ended: + return + + self._raise_if_failed() + self._connection.end_stream(self._stream_id) + self._send_ended = True + await self._wait_writable() + + async def receive_headers(self) -> H2Headers: + with self._receive_guard: + while self._inbound_headers is None: + self._raise_if_failed() + if self._receive_ended: + raise H2StreamError( + "peer ended the stream before sending headers", + stream_id=self._stream_id, + ) + await self._wait_to_receive() + + return self._inbound_headers + + async def receive_data(self, max_bytes: int = 64 * 1024) -> bytes: + if max_bytes <= 0: + raise ValueError("max_bytes must be positive") + + with self._receive_guard: + while not self._inbound_chunks: + self._raise_if_failed() + if self._receive_ended: + return b"" + await self._wait_to_receive() + + return self._take_data(max_bytes) + + async def receive_data_exactly(self, nbytes: int) -> bytes: + if nbytes < 0: + raise ValueError("nbytes must not be negative") + + with self._receive_guard: + chunks = self._inbound_chunks + if nbytes == 0 or (chunks and len(chunks[0]) - self._chunk_offset >= nbytes): + return self._take_data(nbytes) if nbytes else b"" + + parts: list[bytes] = [] + remaining = nbytes + try: + while remaining: + while not chunks: + self._raise_if_failed() + if self._receive_ended: + return b"".join(parts) + await self._wait_to_receive() + + part = self._take_data(remaining) + parts.append(part) + remaining -= len(part) + except asyncio.CancelledError: + if parts: + self._put_back(b"".join(parts)) + raise + + return b"".join(parts) + + async def receive_trailers(self) -> H2Headers | None: + with self._receive_guard: + while not self._receive_ended: + self._raise_if_failed() + await self._wait_to_receive() + + self._raise_if_failed() + return self._inbound_trailers + + async def reset(self, error_code: int = H2ErrorCode.CANCEL) -> None: + if not 0 <= error_code <= 0xFFFFFFFF: + raise ValueError("error_code must fit an unsigned 32-bit integer") + + if self._finished: + return + + # Reset is cleanup and must remain available while another operation unwinds. + self._reset(error_code) + + async def __aenter__(self) -> Self: + return self + + async def __aexit__( + self, + exc_type: type[BaseException] | None, + exc_value: BaseException | None, + traceback: TracebackType | None, + ) -> None: + self._released = True + try: + # Return connection-level credit before reset drops the stream state. + self._connection.consume(self._stream_id, self._drop_unread()) + if self._finished: + return + if self._send_ended and self._connection.is_server: + # RFC 9113 section 8.1: a server stops a request it no longer reads with NO_ERROR. + self._connection.reset_stream(self._stream_id, H2ErrorCode.NO_ERROR, after_end_stream=True) + else: + self._reset(H2ErrorCode.CANCEL) + except H2Error: + if exc_value is None: + raise + + @property + def _finished(self) -> bool: + """Return whether both directions no longer require cleanup.""" + return self._closed or (self._send_ended and self._receive_ended) + + def _raise_if_failed(self) -> None: + """Raise the stream failure, or an active connection failure.""" + if self._failure is not None: + raise self._failure + if not self._closed: + # A normally closed stream may still expose data buffered before GOAWAY. + self._connection.raise_if_failed() + + def _raise_if_send_failed(self) -> None: + """Raise a failure of the stream or of its local direction alone.""" + self._raise_if_failed() + if self._send_failure is not None: + raise self._send_failure + + def _check_sendable(self) -> None: + self._raise_if_send_failed() + if self._send_ended: + raise H2StreamError("local stream direction is closed", stream_id=self._stream_id) + + async def _wait_writable(self) -> None: + """Wait for the connection to take more output, resetting the stream if cancelled.""" + try: + await self._connection.wait_writable(self) + except asyncio.CancelledError: + self._reset_after_cancel() + raise + + def _reset(self, error_code: int) -> None: + """Reset the stream locally after returning its unread credit.""" + self._connection.consume(self._stream_id, self._drop_unread()) + self._connection.reset_stream(self._stream_id, error_code) + self._fail(H2StreamError("the HTTP/2 stream was reset locally", stream_id=self._stream_id)) + + def _reset_after_cancel(self) -> None: + """Reset after cancellation without replacing that exception.""" + try: + self._reset(H2ErrorCode.CANCEL) + except H2Error: + self._fail(H2StreamError("the HTTP/2 stream operation was cancelled", stream_id=self._stream_id)) + + def _take_data(self, max_bytes: int) -> bytes: + """Take at most max_bytes without copying a whole queued chunk, returning their window credit.""" + chunk = self._inbound_chunks[0] + available = len(chunk) - self._chunk_offset + if available <= max_bytes: + self._inbound_chunks.popleft() + data = chunk if self._chunk_offset == 0 else chunk[self._chunk_offset :] + self._chunk_offset = 0 + else: + end = self._chunk_offset + max_bytes + data = chunk[self._chunk_offset : end] + self._chunk_offset = end + + # Window credit follows application consumption, not socket reception. + credit = len(data) + if self._credited: + returned = min(self._credited, credit) + self._credited -= returned + credit -= returned + self._connection.consume(self._stream_id, credit) + return data + + def _put_back(self, data: bytes) -> None: + """Queue ``data`` taken from the front of the input in front again, its window credit kept returned.""" + chunks = self._inbound_chunks + if self._chunk_offset: + chunks[0] = chunks[0][self._chunk_offset :] + self._chunk_offset = 0 + chunks.appendleft(data) + self._credited += len(data) + + def _drop_unread(self) -> int: + """Drop queued input and return how many bytes were never read.""" + amount = sum(map(len, self._inbound_chunks)) - self._chunk_offset - self._credited + self._inbound_chunks.clear() + self._chunk_offset = 0 + self._credited = 0 + return amount + + # Waiting and waking. Checking state and starting to wait happen without + # an await in between, so no wakeup is lost. + + # One task at most waits in each direction, so a plain future serves it; + # cancelling that task cancels only its own future. + + async def _wait_to_receive(self) -> None: + waiter = self._receive_waiter = asyncio.get_running_loop().create_future() + await waiter + + async def _wait_to_send(self) -> None: + waiter = self._send_waiter = asyncio.get_running_loop().create_future() + await waiter + + def _wake_receiver(self) -> None: + waiter = self._receive_waiter + if waiter is not None: + self._receive_waiter = None + if not waiter.done(): + waiter.set_result(None) + + def _wake_sender(self) -> None: + waiter = self._send_waiter + if waiter is not None: + self._send_waiter = None + if not waiter.done(): + waiter.set_result(None) + + def _wake(self) -> None: + self._wake_receiver() + self._wake_sender() + + # Called by the connection as frames arrive or the stream ends. + + def _on_headers(self, headers: H2Headers, *, end_stream: bool) -> None: + self._inbound_headers = headers + self._receive_ended = self._receive_ended or end_stream + self._wake_receiver() + + def _on_data(self, data: bytes, *, end_stream: bool) -> None: + if data: + self._inbound_chunks.append(data) + self._receive_ended = self._receive_ended or end_stream + self._wake_receiver() + + def _on_trailers(self, trailers: H2Headers) -> None: + self._inbound_trailers = trailers + self._receive_ended = True + self._wake_receiver() + + def _on_closed(self) -> None: + """Record that both directions ended normally.""" + self._closed = True + self._send_ended = True + self._receive_ended = True + self._wake() + + def _stop_sending(self, error: H2Error) -> None: + """Fail the local direction with ``error``, keeping what the peer sent readable.""" + self._send_failure = error + self._send_ended = True + self._wake() + + def _abort(self, error: H2Error) -> None: + """Fail the stream for a cause on the peer's side or the connection's, and report it once. + + The report comes first, so that what it cancels sees the cancellation before the failure. + """ + on_abort, self._on_abort = self._on_abort, None + if on_abort is not None: + on_abort() + self._fail(error) + + def _fail(self, error: H2Error) -> None: + """Keep the first failure, stop further operations and wake both directions.""" + if self._failure is None: + self._failure = error + self._closed = True + self._wake() + + +class _StreamOperationGuard: + """Rejects overlapping operations instead of hiding them behind a lock.""" + + __slots__ = ("_action", "_busy", "_stream_id") + + def __init__(self, stream_id: int, action: str) -> None: + self._stream_id = stream_id + self._action = action + self._busy = False + + def __enter__(self) -> None: + if self._busy: + raise H2StreamError( + f"another task is already {self._action} this stream", + stream_id=self._stream_id, + ) + self._busy = True + + def __exit__( + self, + exc_type: type[BaseException] | None, + exc_value: BaseException | None, + traceback: TracebackType | None, + ) -> None: + self._busy = False diff --git a/src/dubbo/transport/h2/aio/tasks.py b/src/dubbo/transport/h2/aio/tasks.py new file mode 100644 index 00000000..93f52566 --- /dev/null +++ b/src/dubbo/transport/h2/aio/tasks.py @@ -0,0 +1,41 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio + +import anyio + +__all__ = ["join_shielded"] + + +async def join_shielded(task: asyncio.Task[None]) -> None: + """Wait until ``task`` finishes even when the caller is cancelled, then raise that cancellation or its error. + + AnyIO cancellation stays out while waiting, and `asyncio.Task.cancel` on the + caller is held until ``task`` is done; ``task`` itself is never cancelled. + """ + cancelled = False + with anyio.CancelScope(shield=True): + while not task.done(): + try: + await asyncio.wait((task,)) + except asyncio.CancelledError: + cancelled = True + + if cancelled: + raise asyncio.CancelledError + task.result() diff --git a/src/dubbo/transport/h2/base.py b/src/dubbo/transport/h2/base.py new file mode 100644 index 00000000..73fc6d96 --- /dev/null +++ b/src/dubbo/transport/h2/base.py @@ -0,0 +1,417 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from collections.abc import Awaitable, Callable +from enum import IntEnum +from types import TracebackType +from typing import Self, TypeAlias + +from dubbo.extension import Resource, extension_point +from dubbo.url import URL + +__all__ = [ + "H2Client", + "H2ErrorCode", + "H2Header", + "H2Headers", + "H2Server", + "H2Stream", + "H2StreamHandler", +] + +# A lowercase HTTP/2 field name and its raw value. +H2Header: TypeAlias = tuple[bytes, bytes] +# An ordered field section; repeated field names remain separate entries. +H2Headers: TypeAlias = tuple[H2Header, ...] + + +class H2ErrorCode(IntEnum): + """The HTTP/2 error codes of RFC 9113 section 7, carried by RST_STREAM and GOAWAY. + + Attributes: + NO_ERROR: Not the result of an error, such as a GOAWAY for a graceful shutdown. + PROTOCOL_ERROR: An unspecific protocol error. + INTERNAL_ERROR: An unexpected internal error. + FLOW_CONTROL_ERROR: The peer violated flow control. + SETTINGS_TIMEOUT: A SETTINGS frame was not acknowledged in time. + STREAM_CLOSED: A frame arrived after the stream was half-closed. + FRAME_SIZE_ERROR: A frame had an invalid size. + REFUSED_STREAM: The stream was refused before any application processing. + CANCEL: The stream is no longer needed. + COMPRESSION_ERROR: The field compression context cannot be maintained. + CONNECT_ERROR: The connection of a CONNECT request was reset or closed abnormally. + ENHANCE_YOUR_CALM: The peer behaves in a way that might generate excessive load. + INADEQUATE_SECURITY: The transport does not meet minimum security requirements. + HTTP_1_1_REQUIRED: The endpoint requires HTTP/1.1 instead of HTTP/2. + """ + + NO_ERROR = 0x00 + PROTOCOL_ERROR = 0x01 + INTERNAL_ERROR = 0x02 + FLOW_CONTROL_ERROR = 0x03 + SETTINGS_TIMEOUT = 0x04 + STREAM_CLOSED = 0x05 + FRAME_SIZE_ERROR = 0x06 + REFUSED_STREAM = 0x07 + CANCEL = 0x08 + COMPRESSION_ERROR = 0x09 + CONNECT_ERROR = 0x0A + ENHANCE_YOUR_CALM = 0x0B + INADEQUATE_SECURITY = 0x0C + HTTP_1_1_REQUIRED = 0x0D + + +class H2Stream(typing.Protocol): + """One bidirectional HTTP/2 stream. + + Callers use each direction in order: initial fields, zero or more data + operations, then trailers or an end operation. + + One send and one receive operation may be active concurrently. Starting a + second operation in the same direction before the first completes raises + `H2StreamError`; operations are never silently queued. Outbound operations + return after the connection accepts their complete input subject to flow + control and transport backpressure; they do not wait for peer processing. + + Implementations translate network-backend and HTTP/2-engine failures into + Dubbo's transport exception hierarchy. A remote reset raises + `H2StreamResetError`, while loss of the owning connection raises + `H2ConnectionError`. Once the peer ends its direction normally, receives + return what is left, then `b""`. Task cancellation propagates unchanged. + Cancelling an outbound operation after protocol submission resets the + stream before propagating cancellation. Cancelling a receive leaves the + stream usable; an exact receive puts the bytes it collected back at the + front, without returning their window credit again. Closing + the context resets a stream whose directions have not both ended, with + `H2ErrorCode.CANCEL`; a server that has ended its response instead resets + with `H2ErrorCode.NO_ERROR` once the response is written, which asks the + client to stop its request. A client keeps a whole response it received + before such a NO_ERROR reset readable; only its sends raise + `H2StreamResetError`. Data that arrives after the context closes is + discarded, and its flow-control credit released. + """ + + @property + def stream_id(self) -> int: + """The HTTP/2 stream identifier, unique on its connection.""" + ... + + @property + def peer(self) -> str | None: + """The address of the other endpoint, as ``host:port`` with an IPv6 host in brackets. + + ``None`` when the transport does not report one. + """ + ... + + async def send_headers(self, headers: H2Headers, *, end_stream: bool = False) -> None: + """Send ``headers``, the ordered initial field section; ``end_stream`` also ends the local direction. + + Client streams returned by `H2Client.open_stream` have already sent + this section. + + Raises: + H2StreamResetError: The peer reset the stream. + H2StreamError: Another send is active, initial fields were already + sent, or the field section is invalid for this stream. + H2ConnectionError: The owning connection failed or closed. + """ + ... + + async def send_data(self, data: bytes, *, end_stream: bool = False) -> None: + """Send ``data``, waiting for flow-control and transport capacity; ``end_stream`` also ends the local direction. + + Raises: + H2StreamResetError: The peer reset the stream. + H2StreamError: Another send is active, the local direction has + ended, or the operation is invalid for this stream. + H2ConnectionError: The owning connection failed or closed. + """ + ... + + async def send_trailers(self, trailers: H2Headers) -> None: + """Send ``trailers``, the ordered trailing field section, and end the local direction. + + Raises: + H2StreamResetError: The peer reset the stream. + H2StreamError: Another send is active, the local direction has + ended, or the field section is invalid for this stream. + H2ConnectionError: The owning connection failed or closed. + """ + ... + + async def end(self) -> None: + """End the local direction without trailers. + + The operation is idempotent after the local direction has ended. + + Raises: + H2StreamResetError: The peer reset the stream. + H2StreamError: Another send is active or the operation is invalid + for this stream. + H2ConnectionError: The owning connection failed or closed. + """ + ... + + async def receive_headers(self) -> H2Headers: + """Return the peer's ordered initial field section, which comes before its data. + + Raises: + H2StreamResetError: The peer reset the stream. + H2StreamError: Another receive is active or the peer ended the + stream without initial fields. + H2ConnectionError: The owning connection failed or closed. + """ + ... + + async def receive_data(self, max_bytes: int = 64 * 1024) -> bytes: + """Return one nonempty chunk of at most ``max_bytes`` application bytes, or ``b""`` once the peer has ended its direction. + + The bytes returned count as consumed for HTTP/2 flow control. + + Raises: + ValueError: ``max_bytes`` is not positive. + H2StreamResetError: The peer reset the stream. + H2StreamError: Another receive is active or the receive state is + invalid. + H2ConnectionError: The owning connection failed or closed. + """ + ... + + async def receive_data_exactly(self, nbytes: int) -> bytes: + """Return ``nbytes`` application bytes, or fewer, ``b""`` for none, once the peer has ended its direction. + + Bytes collected toward the result count as consumed for flow control + as they are taken. Cancellation puts the bytes collected so far back, + so the next receive starts with them. + + Raises: + ValueError: ``nbytes`` is negative. + H2StreamResetError: The peer reset the stream. + H2StreamError: Another receive is active or the receive state is + invalid. + H2ConnectionError: The owning connection failed or closed. + """ + ... + + async def receive_trailers(self) -> H2Headers | None: + """Return the peer's ordered trailing field section after its data, or ``None`` when it ended its direction without one. + + Raises: + H2StreamResetError: The peer reset the stream. + H2StreamError: Another receive is active or the receive state is + invalid. + H2ConnectionError: The owning connection failed or closed. + """ + ... + + async def reset(self, error_code: int = H2ErrorCode.CANCEL) -> None: + """Abort the stream with ``error_code``, a registered or extension HTTP/2 error code. + + Raises: + ValueError: ``error_code`` is outside the HTTP/2 wire range. + H2StreamError: The stream cannot be reset in its current state. + H2ConnectionError: The owning connection failed or closed. + """ + ... + + async def __aenter__(self) -> Self: + """Enter this stream's managed lifetime.""" + ... + + async def __aexit__( + self, + exc_type: type[BaseException] | None, + exc_value: BaseException | None, + traceback: TracebackType | None, + ) -> None: + """Release the stream without suppressing an active exception. + + An unfinished stream is reset and unread flow-control credit is + released. A cleanup failure is suppressed only when preserving an + exception already leaving the context. + + Raises: + H2Error: Cleanup fails and no exception is already active. + """ + ... + + +# An application coroutine invoked once for each peer-initiated stream. +H2StreamHandler: TypeAlias = Callable[[H2Stream], Awaitable[None]] + + +@extension_point("apache_dubbo.transport.h2.client", default="aio") +class H2Client(Resource, typing.Protocol): + """Reusable client-side HTTP/2 connections to one endpoint. + + The implementation is named by the ``client`` parameter, ``aio`` when + absent, and created with a URL whose host and port name the server. The + TLS parameters configure it as `dubbo.transport.tls.get_ssl_context` reads + them, and these HTTP/2 parameters each connection, for the side that sets + them: + + - ``max-concurrent-streams``: streams the peer may open at once; 100 + when absent. This side opens at most as many as the peer allows. + - ``initial-window-size``: bytes the peer may send on one stream before + it waits for more credit. When absent, the window starts at 1 MiB and + grows with the bandwidth-delay product measured on the connection, up + to 16 MiB. + - ``connection-initial-window-size``: bytes the peer may send on the + connection before it waits for more credit; 16 MiB when absent. + - ``max-header-list-size``: bytes of the largest field section accepted; + 64 KiB when absent. + - ``keep-alive-interval``: whole milliseconds without inbound traffic + before a PING checks the connection; no PING when absent. + - ``keep-alive-timeout``: whole milliseconds to wait for the PING + acknowledgement before the connection fails; 20000 when absent. + + And this one, for the client alone: + + - ``connect-timeout``: whole milliseconds to establish a connection, + the TLS handshake included; 3000 when absent. + + The client may be shared by concurrent callers. It assigns each opened + stream to a usable connection and keeps physical connection state private. + Entering it starts connecting in the background, so that `available` + tells whether the server can be reached before the first call. + Task cancellation propagates unchanged. It holds no task group or cancel + scope of the tasks that use it, so that its owner may close it from any + task. + + Attributes: + url: The URL the instance was created with. + """ + + url: URL + + def __init__(self, url: URL) -> None: + self.url = url + + @property + def available(self) -> bool: + """Whether a connection to the server is established now. + + It is false until an attempt to connect succeeds, and from a failed + attempt or a lost connection until the next succeeds, while the + client waits a backoff, longer after each failure in a row, and then + tries again. Opening a stream still tries to connect while it is + false. A client that does not say otherwise is always available. + """ + return True + + async def open_stream(self, headers: H2Headers, *, end_stream: bool = False) -> H2Stream: + """Open a stream, send ``headers``, its ordered initial field section, and return the stream. + + It waits for room for one more stream; ``end_stream`` also ends the + local direction. The stream returns once its headers have entered + the connection's bounded write path. A cancellation after the stream + is allocated resets it before propagating. + + Raises: + RuntimeError: The client is closed. + H2StreamResetError: The peer reset the newly allocated stream + before it could be returned. + H2StreamError: The initial field section is invalid for a new + stream. + H2ConnectionError: A connection cannot be established or fails + while opening the stream. + """ + ... + + async def aclose(self) -> None: + """Stop opening streams and close all owned connections. + + Each connection sends a final GOAWAY and closes once its open streams + finish, or is aborted after a grace period. A cancelled close aborts + the connections at once. Closing again waits for the close under + way; it returns once each connection has reported transport closure. + """ + ... + + +@extension_point("apache_dubbo.transport.h2.server", default="aio") +class H2Server(Resource, typing.Protocol): + """Serves HTTP/2 streams with the handler given when the server is created. + + The implementation is named by the ``server`` parameter, ``aio`` when + absent, and created with a URL whose host is the interface to bind, such + as ``0.0.0.0`` for every IPv4 interface, and whose port is 0 for an + ephemeral port. The HTTP/2 parameters of `H2Client` configure each + connection, the TLS parameters configure it as + `dubbo.transport.tls.get_ssl_context` reads them, and ``shutwait`` is the + whole milliseconds closing waits for running handlers, 10000 when absent. + + Entering the server starts listening; closing it stops. The server is + single-use and owns its listener, connections and handler tasks. Each + accepted stream runs its own handler; an ordinary handler failure resets + only that stream. When the peer resets the stream or the connection + fails, the handler is cancelled as AnyIO cancels, so that what it + shields from cancellation finishes first. + + Attributes: + url: The URL the instance was created with. + handler: The handler each accepted stream runs. + """ + + url: URL + handler: H2StreamHandler + + def __init__(self, url: URL, handler: H2StreamHandler) -> None: + self.url = url + self.handler = handler + + @property + def address(self) -> tuple[str, int]: + """The host and port actually bound, with port 0 resolved. + + Raises: + RuntimeError: The server is not listening. + """ + ... + + def announce_shutdown(self) -> None: + """Send the connections established now a GOAWAY that refuses no stream, and keep serving. + + Peers open their next streams on new connections, which the server + still accepts and serves; `aclose` stops serving. + """ + ... + + async def aclose(self) -> None: + """Stop accepting work, let running handlers finish, then release everything. + + New connections are refused at once, and established ones receive a + GOAWAY so peers open no more streams. Handlers still running when the + grace period ends are cancelled. Connections then close once the + responses they still queue are written, or are aborted after a + second. A cancelled close cancels the handlers and aborts the + connections at once. Closing again waits for the close under way. + """ + ... + + async def __aenter__(self) -> Self: + """Start listening. + + Raises: + RuntimeError: The server has already been started. + OSError: The address cannot be bound. + ValueError: A host name with port 0 would listen on several + ports, one per address. + """ + ... diff --git a/src/dubbo/transport/h2/exceptions.py b/src/dubbo/transport/h2/exceptions.py new file mode 100644 index 00000000..7dabf6a6 --- /dev/null +++ b/src/dubbo/transport/h2/exceptions.py @@ -0,0 +1,87 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from dubbo.exceptions import DubboError + +__all__ = [ + "H2ConnectionError", + "H2Error", + "H2StreamError", + "H2StreamResetError", +] + + +class H2Error(DubboError): + """A failure of the HTTP/2 transport.""" + + +class H2ConnectionError(H2Error): + """A failure to listen, to establish an HTTP/2 connection, or of the connection. + + Attributes: + error_code: The received or generated HTTP/2 error code, if known. + last_stream_id: The GOAWAY last-stream identifier, if received. + """ + + error_code: int | None + last_stream_id: int | None + + def __init__( + self, + message: str, + *, + error_code: int | None = None, + last_stream_id: int | None = None, + ) -> None: + super().__init__(message) + self.error_code = error_code + self.last_stream_id = last_stream_id + + +class H2StreamError(H2Error): + """An invalid local use of one HTTP/2 stream, or a failure confined to it. + + This includes operation ordering, overlapping use in one direction, and + stream-level protocol-engine failures. + + Attributes: + stream_id: The connection-local stream identifier. + """ + + stream_id: int + + def __init__(self, message: str, *, stream_id: int) -> None: + super().__init__(message) + self.stream_id = stream_id + + +class H2StreamResetError(H2StreamError): + """An RST_STREAM the peer sent on an HTTP/2 stream. + + Attributes: + error_code: The peer's error code. Unknown extension codes are + preserved as integers. + """ + + error_code: int + + def __init__(self, stream_id: int, error_code: int) -> None: + super().__init__( + f"the HTTP/2 stream {stream_id} was reset with error code {error_code}", + stream_id=stream_id, + ) + self.error_code = error_code diff --git a/src/dubbo/transport/listener.py b/src/dubbo/transport/listener.py new file mode 100644 index 00000000..6c8e0bf9 --- /dev/null +++ b/src/dubbo/transport/listener.py @@ -0,0 +1,67 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The asyncio listeners that servers accept connections on.""" + +import asyncio +import ssl +from collections.abc import Callable +from typing import cast + +__all__ = ["abort_handshakes", "create_listener"] + +_SEVERAL_PORTS = "the host has several addresses, which port 0 binds to different ports; use an IP address or a port" + + +async def create_listener( + create_connection: Callable[[], asyncio.BaseProtocol], + host: str, + port: int, + ssl_context: ssl.SSLContext | None, + ssl_handshake_timeout: float, +) -> tuple[asyncio.Server, tuple[str, int]]: + """Return a listener on ``host`` and ``port`` that does not serve yet, which the caller closes, and the address it is bound to. + + Raises: + OSError: The address cannot be bound. + ValueError: A host name with port 0 would listen on several ports, + one per address. + """ + listener = await asyncio.get_running_loop().create_server( + create_connection, + host, + port, + ssl=ssl_context, + ssl_handshake_timeout=ssl_handshake_timeout if ssl_context is not None else None, + start_serving=False, + ) + + addresses = [listening.getsockname() for listening in listener.sockets] + if len({address[1] for address in addresses}) > 1: + listener.close() + await listener.wait_closed() + raise ValueError(_SEVERAL_PORTS) + return listener, (cast(str, addresses[0][0]), cast(int, addresses[0][1])) + + +def abort_handshakes(listener: asyncio.Server) -> None: + """Abort the transports of ``listener`` still in a TLS handshake, which never became connections and which closing it waits for.""" + # shortcut: CPython before 3.13 and uvloop have no abort_clients, so there a handshake under way outlives the + # close by up to the handshake timeout; abort those transports directly if that ever matters. + abort_clients = getattr(listener, "abort_clients", None) + if abort_clients is not None: + abort_clients() diff --git a/src/dubbo/transport/nacos/__init__.py b/src/dubbo/transport/nacos/__init__.py new file mode 100644 index 00000000..46e51709 --- /dev/null +++ b/src/dubbo/transport/nacos/__init__.py @@ -0,0 +1,36 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .base import ( + DEFAULT_GROUP, + NacosConfigClient, + NacosInstance, + NacosNamingClient, + get_nacos_config_client, + get_nacos_naming_client, +) +from .exceptions import NacosError + +__all__ = [ + "DEFAULT_GROUP", + "NacosConfigClient", + "NacosError", + "NacosInstance", + "NacosNamingClient", + "get_nacos_config_client", + "get_nacos_naming_client", +] diff --git a/src/dubbo/transport/nacos/base.py b/src/dubbo/transport/nacos/base.py new file mode 100644 index 00000000..2589d5f8 --- /dev/null +++ b/src/dubbo/transport/nacos/base.py @@ -0,0 +1,228 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from collections.abc import AsyncIterator, Callable, Mapping +from contextlib import AbstractAsyncContextManager +from typing import Any, Self, TypeVar + +import attrs + +from dubbo.constants import ACCESS_KEY_KEY, BACKUP_KEY, CLIENT_KEY, NAMESPACE_KEY, SECRET_KEY_KEY +from dubbo.extension import Resource, extension_point, extensions +from dubbo.url import URL +from dubbo.utils import freeze_mapping + +__all__ = [ + "DEFAULT_GROUP", + "NacosConfigClient", + "NacosInstance", + "NacosNamingClient", + "get_nacos_config_client", + "get_nacos_naming_client", +] + +C = TypeVar("C", bound=Resource) + +DEFAULT_GROUP = "DEFAULT_GROUP" # The group of a service or configuration that names none, as Nacos has it. + + +@attrs.define(frozen=True, kw_only=True) +class NacosInstance: + """One instance of a Nacos service. + + Attributes: + host: Address of the instance. + port: Port of the instance. + metadata: Text the instance carries, such as the parameters of a URL. + """ + + host: str + port: int + metadata: Mapping[str, str] = attrs.field(factory=dict, converter=freeze_mapping, hash=False) + + +@extension_point("apache_dubbo.transport.nacos.naming", default="sdk") +class NacosNamingClient(Resource, typing.Protocol): + """Register and watch the instances of services in one Nacos namespace. + + The implementation is created with a registry URL and reads only its + connection part: the host and port, 8848 if absent, then the + ``host[:port]`` entries of ``backup``; ``namespace``, the public + namespace if absent; the user and password, or ``accessKey`` and + ``secretKey``; and ``timeout`` for each operation, in milliseconds. + Service names and groups are stored with ``$`` as ``___``. + + Entering ``async with`` connects, and closing disconnects, which removes + the instances the client registered. Operations fail with ``NacosError`` + when the server is unreachable, times out or refuses them. + + Attributes: + url: The URL the instance was created with. + """ + + url: URL + + def __init__(self, url: URL) -> None: + self.url = url + + def keep_registered(self, service: str, group: str, instance: NacosInstance) -> AbstractAsyncContextManager[None]: + """Keep ``instance`` of ``service`` in ``group`` registered until the context exits. + + Entering registers the instance, replacing one at the same host and + port, and exiting removes it, unless a later keeper at the address + has replaced it meanwhile. The instance is ephemeral: it stays + registered while the client is open, including after the connection + is lost and found again. Entering is all or nothing: one that fails + leaves registered what was before, as far as the server allows. An + exit that is cancelled leaves the instance to the connection, which + removes it as the client closes. + """ + ... + + def watch(self, service: str, group: str) -> AbstractAsyncContextManager[AsyncIterator[list[NacosInstance]]]: + """Watch the healthy, enabled instances of ``service`` in ``group`` until the context exits. + + The iterator yields the current instances first, then the instances + after each change, including when none are left. Changes made while + the consumer is busy may be skipped, but the latest is always + yielded. Only entering can fail, with ``NacosError``: after it the + iterator neither raises nor ends until the context exits. + """ + ... + + async def aclose(self) -> None: + """Disconnect from the server.""" + ... + + async def __aenter__(self) -> Self: + """Connect to the server.""" + ... + + +@extension_point("apache_dubbo.transport.nacos.config", default="sdk") +class NacosConfigClient(Resource, typing.Protocol): + """Read, write and watch the configurations in one Nacos namespace. + + The implementation is created with a configuration center or metadata + report URL and reads only its connection part, as `NacosNamingClient` + does. Data ids and groups are stored with ``$`` as ``___`` and ``/`` as + ``-``. + + Entering ``async with`` connects, and closing disconnects. Operations + fail with ``NacosError`` when the server is unreachable, times out or + refuses them. + + Attributes: + url: The URL the instance was created with. + """ + + url: URL + + def __init__(self, url: URL) -> None: + self.url = url + + async def get(self, data_id: str, group: str) -> str | None: + """Return the content of ``data_id`` in ``group``, or ``None`` if it does not exist.""" + ... + + async def update(self, data_id: str, group: str, change: Callable[[str | None], str]) -> None: + """Replace the content of ``data_id`` in ``group`` with ``change`` of its content. + + ``change`` receives ``None`` while the configuration does not exist. + When another client writes it in between, ``change`` runs again on + the new content. Content that ``change`` returns unchanged is not + written. + """ + ... + + def watch(self, data_id: str, group: str) -> AbstractAsyncContextManager[AsyncIterator[str | None]]: + """Watch the content of ``data_id`` in ``group`` until the context exits. + + The iterator yields the current content first, then the content after + each change, with ``None`` while it does not exist. Changes made while + the consumer is busy may be skipped, but the latest is always yielded. + Only entering can fail, with ``NacosError``: after it the iterator + neither raises nor ends until the context exits. + """ + ... + + async def aclose(self) -> None: + """Disconnect from the server.""" + ... + + async def __aenter__(self) -> Self: + """Connect to the server.""" + ... + + +async def get_nacos_naming_client(url: URL) -> NacosNamingClient: + """Return the naming client of the Nacos namespace ``url`` names, the same for the same connection in its application. + + The ``client`` parameter names the implementation, ``sdk`` if absent, + installed with ``apache-dubbo[nacos]``. The application of + ``url.scope`` connects it on first use and disconnects it when it stops. + URLs that differ only in ``timeout`` share it, with the ``timeout`` of + the first. + + Raises: + ValueError: The URL has no host, or ``timeout`` is not positive + whole milliseconds. + ExtensionError: No implementation has the name in ``client``. + NacosError: The server cannot be reached. + RuntimeError: ``url`` belongs to no running application. + """ + return await _share(NacosNamingClient, url) + + +async def get_nacos_config_client(url: URL) -> NacosConfigClient: + """Return the configuration client of the Nacos namespace ``url`` names, the same for the same connection in its application. + + The ``client`` parameter names the implementation, ``sdk`` if absent, + installed with ``apache-dubbo[nacos]``. The application of + ``url.scope`` connects it on first use and disconnects it when it stops. + URLs that differ only in ``timeout`` share it, with the ``timeout`` of + the first. + + Raises: + ValueError: The URL has no host, or ``timeout`` is not positive + whole milliseconds. + ExtensionError: No implementation has the name in ``client``. + NacosError: The server cannot be reached. + RuntimeError: ``url`` belongs to no running application. + """ + return await _share(NacosConfigClient, url) + + +async def _share(point: type[C], url: URL) -> C: + if url.host is None: + raise ValueError(f"a Nacos client needs a host: {url}") + + implementation: Any = extensions.get(point, url.parameters.get(CLIENT_KEY)) + parameters = url.parameters + key = ( + implementation, + url.host, + url.port, + parameters.get(BACKUP_KEY), + parameters.get(NAMESPACE_KEY), + url.username, + url.password, + parameters.get(ACCESS_KEY_KEY), + parameters.get(SECRET_KEY_KEY), + ) + return await url.scope.share(key, lambda: implementation(url)) diff --git a/src/dubbo/transport/nacos/exceptions.py b/src/dubbo/transport/nacos/exceptions.py new file mode 100644 index 00000000..32fe01cf --- /dev/null +++ b/src/dubbo/transport/nacos/exceptions.py @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from dubbo.exceptions import DubboError + +__all__ = ["NacosError"] + + +class NacosError(DubboError): + """A Nacos operation failed: the server is unreachable, timed out or refused it. + + The error of the client library is kept as ``__cause__``. + """ diff --git a/src/dubbo/transport/nacos/sdk/__init__.py b/src/dubbo/transport/nacos/sdk/__init__.py new file mode 100644 index 00000000..86150dfc --- /dev/null +++ b/src/dubbo/transport/nacos/sdk/__init__.py @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .config import SdkNacosConfigClient +from .naming import SdkNacosNamingClient + +__all__ = ["SdkNacosConfigClient", "SdkNacosNamingClient"] diff --git a/src/dubbo/transport/nacos/sdk/config.py b/src/dubbo/transport/nacos/sdk/config.py new file mode 100644 index 00000000..0296875c --- /dev/null +++ b/src/dubbo/transport/nacos/sdk/config.py @@ -0,0 +1,145 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import hashlib +import random +from collections.abc import AsyncGenerator, AsyncIterator, Callable +from contextlib import asynccontextmanager +from typing import Self + +import anyio + +from dubbo.url import URL +from dubbo.utils import Latest, require_optional_dependency + +from ..base import NacosConfigClient +from ..exceptions import NacosError +from .connection import call, client_config, release + +with require_optional_dependency("v2.nacos", extra="nacos"): + from v2.nacos import ConfigParam, NacosConfigService, NacosException + +__all__ = ["SdkNacosConfigClient"] + + +# A compare-and-set is tried 10 times, waiting up to 100 ms at random in between. +_CAS_TRIES = 10 +_CAS_WAIT = 0.1 # Seconds. +# The compare-and-set MD5 that stands for a configuration that does not exist. +_MISSING_MD5 = "0" + + +class SdkNacosConfigClient(NacosConfigClient): + """A ``NacosConfigClient`` backed by the configuration service of nacos-sdk-python, the official client. + + The SDK reconnects by itself, and then watches again. + """ + + def __init__(self, url: URL) -> None: + super().__init__(url) + self._settings = client_config(url) + self._config: NacosConfigService | None = None + + async def get(self, data_id: str, group: str) -> str | None: + config = self._connected() + + return await self._read(config, _name(data_id), _name(group)) + + async def update(self, data_id: str, group: str, change: Callable[[str | None], str]) -> None: + config = self._connected() + data_id, group = _name(data_id), _name(group) + + for tries_left in reversed(range(_CAS_TRIES)): + current = await self._read(config, data_id, group) + content = change(current) + if content == current: + return + + expected = hashlib.md5(current.encode()).hexdigest() if current else _MISSING_MD5 + param = ConfigParam(data_id=data_id, group=group, content=content, cas_md5=expected) + try: + if await config.publish_config(param): + return + except NacosException as error: + if not tries_left: + raise NacosError(f"cannot write {data_id}: {error}") from error + await anyio.sleep(random.uniform(0, _CAS_WAIT)) + + raise NacosError(f"cannot write {data_id}: it kept changing") + + @asynccontextmanager + async def watch(self, data_id: str, group: str) -> AsyncGenerator[AsyncIterator[str | None]]: + config = self._connected() + latest: Latest[str | None] = Latest() + + async def changed(_tenant: str, _group: str, _data_id: str, content: str | None) -> None: + latest.publish(content or None) + + data_id, group = _name(data_id), _name(group) + try: + await call(config.add_listener(data_id, group, changed), f"watch {data_id}") + # The SDK calls back only on a change. + latest.publish(await self._read(config, data_id, group)) + yield aiter(latest) + finally: + await release(config.remove_listener(data_id, group, changed), f"stop watching {data_id} in Nacos") + + async def aclose(self) -> None: + config, self._config = self._config, None + if config is not None: + await release(_shut_down(config), f"disconnect from Nacos at {self.url.address} cleanly") + + async def __aenter__(self) -> Self: + # The service, whose tasks run from the start, is kept before connecting, so that a start that fails or + # is cancelled shuts them down. + config = NacosConfigService(self._settings) + try: + await call(config.grpc_client_proxy.start(), f"connect to Nacos at {self.url.address}") + except BaseException: + await release(_shut_down(config), f"disconnect from Nacos at {self.url.address} cleanly") + raise + + self._config = config + return self + + def _connected(self) -> NacosConfigService: + if self._config is None: + raise RuntimeError("the Nacos configuration client is not connected") + return self._config + + @staticmethod + async def _read(config: NacosConfigService, data_id: str, group: str) -> str | None: + content = await call(config.get_config(ConfigParam(data_id=data_id, group=group)), f"read {data_id}") + # nacos-sdk-python 3.2.0 answers a failed read with the (content, key) pair of its local cache. + if isinstance(content, tuple): + content = content[0] + if not content: + raise NacosError(f"cannot read {data_id}: the server failed and the local cache holds nothing") + + # The SDK returns an empty text for a configuration that does not exist, which Nacos never stores. + return content or None + + +def _name(name: str) -> str: + return name.replace("$", "___").replace("/", "-") + + +async def _shut_down(service: NacosConfigService) -> None: + # nacos-sdk-python 3.2.0 stops its listen task by a flag it reads every five seconds, and waits for it; the task + # ends at once when cancelled. + service.grpc_client_proxy.listen_task.cancel() + await service.shutdown() diff --git a/src/dubbo/transport/nacos/sdk/connection.py b/src/dubbo/transport/nacos/sdk/connection.py new file mode 100644 index 00000000..f5ffa022 --- /dev/null +++ b/src/dubbo/transport/nacos/sdk/connection.py @@ -0,0 +1,100 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""What the naming and configuration clients of the SDK share: their settings, errors and disconnection.""" + +import logging +from collections.abc import Awaitable +from typing import TypeVar + +from dubbo.constants import ACCESS_KEY_KEY, BACKUP_KEY, NAMESPACE_KEY, SECRET_KEY_KEY, TIMEOUT_KEY +from dubbo.url import URL +from dubbo.utils import release_scope, require_optional_dependency +from dubbo.utils.converters import comma_separated, milliseconds +from dubbo.utils.net import format_address, split_address + +from ..exceptions import NacosError + +with require_optional_dependency("v2.nacos", extra="nacos"): + from v2.nacos import ClientConfig, NacosException + +__all__ = ["call", "client_config", "release"] + +T = TypeVar("T") + +_logger = logging.getLogger(__name__) + +_DEFAULT_PORT = 8848 +_CLOSE_TIMEOUT = 10.0 # Seconds. + + +def client_config(url: URL) -> ClientConfig: + """Return the settings of an SDK client of the connection ``url`` names. + + Raises: + ValueError: ``timeout`` is not positive whole milliseconds. + """ + parameters = url.parameters + timeout = url.get_parameter(TIMEOUT_KEY, milliseconds, None) + if timeout is not None and timeout <= 0: + raise ValueError(f"URL parameter {TIMEOUT_KEY!r} must be positive") + + servers = [ + format_address(url.host or "", url.port or _DEFAULT_PORT), + *map(_with_port, comma_separated(parameters.get(BACKUP_KEY, ""))), + ] + config = ClientConfig( + server_addresses=",".join(servers), + namespace_id=parameters.get(NAMESPACE_KEY, ""), + username=url.username, + password=url.password, + access_key=parameters.get(ACCESS_KEY_KEY), + secret_key=parameters.get(SECRET_KEY_KEY), + ) + # Otherwise the SDK keeps the last instances of a service when none are left. + config.update_cache_when_empty = True + # The SDK reads its disk cache at start in a task that no one owns, and that leaves a file open when cut short. + config.load_cache_at_start = False + if timeout is not None: + config.timeout_ms = config.grpc_config.grpc_timeout = round(timeout * 1000) + return config + + +async def call(operation: Awaitable[T], action: str) -> T: + """Return the result of the SDK ``operation``, raising its failure as a `NacosError` that names ``action``.""" + try: + return await operation + except NacosException as error: + raise NacosError(f"cannot {action}: {error}") from error + + +async def release(operation: Awaitable[object], action: str) -> None: + """Await ``operation``, which releases what the SDK holds, logging a failure. + + It waits at most ten seconds, or a moment once the caller is cancelled, + as `dubbo.utils.release_scope` bounds it, then gives up. + """ + with release_scope(_CLOSE_TIMEOUT): + try: + await operation + except Exception: + _logger.warning("Cannot %s", action, exc_info=True) + + +def _with_port(address: str) -> str: + host, port = split_address(address) + return format_address(host, port or _DEFAULT_PORT) diff --git a/src/dubbo/transport/nacos/sdk/naming.py b/src/dubbo/transport/nacos/sdk/naming.py new file mode 100644 index 00000000..b69a4ca4 --- /dev/null +++ b/src/dubbo/transport/nacos/sdk/naming.py @@ -0,0 +1,213 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +from collections.abc import AsyncGenerator, AsyncIterator, Iterable +from contextlib import asynccontextmanager +from typing import Self + +import anyio + +from dubbo.url import URL +from dubbo.utils import Latest, require_optional_dependency + +from ..base import NacosInstance, NacosNamingClient +from ..exceptions import NacosError +from .connection import call, client_config, release + +with require_optional_dependency("v2.nacos", extra="nacos"): + from v2.nacos import ( + BatchRegisterInstanceParam, + DeregisterInstanceParam, + Instance, + ListInstanceParam, + NacosNamingService, + RegisterInstanceParam, + SubscribeServiceParam, + ) + +__all__ = ["SdkNacosNamingClient"] + + +class SdkNacosNamingClient(NacosNamingClient): + """A ``NacosNamingClient`` backed by the naming service of nacos-sdk-python, the official client. + + The SDK reconnects by itself, and then registers its instances and + watches again. Nacos keeps one registration of a service for each + connection, which a later one replaces, so the instances of a service at + several addresses register together. An instance kept again at its + address, as with other metadata, replaces the one there, whose keeper + then leaves it on exiting. + """ + + def __init__(self, url: URL) -> None: + super().__init__(url) + self._config = client_config(url) + self._naming: NacosNamingService | None = None + # The instances registered of each service and group, by host and port, and the keeper of each. + self._registered: dict[tuple[str, str], dict[tuple[str, int], RegisterInstanceParam]] = {} + self._keepers: dict[tuple[tuple[str, str], tuple[str, int]], object] = {} + self._registering = anyio.Lock() + + @asynccontextmanager + async def keep_registered(self, service: str, group: str, instance: NacosInstance) -> AsyncGenerator[None]: + key = (_name(service), _name(group)) + address = (instance.host, instance.port) + keeper = object() + + await self._register(key, service, instance) + self._keepers[key, address] = keeper + try: + yield + finally: + # Taken before deregistering, so that a cancelled exit still leaves the instance to the connection. + if self._keepers.get((key, address)) is keeper: + del self._keepers[key, address] + await self._deregister(key, service, instance) + + @asynccontextmanager + async def watch(self, service: str, group: str) -> AsyncGenerator[AsyncIterator[list[NacosInstance]]]: + naming = self._connected() + latest: Latest[list[NacosInstance]] = Latest() + + async def changed(instances: list[Instance] | None) -> None: + latest.publish(_instances(instances)) + + service_name, group_name = _name(service), _name(group) + param = SubscribeServiceParam(service_name=service_name, group_name=group_name, subscribe_callback=changed) + try: + await call(naming.subscribe(param), f"watch {service}") + # The SDK calls back only on a change, which a service already watched may not have. + listed = ListInstanceParam(service_name=service_name, group_name=group_name, healthy_only=None) + latest.publish(_instances(await call(naming.list_instances(listed), f"list {service}"))) + yield aiter(latest) + finally: + await release(naming.unsubscribe(param), f"stop watching {service} in Nacos") + + async def aclose(self) -> None: + naming, self._naming = self._naming, None + self._registered = {} + self._keepers = {} + if naming is not None: + await release(_shut_down(naming), f"disconnect from Nacos at {self.url.address} cleanly") + + async def __aenter__(self) -> Self: + # The service is kept before connecting, so that a start that fails or is cancelled shuts it down. + naming = NacosNamingService(self._config) + try: + await call(naming.grpc_client_proxy.start(), f"connect to Nacos at {self.url.address}") + except BaseException: + await release(_shut_down(naming), f"disconnect from Nacos at {self.url.address} cleanly") + raise + + self._naming = naming + return self + + async def _register(self, key: tuple[str, str], service: str, instance: NacosInstance) -> None: + naming = self._connected() + param = RegisterInstanceParam( + ip=instance.host, + port=instance.port, + metadata=dict(instance.metadata), + service_name=key[0], + group_name=key[1], + ) + action = f"register {instance.host}:{instance.port} in {service}" + + async with self._registering: + before = self._registered.get(key, {}) + instances = {**before, (instance.host, instance.port): param} + try: + if len(instances) == 1: + registered = await call(naming.register_instance(param), action) + else: + registered = await call(naming.batch_register_instances(_batch(key, instances)), action) + if not registered: + raise NacosError(f"cannot {action}: the server refused it") + except BaseException: + # The server may hold the instance: it holds again what it held before, as far as it can. + await release(self._replace(naming, key, before, instance, action), f"undo the attempt to {action}") + raise + self._registered[key] = instances + + async def _deregister(self, key: tuple[str, str], service: str, instance: NacosInstance) -> None: + naming = self._connected() + action = f"deregister {instance.host}:{instance.port} from {service}" + + async with self._registering: + instances = dict(self._registered.get(key, {})) + instances.pop((instance.host, instance.port), None) + await self._replace(naming, key, instances, instance, action) + + async def _replace( + self, + naming: NacosNamingService, + key: tuple[str, str], + instances: dict[tuple[str, int], RegisterInstanceParam], + instance: NacosInstance, + action: str, + ) -> None: + """Make the server hold ``instances`` of the service ``key``, registered together, or none, ``instance`` deregistered.""" + if not instances: + param = DeregisterInstanceParam( + ip=instance.host, port=instance.port, service_name=key[0], group_name=key[1] + ) + await call(naming.deregister_instance(param), action) + self._registered.pop(key, None) + return + + if not await call(naming.batch_register_instances(_batch(key, instances)), action): + raise NacosError(f"cannot {action}: the server refused it") + self._registered[key] = instances + + def _connected(self) -> NacosNamingService: + if self._naming is None: + raise RuntimeError("the Nacos naming client is not connected") + return self._naming + + +def _name(name: str) -> str: + return name.replace("$", "___") + + +def _batch(key: tuple[str, str], instances: dict[tuple[str, int], RegisterInstanceParam]) -> BatchRegisterInstanceParam: + service_name, group_name = key + return BatchRegisterInstanceParam( + service_name=service_name, group_name=group_name, instances=list(instances.values()) + ) + + +def _instances(instances: Iterable[Instance] | None) -> list[NacosInstance]: + return [ + NacosInstance( + host=instance.ip, + port=instance.port, + metadata={str(key): str(value) for key, value in (instance.metadata or {}).items()}, + ) + for instance in instances or () + if instance.healthy and instance.enabled + ] + + +async def _shut_down(naming: NacosNamingService) -> None: + try: + await naming.shutdown() + finally: + # nacos-sdk-python 3.2.0 leaves the task of the redo service running after shutdown; it ends when cancelled. + task = naming.grpc_client_proxy.redo_service._listen_task + task.cancel() + await asyncio.wait((task,)) diff --git a/src/dubbo/transport/tls.py b/src/dubbo/transport/tls.py new file mode 100644 index 00000000..e226fb6a --- /dev/null +++ b/src/dubbo/transport/tls.py @@ -0,0 +1,123 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""TLS for the transports, configured by the parameters of a URL.""" + +import ssl +from collections.abc import Sequence + +from dubbo.constants import ( + CA_CERT_FILE_KEY, + SSL_ENABLED_KEY, + TLS_CERT_FILE_KEY, + TLS_KEY_FILE_KEY, + TLS_SERVER_NAME_KEY, +) +from dubbo.url import SSL_CONTEXT, URL +from dubbo.utils.converters import boolean, milliseconds + +__all__ = ["TLS_KEYS", "get_ssl_context", "server_hostname", "ssl_handshake_timeout"] + +_SSL_HANDSHAKE_TIMEOUT_KEY = "ssl-handshake-timeout" +_DEFAULT_SSL_HANDSHAKE_TIMEOUT = 10.0 # Seconds. + +# The URL parameters that configure TLS. +TLS_KEYS = (SSL_ENABLED_KEY, CA_CERT_FILE_KEY, TLS_CERT_FILE_KEY, TLS_KEY_FILE_KEY, TLS_SERVER_NAME_KEY) + + +def get_ssl_context(url: URL, *, server: bool, alpn: Sequence[str] = ()) -> ssl.SSLContext | None: + """Return the TLS context of the server or client of ``url``, or ``None`` for cleartext. + + ``ssl-enabled=true`` enables TLS. The ``ssl.SSLContext`` in the + attributes of ``url``, if any, is returned as it is. Otherwise a new + context enables TLS 1.2 or later without compression, offers the + protocols of ``alpn`` through ALPN, and takes PEM file paths and a name: + + - A client trusts ``ca-cert-file``, or the system certificates when it is + absent, checks that the server certificate carries the name + `server_hostname` returns, and presents ``tls-cert-file`` when the + server asks for a client certificate. + - A server presents ``tls-cert-file``, which it requires, and with + ``ca-cert-file`` requires each client to present a certificate it + trusts. + + ``tls-key-file`` holds the private key of ``tls-cert-file``; it may be + omitted when the certificate file holds the key too. An encrypted key + fails with `ssl.SSLError`. + + Raises: + ValueError: ``ssl-enabled`` is not a boolean, a TLS parameter or + context is set without enabling TLS, a certificate is missing, + or the context is made for the other side. + OSError: A file cannot be read, or holds no valid certificate or key. + """ + parameters = url.parameters + context = url.attributes.get(SSL_CONTEXT) + if not url.get_parameter(SSL_ENABLED_KEY, boolean, False): + configured = [key for key in TLS_KEYS[1:] if key in parameters] + if context is not None: + configured.append("the TLS context") + if configured: + raise ValueError(f"{configured} need {SSL_ENABLED_KEY}=true") + return None + + if isinstance(context, ssl.SSLContext): + other = ssl.PROTOCOL_TLS_CLIENT if server else ssl.PROTOCOL_TLS_SERVER + if context.protocol == other: + raise ValueError(f"a {'server' if server else 'client'} cannot use a TLS context made with {other.name}") + return context + + ca_file = parameters.get(CA_CERT_FILE_KEY) + cert_file = parameters.get(TLS_CERT_FILE_KEY) + key_file = parameters.get(TLS_KEY_FILE_KEY) + if cert_file is None and (server or key_file is not None): + raise ValueError(f"URL parameter {TLS_CERT_FILE_KEY!r} is required by a server and by {TLS_KEY_FILE_KEY!r}") + + if server: + context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) + if ca_file is not None: + context.load_verify_locations(ca_file) + context.verify_mode = ssl.CERT_REQUIRED + else: + context = ssl.create_default_context(cafile=ca_file) + if cert_file is not None: + # With an empty password, an encrypted key fails at once, with no prompt on the terminal. + context.load_cert_chain(cert_file, key_file, password="") + + context.minimum_version = ssl.TLSVersion.TLSv1_2 + context.options |= ssl.OP_NO_COMPRESSION | ssl.OP_NO_RENEGOTIATION + if alpn: + context.set_alpn_protocols(list(alpn)) + + return context + + +def server_hostname(url: URL) -> str | None: + """Return the name a client checks the server certificate for: ``tls-server-name``, or the URL host when it is absent or empty.""" + return url.parameters.get(TLS_SERVER_NAME_KEY) or url.host + + +def ssl_handshake_timeout(url: URL) -> float: + """Return the seconds a server of ``url`` gives each TLS handshake: ``ssl-handshake-timeout``, whole milliseconds, 10000 when absent. + + Raises: + ValueError: The timeout is not positive whole milliseconds. + """ + timeout = url.get_parameter(_SSL_HANDSHAKE_TIMEOUT_KEY, milliseconds, _DEFAULT_SSL_HANDSHAKE_TIMEOUT) + if not timeout > 0: + raise ValueError(f"URL parameter {_SSL_HANDSHAKE_TIMEOUT_KEY!r} must be positive") + return timeout diff --git a/src/dubbo/transport/zookeeper/__init__.py b/src/dubbo/transport/zookeeper/__init__.py new file mode 100644 index 00000000..da9c10fa --- /dev/null +++ b/src/dubbo/transport/zookeeper/__init__.py @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from .base import ZookeeperClient, get_zookeeper_client +from .exceptions import ZookeeperError + +__all__ = ["ZookeeperClient", "ZookeeperError", "get_zookeeper_client"] diff --git a/src/dubbo/transport/zookeeper/base.py b/src/dubbo/transport/zookeeper/base.py new file mode 100644 index 00000000..ef69009f --- /dev/null +++ b/src/dubbo/transport/zookeeper/base.py @@ -0,0 +1,155 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from collections.abc import AsyncIterator, Callable +from contextlib import AbstractAsyncContextManager +from typing import Self + +from dubbo.constants import BACKUP_KEY, CLIENT_KEY, SESSION_KEY +from dubbo.extension import Resource, extension_point, extensions +from dubbo.url import URL + +__all__ = ["ZookeeperClient", "get_zookeeper_client"] + + +@extension_point("apache_dubbo.transport.zookeeper", default="kazoo") +class ZookeeperClient(Resource, typing.Protocol): + """Read, write and watch the nodes of one ZooKeeper ensemble. + + The implementation is created with a registry or configuration center + URL and reads only its connection part: the host and port, 2181 if + absent, then the ``host[:port]`` entries of ``backup``; ``timeout``, to + connect and for each operation, and ``session``, for the session to + survive without a connection, in milliseconds, 30000 and 60000 if + absent; the user and password, which authenticate with digest and make + the nodes the client creates open only to that user. + + Entering ``async with`` connects within ``timeout``, and closing + disconnects. Paths are absolute, as in ``/dubbo/config``. + + Operations fail with ``ZookeeperError`` when the ensemble is unreachable, + times out or refuses them. Missing and existing nodes are not errors; + each operation states what it does with them. + + Attributes: + url: The URL the instance was created with. + """ + + url: URL + + def __init__(self, url: URL) -> None: + self.url = url + + async def get(self, path: str) -> bytes | None: + """Return the data of the node at ``path``, or ``None`` if it does not exist.""" + ... + + def keep_ephemeral(self, path: str, data: bytes = b"") -> AbstractAsyncContextManager[None]: + """Keep the ephemeral node at ``path`` with ``data``, creating missing parents, until the context exits. + + Entering creates the node, replacing one that exists, and exiting + deletes it. Meanwhile the client creates it again in each new + session, retrying after a delay while it cannot. A later keeper of + the same path replaces the node and its data, and the earlier one + then leaves the node on exiting. Entering is all or nothing: one + that fails deletes what it may have created. An entry or an exit + that is cancelled returns at once and stops creating the node again, + but may leave the node to the session, which deletes it as the + client closes; one after the client has closed has nothing left to + delete. + """ + ... + + async def update(self, path: str, change: Callable[[bytes | None], bytes]) -> None: + """Replace the data of the persistent node at ``path`` with ``change`` of its data. + + ``change`` receives ``None`` while the node does not exist, which is + then created with its parents. When another client writes the node + in between, ``change`` runs again on the new data. Data that + ``change`` returns unchanged is not written. ``change`` may run in + another thread, so it only computes the new data. A cancelled update + returns at once, and the write it began may still complete. + """ + ... + + def watch(self, path: str) -> AbstractAsyncContextManager[AsyncIterator[bytes | None]]: + """Watch the data of the node at ``path`` until the context exits. + + The iterator yields the current data first, then the data after each + change, with ``None`` while the node does not exist. Changes made + while the consumer is busy may be skipped, but the latest is always + yielded. The watch continues in new sessions. Only entering can + fail, with ``ZookeeperError``: after it the iterator neither raises + nor ends until the context exits. + """ + ... + + def watch_children(self, path: str) -> AbstractAsyncContextManager[AsyncIterator[list[str]]]: + """Watch the children of ``path`` until the context exits. + + The iterator yields the current names first, then the names after + each change, with none while the node does not exist; the watch + follows the node as it is deleted and created again, and continues + in new sessions. Changes made while the consumer is busy may be + skipped, but the latest is always yielded. Only entering can fail, + with ``ZookeeperError``: after it the iterator neither raises nor + ends until the context exits. + """ + ... + + async def aclose(self) -> None: + """Disconnect from the ensemble, which deletes the ephemeral nodes of the client.""" + ... + + async def __aenter__(self) -> Self: + """Connect to the ensemble within ``timeout``.""" + ... + + +async def get_zookeeper_client(url: URL) -> ZookeeperClient: + """Return the client of the ensemble a registry or configuration center URL names, the same for the same connection in its application. + + The ``client`` parameter names the implementation, ``kazoo`` if absent, + installed with ``apache-dubbo[zookeeper]``. The application of + ``url.scope`` connects it on first use and disconnects it when it stops. + URLs that differ only in ``timeout`` share it, with the ``timeout`` of + the first. + + Raises: + ValueError: The URL has no host, or a time is not positive whole + milliseconds. + ExtensionError: No implementation has the name in ``client``. + ZookeeperError: The ensemble cannot be reached. + RuntimeError: ``url`` belongs to no running application. + """ + if url.host is None: + raise ValueError(f"a ZooKeeper client needs a host: {url}") + + implementation = extensions.get(ZookeeperClient, url.parameters.get(CLIENT_KEY)) + # shortcut: zk and zk:2181 are two connections; normalize the hosts if that ever matters. + parameters = url.parameters + key = ( + implementation, + url.host, + url.port, + parameters.get(BACKUP_KEY), + url.username, + url.password, + parameters.get(SESSION_KEY), + ) + return await url.scope.share(key, lambda: implementation(url)) diff --git a/src/dubbo/transport/zookeeper/exceptions.py b/src/dubbo/transport/zookeeper/exceptions.py new file mode 100644 index 00000000..0949c847 --- /dev/null +++ b/src/dubbo/transport/zookeeper/exceptions.py @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from dubbo.exceptions import DubboError + +__all__ = ["ZookeeperError"] + + +class ZookeeperError(DubboError): + """A ZooKeeper operation failed: the ensemble is unreachable, timed out or refused it. + + The error of the client library is kept as ``__cause__``. + """ diff --git a/src/dubbo/transport/zookeeper/kazoo.py b/src/dubbo/transport/zookeeper/kazoo.py new file mode 100644 index 00000000..aba9645d --- /dev/null +++ b/src/dubbo/transport/zookeeper/kazoo.py @@ -0,0 +1,392 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import contextlib +import functools +import logging +import posixpath +import threading +from collections.abc import AsyncGenerator, AsyncIterator, Callable, Generator +from contextlib import asynccontextmanager +from typing import Any, Self, TypeVar + +import anyio +import attrs +from anyio import from_thread, to_thread +from anyio.lowlevel import EventLoopToken, current_token + +from dubbo.constants import BACKUP_KEY, SESSION_KEY, TIMEOUT_KEY +from dubbo.url import URL +from dubbo.utils import Latest, backoff, release_scope, require_optional_dependency +from dubbo.utils.converters import milliseconds + +from .base import ZookeeperClient +from .exceptions import ZookeeperError + +with require_optional_dependency("kazoo", extra="zookeeper"): + from kazoo.client import KazooClient + from kazoo.exceptions import BadVersionError, KazooException, NodeExistsError, NoNodeError, SessionExpiredError + from kazoo.handlers.threading import KazooTimeoutError + from kazoo.interfaces import IAsyncResult + from kazoo.protocol.states import KazooState, ZnodeStat + from kazoo.security import CREATOR_ALL_ACL + +__all__ = ["KazooZookeeperClient"] + +T = TypeVar("T") + +_logger = logging.getLogger(__name__) + +_DEFAULT_TIMEOUT = 30.0 # Seconds. +_DEFAULT_SESSION = 60.0 # Seconds. +# Reconnects without end, waiting at most a second between rounds of the hosts, so that a client connects again soon +# after ZooKeeper recovers from an outage of any length. +_CONNECTION_RETRY = {"max_tries": -1, "delay": 0.1, "backoff": 2, "max_delay": 1.0} + + +class KazooZookeeperClient(ZookeeperClient): + """A ``ZookeeperClient`` backed by kazoo. + + kazoo blocks and calls back from threads of its own. Its calls run in + worker threads, waiting at most the URL's ``timeout``, and its + callbacks hand their values to the event loop that connected. kazoo + parses the hosts, with port 2181 by default. With a user, the nodes it + creates are open only to that user. + """ + + def __init__(self, url: URL) -> None: + super().__init__(url) + + backups = url.parameters.get(BACKUP_KEY) + auth = None if url.userinfo is None else [("digest", url.userinfo)] + + self._hosts = url.address + (f",{backups}" if backups else "") + self._timeout = _positive_seconds(url, TIMEOUT_KEY, _DEFAULT_TIMEOUT) + session = _positive_seconds(url, SESSION_KEY, _DEFAULT_SESSION) + acl = None if auth is None else CREATOR_ALL_ACL + self._kazoo = KazooClient( + hosts=self._hosts, timeout=session, auth_data=auth, default_acl=acl, connection_retry=_CONNECTION_RETRY + ) + self._token: EventLoopToken | None = None + + # The ephemeral nodes to create again in each new session, by path. Only kazoo and worker threads take the + # lock, which they hold across network calls. + self._ephemeral: dict[str, _Ephemeral] = {} + # One lock per kept path, so that the nodes of other paths do not wait for one; the lock of the map is never + # held across a call to the server. + self._path_locks: dict[str, tuple[threading.Lock, list[int]]] = {} + self._path_locks_lock = threading.Lock() + self._lost = False + # Counts the new sessions, so that the recovery of an earlier one stops. + self._session = 0 + self._closed = threading.Event() + + async def get(self, path: str) -> bytes | None: + def get() -> bytes | None: + try: + data, _stat = self._wait(self._kazoo.get_async(path)) + except NoNodeError: + return None + return data + + return await self._run(get, f"get {path}") + + @asynccontextmanager + async def keep_ephemeral(self, path: str, data: bytes = b"") -> AsyncGenerator[None]: + node = _Ephemeral(data=data) + # The name of a node may hold a URL with a token, so errors name its parent. + parent = posixpath.dirname(path) + + def create() -> None: + with self._path_locked(path): + # The keeper was cancelled before the call began. + if node.released: + return + replaced = self._ephemeral.get(path) + self._ephemeral[path] = node + try: + self._create_ephemeral(path, data) + except BaseException: + # The node may have been created, or the one replaced deleted, before the failure. + with contextlib.suppress(KazooException, KazooTimeoutError): + if replaced is None or replaced.released: + del self._ephemeral[path] + self._wait(self._kazoo.delete_async(path)) + else: + self._ephemeral[path] = replaced + self._create_ephemeral(path, replaced.data) + raise + + def delete() -> None: + with self._path_locked(path): + # A later keeper of the path has replaced the node. + if self._ephemeral.get(path) is not node: + return + del self._ephemeral[path] + # The session of a closed client, or an expired one, has deleted the node. + if not self._closed.is_set(): + with contextlib.suppress(NoNodeError, SessionExpiredError): + self._wait(self._kazoo.delete_async(path)) + + try: + await self._run(create, f"create a node in {parent}") + yield + finally: + # Released at once, so that a new session no longer creates the node; a cancelled exit leaves deleting + # it to the worker thread, or to the session. + node.released = True + await self._run(delete, f"delete a node in {parent}") + + async def update(self, path: str, change: Callable[[bytes | None], bytes]) -> None: + def update() -> None: + while True: + try: + data, stat = self._wait(self._kazoo.get_async(path)) + except NoNodeError: + try: + self._wait(self._kazoo.create_async(path, change(None), makepath=True)) + except NodeExistsError: + continue + return + + changed = change(data) + if changed == data: + return + try: + self._wait(self._kazoo.set_async(path, changed, version=stat.version)) + except (BadVersionError, NoNodeError): + continue + return + + await self._run(update, f"update {path}") + + @asynccontextmanager + async def watch(self, path: str) -> AsyncGenerator[AsyncIterator[bytes | None]]: + latest: Latest[bytes | None] = Latest() + + recipes: list[Any] = [] + + def changed(data: bytes | None, _stat: object) -> bool: + return self._publish(latest, data) + + def register() -> None: + recipes.append(self._kazoo.DataWatch(path, changed)) + + async with self._watching(latest, register, recipes, f"watch {path}"): + yield aiter(latest) + + @asynccontextmanager + async def watch_children(self, path: str) -> AsyncGenerator[AsyncIterator[list[str]]]: + latest: Latest[list[str]] = Latest() + # kazoo's ChildrenWatch stops for good once its node is deleted, so a + # DataWatch follows the node and starts one for each node created at + # path, told apart by its creation zxid. A watch left from an earlier + # node stops when it next calls back. + following: int | None = None + recipes: list[Any] = [] + + def node_changed(_data: bytes | None, stat: ZnodeStat | None) -> bool: + nonlocal following + + if stat is None: + following = None + return self._publish(latest, []) + if latest.closed or stat.czxid == following: + return not latest.closed + + following = stat.czxid + try: + recipes.append(self._kazoo.ChildrenWatch(path, functools.partial(children_changed, stat.czxid))) + except Exception: + # The next change of the node tries again. + following = None + raise + return True + + def children_changed(node: int, children: list[str]) -> bool: + return node == following and self._publish(latest, children) + + def register() -> None: + recipes.append(self._kazoo.DataWatch(path, node_changed)) + + async with self._watching(latest, register, recipes, f"watch the children of {path}"): + yield aiter(latest) + + async def aclose(self) -> None: + self._closed.set() + + def close() -> None: + self._kazoo.stop() + self._kazoo.close() + + # Whatever the wait ends with, the thread finishes disconnecting alone. + with release_scope(self._timeout): + await to_thread.run_sync(close, abandon_on_cancel=True) + + async def __aenter__(self) -> Self: + self._token = current_token() + self._kazoo.add_listener(self._state_changed) + # start stops and closes the client itself when it times out. + await self._run(lambda: self._kazoo.start(self._timeout), "connect") + return self + + def _create_ephemeral(self, path: str, data: bytes) -> None: + try: + self._wait(self._kazoo.create_async(path, data, ephemeral=True, makepath=True)) + except NodeExistsError: + stat = self._wait(self._kazoo.exists_async(path)) + session = self._kazoo.client_id + if stat is not None and session is not None and stat.ephemeralOwner == session[0]: + # The node of this session changes in place, so that watchers never see it missing. + self._wait(self._kazoo.set_async(path, data)) + return + # A node left by an expired session must belong to this one. + self._wait(self._kazoo.delete_async(path)) + self._wait(self._kazoo.create_async(path, data, ephemeral=True, makepath=True)) + + def _state_changed(self, state: str) -> None: + # kazoo calls listeners from its connection thread, which must not block. + if state == KazooState.LOST: + self._lost = True + elif state == KazooState.CONNECTED and self._lost: + self._lost = False + self._session += 1 + self._kazoo.handler.spawn(self._create_ephemeral_again, self._session) + + @contextlib.contextmanager + def _path_locked(self, path: str) -> Generator[None]: + """Hold the lock of ``path``, which orders the creating and deleting of its node, in a thread.""" + with self._path_locks_lock: + lock, users = self._path_locks.setdefault(path, (threading.Lock(), [0])) + users[0] += 1 + try: + with lock: + yield + finally: + with self._path_locks_lock: + users[0] -= 1 + if not users[0]: + del self._path_locks[path] + + def _create_ephemeral_again(self, session: int) -> None: + """Create the ephemeral nodes again in a new session, in a thread of kazoo. + + A node that cannot be created does not hold up the others; those + that failed are tried again after a delay until they are created, + the session is replaced or the client closes. + """ + delays = backoff() + # Keepers of other paths change the map meanwhile; copying it is atomic. + pending = list(self._ephemeral.copy()) + while True: + pending = [path for path in pending if not self._try_create(path)] + if not pending: + return + parents = ", ".join(sorted({posixpath.dirname(path) for path in pending})) + _logger.warning("Cannot create the nodes in %s again on ZooKeeper %s; retrying", parents, self._hosts) + if self._closed.wait(next(delays)) or session != self._session: + return + + def _try_create(self, path: str) -> bool: + """Create the node kept at ``path`` again, unless its keeper has exited; return whether nothing is left to do.""" + # Only the keeper of this path waits for it. + with self._path_locked(path): + node = self._ephemeral.get(path) + if node is None or node.released: + return True + try: + self._create_ephemeral(path, node.data) + except (KazooException, KazooTimeoutError): + _logger.debug("Cannot create a node in %s again", posixpath.dirname(path), exc_info=True) + return False + return True + + @asynccontextmanager + async def _watching( + self, latest: Latest[T], register: Callable[[], None], recipes: list[Any], action: str + ) -> AsyncGenerator[None]: + """Register kazoo watches, which ``register`` adds to ``recipes`` and which publish to ``latest``, and stop them on exit. + + kazoo calls the watch function once while registering, then after + each change; it drops the watch when the function returns false. + """ + try: + try: + # kazoo retries the first read of a watch without limit while + # disconnected; an abandoned registration ends when it publishes. + with anyio.fail_after(self._timeout): + await self._run(register, action) + except TimeoutError as error: + raise ZookeeperError(f"cannot {action}: timed out") from error + + yield + finally: + latest.close() + for recipe in recipes: + self._stop(recipe) + + def _stop(self, recipe: Any) -> None: + """Stop a kazoo ``DataWatch`` or ``ChildrenWatch`` now, which kazoo does only when its function next returns false. + + kazoo has no call for it, so this sets what its recipes set to stop themselves, and drops their callbacks. + """ + # shortcut: uses kazoo private attributes; switch to a public stop once kazoo has one. + # Not under the recipe's lock, which kazoo holds across its reads: a read in progress calls back once more, + # and the function of the closed watch returns false. + recipe._stopped = True + self._kazoo.remove_listener(recipe._session_watcher) + for watchers in (self._kazoo._data_watchers, self._kazoo._child_watchers): + if recipe._path in watchers: + watchers[recipe._path].discard(recipe._watcher) + + def _publish(self, latest: Latest[T], value: T) -> bool: + """Hand a value from a kazoo thread to the event loop; return False once the watch has ended.""" + if latest.closed: + return False + try: + from_thread.run_sync(latest.publish, value, token=self._token) + except RuntimeError: + return False # The event loop has ended. + return True + + def _wait(self, result: IAsyncResult) -> T: + return result.get(timeout=self._timeout) + + async def _run(self, call: Callable[[], T], action: str) -> T: + """Run a blocking kazoo call in a worker thread, raising ZookeeperError for kazoo errors. + + A cancelled call returns at once and leaves the thread to finish. + """ + try: + return await to_thread.run_sync(call, abandon_on_cancel=True) + except (KazooException, KazooTimeoutError) as error: + raise ZookeeperError(f"cannot {action} on ZooKeeper {self._hosts}") from error + + +@attrs.define(kw_only=True, eq=False) +class _Ephemeral: + """An ephemeral node a keeper keeps: its data, and whether the keeper has exited.""" + + data: bytes + released: bool = False + + +def _positive_seconds(url: URL, key: str, default: float) -> float: + seconds = url.get_parameter(key, milliseconds, default) + if seconds <= 0: + raise ValueError(f"URL parameter {key!r} must be positive") + return seconds diff --git a/src/dubbo/types.py b/src/dubbo/types.py deleted file mode 100644 index f6c452b0..00000000 --- a/src/dubbo/types.py +++ /dev/null @@ -1,60 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import enum -from dataclasses import dataclass -from typing import Any, Callable - -__all__ = [ - "SerializingFunction", - "DeserializingFunction", - "RpcType", - "RpcTypes", -] - -SerializingFunction = Callable[..., bytes] -DeserializingFunction = Callable[[bytes], Any] - - -@dataclass -class RpcType: - """ - RpcType - """ - - name: str - client_stream: bool - server_stream: bool - - -@enum.unique -class RpcTypes(enum.Enum): - UNARY = RpcType("Unary", False, False) - CLIENT_STREAM = RpcType("ClientStream", True, False) - SERVER_STREAM = RpcType("ServerStream", False, True) - BI_STREAM = RpcType("BiStream", True, True) - - @classmethod - def from_name(cls, name: str) -> RpcType: - """ - Get RpcType by name. Case-insensitive. - :param name: RpcType name - :return: RpcType - """ - for item in cls: - # ignore case - if item.value.name.lower() == name.lower(): - return item.value - raise ValueError(f"Unknown RpcType name: {name}") diff --git a/src/dubbo/url.py b/src/dubbo/url.py index 8dae9fa1..581ce526 100644 --- a/src/dubbo/url.py +++ b/src/dubbo/url.py @@ -1,362 +1,285 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import copy -from typing import Any, Optional -from urllib import parse -from urllib.parse import urlencode, urlunparse - -from dubbo.constants import common_constants - -__all__ = ["URL", "create_url"] - - -def create_url(url: str, encoded: bool = False) -> "URL": - """ - Creates a URL object from a URL string. - - This function takes a URL string and converts it into a URL object. - If the 'encoded' parameter is set to True, the URL string will be decoded before being converted. - - :param url: The URL string to be converted into a URL object. - :type url: str - :param encoded: Determines if the URL string should be decoded before being converted. Defaults to False. - :type encoded: bool - :return: A URL object. - :rtype: URL - :raises ValueError: If the URL format is invalid. - """ - # If the URL is encoded, decode it - if encoded: - url = parse.unquote(url) - - if common_constants.PROTOCOL_SEPARATOR not in url: - raise ValueError("Invalid URL format: missing protocol") - - parsed_url = parse.urlparse(url) - - if not parsed_url.scheme: - raise ValueError("Invalid URL format: missing scheme.") - - return URL( - parsed_url.scheme, - parsed_url.hostname or "", - parsed_url.port, - parsed_url.username or "", - parsed_url.password or "", - parsed_url.path.lstrip("/"), - {k: v[0] for k, v in parse.parse_qs(parsed_url.query).items()}, - ) - - +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import re +from collections.abc import Callable, Mapping +from typing import Any, Self, TypeVar, cast +from urllib.parse import parse_qsl, quote, unquote, urlencode, urlsplit + +import attrs + +from dubbo.constants import ACCESS_KEY_KEY, GROUP_KEY, SECRET_KEY_KEY, TOKEN_KEY, VERSION_KEY +from dubbo.extension import ApplicationScope +from dubbo.utils import freeze_mapping +from dubbo.utils.net import format_address + +__all__ = [ + "ADVERTISED_PORT", + "APPLICATION_SCOPE", + "CONFIG_CENTER_URL", + "METADATA_CONSUMER_URL", + "METADATA_REPORT_URL", + "PROVIDER_URL", + "SSL_CONTEXT", + "URL", + "service_key", +] + +T = TypeVar("T") +D = TypeVar("D") + +# The keys of URL.attributes the framework sets: "dubbo." and the name of the constant in lowercase, ending with +# _url for one that holds a URL. An extension names its own keys after its package. +# On the URL a service is served with: the port registries publish in place of the one bound, if the configuration +# sets one. +ADVERTISED_PORT = "dubbo.advertised_port" +# The attribute that holds the scope of the application that made a URL. +APPLICATION_SCOPE = "dubbo.application_scope" +# The attribute that holds the URL of the configuration center of the application that made a URL, if it has one. +CONFIG_CENTER_URL = "dubbo.config_center_url" +# On a registry URL: the URL whose settings, such as TLS, the calls to the MetadataService of the instances it finds +# use. +METADATA_CONSUMER_URL = "dubbo.metadata_consumer_url" +# The attribute that holds the URL of the metadata report a registry URL stores metadata in, if not the registry itself. +METADATA_REPORT_URL = "dubbo.metadata_report_url" +# On the URL a consumer calls a provider with: the URL the provider published, before the settings of the reference +# and the override rules changed it. +PROVIDER_URL = "dubbo.provider_url" +# The attribute that holds the ssl.SSLContext the application gives the server or client of a URL, if it gives one. +SSL_CONTEXT = "dubbo.ssl_context" + +_SCHEME = re.compile(r"[A-Za-z][A-Za-z0-9+.-]*\Z") +# The parameters whose values are credentials; ``str`` and ``repr`` hide them. +_SECRET_PARAMETERS = frozenset({ACCESS_KEY_KEY, SECRET_KEY_KEY, TOKEN_KEY}) + + +def _decode(value: str | None) -> str | None: + # urlsplit leaves percent-escapes in place; components hold decoded text. + return None if value is None else unquote(value, errors="strict") + + +def _host(value: str | None) -> str | None: + # Host names are case-insensitive; an empty host is no host. + return value.lower() or None if value is not None else None + + +def _hide_secrets(parameters: Mapping[str, str]) -> dict[str, str]: + return {key: "***" if key in _SECRET_PARAMETERS else value for key, value in parameters.items()} + + +def _repr_parameters(parameters: Any) -> str: + return repr(_hide_secrets(parameters)) + + +def _check_port(_url: object, _attribute: object, port: int | None) -> None: + if port is not None and not 0 <= port <= 65535: + raise ValueError("port must be between 0 and 65535") + + +@attrs.define(frozen=True, kw_only=True) class URL: - """ - URL - Uniform Resource Locator. + """An immutable Dubbo URL: what an extension is selected and configured by. + + Every component but the host holds decoded text, which + ``render_as_string`` escapes; the host is kept as written, in lowercase. + + Attributes: + protocol: Scheme that selects the implementation, in lowercase. + host: Host name in lowercase, or an IPv6 address without brackets. + port: Port from 0 to 65535, if any. + path: Path without its leading slash, such as a service name. + username: User name, if any. + password: Password, if any; ``repr`` and ``str`` hide it. + parameters: Read-only query parameters. A repeated key keeps its last + value, and equality ignores the order. ``repr`` and ``str`` hide + the values of ``token``, ``accessKey`` and ``secretKey``. + attributes: Values that text cannot hold, such as the scope of the + application that made the URL under `APPLICATION_SCOPE`. They are + read-only, set when the URL is made or with `replace`, and not + part of the text, equality or ``repr``: URLs that differ only in + attributes share one extension instance in `ApplicationScope.share`. + + Raises: + ValueError: The protocol is not a scheme, the port is out of range, a + password has no username, or a port or username has no host. """ - __slots__ = [ - "_scheme", - "_host", - "_port", - "_location", - "_username", - "_password", - "_path", - "_parameters", - "_attributes", - ] - - def __init__( - self, - scheme: str, - host: str, - port: Optional[int] = None, - username: str = "", - password: str = "", - path: str = "", - parameters: Optional[dict[str, str]] = None, - attributes: Optional[dict[str, Any]] = None, - ): - """ - Initialize the URL object. - - :param scheme: The scheme of the URL (e.g., 'http', 'https'). - :type scheme: str - :param host: The host of the URL. - :type host: str - :param port: The port number of the URL, defaults to None. - :type port: int, optional - :param username: The username for authentication, defaults to an empty string. - :type username: str, optional - :param password: The password for authentication, defaults to an empty string. - :type password: str, optional - :param path: The path of the URL, defaults to an empty string. - :type path: str, optional - :param parameters: The query parameters of the URL as a dictionary, defaults to None. - :type parameters: Dict[str, str], optional - :param attributes: Additional attributes of the URL as a dictionary, defaults to None. - :type attributes: Dict[str, Any], optional + protocol: str = attrs.field(converter=str.lower) + host: str | None = attrs.field(default=None, converter=_host) + port: int | None = attrs.field(default=None, validator=_check_port) + path: str = "" + username: str | None = None + password: str | None = attrs.field(default=None, repr=False) + # Left out of the hash, which a read-only mapping cannot take part in; equality still compares it. + parameters: Mapping[str, str] = attrs.field( + factory=dict, converter=freeze_mapping, hash=False, repr=_repr_parameters + ) + attributes: Mapping[str, object] = attrs.field(factory=dict, converter=freeze_mapping, eq=False, repr=False) + + def __attrs_post_init__(self) -> None: + if not _SCHEME.match(self.protocol): + raise ValueError(f"protocol must be a URL scheme, not {self.protocol!r}") + if self.password is not None and self.username is None: + raise ValueError("password requires username") + if self.host is None and (self.port is not None or self.username is not None): + raise ValueError("port and username require host") + + @classmethod + def parse(cls, text: str) -> Self: + """Parse a URL such as ``zookeeper://user:secret@127.0.0.1:2181/path?timeout=3000``. + + Surrounding whitespace is ignored. Components are decoded once, and the + query is form-encoded: ``+`` means a space and a bare key has an empty + value. + + Raises: + ValueError: The text has no scheme, an invalid host or port, + escapes that do not decode to UTF-8, or a fragment. """ - self._scheme = scheme - self._host = host - self._port = port - self._location = f"{host}:{port}" if port else host - self._username = username - self._password = password - self._path = path - self._parameters = parameters or {} - self._attributes = attributes or {} + try: + parts = urlsplit(text.strip()) + port = parts.port + except ValueError: + # The errors of urlsplit quote the authority, which may hold a password. + raise ValueError("URL has an invalid host or port") from None + if not parts.scheme: + raise ValueError("URL needs a scheme, as in zookeeper://127.0.0.1:2181") + if parts.fragment: + raise ValueError("URL fragments are not supported") + + return cls( + protocol=parts.scheme, + host=parts.hostname, + port=port, + path=unquote(parts.path, errors="strict").removeprefix("/"), + username=_decode(parts.username), + password=_decode(parts.password), + parameters=dict(parse_qsl(parts.query, keep_blank_values=True, errors="strict")), + ) @property - def scheme(self) -> str: - """ - Get or set the scheme of the URL. - - :return: The scheme of the URL. - :rtype: str - """ - return self._scheme - - @scheme.setter - def scheme(self, value: str): - self._scheme = value + def address(self) -> str: + """The host and the port, if any, as in ``127.0.0.1:2181``, an IPv6 host in brackets; empty without a host.""" + return format_address(self.host or "", self.port) @property - def host(self) -> str: - """ - Get or set the host of the URL. - - :return: The host of the URL. - :rtype: str - """ - return self._host - - @host.setter - def host(self, value: str): - self._host = value - self._location = f"{self.host}:{self.port}" if self.port else self.host + def userinfo(self) -> str | None: + """The user and the password, if any, unescaped, as in ``user:secret``; ``None`` without a user.""" + if self.username is None: + return None + return self.username if self.password is None else f"{self.username}:{self.password}" @property - def port(self) -> Optional[int]: - """ - Get or set the port of the URL. + def scope(self) -> ApplicationScope: + """The `ApplicationScope` of the application that made the URL, under `APPLICATION_SCOPE`; extensions share clients and state through it. - :return: The port of the URL. - :rtype: int, optional + Raises: + RuntimeError: No application made the URL, as for one from `parse`. """ - return self._port - - @port.setter - def port(self, value: int): - if value > 0: - self._port = value - self._location = f"{self.host}:{self.port}" + scope = self.attributes.get(APPLICATION_SCOPE) + if scope is None: + raise RuntimeError(f"{self} belongs to no application") + return cast(ApplicationScope, scope) @property - def location(self) -> str: - """ - Get or set the location (host:port) of the URL. + def service_key(self) -> str: + """``group/path:version`` from the path and the ``group`` and ``version`` parameters, as `service_key` makes it.""" + return service_key(self.path, self.parameters.get(GROUP_KEY), self.parameters.get(VERSION_KEY)) - :return: The location of the URL. - :rtype: str - """ - return self._location + def get_parameter(self, key: str, convert: Callable[[str], T], default: D) -> T | D: + """Return the parameter ``key`` converted by ``convert``, or ``default`` when it is absent. - @location.setter - def location(self, value: str): - try: - values = value.split(":") - self.host = values[0] - if len(values) == 2: - self.port = int(values[1]) - except Exception as e: - raise ValueError(f"Invalid location: {value}") from e + ``convert`` takes the text and raises `ValueError` to reject it, as + `int`, `float` and the converters in `dubbo.utils.converters` do, as in + ``url.get_parameter("timeout", milliseconds, 3.0)``. - @property - def username(self) -> str: + Raises: + ValueError: ``convert`` rejects the text; the message names the key. """ - Get or set the username for authentication. + value = self.parameters.get(key) + if value is None: + return default - :return: The username. - :rtype: str - """ - return self._username + return _convert(key, value, convert) - @username.setter - def username(self, value: str): - self._username = value + def get_method_parameters(self, key: str, convert: Callable[[str], T]) -> dict[str, T]: + """Return the parameter ``key`` of each method that sets it as ``{method}.{key}``, by method, converted by ``convert``. - @property - def password(self) -> str: - """ - Get or set the password for authentication. + For ``a.timeout=1&b.timeout=2&timeout=3``, + ``get_method_parameters("timeout", int)`` is ``{"a": 1, "b": 2}``; + ``timeout`` belongs to no method. - :return: The password. - :rtype: str + Raises: + ValueError: ``convert`` rejects the text; the message names the key. """ - return self._password - - @password.setter - def password(self, value: str): - self._password = value - - @property - def path(self) -> str: - """ - Get or set the path of the URL. - - :return: The path of the URL. - :rtype: str - """ - return self._path - - @path.setter - def path(self, value: str): - self._path = value.lstrip("/") - - @property - def parameters(self) -> dict[str, str]: - """ - Get the query parameters of the URL. - - :return: The query parameters as a dictionary. - :rtype: Dict[str, str] - """ - return self._parameters - - @property - def attributes(self) -> dict[str, Any]: - """ - Get the additional attributes of the URL. - - :return: The attributes as a dictionary. - :rtype: Dict[str, Any] + suffix = f".{key}" + return { + name.removesuffix(suffix): _convert(name, value, convert) + for name, value in self.parameters.items() + if name.endswith(suffix) and name != suffix + } + + def replace(self, **changes: Any) -> Self: + """Return a copy with the components ``changes`` names replaced, as in ``url.replace(port=50051)``. + + Raises: + ValueError: As the constructor raises. + TypeError: ``changes`` names a component the URL does not have. """ - return self._attributes - - def to_str( - self, - contain_ip: bool = True, - contain_user: bool = True, - contain_path: bool = True, - contain_parameters: bool = True, - encode: bool = False, - ) -> str: - """ - Converts the URL to a string. - :param contain_ip: Determines if the URL should contain the IP address. Defaults to True. - :type contain_ip: bool - :param contain_user: Determines if the URL should contain the username. Defaults to True. - :type contain_user: bool - :param contain_path: Determines if the URL should contain the path. Defaults to True. - :type contain_path: bool - :param contain_parameters: Determines if the URL should contain the parameters. Defaults to True. - :param encode: Determines if the URL should be encoded. Defaults to False. - :type encode: bool - :return: The URL string. - :rtype: str - """ - - # Construct the scheme part - scheme = "" - netloc = "" - if contain_ip: - scheme = self.scheme - - # Construct the netloc part - if contain_user and self.username and self.password: - netloc = f"{self.username}:{self.password}@{self.location}" - else: - netloc = self.location - - # Construct the path part - path = self.path if contain_path else "" - - # Construct the query part - query = urlencode(self.parameters) if contain_parameters else "" - - # Construct the URL - url = "" - if scheme or netloc or path or query: - url = urlunparse((scheme, netloc, path, "", query, "")) - - if encode: - url = parse.quote(url, safe="") + return attrs.evolve(self, **changes) - return url + def update_parameters(self, parameters: Mapping[str, str]) -> Self: + """Return a copy with ``parameters`` added, replacing the values of existing keys.""" + return self.replace(parameters={**self.parameters, **parameters}) - def copy(self) -> "URL": - """ - Copy the URL object. + def render_as_string(self, *, hide_secrets: bool = True) -> str: + """Render the URL, escaping each component. - :return: A shallow copy of the URL object. - :rtype: URL + The secrets, the password and the values of the parameters + ``token``, ``accessKey`` and ``secretKey``, render as ``***`` unless + ``hide_secrets`` is false, so that logs and error messages never + reveal them. """ - return copy.copy(self) + authority = self.address + if self.username is not None: + userinfo = quote(self.username, safe="") + if self.password is not None: + userinfo += ":" + ("***" if hide_secrets else quote(self.password, safe="")) + authority = f"{userinfo}@{authority}" + + path = "/" + quote(self.path) if self.path else "" + parameters = _hide_secrets(self.parameters) if hide_secrets else self.parameters + query = "?" + urlencode(list(parameters.items())) if parameters else "" + return f"{self.protocol}://{authority}{path}{query}" - def deepcopy(self) -> "URL": - """ - Deep copy the URL object. + def __str__(self) -> str: + """Render the URL with the password and the secret parameters hidden.""" + return self.render_as_string() - :return: A deep copy of the URL object. - :rtype: URL - """ - return copy.deepcopy(self) - - def __eq__(self, other: Any) -> bool: - if not isinstance(other, URL): - return False - - return ( - self.scheme == other.scheme - and self.host == other.host - and self.port == other.port - and self.username == other.username - and self.password == other.password - and self.path == other.path - and self.parameters == other.parameters - and self.attributes == other.attributes - ) - def __copy__(self) -> "URL": - return URL( - self.scheme, - self.host, - self.port, - self.username, - self.password, - self.path, - self.parameters.copy(), - self.attributes.copy(), - ) +def service_key(interface: str, group: str | None, version: str | None) -> str: + """Return the key that registries and servers tell services apart by: ``group/interface:version``, leaving out an empty group or version, as in ``a/com.example.UserService:1.0``.""" + key = f"{group}/{interface}" if group else interface - def __deepcopy__(self, memo) -> "URL": - return URL( - self.scheme, - self.host, - self.port, - self.username, - self.password, - self.path, - copy.deepcopy(self.parameters, memo), - copy.deepcopy(self.attributes, memo), - ) + return f"{key}:{version}" if version else key - def __str__(self) -> str: - return self.to_str() - def __repr__(self) -> str: - return self.to_str() +def _convert(key: str, value: str, convert: Callable[[str], T]) -> T: + try: + return convert(value) + except ValueError as error: + raise ValueError(f"URL parameter {key!r}: {error}") from None diff --git a/src/dubbo/utils.py b/src/dubbo/utils.py deleted file mode 100644 index d5e039e8..00000000 --- a/src/dubbo/utils.py +++ /dev/null @@ -1,387 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import inspect -import os -import socket -from collections.abc import Callable -from typing import Any, Optional - -import psutil - -__all__ = ["EventHelper", "FutureHelper", "NetworkUtils", "CpuUtils", "FunctionHelper"] - - -class EventHelper: - """ - Helper class for event operations. - """ - - @staticmethod - def is_set(event) -> bool: - """ - Check if the event is set. - - :param event: Event object, you can use threading.Event or any other object that supports the is_set operation. - :type event: Any - :return: True if the event is set, or False if the is_set method is not supported or the event is invalid. - :rtype: bool - """ - return event.is_set() if event and hasattr(event, "is_set") else False - - @staticmethod - def set(event) -> bool: - """ - Attempt to set the event object. - - :param event: Event object, you can use threading.Event or any other object that supports the set operation. - :type event: Any - :return: True if the event was set, False otherwise - (such as the event is invalid or does not support the set operation). - :rtype: bool - """ - if event is None: - return False - - # If the event supports the set operation, set the event and return True - if hasattr(event, "set"): - event.set() - return True - - # If the event is invalid or does not support the set operation, return False - return False - - @staticmethod - def clear(event) -> bool: - """ - Attempt to clear the event object. - - :param event: Event object, you can use threading.Event or any other object that supports the clear operation. - :type event: Any - :return: True if the event was cleared, False otherwise - (such as the event is invalid or does not support the clear operation). - :rtype: bool - """ - if not event: - return False - - # If the event supports the clear operation, clear the event and return True - if hasattr(event, "clear"): - event.clear() - return True - - # If the event is invalid or does not support the clear operation, return False - return False - - -class FutureHelper: - """ - Helper class for future operations. - """ - - @staticmethod - def done(future) -> bool: - """ - Check if the future is done. - - :param future: Future object - :type future: Any - :return: True if the future is done, False otherwise. - :rtype: bool - """ - return future.done() if future and hasattr(future, "done") else False - - @staticmethod - def set_result(future, result): - """ - Set the result of the future. - - :param future: Future object - :type future: Any - :param result: Result to set - :type result: Any - """ - if not future or FutureHelper.done(future): - return - - if hasattr(future, "set_result"): - future.set_result(result) - - @staticmethod - def set_exception(future, exception): - """ - Set the exception to the future. - - :param future: Future object - :type future: Any - :param exception: Exception to set - :type exception: Exception - """ - if not future or FutureHelper.done(future): - return - - if hasattr(future, "set_exception"): - future.set_exception(exception) - - -class NetworkUtils: - """ - Helper class for network operations. - """ - - @staticmethod - def is_address_reachable(ip: str, timeout: int = 0) -> bool: - """ - Use ping to check if the IP address is reachable. - - :param ip: The IP address. - :type ip: str - :param timeout: The timeout in seconds. - :type timeout: int - :return: True if the IP address is reachable, False otherwise. - :rtype: bool - """ - try: - # Use the ping command to check if the IP address is reachable - result = os.system(f"ping -c 1 -W {timeout} {ip} > /dev/null 2>&1") - return result == 0 - except Exception: - return False - - @staticmethod - def is_loopback_address(ip: str) -> bool: - """ - Check if the IP address is a loopback address. - - :param ip: The IP address. - :type ip: str - :return: True if the IP address is a loopback address, False otherwise. - :rtype: bool - """ - return ip.startswith("127.") or ip == "localhost" - - @staticmethod - def get_local_address() -> Optional[str]: - """ - Find first valid IP from local network card. - - :return: The local IP address. If not found, return None. - :rtype: str - """ - try: - # use psutil to get the local IP address - for iface_name, iface_addrs in psutil.net_if_addrs().items(): - for addr in iface_addrs: - # only consider IPv4 address - if addr.family == socket.AF_INET: - # ignore the loopback address and check if the IP address is reachable - if not NetworkUtils.is_loopback_address(addr.address) and NetworkUtils.is_address_reachable( - addr.address - ): - return addr.address - except Exception: - pass - - # if the local IP address is not found, try to get the IP address using the socket - try: - local_host_ip = socket.gethostbyname(socket.gethostname()) - return local_host_ip - except Exception: - pass - - return None - - -class CpuUtils: - """ - Helper class for CPU operations. - """ - - @staticmethod - def get_cpu_count(logical=True) -> int: - """ - Get the number of CPUs in the system. - - :return: The number of CPUs in the system. - :rtype: int - """ - return psutil.cpu_count(logical=logical) - - @staticmethod - def get_total_cpu_usage(interval=1) -> float: - """ - Get the total CPU usage of the system. - - :param interval: The interval in seconds. - :type interval: int - :return: The total CPU usage of the system. - :rtype: float - """ - return psutil.cpu_percent(interval=interval) - - @staticmethod - def get_per_cpu_usage(interval=1) -> list[float]: - """ - Get the per CPU usage of the system. - - :param interval: The interval in seconds. - :type interval: int - :return: The per CPU usage of the system. - :rtype: list - """ - return psutil.cpu_percent(interval=interval, percpu=True) - - @staticmethod - def get_load_avg() -> tuple[float, float, float]: - """ - Get the load average over the last 1, 5, and 15 minutes - - :return: The load average of the system. - :rtype: list - """ - return psutil.getloadavg() - - @staticmethod - def get_cpu_stats(): - """ - Get the CPU stats of the system. - - :return: The CPU stats of the system. - """ - return psutil.cpu_stats() - - @staticmethod - def get_cpu_freq(): - """ - Get the current CPU frequency. - - :return: The current CPU frequency. - """ - return psutil.cpu_freq() - - -class FunctionHelper: - """ - Helper class for function operations. - """ - - @staticmethod - def is_callable(callable_func: Callable) -> bool: - """ - Check if the function is callable. - - :param callable_func: The callable function. - :type callable_func: Callable - :return: True if the function is callable, False otherwise. - :rtype: bool - """ - return inspect.isfunction(callable_func) or inspect.ismethod(callable_func) - - @staticmethod - def has_args(func: Callable) -> bool: - """ - Check if the function has arguments. - - :param func: The callable function. - :type func: Callable - :return: True if the function has arguments, False otherwise. - :rtype: bool - """ - return inspect.Parameter.VAR_POSITIONAL in [p.kind for p in inspect.signature(func).parameters.values()] - - @staticmethod - def has_kwargs(func: Callable) -> bool: - """ - Check if the function has keyword arguments. - - :param func: The callable function. - :type func: Callable - :return: True if the function has keyword arguments, False otherwise. - :rtype: bool - """ - return inspect.Parameter.VAR_KEYWORD in [p.kind for p in inspect.signature(func).parameters.values()] - - @staticmethod - def call_func(func: Callable, args_and_kwargs: Any = None) -> Any: - """ - Call the function with the given arguments and keyword arguments. - - :param func: - The callable function. - :type func: Callable - :param args_and_kwargs: - The arguments and keyword arguments. - - the provided values must follow these forms: - - No arguments required, pass -> None - - Multiple positional arguments -> Tuple (e.g., ((1, 2),{})) - - Multiple keyword arguments -> Dict (e.g., ((),{"a": 1, "b": 2})) - - Both positional and keyword arguments -> Tuple of length 2 - (e.g., ((1, 2), {"a": 1, "b": 2})) - - :type args_and_kwargs: Tuple - :return: The result of the function. - :rtype: Any - """ - - # split the arguments and keyword arguments - if isinstance(args_and_kwargs, tuple) and len(args_and_kwargs) == 2: - args, kwargs = args_and_kwargs - else: - raise ValueError( - "Invalid function arguments, the provided values must follow these forms:" - "1.No arguments required, pass -> None" - "2.Multiple positional arguments -> Tuple (e.g., ((1, 2),{}))" - "3.Multiple keyword arguments -> Dict (e.g., ((),{'a': 1, 'b': 2}))" - "4.Both positional and keyword arguments -> Tuple of length 2" - " (e.g., ((1, 2), {'a': 1, 'b': 2}))" - ) - - # If the function is not callable, try to call the function directly - try: - if not FunctionHelper.is_callable(func): - return func(*args, **kwargs) - except Exception as e: - raise e - - # Get the function signature - sig = inspect.signature(func) - - # Get the function parameters and check if the function supports *args and **kwargs - params = sig.parameters - param_kinds = [p.kind for p in params.values()] - has_var_positional = inspect.Parameter.VAR_POSITIONAL in param_kinds - has_var_keyword = inspect.Parameter.VAR_KEYWORD in param_kinds - - # If the function has no arguments or only one argument, call the function directly - if len(params) == 0 or args_and_kwargs is None: - return func() - - # If the function accepts both *args and **kwargs - if has_var_positional and has_var_keyword: - return func(*args, **kwargs) - - # If the function supports *args but not **kwargs - if has_var_positional: - return func(*args) - - # If the function supports **kwargs but not *args - if has_var_keyword: - return func(**kwargs) - - # common case - bound_args = sig.bind(*args, **kwargs) - bound_args.apply_defaults() - return func(*bound_args.args, **bound_args.kwargs) diff --git a/src/dubbo/utils/__init__.py b/src/dubbo/utils/__init__.py new file mode 100644 index 00000000..946b05fe --- /dev/null +++ b/src/dubbo/utils/__init__.py @@ -0,0 +1,46 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Helpers shared across the framework.""" + +from .async_ import ( + Latest, + close_then_abort, + create_background_task_group, + follow, + release_scope, + release_shield, + wait_then_cancel, +) +from .backoff import backoff +from .dialer import Dialer +from .mapping import freeze_mapping +from .optional import require_optional_dependency + +__all__ = [ + "Dialer", + "Latest", + "backoff", + "close_then_abort", + "create_background_task_group", + "follow", + "freeze_mapping", + "release_scope", + "release_shield", + "require_optional_dependency", + "wait_then_cancel", +] diff --git a/src/dubbo/utils/annotations.py b/src/dubbo/utils/annotations.py new file mode 100644 index 00000000..173ae68a --- /dev/null +++ b/src/dubbo/utils/annotations.py @@ -0,0 +1,28 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The kinds of type annotations that several readers of annotations take apart.""" + +import types +import typing + +__all__ = ["TYPE_ALIASES", "UNIONS"] + +# The aliases a type statement makes, from Python 3.12. +TYPE_ALIASES = tuple(alias for alias in (getattr(typing, "TypeAliasType", None),) if alias is not None) +# The origins of ``X | Y`` and ``Union[X, Y]``. +UNIONS = (typing.Union, types.UnionType) diff --git a/src/dubbo/utils/async_.py b/src/dubbo/utils/async_.py new file mode 100644 index 00000000..3c611def --- /dev/null +++ b/src/dubbo/utils/async_.py @@ -0,0 +1,247 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Async helpers: tasks ended after a grace period, tasks behind a body, latest values, and subscriptions kept up.""" + +import asyncio +import logging +import math +from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Collection +from contextlib import AbstractAsyncContextManager, asynccontextmanager +from typing import Any, Generic, TypeVar, cast + +import anyio +from anyio.abc import TaskGroup, TaskStatus + +from .backoff import backoff + +__all__ = [ + "Latest", + "close_then_abort", + "create_background_task_group", + "follow", + "release_scope", + "release_shield", + "wait_then_cancel", +] + +T = TypeVar("T") + +_logger = logging.getLogger(__name__) + +# Seconds that what is cancelled gets to release what it holds, waiting on no peer. +_RELEASE_TIMEOUT = 1.0 +# Seconds a closing connection waits for the peer to read what was written. +_CLOSE_GRACE = 1.0 + + +def release_scope(graceful: float) -> anyio.CancelScope: + """Return the scope of a release that waits on a peer, such as unsubscribing or closing a session. + + Unless the caller is cancelled, the release may take ``graceful`` seconds + and its caller's cancellation cuts it short. A cancelled caller stops at + once, so the release then gets only a short, shielded moment. + """ + if anyio.current_effective_deadline() == -math.inf: + return release_shield() + return anyio.move_on_after(graceful) + + +def release_shield() -> anyio.CancelScope: + """Return the shielded scope of a moment in which what is cancelled releases what it holds, waiting on no peer. + + Aborting sockets and cancelling tasks take it, as they need no answer. + """ + return anyio.move_on_after(_RELEASE_TIMEOUT, shield=True) + + +async def close_then_abort( + wait_closed: Callable[[], Awaitable[object]], closed: Callable[[], bool], abort: Callable[[], None] +) -> None: + """Wait a moment for a close already begun to finish, then abort what is still open. + + A cancelled wait aborts at once. The abort is awaited under a + `release_shield`. + """ + try: + with anyio.move_on_after(_CLOSE_GRACE): + await wait_closed() + finally: + if not closed(): + abort() + with release_shield(): + await wait_closed() + + +async def wait_then_cancel(tasks: Collection[asyncio.Task[Any]], grace: float) -> None: + """Wait up to ``grace`` seconds for ``tasks`` to finish, then cancel the rest and wait as long again for them. + + Tasks that still run after that are logged and left running. Cancelling + the wait cancels the tasks at once and waits up to a second for them. + """ + if not tasks: + return + + try: + _, pending = await asyncio.wait(tasks, timeout=grace) + if not pending: + return + + for task in pending: + task.cancel() + _, stuck = await asyncio.wait(pending, timeout=grace) + except BaseException: + cancelled = [task for task in tuple(tasks) if task.cancel()] + if cancelled: + with release_shield(): + await asyncio.wait(cancelled) + raise + + if stuck: + _logger.warning("%d tasks kept running after being cancelled", len(stuck)) + + +@asynccontextmanager +async def create_background_task_group() -> AsyncGenerator[TaskGroup]: + """Open a task group for the background tasks of the body, as `anyio.create_task_group` does, except that when only the body fails its exception is raised alone, not in a group. + + A failure to start, such as that of a first subscription, so keeps its + type. When tasks fail too, every exception stays in the group. + """ + failure: Exception | None = None + try: + async with anyio.create_task_group() as task_group: + try: + yield task_group + except Exception as error: + failure = error + raise + except BaseExceptionGroup as group: + if failure is None or group.exceptions != (failure,): + raise + else: + return + + # Raised outside the handler, so that the group does not become the context of the exception it holds. + raise failure + + +class Latest(Generic[T]): + """The latest of the values published in the event loop, which each iteration reads, skipping older ones. + + Every ``async for`` reads on its own, starting with the current value, if + any. `close` ends every iteration once it has read the last value. It is + not thread-safe: publish and close in the event loop; from another + thread, go through ``anyio.from_thread.run_sync``. + """ + + def __init__(self) -> None: + self._value: T | None = None + self._version = 0 + self._closed = False + self._error: BaseException | None = None + self._changed = anyio.Event() + + @property + def closed(self) -> bool: + """Whether `close` has been called.""" + return self._closed + + @property + def empty(self) -> bool: + """Whether nothing has been published yet.""" + return self._version == 0 + + def publish(self, value: T) -> None: + """Make ``value`` the next one each iteration reads, replacing one not yet read; ignored once closed.""" + if self._closed: + return + + self._value = value + self._version += 1 + self._changed.set() + self._changed = anyio.Event() + + def close(self, error: BaseException | None = None) -> None: + """End every iteration after its last value, raising ``error`` if given.""" + if self._closed: + return + + self._closed, self._error = True, error + self._changed.set() + + def __aiter__(self) -> AsyncIterator[T]: + return _LatestReader(self) + + +class _LatestReader(AsyncIterator[T]): + """One iteration of a `Latest`; a cancelled wait for the next value leaves it able to read on, unlike a generator.""" + + def __init__(self, latest: Latest[T]) -> None: + self._latest = latest + self._seen = 0 + + async def __anext__(self) -> T: + latest = self._latest + while self._seen == latest._version: + if latest._closed: + if latest._error is not None: + raise latest._error + raise StopAsyncIteration + await latest._changed.wait() + + self._seen = latest._version + # Something was published, so the value is set. + return cast(T, latest._value) + + +async def follow( + subscribe: Callable[[], AbstractAsyncContextManager[AsyncIterator[T]]], + receive: Callable[[T], Awaitable[None]], + name: str, + *, + retry_first: bool = False, + task_status: TaskStatus[None] = anyio.TASK_STATUS_IGNORED, +) -> None: + """Hand ``receive`` each value of ``subscribe()`` until cancelled, subscribing again after a delay when it fails or ends. + + ``task_status`` starts with the first value. A failure before it is + raised, unless ``retry_first``, which starts ``task_status`` and tries + again. Later failures are logged with ``name``, what is followed. A + failure of ``receive`` counts as one of the subscription. + """ + started = False + delays = backoff() + while True: + try: + async with subscribe() as values: + async for value in values: + await receive(value) + delays = backoff() + if not started: + started = True + task_status.started() + _logger.warning("Following %s ended; subscribing again", name) + except Exception: + if not started and not retry_first: + raise + _logger.warning("Following %s failed; subscribing again", name, exc_info=True) + + if not started: + started = True + task_status.started() + await anyio.sleep(next(delays)) diff --git a/src/dubbo/utils/backoff.py b/src/dubbo/utils/backoff.py new file mode 100644 index 00000000..cded0fb2 --- /dev/null +++ b/src/dubbo/utils/backoff.py @@ -0,0 +1,31 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Waits between attempts that fail.""" + +import random +from collections.abc import Iterator + +__all__ = ["backoff"] + + +def backoff(first: float = 1.0, longest: float = 30.0) -> Iterator[float]: + """Yield the seconds to wait before each next attempt, from ``first`` doubling up to ``longest``, each with jitter.""" + delay = first + while True: + yield random.uniform(delay / 2, delay) + delay = min(delay * 2, longest) diff --git a/src/dubbo/utils/converters.py b/src/dubbo/utils/converters.py new file mode 100644 index 00000000..44a4fcec --- /dev/null +++ b/src/dubbo/utils/converters.py @@ -0,0 +1,65 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Convert the text values of Dubbo URL parameters and configuration. + +Each converter takes the text and raises `ValueError` to reject it, so it +works with `dubbo.URL.get_parameter`. +""" + +import math + +from attrs.converters import to_bool + +__all__ = ["boolean", "comma_separated", "is_true", "milliseconds", "to_milliseconds", "to_text"] + + +# Converts true, t, yes, y, on and 1, or false, f, no, n, off and 0, in any case. +boolean = to_bool + + +def is_true(value: object) -> bool: + """Return whether ``value`` reads ``true`` in any case; anything else, such as a value another side sent, is false.""" + return str(value).lower() == "true" + + +def to_text(value: object) -> str: + """Convert a value to its text in a URL parameter or a rule, booleans in lowercase and ``None`` as ``null``, as every Dubbo implementation spells them.""" + if isinstance(value, bool): + return "true" if value else "false" + return "null" if value is None else str(value) + + +def milliseconds(value: str) -> float: + """Convert whole milliseconds, such as ``3000``, to seconds.""" + try: + count = int(value) + except ValueError: + count = -1 + if count < 0: + raise ValueError(f"must be whole milliseconds, not {value!r}") + return count / 1000 + + +def to_milliseconds(seconds: float) -> str: + """Convert seconds to whole milliseconds, rounded up so a positive time never becomes ``0``.""" + return str(math.ceil(seconds * 1000)) + + +def comma_separated(value: str) -> tuple[str, ...]: + """Convert a comma-separated list, such as ``a, b``, dropping surrounding spaces and empty items.""" + return tuple(item for item in (item.strip() for item in value.split(",")) if item) diff --git a/src/dubbo/utils/dialer.py b/src/dubbo/utils/dialer.py new file mode 100644 index 00000000..ec543631 --- /dev/null +++ b/src/dubbo/utils/dialer.py @@ -0,0 +1,139 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The attempts of one client to connect to its peer.""" + +import asyncio +import copy +from collections.abc import Callable, Coroutine +from typing import Any, Generic, TypeVar + +from .backoff import backoff + +__all__ = ["Dialer"] + +T = TypeVar("T") + + +class Dialer(Generic[T]): + """Connects one client to its peer: one attempt at a time, and again after a backoff once one fails or the connection is lost. + + ``connect`` opens a connection, bounded by the connect timeout, and + returns it. An attempt belongs to the dialer, not to the callers waiting + for it: one that stops waiting leaves it to the others, and only closing + cancels it. + + The dialer is connected from an attempt that succeeds until the + connection is lost, an attempt fails or it closes; before its first + attempt succeeds, it is not. + """ + + def __init__(self, connect: Callable[[], Coroutine[Any, Any, T]]) -> None: + self._connect = connect + self._attempt: asyncio.Task[T] | None = None + self._retry: asyncio.TimerHandle | None = None + self._delays = backoff() + self._connected = False + self._closed = False + + @property + def connected(self) -> bool: + return self._connected + + def start(self) -> None: + """Start an attempt in the background unless one is under way.""" + if self._attempt is None and not self._closed: + self._start() + + async def connect(self) -> T | None: + """Return what the attempt under way connects, starting one at once if none is, even during a backoff. + + Returns ``None`` once the dialer is closed. + + Raises: + Exception: A copy of what the attempt raised. + """ + if self._closed: + return None + attempt = self._attempt or self._start() + + await asyncio.wait((attempt,)) + if attempt.cancelled(): + return None + error = attempt.exception() + if error is not None: + # Each waiter raises its own copy, so that the shared one gathers no traceback; one that cannot be copied + # is raised itself. + try: + raised = copy.copy(error) + except Exception: + raised = error + raise raised from error.__cause__ + return attempt.result() + + def lost(self) -> None: + """Connect again after the next backoff, as the connection has been lost or an attempt failed. + + A loss while an attempt is under way leaves connecting again to that attempt. + """ + if self._closed: + return + self._connected = False + if self._attempt is not None: + return + if self._retry is not None: + self._retry.cancel() + self._retry = asyncio.get_running_loop().call_later(next(self._delays), self._start) + + def close(self) -> None: + """Stop for good: cancel the retry pending and the attempt under way.""" + self._closed, self._connected = True, False + if self._retry is not None: + self._retry.cancel() + if self._attempt is not None: + self._attempt.cancel() + + async def aclose(self) -> None: + """Close, and wait for the attempt under way to end.""" + attempt = self._attempt + self.close() + if attempt is not None: + await asyncio.wait((attempt,)) + + def _start(self) -> asyncio.Task[T]: + if self._retry is not None: + self._retry.cancel() + self._retry = None + attempt = self._attempt = asyncio.get_running_loop().create_task(self._run()) + # An attempt nobody waits for fails quietly; the next one follows the backoff. + attempt.add_done_callback(lambda attempt: attempt.cancelled() or attempt.exception()) + return attempt + + async def _run(self) -> T: + # The attempt is over once the connection is returned, so that a loss reported from then on starts the next. + try: + connection = await self._connect() + except Exception: + self._attempt = None + self.lost() + raise + finally: + self._attempt = None + + self._connected = True + self._delays = backoff() + return connection diff --git a/src/dubbo/utils/mapping.py b/src/dubbo/utils/mapping.py new file mode 100644 index 00000000..33446a48 --- /dev/null +++ b/src/dubbo/utils/mapping.py @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Iterable, Mapping +from types import MappingProxyType +from typing import TypeVar + +__all__ = ["freeze_mapping"] + +K = TypeVar("K") +V = TypeVar("V") + + +def freeze_mapping(values: Mapping[K, V] | Iterable[tuple[K, V]]) -> Mapping[K, V]: + """Return a read-only copy of ``values``, in which a repeated key keeps its last value. + + It copies first, since a read-only view reflects later changes to its source. + """ + return MappingProxyType(dict(values)) diff --git a/src/dubbo/utils/net.py b/src/dubbo/utils/net.py new file mode 100644 index 00000000..561bf2ec --- /dev/null +++ b/src/dubbo/utils/net.py @@ -0,0 +1,159 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import ipaddress +import socket +from collections.abc import Iterable + +import psutil + +__all__ = ["format_address", "local_host", "match_address", "split_address"] + +# Any port picks the route; nothing is sent to it. +_DISCARD_PORT = 9 +# The private IPv4 networks of RFC 1918. +_PRIVATE_NETWORKS = tuple( + ipaddress.ip_network(network) for network in ("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16") +) + + +def format_address(host: str, port: int | str | None) -> str: + """Return ``host`` and ``port``, if any, as ``host:port``, an IPv6 host in brackets.""" + host = f"[{host}]" if ":" in host else host + return host if port is None else f"{host}:{port}" + + +def split_address(address: str) -> tuple[str, str | None]: + """Split ``host:port`` or ``[host]:port`` into the host and the port, if any; an IPv6 host without brackets has none.""" + if address.startswith("["): + host, _, rest = address[1:].partition("]") + return host, rest.removeprefix(":") or None + if address.count(":") == 1: + host, _, port = address.partition(":") + return host, port + return address, None + + +def local_host(targets: Iterable[tuple[str, int | None]]) -> str: + """Return the local IP address of the route to the first of ``targets``, ``(host, port)`` pairs, that can be reached. + + IPv4 and IPv6 targets both work. When none can be reached, it returns an + address of an interface that is up, a private IPv4 one first, then + another IPv4 one, then an IPv6 one, else the address of the host name, + and else ``127.0.0.1``; none of these is a loopback or a link-local + address. It blocks on name resolution, so async callers run it in a + thread. + """ + for host, port in targets: + try: + infos = socket.getaddrinfo(host, port or _DISCARD_PORT, type=socket.SOCK_DGRAM) + except OSError: + continue + for family, kind, proto, _, address in infos: + try: + # Connecting a UDP socket sends nothing; it only picks the route. + with socket.socket(family, kind, proto) as udp: + udp.connect(address) + return udp.getsockname()[0] + except OSError: + continue + + return _interface_address() or _host_name_address() or "127.0.0.1" + + +def match_address(pattern: str, host: str | None, port: int | None) -> bool: + """Return whether the address at ``host`` and ``port`` matches ``pattern``, as tag rules list providers. + + ``pattern`` is ``*``, a CIDR block, an IP address, or an IP address whose + segments are ``*`` or a range such as ``1-9``, with an optional port + after ``:``, or ``]:`` for IPv6. Host names are not resolved. + + Raises: + ValueError: ``pattern`` is malformed or of another IP version than + ``host``, or ``host`` is not an IP address. + """ + if pattern in ("*", "*.*.*.*"): + return True + if "/" in pattern: + return ipaddress.ip_address(host) in ipaddress.ip_network(pattern, strict=False) # ty: ignore[invalid-argument-type] + + address = ipaddress.ip_address(host) # ty: ignore[invalid-argument-type] + ipv4 = address.version == 4 + pattern_port = None + if pattern.startswith("["): + pattern, _, rest = pattern[1:].partition("]") + pattern_port = rest.removeprefix(":") or None + elif ipv4 and ":" in pattern: + pattern, _, pattern_port = pattern.partition(":") + if pattern_port is not None and pattern_port != str(port or 0): + return False + + if "*" not in pattern and "-" not in pattern: + return ipaddress.ip_address(pattern) == address + + masks = pattern.split("." if ipv4 else ":") + values = str(address).split(".") if ipv4 else [f"{int(group, 16):x}" for group in address.exploded.split(":")] + if len(masks) != len(values): + raise ValueError(f"{pattern!r} is not an IPv{address.version} pattern") + + base = 10 if ipv4 else 16 + for mask, value in zip(masks, values, strict=True): + if mask == "*": + continue + low, _, high = mask.partition("-") + if not int(low, base) <= int(value, base) <= int(high or low, base): + return False + return True + + +def _interface_address() -> str | None: + """Return the best address of an interface that is up, a private IPv4 one first, then another IPv4 one, then IPv6.""" + stats = psutil.net_if_stats() + candidates = [ + ip + for name, addresses in psutil.net_if_addrs().items() + if (stat := stats.get(name)) is not None and stat.isup + for address in addresses + if address.family in (socket.AF_INET, socket.AF_INET6) + and _is_reachable(ip := ipaddress.ip_address(address.address.partition("%")[0])) + ] + + best = min(candidates, key=_preference, default=None) + return None if best is None else str(best) + + +def _host_name_address() -> str | None: + """Return the address the host name resolves to, unless it is a loopback one, as ``/etc/hosts`` often maps it.""" + try: + address = ipaddress.ip_address(socket.gethostbyname(socket.gethostname())) + except (OSError, ValueError): + return None + + return str(address) if _is_reachable(address) else None + + +def _is_reachable(address: ipaddress.IPv4Address | ipaddress.IPv6Address) -> bool: + """Return whether another host may reach ``address``: not a loopback, link-local or unspecified one.""" + return not (address.is_loopback or address.is_link_local or address.is_unspecified) + + +def _preference(address: ipaddress.IPv4Address | ipaddress.IPv6Address) -> int: + """Rank ``address``: a private IPv4 one first, then another IPv4 one, then IPv6.""" + if address.version == 6: + return 2 + + return 0 if any(address in network for network in _PRIVATE_NETWORKS) else 1 diff --git a/src/dubbo/utils/optional.py b/src/dubbo/utils/optional.py new file mode 100644 index 00000000..93391ced --- /dev/null +++ b/src/dubbo/utils/optional.py @@ -0,0 +1,38 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Generator +from contextlib import contextmanager + +__all__ = ["require_optional_dependency"] + + +@contextmanager +def require_optional_dependency(module: str, *, extra: str) -> Generator[None]: + """Explain how to install a missing optional dependency. + + Only a missing ``module``, or a missing package that contains it, is + reported; a dependency that fails to import one of its own modules is a + broken installation and propagates. + """ + try: + yield + except ModuleNotFoundError as error: + # A broken dependency may itself import a missing module. + if error.name is None or not f"{module}.".startswith(f"{error.name}."): + raise + raise ModuleNotFoundError(f"install apache-dubbo[{extra}] to use {module!r}", name=module) from error diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index bcba37aa..00000000 --- a/tests/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/tests/certificates/localhost-cert.pem b/tests/certificates/localhost-cert.pem new file mode 100644 index 00000000..6d70dff7 --- /dev/null +++ b/tests/certificates/localhost-cert.pem @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDODCCAiCgAwIBAgIUNLHovdtztwg9EHg6aHqlNGESwN0wDQYJKoZIhvcNAQEL +BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTI2MDcyODE4MzUxNloXDTM2MDcy +NTE4MzUxNlowFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF +AAOCAQ8AMIIBCgKCAQEAz8G9ht5Xv1kqGdwmCP6WtNjFrbUyaVQoPvPUiXj33p2F +NkYqaBTMhDhMxYxsWJRE5eoLIcVdlOjzXphMpP7vL1JCnXyH8LgH3CYS/TbJVK8n +YRc/Na6+TjaJzIX4Jao4wE2hk/H6JwoZFWMAH/TvVy1OS3mK8U0glLenWduzll57 +4qyWrncBIi6HfbfamX2JEfEhQrHgotIOArMtSTDFosi3EPnV1/Toc7aVlfceCtT3 +sgZwiZoq1hPCFvh0uxZSQe82V8vtEdrMk2CgJQyS9N1B4Xj5DJXzd4gd0bfVD5wU +5f4h/cfdCmKzD2LDODqPg5Z+x8RgJACCkJ3kkZf94wIDAQABo4GBMH8wHQYDVR0O +BBYEFM/9hUGNLWq5tz1HG91imERFiSWsMB8GA1UdIwQYMBaAFM/9hUGNLWq5tz1H +G91imERFiSWsMA8GA1UdEwEB/wQFMAMBAf8wLAYDVR0RBCUwI4IJbG9jYWxob3N0 +hwR/AAABhxAAAAAAAAAAAAAAAAAAAAABMA0GCSqGSIb3DQEBCwUAA4IBAQBVhQSN +wKODkqogwV1SnNhcnrrb5inBDIKCuS7VXOFBx9eHPIrZleYJfWhJc5GRxGIJS+Hz +ScxSCnUINS1HOULO3YTk7KfysZd72l7/2Yyif7IEOj6gW+O3Lvn3jVsLH2aBFW61 +d/xASbDIepq5uXfUxXuvv8F/VdFz8M6UaPmhi/LKV+uXQOPsPv+cy0vrQsU6m4G+ +wydFugA8D2ldgGpJgGg1e0q6WTl+MB/AYvsAqtQpwtBWK4Fh0GnPDTr3QqmBGvll +8w+4PJzcUPytEyTJs0g3KgmoX3fLyXlkb9qjX/pqi/IIu+iFpA3FsaQl9qox1G1K +gkqDp1UJ65TFku3b +-----END CERTIFICATE----- diff --git a/tests/certificates/localhost-key-encrypted.pem b/tests/certificates/localhost-key-encrypted.pem new file mode 100644 index 00000000..aaedb937 --- /dev/null +++ b/tests/certificates/localhost-key-encrypted.pem @@ -0,0 +1,30 @@ +-----BEGIN ENCRYPTED PRIVATE KEY----- +MIIFNTBfBgkqhkiG9w0BBQ0wUjAxBgkqhkiG9w0BBQwwJAQQR1PdvyS/8nN2bL/T +sIPeqAICCAAwDAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEAdnrhXbBpfqoQWC +SObTFxUEggTQi8NWBvVx6+QtiaUNDhN5CKWh5q3o2U4EMEqdQ/V3fNcuIeKkXfnW +04y/beR1xw0k9tv8TLIexQHiFKQGTx676Utot5sAgmpSczif1HeDZqebFjQ/GSpw +n6Odd5H03YtnBwvuRsl90Y05atGscoXmFozLq3laSV4voO2kmlP6+YFpwH+JJq6B +gyUzeZhbyiTIGO9MfrDIobU1K3mYE395QpXiAvJNiHc9xUv01keQXV3D+SRiW5Nj +LfPOA7KY1XSjp9jPXkt+5wW/Lp1DvsnHnPnmQriRdq4WYr9LHhka4twJlW6WeJDJ +VQo+AEj1V5KcliTOYZdrkVFCdXLzLdSWP1odC9auJ7bKW/H2dH1/LeWXVQQIXpZJ +FlbBDd7CGxIRQx7Z3ODmXUAEy2scRBOFQHDCTDQmEmH9Xl7/ZyrRzQhPSfS7DTBA +M60L9+qFnQq7nD6Zhoyt0LSsSs0AKY7Suuy3PuVJ/SKkAv2uelHTmCTS6D4rLpQI +panjtPRjE8jJwGSBMcI38be6bYc2T1M2Iv7etnqcqekJYpOW2Zy3dQKdYP3Rw5KZ +GbPsIsNjQ6ESqFCTnLIGNXGbK3zTb2XwHGyb18Nus8msvgtJ0jrxEiQsjJozci/l +FxwKaKiHhsGDaQlB7fwWV2ZNoBbzYclFoNsoh1N6LRinAJPl8RDJJNcHZw0sBsmM +TBajr/7KzpJXrIed362iZdAGCtaThTDv0HQNtLbKCaV1taFCCPbd5ut8GG8ZyP70 +aO7z25Fry3jK70o7xCwtQmLOhzU5h4RyuBGzwyM6+mYmhnVtg1v97j6W3T35N9HY +CMHYJyGOhc0FRwrzz1AaJGGB7WN7QNBUy6IkM1SFU8PTTTQrUu3K8HFGcAcGlxxr +o6qk8gFK5mRb7jAPhfXObyg+aeXZ8iIvCWUVhwWk9Pww4OOmmN7JdSIOv1eq38Hi +rKlYMrjWF0RWhqkOBDXk9Mqt6+vMSHWAu3wqAss29enxHRngfNbDIOZ+hsX8R7ZK +N15olnTGJgL4xLcSA+v9q7lt+OKTZS3e390du+/D04vkJEjXVdbJLeD+l0y0mIwo +w8tILY8yGVD3v3BGEJOPG4qqETc3ycMEKQW8GuLmUjYr7T4S7h/uaZywDgL7wNeP +U0fi/5gFStiNtujKI05xSQgSFZD+BvINVCQ1VMiDjyLb3PB9FBhK2qp6yE1NUTHX +DzxkuusvzOHvSyhj3LcyOatRcklsbe7bKCkOghjzJmgFXzq+9Yb0tsv3MWj0HtWe +by1ANjB5Qxr3eI7sjGa0iOsk7XaFfeQnaku7whi3mi4SGWFbo0V1lKf6Z5+cNBm+ +muqwmv5NYE02cie0OBc99MWNeVYeB21I+DSIDqDnOmZP8nO75JVhj4CPc1sRTbkZ +Br4dfsJn4R5EtfXLpGcyFmEvT9wj8uXKq5z4oAprJQL6bvpXxppuVBt4o97x7Mfl +kTaPRdROhMdS8UCfU8Kut43+AcSBZw0D6qQ2TK55yVnGxKGvdKCRMt4LqSsKld8h +84TkciDFC/3yCUloe8qCx7i64EwJMqSbD3mzVgVzjVPV2yXzhBrAr/j4H4c7BfAZ +cxtBps7IqffQ7Y6wMz66RNJu60PnedhfcYb+9vtcAcDa7P4NsvVwD9M= +-----END ENCRYPTED PRIVATE KEY----- diff --git a/tests/certificates/localhost-key.pem b/tests/certificates/localhost-key.pem new file mode 100644 index 00000000..214fc2d7 --- /dev/null +++ b/tests/certificates/localhost-key.pem @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDPwb2G3le/WSoZ +3CYI/pa02MWttTJpVCg+89SJePfenYU2RipoFMyEOEzFjGxYlETl6gshxV2U6PNe +mEyk/u8vUkKdfIfwuAfcJhL9NslUrydhFz81rr5ONonMhfglqjjATaGT8fonChkV +YwAf9O9XLU5LeYrxTSCUt6dZ27OWXnvirJaudwEiLod9t9qZfYkR8SFCseCi0g4C +sy1JMMWiyLcQ+dXX9OhztpWV9x4K1PeyBnCJmirWE8IW+HS7FlJB7zZXy+0R2syT +YKAlDJL03UHhePkMlfN3iB3Rt9UPnBTl/iH9x90KYrMPYsM4Oo+Dln7HxGAkAIKQ +neSRl/3jAgMBAAECggEAZm5nO2+0Y6tajpV0S0r6kv+ttw93Y2cS0Lb3OzBhRWj0 +nOXLUrWugCIh9+RcJvAzaAgUpPniQeD43NLKNy9aTkKIhY04mP6jIW/EPQQeD5qs +F7qWd6lIOte46RXEWw2qHWYpHABaDZV0+I5vKVJiDuFPkPbEAmS8g5Zo9GzWBnR6 +w0UQy9SqAAFwmkQfI+TFmQ2ywrgMYr2RYm4x8QUSf5XsPrju+flD7ETsekEomd+Z +xmvzZUZUk+0Ryj/CDVG2lNF6kBdsd89yS3cXkLYFAs75Be9w2GuSQyUrIuUtFl+R +qHTN6p1Id/BbzITIRwV1aXDGR8GzKBIc9sOJbjp+wQKBgQD9dNhDO+uiaCuLUyYO +Uy13CQP9QLe0EeYBt/9NytqEmPyWzc+psiS0iq6zDZJiKZOOuS+VRz1ZC5bXY17e +woYVwKcWFgUm1G6jFrTJ2gREGXPZlA5yote0LVbpvkd7/88G9EWiSlzutW8azULx +VQWn8sPmolGFxzOpyb/+Q4cqTwKBgQDR130UgIIyYrUVbSWHwjGSZpQvegAjm22R +dRvI74uHzJEmgBjjLAXXM7Aog1d25W/nTt3goxHjI8e5xqppT023uzZiSd+luyQ0 +76KfZ+Px3nxkRTx0uwb9ENYCoy/TO/D96IrgbSpBw7yc6PDxS3zvTppQNBcNf22r +pFHS5WQSLQKBgDDdRRB5Te2KvdJnnm+mk55ea5l4z7H0vW5ZZew+jrB/ujrsxPuH +b9Iq5pF4rV8leuBKTaUvDeHL/THbY5/4ytcIxG3aovWggRAKQaKk2Ku0aIRrKfnp +8UI4d4gq+icq42QI1h/6zD3tVtVI+34BkUyW3jPp2WO8SvaSAeToafe7AoGAFm3f +C7r0r6gHTQP+l/U00T4vpqd2rlelrX+D+cVI97nw5dmZT2bcNPVsZdgsGCRMAsBW +TPWBKvMfHQdUHa+BUhsro/PbeN5470OR8VHsdmTejOUtohh/lbsf9OY2bXChwLID +bhudAayHU4o+frwf3YBcVChNMn8lXMxShqVIPf0CgYEAiXAnkXuneJWg4SH1tfLK +V198K9VLRrLshp0Iby/qZGujRpH5kjPZxUrt+uO13v0tyx9I7db9h0dJ541Vf8v6 +aTZKl46Mmkj223J6+6wYx/2+jTdPEAJs4V7KrRQGhgfXkLHPo9ZtasTMZJdLvXAm +7eLE92W3vSbUnT8kGsR+HpA= +-----END PRIVATE KEY----- diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..a5b68ba4 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,368 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Fixtures shared by the tests.""" + +import asyncio +import gc +import math +import selectors +import sys +import threading +import typing +from collections.abc import AsyncIterator, Callable +from contextlib import asynccontextmanager +from typing import Self + +import anyio +import attrs +import pytest + +from dubbo.config_center import ConfigCenter +from dubbo.extension import extensions +from dubbo.transport.zookeeper import ZookeeperClient +from dubbo.url import URL +from dubbo.utils import Latest + +_H2_REQUEST_HEADERS = ( + (b":method", b"POST"), + (b":scheme", b"http"), + (b":authority", b"127.0.0.1"), + (b":path", b"/test"), + (b"content-type", b"application/grpc"), +) + + +_H2_RESPONSE_HEADERS = ( + (b":status", b"200"), + (b"content-type", b"application/grpc"), +) + + +def _h2_url(host: str, port: int, **parameters: str) -> URL: + """Return an H2 URL; underscores in parameter names stand for hyphens.""" + return URL( + protocol="tri", + host=host, + port=port, + parameters={name.replace("_", "-"): value for name, value in parameters.items()}, + ) + + +class Ensemble: + """The nodes of a ZooKeeper ensemble held in memory, shared by the clients created with ``client=memory``.""" + + def __init__(self) -> None: + self.nodes: dict[str, bytes] = {"/": b""} + self.owners: dict[str, object] = {} + self.urls: list[URL] = [] + self.changed = anyio.Event() + + def touch(self) -> None: + self.changed.set() + self.changed = anyio.Event() + + def put(self, path: str, data: bytes, owner: object | None = None) -> None: + parts = path.strip("/").split("/") + for depth in range(1, len(parts)): + self.nodes.setdefault("/" + "/".join(parts[:depth]), b"") + self.nodes[path] = data + if owner is None: + self.owners.pop(path, None) + else: + self.owners[path] = owner + self.touch() + + def remove(self, path: str) -> None: + if self.nodes.pop(path, None) is not None: + self.owners.pop(path, None) + self.touch() + + def children(self, path: str) -> list[str] | None: + if path not in self.nodes: + return None + prefix = path.rstrip("/") + "/" + return sorted( + node[len(prefix) :] for node in self.nodes if node.startswith(prefix) and "/" not in node[len(prefix) :] + ) + + def close(self, owner: object) -> None: + for path in [path for path, holder in self.owners.items() if holder is owner]: + self.remove(path) + + +def memory_client(ensemble: Ensemble) -> Callable[[URL], ZookeeperClient]: + class MemoryClient(ZookeeperClient): + def __init__(self, url: URL) -> None: + super().__init__(url) + ensemble.urls.append(url) + # The keeper of each ephemeral node this client keeps. + self._keepers: dict[str, object] = {} + + async def __aenter__(self) -> Self: + return self + + async def aclose(self) -> None: + ensemble.close(self) + + async def get(self, path: str) -> bytes | None: + return ensemble.nodes.get(path) + + @asynccontextmanager + async def keep_ephemeral(self, path: str, data: bytes = b"") -> AsyncIterator[None]: + keeper = self._keepers[path] = object() + ensemble.put(path, data, self) + try: + yield + finally: + if self._keepers.get(path) is keeper: + del self._keepers[path] + ensemble.remove(path) + + async def update(self, path: str, change: Callable[[bytes | None], bytes]) -> None: + current = ensemble.nodes.get(path) + changed = change(current) + if changed != current: + ensemble.put(path, changed) + + @asynccontextmanager + async def watch(self, path: str) -> AsyncIterator[AsyncIterator[bytes | None]]: + yield self._follow(lambda: ensemble.nodes.get(path)) + + @asynccontextmanager + async def watch_children(self, path: str) -> AsyncIterator[AsyncIterator[list[str]]]: + yield self._follow(lambda: ensemble.children(path) or []) + + # The node operations that only tests use, which the integration NodesClient has too. + + async def children(self, path: str) -> list[str]: + return ensemble.children(path) or [] + + async def create(self, path: str, data: bytes = b"") -> None: + if path not in ensemble.nodes: + ensemble.put(path, data) + + async def set(self, path: str, data: bytes) -> None: + ensemble.put(path, data) + + async def delete(self, path: str) -> None: + ensemble.remove(path) + + async def _follow(self, read: Callable[[], object]) -> AsyncIterator[typing.Any]: + last: object = object() + while True: + changed = ensemble.changed + value = read() + if value != last: + last = value + yield value + await changed.wait() + + return MemoryClient + + +@attrs.define +class ConfigStore: + """The entries by group and key of the configuration center ``memory``, the centers created for it and the reads they served. + + A watch sees each entry that `put` changes; ``error``, when set, fails every read. + """ + + entries: dict[tuple[str, str], str] = attrs.field(factory=dict) + centers: list["MemoryConfigCenter"] = attrs.field(factory=list) + reads: list[tuple[str, str]] = attrs.field(factory=list) + error: Exception | None = None + _latest: dict[tuple[str, str], Latest[str | None]] = attrs.field(factory=dict) + + def put(self, key: str, text: str | None, *, group: str = "dubbo") -> None: + if text is None: + self.entries.pop((group, key), None) + else: + self.entries[group, key] = text + self.watched(group, key).publish(text) + + def watched(self, group: str, key: str) -> Latest[str | None]: + latest = self._latest.get((group, key)) + if latest is None: + latest = self._latest[group, key] = Latest() + latest.publish(self.entries.get((group, key))) + return latest + + def create(self, url: URL) -> "MemoryConfigCenter": + center = MemoryConfigCenter(self, url) + self.centers.append(center) + return center + + +@attrs.define +class MemoryConfigCenter(ConfigCenter): + store: ConfigStore + url: URL + connected: bool = False + closed: bool = False + + async def __aenter__(self) -> Self: + self.connected = True + return self + + async def aclose(self) -> None: + self.closed = True + + async def get(self, key: str, *, group: str) -> str | None: + if self.store.error is not None: + raise self.store.error + self.store.reads.append((group, key)) + return self.store.entries.get((group, key)) + + @asynccontextmanager + async def watch(self, key: str, *, group: str) -> AsyncIterator[AsyncIterator[str | None]]: + yield aiter(self.store.watched(group, key)) + + +# Real time an idle event loop waits for I/O before its clock jumps, so that bytes between its sockets arrive first. +_SETTLE = 0.005 + +_Poller = asyncio.IocpProactor if sys.platform == "win32" else selectors.DefaultSelector # ty: ignore[unresolved-attribute] +_Loop = asyncio.ProactorEventLoop if sys.platform == "win32" else asyncio.SelectorEventLoop # ty: ignore[unresolved-attribute] + + +class _JumpingPoller(_Poller): + """Waits for I/O, and moves its clock to the next timer of its loop when none comes and no thread works for it.""" + + def __init__(self, working: Callable[[], bool]) -> None: + super().__init__() + self.now = 0.0 + self._working = working + + def select(self, timeout: float | None = None) -> typing.Any: + # Without a timeout the loop waits for I/O alone; with a zero one it has callbacks ready. + if not timeout: + return super().select(timeout) + events = super().select(min(timeout, _SETTLE)) + if not events and not self._working(): + self.now += timeout + return events + + +class VirtualClockLoop(_Loop): + """The default event loop of the platform, on a clock that starts at 0 and moves only while every task waits. + + A deadline then passes exactly when it is due, whatever the speed or clock of the host. + """ + + def __init__(self) -> None: + self._poller = _JumpingPoller(self._working) + super().__init__(self._poller) + # Timers this close to due run at once; the resolution of the host's clock, 15.6 ms on Windows, would run them + # early, while a jump lands on them to within a rounding. + self._clock_resolution = 1e-9 + self._executing = 0 + # The threads of AnyIO, which the tests give the loop from inside a task. + self.thread_limiter: anyio.CapacityLimiter | None = None + + def time(self) -> float: + return self._poller.now + + def run_in_executor(self, executor: typing.Any, func: Callable[..., typing.Any], *args: typing.Any) -> typing.Any: + future = super().run_in_executor(executor, func, *args) + self._executing += 1 + future.add_done_callback(self._executed) + return future + + def _executed(self, _: object) -> None: + self._executing -= 1 + + def _working(self) -> bool: + return self._executing > 0 or (self.thread_limiter is not None and self.thread_limiter.borrowed_tokens > 0) + + +_AGAINST_SERVERS = ("zookeeper", "nacos") + + +@pytest.fixture +def anyio_backend(request: pytest.FixtureRequest) -> tuple[str, dict[str, typing.Any]]: + """The virtual clock, except in a test that waits for a server, a thread or a process, which run in real time.""" + if any(request.node.get_closest_marker(marker) for marker in (*_AGAINST_SERVERS, "real_clock")): + return "asyncio", {} + return "asyncio", {"loop_factory": VirtualClockLoop} + + +@pytest.fixture(autouse=True) +async def _bound_runtime(anyio_backend: object, request: pytest.FixtureRequest) -> AsyncIterator[None]: + """Fail a test instead of hanging when an asynchronous invariant breaks. + + A test against a real ZooKeeper or Nacos runs at the server's pace and bounds its own waits. + + After a test against Nacos, the channels of grpcio that it leaves are released before its event loop closes. + The Nacos SDK calls through grpcio, which keeps one completion queue for the process while any of its channels + lives, and a channel lives in a reference cycle until a collection. A queue that outlives the event loop of a + test delivers to it the events of its calls once it is closed, in the event loop of a later test. + """ + if any(request.node.get_closest_marker(marker) for marker in _AGAINST_SERVERS): + yield + else: + with anyio.fail_after(10) as scope: + # A test that keeps its event loop busy never moves the clock, so it fails after as long in real time. + loop = asyncio.get_running_loop() + if isinstance(loop, VirtualClockLoop): + loop.thread_limiter = anyio.to_thread.current_default_thread_limiter() + watchdog = threading.Timer(10, loop.call_soon_threadsafe, (setattr, scope, "deadline", -math.inf)) + watchdog.start() + try: + yield + finally: + watchdog.cancel() + + if request.node.get_closest_marker("nacos"): + gc.collect() + + +@pytest.fixture +def request_headers(): + return _H2_REQUEST_HEADERS + + +@pytest.fixture +def response_headers(): + return _H2_RESPONSE_HEADERS + + +@pytest.fixture +def h2_url(): + return _h2_url + + +@pytest.fixture +def isolated_extensions(monkeypatch) -> None: + """Start from a fresh view of the shared extensions so the test's registrations are undone.""" + monkeypatch.setattr(extensions, "_points", {}) + + +@pytest.fixture +def memory_zookeeper(isolated_extensions) -> Ensemble: + """An in-memory ensemble that URLs with ``client=memory`` connect to.""" + ensemble = Ensemble() + extensions.register(ZookeeperClient, "memory", memory_client(ensemble)) + return ensemble + + +@pytest.fixture +def config_store(isolated_extensions) -> ConfigStore: + """The configuration center ``memory``, registered on the shared extensions.""" + store = ConfigStore() + extensions.register(ConfigCenter, "memory", store.create) + return store diff --git a/tests/integration/compose.yaml b/tests/integration/compose.yaml new file mode 100644 index 00000000..e00a7827 --- /dev/null +++ b/tests/integration/compose.yaml @@ -0,0 +1,54 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# The servers of the integration tests: +# +# docker compose -f tests/integration/compose.yaml up -d --wait +# DUBBO_TEST_ZOOKEEPER=127.0.0.1:2181 DUBBO_TEST_NACOS=127.0.0.1:8848 .venv/bin/python -m pytest +# docker compose -f tests/integration/compose.yaml down -v +# +# The tags and host ports come from the variables below. A Nacos client reaches +# gRPC at the HTTP port plus 1000, so NACOS_GRPC_PORT keeps that offset. + +name: dubbo-test + +services: + zookeeper: + image: zookeeper:${ZOOKEEPER_TAG:-3.9.5} + ports: + - 127.0.0.1:${ZOOKEEPER_PORT:-2181}:2181 + healthcheck: + test: [CMD, zkServer.sh, status] + interval: 2s + timeout: 5s + retries: 30 + + nacos: + image: nacos/nacos-server:${NACOS_TAG:-v2.4.3} + environment: + MODE: standalone + JVM_XMS: 512m + JVM_XMX: 512m + JVM_XMN: 256m + ports: + - 127.0.0.1:${NACOS_PORT:-8848}:8848 + - 127.0.0.1:${NACOS_GRPC_PORT:-9848}:9848 + healthcheck: + test: [CMD-SHELL, curl -fs http://localhost:8848/nacos/v1/console/health/readiness && nc -z localhost 9848] + interval: 2s + timeout: 5s + retries: 60 diff --git a/tests/integration/config/parsers/test_base.py b/tests/integration/config/parsers/test_base.py new file mode 100644 index 00000000..37654a8b --- /dev/null +++ b/tests/integration/config/parsers/test_base.py @@ -0,0 +1,48 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import subprocess +import sys + + +def test_optional_parsers_are_loaded_only_when_selected(): + # A fresh interpreter also verifies the package's __init__ imports. + script = """ +import importlib.abc +import sys +import pytest + +class BlockOptional(importlib.abc.MetaPathFinder): + def find_spec(self, fullname, path=None, target=None): + if fullname in ("yaml", "dotproperties"): + raise ModuleNotFoundError(fullname, name=fullname) + +sys.meta_path.insert(0, BlockOptional()) +from dubbo.config import ConfigParser +from dubbo.extension import Extensions, ExtensionError +extensions = Extensions() +assert "dubbo.config.parsers.yaml" not in sys.modules +assert "dubbo.config.parsers.properties" not in sys.modules +assert extensions.get(ConfigParser, "json")().loads("{}") == {} +for name in ("yaml", "properties"): + with pytest.raises(ExtensionError) as caught: + extensions.get(ConfigParser, name) + assert isinstance(caught.value.__cause__, ModuleNotFoundError) + assert "apache-dubbo[" + name + "]" in str(caught.value.__cause__) +""" + result = subprocess.run([sys.executable, "-c", script], capture_output=True, text=True, timeout=10) + assert result.returncode == 0, result.stderr diff --git a/tests/integration/config_center/test_nacos.py b/tests/integration/config_center/test_nacos.py new file mode 100644 index 00000000..a5df8ccb --- /dev/null +++ b/tests/integration/config_center/test_nacos.py @@ -0,0 +1,68 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import uuid + +import anyio +import pytest +from v2.nacos import ConfigParam + +from dubbo.config_center.nacos import NacosConfigCenter +from dubbo.extension import ApplicationScope +from dubbo.transport.nacos import get_nacos_config_client +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = [pytest.mark.anyio, pytest.mark.nacos] + + +@pytest.fixture +async def storage(nacos): + group = f"dubbo-test-{uuid.uuid4().hex}" + async with ApplicationScope() as scope: + url = URL.parse(f"nacos://{nacos}").replace(attributes={APPLICATION_SCOPE: scope}) + client = await get_nacos_config_client(url) + async with NacosConfigCenter(url) as center: + yield center, client, group + + # The framework has no configuration deletion API. + for key in ("dubbo.yaml", "rules"): + await client._connected().remove_config(ConfigParam(data_id=key, group=group)) + + +async def test_entries_are_read_and_watched_by_key_and_group(storage): + center, client, group = storage + with anyio.fail_after(10): + async with client.watch("dubbo.yaml", group) as contents: + assert await anext(contents) is None + await client.update("dubbo.yaml", group, lambda _: "application: {name: orders}") + async for content in contents: + if content == "application: {name: orders}": + break + + assert await center.get("dubbo.yaml", group=group) == "application: {name: orders}" + assert await center.get("missing.yaml", group=group) is None + assert await center.get("dubbo.yaml", group=group + "-other") is None + + with anyio.fail_after(10): + async with center.watch("rules", group=group) as contents: + assert await anext(contents) is None + await client.update("rules", group, lambda _: "force: true") + async for content in contents: + if content == "force: true": + break + + assert content == "force: true" diff --git a/tests/integration/config_center/test_zookeeper.py b/tests/integration/config_center/test_zookeeper.py new file mode 100644 index 00000000..3e8dadf5 --- /dev/null +++ b/tests/integration/config_center/test_zookeeper.py @@ -0,0 +1,61 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import uuid + +import anyio +import pytest + +from dubbo import Dubbo +from dubbo.config import ConfigCenterConfig +from dubbo.config_center.zookeeper import ZookeeperConfigCenter +from dubbo.extension import ApplicationScope +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = [pytest.mark.anyio, pytest.mark.zookeeper] + + +async def test_application_reads_its_configuration_from_zookeeper(namespace, zookeeper, zk): + async with zk(f"zookeeper://{zookeeper}") as client: + await client.set(f"/{namespace}/config/dubbo/dubbo.yaml", b"application: {name: from-zookeeper}") + + center = ConfigCenterConfig(address=f"zookeeper://{zookeeper}", namespace=namespace) + async with Dubbo(env_prefix=None, config_center=center) as app: + assert app.config.application.name == "from-zookeeper" + + +async def test_watch_follows_the_node(namespace, zookeeper, zk): + url = URL.parse(f"zookeeper://{zookeeper}?namespace={namespace}") + + async with ( + ApplicationScope() as scope, + ZookeeperConfigCenter(url.replace(attributes={APPLICATION_SCOPE: scope})) as center, + center.watch("dubbo.yaml", group="dubbo") as values, + ): + with anyio.fail_after(5): + assert await anext(values) is None + async with zk(f"zookeeper://{zookeeper}") as writer: + await writer.set(f"/{namespace}/config/dubbo/dubbo.yaml", b"retries: 1") + assert await anext(values) == "retries: 1" + + +@pytest.fixture +async def namespace(zookeeper, delete_tree, zk): + name = f"dubbo-python-test-{uuid.uuid4().hex}" + yield name + async with zk(f"zookeeper://{zookeeper}") as client: + await delete_tree(client, f"/{name}") diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py new file mode 100644 index 00000000..0480b3c2 --- /dev/null +++ b/tests/integration/conftest.py @@ -0,0 +1,140 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Fixtures of the tests that run real ZooKeeper or Nacos servers, which their variables name.""" + +import contextlib +import os +from collections.abc import AsyncIterator +from contextlib import asynccontextmanager +from typing import Any + +import pytest +from anyio import to_thread +from kazoo.exceptions import NodeExistsError, NoNodeError + +from dubbo.extension import ApplicationScope +from dubbo.protocol.triple import TripleProtocol +from dubbo.transport.zookeeper import get_zookeeper_client +from dubbo.transport.zookeeper.kazoo import KazooZookeeperClient +from dubbo.url import APPLICATION_SCOPE, URL + +# The servers a marker needs, by the variable that holds their host:port. +_SERVERS = {"zookeeper": "DUBBO_TEST_ZOOKEEPER", "nacos": "DUBBO_TEST_NACOS"} + + +def pytest_runtest_setup(item: pytest.Item) -> None: + for marker, variable in _SERVERS.items(): + if item.get_closest_marker(marker) and not os.environ.get(variable): + pytest.skip(f"set {variable} to host:port") + + +@pytest.fixture +def zookeeper() -> str: + """The host:port of the ZooKeeper that tests marked ``zookeeper`` use.""" + return os.environ[_SERVERS["zookeeper"]] + + +@pytest.fixture +def nacos() -> str: + """The host:port of the Nacos that tests marked ``nacos`` use.""" + return os.environ[_SERVERS["nacos"]] + + +@pytest.fixture +def exported_urls(monkeypatch) -> list[URL]: + """The URLs of the services exported over Triple, in export order.""" + urls = [] + export = TripleProtocol.export + + async def record(protocol, *args): + exporter = await export(protocol, *args) + urls.append(exporter.url) + return exporter + + # Dubbo does not expose the port assigned to an exported service. + monkeypatch.setattr(TripleProtocol, "export", record) + return urls + + +class _NodesClient(KazooZookeeperClient): + """A kazoo client with the node operations that only tests use, which the in-memory client has too.""" + + async def children(self, path: str) -> list[str]: + def children() -> list[str]: + try: + return self._kazoo.get_children(path) + except NoNodeError: + return [] + + return await to_thread.run_sync(children) + + async def create(self, path: str, data: bytes = b"") -> None: + def create() -> None: + with contextlib.suppress(NodeExistsError): + self._kazoo.create(path, data, makepath=True) + + await to_thread.run_sync(create) + + async def set(self, path: str, data: bytes) -> None: + def set_() -> None: + try: + self._kazoo.set(path, data) + except NoNodeError: + self._kazoo.create(path, data, makepath=True) + + await to_thread.run_sync(set_) + + async def delete(self, path: str) -> None: + def delete() -> None: + with contextlib.suppress(NoNodeError): + self._kazoo.delete(path) + + await to_thread.run_sync(delete) + + +@asynccontextmanager +async def _zk(address: str) -> AsyncIterator[Any]: + """Yield a client of ``address`` with the node operations of `_NodesClient`, which disconnects on exit. + + With ``client=memory`` it is the in-memory client, in an application of its own. + """ + url = URL.parse(address) + if url.parameters.get("client") == "memory": + async with ApplicationScope() as scope: + yield await get_zookeeper_client(url.replace(attributes={APPLICATION_SCOPE: scope})) + return + + async with _NodesClient(url) as client: + yield client + + +async def _delete_tree(client: Any, path: str) -> None: + """Delete the node at ``path`` and those under it, through a client that `_zk` yields.""" + for child in await client.children(path): + await _delete_tree(client, f"{path}/{child}") + await client.delete(path) + + +@pytest.fixture +def zk(): + return _zk + + +@pytest.fixture +def delete_tree(): + return _delete_tree diff --git a/tests/integration/metadata/report/test_nacos.py b/tests/integration/metadata/report/test_nacos.py new file mode 100644 index 00000000..311a4f63 --- /dev/null +++ b/tests/integration/metadata/report/test_nacos.py @@ -0,0 +1,94 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import uuid + +import anyio +import pytest +from v2.nacos import ConfigParam + +from dubbo.extension import ApplicationScope +from dubbo.metadata import MetadataInfo +from dubbo.metadata.report.nacos import NacosMetadataReport +from dubbo.transport.nacos import get_nacos_config_client +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = [pytest.mark.anyio, pytest.mark.nacos] + + +@pytest.fixture +async def storage(nacos): + app, interface = f"orders-{uuid.uuid4().hex}", f"org.example.Users{uuid.uuid4().hex}" + async with ApplicationScope() as scope: + url = URL.parse(f"nacos://{nacos}").replace(attributes={APPLICATION_SCOPE: scope}) + client = await get_nacos_config_client(url) + async with NacosMetadataReport(url) as report: + yield report, client, app, interface + + # The framework has no configuration deletion API. + for data_id, group in ((app, "0"), (interface, "mapping")): + await client._connected().remove_config(ConfigParam(data_id=data_id, group=group)) + + +async def test_app_metadata_is_stored_under_its_application_and_revision(storage): + report, client, app, _ = storage + metadata = MetadataInfo(app=app) + + assert await report.get_app_metadata(app, metadata.revision) is None + with anyio.fail_after(10): + async with client.watch(app, metadata.revision) as contents: + assert await anext(contents) is None + await report.publish_app_metadata(metadata) + async for content in contents: + if content == metadata.to_json(): + break + + assert content == metadata.to_json() + assert await client.get(app, metadata.revision) == metadata.to_json() + assert await report.get_app_metadata(app, metadata.revision) == metadata + + +async def test_publishing_metadata_preserves_an_existing_revision(storage): + report, client, app, _ = storage + metadata = MetadataInfo(app=app) + with anyio.fail_after(10): + async with client.watch(app, metadata.revision) as contents: + assert await anext(contents) is None + await client.update(app, metadata.revision, lambda _: "stored first") + async for content in contents: + if content == "stored first": + break + + await report.publish_app_metadata(metadata) + + assert await client.get(app, metadata.revision) == "stored first" + + +async def test_interface_mapping_stores_unique_application_names_in_the_mapping_group(storage): + report, client, _, interface = storage + + with anyio.fail_after(10): + async with report.subscribe_service_app_mapping(interface) as names: + assert await anext(names) == frozenset() + for app in ("orders", "billing", "orders"): + await report.register_service_app_mapping(interface, app) + async for applications in names: + if applications == {"orders", "billing"}: + break + + assert applications == {"orders", "billing"} + assert await client.get(interface, "mapping") == "orders,billing" diff --git a/tests/integration/metadata/report/test_zookeeper.py b/tests/integration/metadata/report/test_zookeeper.py new file mode 100644 index 00000000..1e820244 --- /dev/null +++ b/tests/integration/metadata/report/test_zookeeper.py @@ -0,0 +1,46 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import uuid + +import anyio +import pytest + +from dubbo.extension import ApplicationScope +from dubbo.metadata.report.zookeeper import ZookeeperMetadataReport +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = [pytest.mark.anyio, pytest.mark.zookeeper] + + +@pytest.fixture +async def root(zookeeper, delete_tree, zk): + root = f"/dubbo-python-test-{uuid.uuid4().hex}" + yield root + async with zk(f"zookeeper://{zookeeper}") as client: + await delete_tree(client, root) + + +async def test_mapping_updates_leave_out_names_that_are_not_utf8(zookeeper, root, zk): + async with zk(f"zookeeper://{zookeeper}") as client: + await client.set(f"{root}/mapping/test.Greeter", b"good-app,\xff\xfe") + async with ApplicationScope() as scope: + url = URL.parse(f"zookeeper://{zookeeper}?group={root}").replace(attributes={APPLICATION_SCOPE: scope}) + async with ZookeeperMetadataReport(url) as report: + with anyio.fail_after(5): + async with report.subscribe_service_app_mapping("test.Greeter") as mappings: + assert await anext(mappings) == {"good-app"} diff --git a/tests/integration/protocol/dubbo/conftest.py b/tests/integration/protocol/dubbo/conftest.py new file mode 100644 index 00000000..d99d86d0 --- /dev/null +++ b/tests/integration/protocol/dubbo/conftest.py @@ -0,0 +1,198 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import abc +import dataclasses +import struct +import typing +from collections.abc import AsyncIterator +from typing import Any + +import anyio +import hessian2 +import pytest + +import dubbo +from dubbo import RemoteError, RpcError, Status +from dubbo.protocol import Exporter +from dubbo.protocol.dubbo import DubboProtocol +from dubbo.rpc.client import proxy +from dubbo.rpc.invocation import Invocation +from dubbo.rpc.server import ServiceInvoker +from dubbo.url import URL + + +@hessian2.java_class("com.example.Address") +@dataclasses.dataclass +class Address: + city: str + + +@hessian2.java_class("java.lang.IllegalStateException") +@dataclasses.dataclass +class IllegalState(Exception): + detail_message: str = "" + + +@hessian2.java_class("com.example.User") +@dataclasses.dataclass +class User: + name: str + user_id: hessian2.Long + address: Address + + +@dubbo.service("com.example.UserService") +class UserService(abc.ABC): + @dubbo.method("find") + @abc.abstractmethod + async def find(self, name: str, user_id: hessian2.Long) -> User | None: ... + + @dubbo.method("forget") + @abc.abstractmethod + async def forget(self, name: str) -> None: ... + + @dubbo.method("fail") + @abc.abstractmethod + async def fail(self, how: str) -> str: ... + + @dubbo.method("sleep") + @abc.abstractmethod + async def sleep(self) -> str: ... + + +@dubbo.service("com.example.UserService") +class WiderUserService(typing.Protocol): + @dubbo.method("find") + async def find(self, name: str, user_id: hessian2.Long) -> User | None: ... + + @dubbo.method("missing") + async def missing(self) -> str: ... + + +class UserServiceImpl(UserService): + def __init__(self) -> None: + self.started = anyio.Event() + self.released = anyio.Event() + self.cancelled = anyio.Event() + self.forgotten: list[str] = [] + + async def find(self, name: str, user_id: int) -> User | None: + call = dubbo.incoming() + call.response_attachments["served-by"] = "users" + call.response_attachments["tag"] = call.attachments.get("tag", "") + return None if name == "nobody" else User(name=name, user_id=user_id, address=Address(city="Hangzhou")) + + async def forget(self, name: str) -> None: + self.forgotten.append(name) + + async def fail(self, how: str) -> str: + if how == "rpc": + raise RpcError(Status.NOT_FOUND, "no such user") + if how == "declared": + raise IllegalState("not now") + if how == "remote": + raise RemoteError("com.example.UserNotFound", "bob", fields={"code": 3}) + raise ValueError("broken") + + async def sleep(self) -> str: + self.started.set() + try: + await self.released.wait() + return "" + finally: + self.cancelled.set() + + +@pytest.fixture +async def protocol() -> AsyncIterator[DubboProtocol]: + async with DubboProtocol() as protocol: + yield protocol + + +@pytest.fixture +def impl() -> UserServiceImpl: + return UserServiceImpl() + + +async def _export(protocol: DubboProtocol, impl: object, query: str = "") -> Exporter: + url = URL.parse(f"dubbo://127.0.0.1:0/com.example.UserService{query}") + return await protocol.export(url, dubbo.get_definition(UserService), ServiceInvoker.from_implementation(impl, url)) + + +def _frame(flags: int, request_id: int, body: bytes, status: int = 0) -> bytes: + return struct.pack(">HBBqI", 0xDABB, flags, status, request_id, len(body)) + body + + +def _find(arguments: tuple[Any, ...]) -> Invocation: + find = next(method for method in dubbo.get_definition(UserService).methods if method.name == "find") + return Invocation(interface="com.example.UserService", method="find", definition=find, arguments=arguments) + + +async def _refer(protocol: DubboProtocol, exporter: Exporter, query: str = "", contract: type = UserService) -> Any: + url = URL.parse(f"dubbo://127.0.0.1:{exporter.url.port}/com.example.UserService{query}") + return proxy(contract, (await protocol.refer(url, dubbo.get_definition(contract))).invoke) + + +@pytest.fixture +async def users(protocol: DubboProtocol, impl: UserServiceImpl) -> UserService: + return await _refer(protocol, await _export(protocol, impl)) + + +@pytest.fixture +def export(): + return _export + + +@pytest.fixture +def refer(): + return _refer + + +@pytest.fixture +def frame(): + return _frame + + +@pytest.fixture +def find_invocation(): + return _find + + +@pytest.fixture +def user_service(): + return UserService + + +@pytest.fixture +def wider_service(): + return WiderUserService + + +@pytest.fixture +def implementation_type(): + return UserServiceImpl + + +@pytest.fixture +def user_type(): + return User + + +@pytest.fixture +def address_type(): + return Address diff --git a/tests/integration/protocol/dubbo/test_client.py b/tests/integration/protocol/dubbo/test_client.py new file mode 100644 index 00000000..d68aafd8 --- /dev/null +++ b/tests/integration/protocol/dubbo/test_client.py @@ -0,0 +1,428 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import struct +import typing +from pathlib import Path +from typing import Any + +import anyio +import hessian2 +import pytest +from anyio.abc import SocketAttribute +from anyio.streams.buffered import BufferedByteReceiveStream + +import dubbo +from dubbo import Method, Parameter, RemoteError, RpcError, Status +from dubbo.protocol.dubbo import DubboProtocol +from dubbo.protocol.dubbo.connection import DubboConnection +from dubbo.rpc.client import proxy +from dubbo.rpc.definition import Service +from dubbo.rpc.invocation import Invocation +from dubbo.rpc.server import ServiceInvoker +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + +_CERT_FILE = Path(__file__).resolve().parents[3] / "certificates" / "localhost-cert.pem" + + +_KEY_FILE = Path(__file__).resolve().parents[3] / "certificates" / "localhost-key.pem" + + +@dubbo.service("com.example.Lookup") +class ByName(typing.Protocol): + @dubbo.method("find") + async def find(self, key: str) -> str: ... + + +@dubbo.service("com.example.Lookup") +class ById(typing.Protocol): + @dubbo.method("find") + async def find(self, key: int) -> str: ... + + +async def test_a_call_returns_the_declared_classes(users, user_type, address_type) -> None: + user = await users.find("bob", 7) + + assert user == user_type(name="bob", user_id=7, address=address_type(city="Hangzhou")) + + +async def test_nothing_returned_reaches_the_caller_as_none(users, impl) -> None: + assert await users.find("nobody", 1) is None + assert await users.forget("bob") is None + assert impl.forgotten == ["bob"] + + +async def test_attachments_travel_both_ways( + protocol: DubboProtocol, impl, export, find_invocation, user_service +) -> None: + exporter = await export(protocol, impl) + url = URL.parse(f"dubbo://127.0.0.1:{exporter.url.port}/com.example.UserService") + invoker = await protocol.refer(url, dubbo.get_definition(user_service)) + + invocation = find_invocation(arguments=("bob", 7)) + invocation.attachments["tag"] = "gray" + result = await invoker.invoke(invocation) + + assert result.error is None + assert result.attachments["served-by"] == "users" + assert result.attachments["tag"] == "gray" + assert result.attachments["dubbo"] == "2.0.2" + + +@pytest.mark.parametrize( + ("how", "class_name", "message", "fields"), + [ + ("rpc", "org.apache.dubbo.rpc.RpcException", "no such user", {"code": 0}), + ("crash", "java.lang.RuntimeException", "ValueError: broken", {}), + ("declared", "java.lang.IllegalStateException", "not now", {}), + ("remote", "com.example.UserNotFound", "bob", {"code": 3}), + ], + ids=["rpc-error", "python-exception", "declared-class", "remote-error"], +) +async def test_handler_exceptions_preserve_their_java_class_message_and_fields(users, how, class_name, message, fields): + with pytest.raises(RemoteError, match=message) as raised: + await users.fail(how) + + assert (raised.value.status, raised.value.class_name, raised.value.message) == (Status.UNKNOWN, class_name, message) + assert {key: raised.value.fields[key] for key in fields} == fields + + +async def test_a_service_of_version_0_0_0_is_one_without_a_version( + protocol: DubboProtocol, impl, export, refer +) -> None: + exporter = await export(protocol, impl, "?version=0.0.0") + + assert (await (await refer(protocol, exporter)).find("bob", 1)).name == "bob" + + +async def test_a_call_travels_over_tls(protocol: DubboProtocol, impl, export, refer) -> None: + exporter = await export(protocol, impl, f"?ssl-enabled=true&tls-cert-file={_CERT_FILE}&tls-key-file={_KEY_FILE}") + + users = await refer(protocol, exporter, f"?ssl-enabled=true&ca-cert-file={_CERT_FILE}&tls-server-name=localhost") + cleartext = await refer(protocol, exporter) + + assert (await users.find("bob", 1)).name == "bob" + with pytest.raises(RpcError) as caught: + await cleartext.find("bob", 1) + assert caught.value.status is Status.UNAVAILABLE + + +async def test_a_serialization_of_no_java_objects_cannot_carry_dubbo(protocol: DubboProtocol, impl, export) -> None: + with pytest.raises(ValueError, match="no id in the Dubbo protocol"): + await export(protocol, impl, "?serialization=protobuf") + + +async def test_a_method_the_provider_lacks_is_not_found( + protocol: DubboProtocol, impl, export, refer, wider_service +) -> None: + wider = await refer(protocol, await export(protocol, impl), contract=wider_service) + + with pytest.raises(RpcError) as caught: + await wider.missing() + + assert caught.value.status is Status.UNAVAILABLE + assert (await wider.find("bob", 1)).name == "bob" + + +async def test_group_and_version_choose_the_service(protocol: DubboProtocol, impl, export, refer) -> None: + exporter = await export(protocol, impl, "?group=a&version=1.0") + + assert (await (await refer(protocol, exporter, "?group=a&version=1.0")).find("bob", 1)).name == "bob" + for query in ("", "?group=a", "?version=1.0", "?group=b&version=1.0"): + with pytest.raises(RpcError) as caught: + await (await refer(protocol, exporter, query)).find("bob", 1) + assert caught.value.status is Status.UNAVAILABLE + + +async def test_a_call_ends_at_its_timeout(protocol: DubboProtocol, impl, export, refer) -> None: + users = await refer(protocol, await export(protocol, impl, "?shutwait=50"), "?timeout=100") + + with pytest.raises(RpcError) as caught: + await users.sleep() + + assert caught.value.status is Status.DEADLINE_EXCEEDED + + +async def test_a_call_may_not_attach_what_routes_it(users) -> None: + with dubbo.outgoing({"group": "admin"}), pytest.raises(RpcError) as caught: + await users.find("bob", 1) + + assert caught.value.status is Status.INVALID_ARGUMENT + assert "group" in caught.value.message + + +async def test_a_call_beyond_the_most_at_once_is_refused(protocol: DubboProtocol, impl, export, refer) -> None: + users = await refer(protocol, await export(protocol, impl, "?max-concurrent-calls=1&shutwait=50")) + + async with anyio.create_task_group() as task_group: + task_group.start_soon(users.sleep) + await impl.started.wait() + with pytest.raises(RpcError) as caught: + await users.find("bob", 1) + task_group.cancel_scope.cancel() + + assert caught.value.status is Status.UNAVAILABLE + assert "1 calls at once" in caught.value.message + + +async def test_a_generic_call_travels_as_invoke(protocol: DubboProtocol, frame) -> None: + requests: list[list[Any]] = [] + + async def answer(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None: + while header := await reader.read(16): + _, _, _, request_id, length = struct.unpack(">HBBqI", header) + requests.append(hessian2.loads_many(await reader.readexactly(length))) + body = hessian2.dumps_many([1, {"class": "com.example.User", "name": "bob"}]) + writer.write(frame(2, request_id, body, status=20)) + writer.close() + + server = await asyncio.start_server(answer, "127.0.0.1", 0) + async with server: + port = server.sockets[0].getsockname()[1] + url = URL.parse(f"dubbo://127.0.0.1:{port}/com.example.UserService?version=1.0&getUser.timeout=2500") + invoker = await protocol.refer(url, Service(interface="com.example.UserService", methods=())) + users = dubbo.GenericService("com.example.UserService", invoker.invoke) + + assert await users.call("getUser", "bob", 7) == {"class": "com.example.User", "name": "bob"} + await users.call("find", {"name": "bob"}, 7, types=["com.example.Query", "long"]) + await invoker.aclose() + + head = [ + "2.0.2", + "com.example.UserService", + "1.0", + "$invoke", + "Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;", + ] + first, second = requests + assert first[:8] == [*head, "getUser", None, ["bob", 7]] + assert second[:8] == [*head, "find", ["com.example.Query", "long"], [{"name": "bob"}, 7]] + assert (first[8]["generic"], first[8]["timeout"], second[8]["timeout"]) == ("true", "2500", "1000") + + +async def test_echo_returns_its_argument(protocol: DubboProtocol, impl, export) -> None: + exporter = await export(protocol, impl) + echo = Service( + interface="com.example.UserService", + methods=[Method(name="$echo", request=(Parameter(name="value", type=Any),), response=Any)], + ) + url = URL.parse(f"dubbo://127.0.0.1:{exporter.url.port}/com.example.UserService") + invoker = await protocol.refer(url, echo) + + result = await invoker.invoke( + Invocation(interface="com.example.UserService", method="$echo", definition=echo.methods[0], arguments=("ping",)) + ) + + assert (result.value, result.error) == ("ping", None) + + +async def test_a_large_body_crosses_several_reads(users, user_type, address_type) -> None: + name = "x" * (3 * 1024 * 1024) + + user = await users.find(name, 1) + + assert user == user_type(name=name, user_id=1, address=address_type(city="Hangzhou")) + + +async def test_a_body_over_the_payload_is_refused(protocol: DubboProtocol, impl, export, refer) -> None: + users = await refer(protocol, await export(protocol, impl), "?payload=1000") + + with pytest.raises(RpcError) as caught: + await users.find("x" * 2000, 1) + + assert caught.value.status is Status.RESOURCE_EXHAUSTED + + +async def test_a_call_in_flight_fails_when_the_provider_closes(impl, export, refer) -> None: + async with DubboProtocol() as caller, DubboProtocol() as provider: + exporter = await export(provider, impl, "?shutwait=50") + users = await refer(caller, exporter) + + async with anyio.create_task_group() as task_group: + + async def call() -> None: + with pytest.raises(RpcError) as caught: + await users.sleep() + assert caught.value.status is Status.UNAVAILABLE + + task_group.start_soon(call) + await impl.started.wait() + await provider.aclose() + + +async def test_a_provider_that_takes_calls_again_is_available_again( + protocol: DubboProtocol, find_invocation, user_service, frame +) -> None: + readonly_in_long_string_form, writable = b"S\x00\x01R", hessian2.dumps("W") + notices: asyncio.Queue[bytes | None] = asyncio.Queue() + + async def serve(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None: + _, _, _, request_id, length = struct.unpack(">HBBqI", await reader.readexactly(16)) + await reader.readexactly(length) + body = hessian2.dumps_many([2]) + writer.write(frame(2, request_id, body, status=20)) + while (notice := await notices.get()) is not None: + writer.write(frame(0x80 | 0x20 | 2, 0, notice)) + writer.close() + await writer.wait_closed() + + server = await asyncio.start_server(serve, "127.0.0.1", 0) + async with server: + port = server.sockets[0].getsockname()[1] + url = URL.parse(f"dubbo://127.0.0.1:{port}/com.example.UserService") + invoker = await protocol.refer(url, dubbo.get_definition(user_service)) + await invoker.invoke(find_invocation(arguments=("bob", 1))) + + for notice, available in ((readonly_in_long_string_form, False), (writable, True)): + notices.put_nowait(notice) + with anyio.fail_after(5): + while invoker.available is not available: + await anyio.wait_all_tasks_blocked() + notices.put_nowait(None) + + +async def test_a_closing_provider_refuses_new_calls_while_running_ones_finish(impl, export, refer): + async with DubboProtocol() as caller, DubboProtocol() as provider: + users = await refer(caller, await export(provider, impl, "?shutwait=5000")) + results = [] + + async def call(): + results.append(await users.sleep()) + + async with anyio.create_task_group() as tasks: + tasks.start_soon(call) + await impl.started.wait() + tasks.start_soon(provider.aclose) + await anyio.wait_all_tasks_blocked() + with pytest.raises(RpcError, match="UNAVAILABLE") as raised: + await users.find("bob", 1) + assert raised.value.status is Status.UNAVAILABLE + assert results == [] + impl.released.set() + + assert results == [""] + + +async def test_a_caller_reconnects_after_the_peer_closes_its_socket( + protocol, user_service, user_type, address_type, frame, monkeypatch +): + accepted = [] + lost = anyio.Event() + connection_lost = DubboConnection.connection_lost + + def record(connection, error): + connection_lost(connection, error) + lost.set() + + # The caller reconnects once it has seen the connection close, which comes after the peer closes it. + monkeypatch.setattr(DubboConnection, "connection_lost", record) + + async def answer(stream): + async with stream: + reader = BufferedByteReceiveStream(stream) + header = await reader.receive_exactly(16) + _, _, _, request_id, length = struct.unpack(">HBBqI", header) + await reader.receive_exactly(length) + accepted.append(request_id) + body = hessian2.dumps_many([1, user_type(name="bob", user_id=1, address=address_type(city="Hangzhou"))]) + await stream.send(frame(2, request_id, body, status=20)) + + async with await anyio.create_tcp_listener(local_host="127.0.0.1") as listener, anyio.create_task_group() as tasks: + tasks.start_soon(listener.serve, answer) + port = listener.extra(SocketAttribute.local_port) + url = URL.parse(f"dubbo://127.0.0.1:{port}/com.example.UserService") + users = proxy(user_service, (await protocol.refer(url, dubbo.get_definition(user_service))).invoke) + + assert (await users.find("bob", 1)).name == "bob" + await lost.wait() + assert (await users.find("bob", 1)).name == "bob" + assert len(accepted) == 2 + tasks.cancel_scope.cancel() + + +async def test_groups_may_export_a_method_with_other_parameters_each_its_own(protocol: DubboProtocol) -> None: + class Named(ByName): + async def find(self, key: str) -> str: + return f"name {key}" + + class Numbered(ById): + async def find(self, key: int) -> str: + return f"id {key}" + + exporters = [] + for contract, impl, group in ((ByName, Named(), "a"), (ById, Numbered(), "b")): + url = URL.parse( + f"dubbo://127.0.0.1:{exporters[0].url.port if exporters else 0}/com.example.Lookup?group={group}" + ) + exporters.append( + await protocol.export(url, dubbo.get_definition(contract), ServiceInvoker.from_implementation(impl, url)) + ) + + port = exporters[0].url.port + for contract, group, key, expected in ((ByName, "a", "bob", "name bob"), (ById, "b", 7, "id 7")): + url = URL.parse(f"dubbo://127.0.0.1:{port}/com.example.Lookup?group={group}") + caller = proxy(contract, (await protocol.refer(url, dubbo.get_definition(contract))).invoke) + assert await caller.find(key) == expected + + url = URL.parse(f"dubbo://127.0.0.1:{port}/com.example.Lookup?group=a") + stale = proxy(ById, (await protocol.refer(url, dubbo.get_definition(ById))).invoke) + with pytest.raises(RpcError, match="SERVICE_NOT_FOUND"): + await stale.find(7) + + +async def test_a_response_in_another_serialization_fails_the_call(protocol: DubboProtocol, user_service, frame) -> None: + async def answer(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None: + header = await reader.readexactly(16) + _, _, _, request_id, length = struct.unpack(">HBBqI", header) + await reader.readexactly(length) + body = hessian2.dumps_many([4, None, {}]) + writer.write(frame(23, request_id, body, status=20)) + writer.close() + await writer.wait_closed() + + server = await asyncio.start_server(answer, "127.0.0.1", 0) + async with server: + port = server.sockets[0].getsockname()[1] + url = URL.parse(f"dubbo://127.0.0.1:{port}/com.example.UserService") + users = proxy(user_service, (await protocol.refer(url, dubbo.get_definition(user_service))).invoke) + + with pytest.raises(RpcError) as caught: + await users.find("bob", 1) + + assert caught.value.status is Status.INTERNAL + assert "serialization 23" in caught.value.message + + +async def test_connecting_takes_at_most_the_connect_timeout(protocol: DubboProtocol, user_service) -> None: + # A listener that never answers the TLS handshake. + async with await anyio.create_tcp_listener(local_host="127.0.0.1") as listener: + port = listener.extra(SocketAttribute.local_port) + url = URL.parse( + f"dubbo://127.0.0.1:{port}/com.example.UserService" + f"?ssl-enabled=true&ca-cert-file={_CERT_FILE}&tls-server-name=localhost&connect-timeout=100" + ) + users = proxy(user_service, (await protocol.refer(url, dubbo.get_definition(user_service))).invoke) + started = anyio.current_time() + + with pytest.raises(RpcError) as caught: + await users.find("bob", 1) + + assert caught.value.status is Status.UNAVAILABLE + assert anyio.current_time() - started == pytest.approx(0.1) diff --git a/tests/integration/protocol/dubbo/test_connection.py b/tests/integration/protocol/dubbo/test_connection.py new file mode 100644 index 00000000..9fe6ffd2 --- /dev/null +++ b/tests/integration/protocol/dubbo/test_connection.py @@ -0,0 +1,116 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import socket +import struct + +import anyio +import hessian2 +import pytest +from anyio.streams.buffered import BufferedByteReceiveStream + +import dubbo +from dubbo.protocol.dubbo import DubboProtocol +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +async def test_bytes_that_are_not_dubbo_close_the_connection(protocol: DubboProtocol, impl, export) -> None: + exporter = await export(protocol, impl) + + with socket.create_connection(("127.0.0.1", exporter.url.port)) as sock: + sock.sendall(b"ls\r\n" + b"\x00" * 16) + sock.setblocking(False) + assert await asyncio.get_running_loop().sock_recv(sock, 1) == b"" + + +async def test_heartbeats_keep_an_idle_connection_open(protocol, user_service, find_invocation, frame): + heartbeats = anyio.Event() + accepted = [] + count = 0 + + async def answer(stream): + nonlocal count + accepted.append(stream) + async with stream: + reader = BufferedByteReceiveStream(stream) + while True: + header = await reader.receive_exactly(16) + _, flags, _, request_id, length = struct.unpack(">HBBqI", header) + body = await reader.receive_exactly(length) + if flags & 0x20: + assert hessian2.loads(body) is None + await stream.send(frame(0x22, request_id, b"N", status=20)) + count += 1 + if count == 5: + heartbeats.set() + else: + response = hessian2.dumps_many([2]) + await stream.send(frame(2, request_id, response, status=20)) + + async with await anyio.create_tcp_listener(local_host="127.0.0.1") as listener, anyio.create_task_group() as tasks: + tasks.start_soon(listener.serve, answer) + port = listener.extra(anyio.abc.SocketAttribute.local_port) + url = URL.parse(f"dubbo://127.0.0.1:{port}/com.example.UserService?heartbeat=50&heartbeat.timeout=250") + invoker = await protocol.refer(url, dubbo.get_definition(user_service)) + find = find_invocation(arguments=("nobody", 1)) + assert (await invoker.invoke(find)).error is None + + await heartbeats.wait() + + assert (await invoker.invoke(find)).error is None + assert len(accepted) == 1 + tasks.cancel_scope.cancel() + + +async def test_heartbeats_keep_a_connection_to_the_server_open(protocol: DubboProtocol, impl, export, frame) -> None: + exporter = await export(protocol, impl, "?heartbeat=50&heartbeat.timeout=250") + + async with await anyio.connect_tcp("127.0.0.1", exporter.url.port) as stream: + reader = BufferedByteReceiveStream(stream) + # A heartbeat each 50 ms, past three times the idle timeout, so that the server would have closed a silent + # connection. + for request_id in range(1, 16): + await stream.send(frame(0xE2, request_id, b"N")) + header = await reader.receive_exactly(16) + assert struct.unpack(">HBBqI", header) == (0xDABB, 0x22, 20, request_id, 1) + assert await reader.receive_exactly(1) == b"N" + await anyio.sleep(0.05) + + +async def test_the_server_acknowledges_a_heartbeat_without_invoking_a_service(protocol, impl, export, frame): + exporter = await export(protocol, impl) + + async with await anyio.connect_tcp("127.0.0.1", exporter.url.port) as stream: + await stream.send(frame(0xE2, 42, b"N")) + reader = BufferedByteReceiveStream(stream) + header = await reader.receive_exactly(16) + body = await reader.receive_exactly(1) + + assert struct.unpack(">HBBqI", header) == (0xDABB, 0x22, 20, 42, 1) + assert body == b"N" + + +async def test_a_silent_connection_is_closed(protocol: DubboProtocol, impl, export) -> None: + exporter = await export(protocol, impl, "?heartbeat=20&heartbeat.timeout=60") + + with socket.create_connection(("127.0.0.1", exporter.url.port)) as sock: + sock.setblocking(False) + with anyio.fail_after(2): + assert await asyncio.get_running_loop().sock_recv(sock, 1) == b"" diff --git a/tests/integration/protocol/dubbo/test_protocol.py b/tests/integration/protocol/dubbo/test_protocol.py new file mode 100644 index 00000000..a8068abf --- /dev/null +++ b/tests/integration/protocol/dubbo/test_protocol.py @@ -0,0 +1,173 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import contextlib + +import anyio +import hessian2 +import pytest + +import dubbo +from dubbo import Method, Parameter, RpcError +from dubbo.protocol.dubbo import DubboProtocol +from dubbo.rpc.client import proxy +from dubbo.rpc.definition import Service +from dubbo.rpc.server import ServiceInvoker +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +async def test_disconnecting_a_caller_cancels_its_call_and_releases_its_capacity(protocol, impl, export, refer, frame): + exporter = await export(protocol, impl, "?max-concurrent-calls=1") + body = hessian2.dumps_many(("2.0.2", "com.example.UserService", "0.0.0", "sleep", "", {})) + + async with await anyio.connect_tcp("127.0.0.1", exporter.url.port) as stream: + await stream.send(frame(0xC2, 5, body)) + await impl.started.wait() + await impl.cancelled.wait() + await anyio.wait_all_tasks_blocked() + users = await refer(protocol, exporter) + + assert (await users.find("bob", 1)).name == "bob" + assert not impl.released.is_set() + + +async def test_announcing_shutdown_makes_callers_turn_away( + protocol: DubboProtocol, impl, export, find_invocation, user_service +) -> None: + exporter = await export(protocol, impl) + url = URL.parse(f"dubbo://127.0.0.1:{exporter.url.port}/com.example.UserService") + invoker = await protocol.refer(url, dubbo.get_definition(user_service)) + await invoker.invoke(find_invocation(arguments=("bob", 1))) + + protocol.announce_shutdown() + + with anyio.fail_after(5): + while invoker.available: + await anyio.wait_all_tasks_blocked() + + +async def test_cancelling_export_closes_the_listener_it_opened(protocol, impl, monkeypatch, export): + listeners = [] + started = anyio.Event() + start_serving = asyncio.base_events.Server.start_serving + + async def start_and_wait(listener): + listeners.append(listener) + await start_serving(listener) + started.set() + await anyio.sleep_forever() + + monkeypatch.setattr(asyncio.base_events.Server, "start_serving", start_and_wait) + scopes = [] + + async def exporting(): + with anyio.CancelScope() as scope: + scopes.append(scope) + await export(protocol, impl) + + async with anyio.create_task_group() as tasks: + tasks.start_soon(exporting) + await started.wait() + scopes[0].cancel() + + assert len(listeners) == 1 + assert not listeners[0].is_serving() + + +async def test_a_failed_first_export_leaves_no_server_behind(protocol: DubboProtocol, impl, export) -> None: + url = URL.parse("dubbo://127.0.0.1:0/com.example.Odd") + odd = Service( + interface="com.example.Odd", + methods=(Method(name="take", request=(Parameter(name="z", type=complex),), response=None),), + ) + with pytest.raises(TypeError, match="no Java type"): + await protocol.export(url, odd, ServiceInvoker.from_implementation(impl, url)) + + # A server left behind would refuse a service asking for other settings. + exporter = await export(protocol, impl, "?payload=1024") + + assert exporter.url.port not in (None, 0) + + +@pytest.mark.parametrize( + ("shared", "versions", "made"), + [(True, ["", ""], 1), (True, ["1", "2"], 2), (False, ["", ""], 2)], + ids=["shared", "per-version", "not-shared"], +) +async def test_references_share_codecs_only_of_a_serialization_that_says_so( + protocol, impl, export, user_service, monkeypatch, shared, versions, made +) -> None: + from dubbo.protocol.dubbo import invoker + from dubbo.serialization.hessian2 import Hessian2Serialization + + calls = [] + from_definition = invoker.ServiceCodecs.from_definition + + def recording(serialization, definition, version): + calls.append(version) + return from_definition(serialization, definition, version) + + monkeypatch.setattr(invoker.ServiceCodecs, "from_definition", recording) + monkeypatch.setattr(Hessian2Serialization, "shared", shared) + exporter = await export(protocol, impl) + + for version, timeout in zip(versions, ("100", "200"), strict=True): + url = URL.parse(f"dubbo://127.0.0.1:{exporter.url.port}/com.example.UserService?timeout={timeout}") + url = url.update_parameters({"version": version}) if version else url + users = proxy(user_service, (await protocol.refer(url, dubbo.get_definition(user_service))).invoke) + # A call settles the connection, so that the server does not close while it accepts one. + with contextlib.suppress(RpcError): + await users.find("alice", hessian2.Long(1)) + + assert len(calls) == made + + +async def test_a_host_name_that_port_0_binds_to_several_ports_is_refused( + protocol: DubboProtocol, impl, user_service, monkeypatch +) -> None: + class Socket: + def __init__(self, host: str, port: int) -> None: + self.address = (host, port) + + def getsockname(self): + return self.address + + closed = [] + + class Listener: + def __init__(self) -> None: + self.sockets = [Socket("127.0.0.1", 20881), Socket("::1", 20882)] + + def close(self) -> None: + closed.append(self) + + async def wait_closed(self) -> None: + pass + + async def create_server(*args, **kwargs): + return Listener() + + monkeypatch.setattr(asyncio.get_running_loop(), "create_server", create_server) + url = URL.parse("dubbo://localhost:0/com.example.UserService") + + with pytest.raises(ValueError, match="port 0 binds to different ports"): + await protocol.export(url, dubbo.get_definition(user_service), ServiceInvoker.from_implementation(impl, url)) + + assert len(closed) == 1 diff --git a/tests/integration/protocol/dubbo/test_server.py b/tests/integration/protocol/dubbo/test_server.py new file mode 100644 index 00000000..05845892 --- /dev/null +++ b/tests/integration/protocol/dubbo/test_server.py @@ -0,0 +1,448 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import importlib.util +import json +import socket +import struct +import sys +from pathlib import Path +from typing import Any + +import anyio +import hessian2 +import pytest +from anyio.streams.buffered import BufferedByteReceiveStream + +import dubbo +from dubbo import RpcError, Status +from dubbo.exceptions import RemoteError +from dubbo.protocol.dubbo import DubboProtocol +from dubbo.rpc import Invocation, Result +from dubbo.rpc.client import proxy +from dubbo.rpc.server import ServiceInvoker +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +def _request_body(method: str, descriptor: str, *arguments: Any) -> bytes: + values = ("2.0.2", "com.example.UserService", "0.0.0", method, descriptor, *arguments, {}) + return hessian2.dumps_many(values) + + +async def _receive(sock: socket.socket, size: int) -> bytes: + """Return the next ``size`` bytes from the non-blocking ``sock``, or fewer if the peer closes it first.""" + received = b"" + while len(received) < size and (chunk := await asyncio.get_running_loop().sock_recv(sock, size - len(received))): + received += chunk + return received + + +async def _response(sock: socket.socket) -> tuple[int, int, int, bytes]: + _, flags, status, request_id, length = struct.unpack(">HBBqI", await _receive(sock, 16)) + return flags, status, request_id, await _receive(sock, length) + + +class _Broken(ServiceInvoker): + async def invoke(self, invocation: Invocation): + raise RuntimeError("broken") + + +async def test_an_invoker_that_raises_answers_service_error_and_is_logged( + protocol: DubboProtocol, impl, refer, user_service, caplog +) -> None: + url = URL.parse("dubbo://127.0.0.1:0/com.example.UserService") + exporter = await protocol.export(url, dubbo.get_definition(user_service), _Broken.from_implementation(impl, url)) + users = await refer(protocol, exporter) + + with pytest.raises(RpcError, match=r"^INTERNAL: SERVICE_ERROR: RuntimeError: broken$"): + await users.find("alice", hessian2.Long(1)) + + [record] = [record for record in caplog.records if "raised instead of returning a result" in record.getMessage()] + assert (record.levelname, str(record.exc_info[1])) == ("ERROR", "broken") + + +class _Refusing(ServiceInvoker): + async def invoke(self, invocation: Invocation): + return Result(error=RpcError(Status.UNAVAILABLE, "full")) + + +async def test_a_refused_call_is_answered_as_a_full_provider_that_callers_retry( + protocol: DubboProtocol, impl, refer, user_service +) -> None: + url = URL.parse("dubbo://127.0.0.1:0/com.example.UserService") + exporter = await protocol.export(url, dubbo.get_definition(user_service), _Refusing.from_implementation(impl, url)) + users = await refer(protocol, exporter) + + with pytest.raises(RpcError) as caught: + await users.find("alice", hessian2.Long(1)) + + assert not isinstance(caught.value, RemoteError) + assert caught.value.status is Status.UNAVAILABLE + assert caught.value.message == "SERVER_THREADPOOL_EXHAUSTED_ERROR: full" + + +# Keeps the frames given on stdin in flight over CONNECTIONS connections to PORT for SECONDS, each sent again once +# answered, and prints the statuses of the answers as JSON. It runs in a process of its own, as a load does: one sharing +# the event loop or the GIL of the server reads answers too late to catch it counting calls already answered. +_LOAD = """ +import json, selectors, socket, struct, sys, time + +port, connections, seconds = int(sys.argv[1]), int(sys.argv[2]), float(sys.argv[3]) +frames = json.load(sys.stdin) +frames = [bytes.fromhex(frame) for frame in frames] +socks = [socket.create_connection(("127.0.0.1", port)) for _ in range(connections)] +statuses = [] +with selectors.DefaultSelector() as selector: + for index, sock in enumerate(socks): + sock.sendall(b"".join(frames[index::connections])) + selector.register(sock, selectors.EVENT_READ, bytearray()) + deadline = time.monotonic() + seconds + while time.monotonic() < deadline: + for key, _ in selector.select(timeout=1): + received = key.data + received += key.fileobj.recv(65536) + while len(received) >= 16 and len(received) >= 16 + int.from_bytes(received[12:16], "big"): + _, flags, status, request_id, length = struct.unpack(">HBBqI", received[:16]) + del received[: 16 + length] + if not flags & 0x80: + statuses.append(status) + key.fileobj.sendall(frames[request_id]) +print(json.dumps(statuses)) +""" + + +@pytest.mark.skipif(importlib.util.find_spec("uvloop") is None, reason="needs uvloop") +@pytest.mark.parametrize("anyio_backend", [pytest.param(("asyncio", {"use_uvloop": True}), id="uvloop")]) +async def test_calls_answered_leave_room_at_once_for_as_many_more(protocol: DubboProtocol, impl, export, frame) -> None: + # On uvloop, the next requests may be read before the callbacks of the calls just answered run. + limit = 32 + exporter = await export(protocol, impl, f"?max-concurrent-calls={limit}") + frames = [frame(0xC2, i, _request_body("find", "Ljava/lang/String;J", "alice", 1)).hex() for i in range(limit)] + + load = await anyio.run_process( + [sys.executable, "-c", _LOAD, str(exporter.url.port), "8", "0.3"], input=json.dumps(frames).encode() + ) + + statuses = json.loads(load.stdout) + assert len(statuses) > 1000 + assert set(statuses) == {20} + + +async def test_a_handler_ends_at_the_timeout_of_its_caller(protocol: DubboProtocol, impl, export, frame) -> None: + exporter = await export(protocol, impl) + body = hessian2.dumps_many(("2.0.2", "com.example.UserService", "0.0.0", "sleep", "", {"timeout": "50"})) + + with socket.create_connection(("127.0.0.1", exporter.url.port)) as sock: + sock.sendall(frame(0xC2, 5, body)) + sock.setblocking(False) + _, status, request_id, _ = await _response(sock) + + assert (status, request_id) == (31, 5) + assert impl.started.is_set() + assert not impl.released.is_set() + + +def _committing(implementation_type: type) -> Any: + class Committing(implementation_type): + def __init__(self) -> None: + super().__init__() + self.committing, self.committed = anyio.Event(), anyio.Event() + + async def sleep(self) -> str: + with anyio.CancelScope(shield=True): + self.committing.set() + await anyio.sleep(0.2) + self.committed.set() + await anyio.sleep_forever() + return "never" + + return Committing() + + +async def test_a_handler_past_the_timeout_of_its_caller_finishes_its_shielded_work_first( + protocol: DubboProtocol, implementation_type, export, frame +) -> None: + impl = _committing(implementation_type) + exporter = await export(protocol, impl) + body = hessian2.dumps_many(("2.0.2", "com.example.UserService", "0.0.0", "sleep", "", {"timeout": "50"})) + + with socket.create_connection(("127.0.0.1", exporter.url.port)) as sock: + sock.sendall(frame(0xC2, 5, body)) + sock.setblocking(False) + _, status, request_id, _ = await _response(sock) + + assert (status, request_id, impl.committed.is_set()) == (31, 5, True) + + +async def test_a_handler_whose_caller_leaves_finishes_its_shielded_work_first( + protocol: DubboProtocol, implementation_type, export, frame +) -> None: + impl = _committing(implementation_type) + exporter = await export(protocol, impl) + body = hessian2.dumps_many(("2.0.2", "com.example.UserService", "0.0.0", "sleep", "", {})) + + with socket.create_connection(("127.0.0.1", exporter.url.port)) as sock: + sock.sendall(frame(0xC2, 5, body)) + with anyio.fail_after(2): + await impl.committing.wait() + + with anyio.fail_after(2): + await impl.committed.wait() + + +async def test_a_timeout_too_large_for_seconds_leaves_the_call_unbounded( + protocol: DubboProtocol, impl, export, frame +) -> None: + exporter = await export(protocol, impl) + body = hessian2.dumps_many( + ("2.0.2", "com.example.UserService", "0.0.0", "forget", "Ljava/lang/String;", "bob", {"timeout": "9" * 400}) + ) + + with socket.create_connection(("127.0.0.1", exporter.url.port)) as sock: + sock.sendall(frame(0xC2, 5, body)) + sock.setblocking(False) + _, status, request_id, _ = await _response(sock) + + assert (status, request_id, impl.forgotten) == (20, 5, ["bob"]) + + +async def test_closing_aborts_a_connection_whose_peer_stops_reading( + protocol: DubboProtocol, export, implementation_type, user_type, address_type, frame +) -> None: + answered, closed = anyio.Event(), anyio.Event() + + class Answering(implementation_type): + async def find(self, name: str, user_id: int) -> Any: + answered.set() + return user_type(name=name, user_id=user_id, address=address_type(city="Hangzhou")) + + async def close() -> None: + await protocol.aclose() + closed.set() + + exporter = await export(protocol, Answering(), "?shutwait=0") + request = frame(0xC2, 1, _request_body("find", "Ljava/lang/String;J", "x" * (4 * 1024 * 1024), 1)) + with socket.socket() as sock: + sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 4096) + sock.connect(("127.0.0.1", exporter.url.port)) + sock.setblocking(False) + await asyncio.get_running_loop().sock_sendall(sock, request) + await answered.wait() + await anyio.wait_all_tasks_blocked() + + async with anyio.create_task_group() as task_group: + task_group.start_soon(close) + with anyio.move_on_after(3): + await closed.wait() + closed_in_time = closed.is_set() + sock.close() + + assert closed_in_time + + +async def test_a_cancelled_close_aborts_a_connection_whose_peer_stops_reading_at_once( + protocol: DubboProtocol, export, implementation_type, user_type, address_type, frame +) -> None: + answered = anyio.Event() + + class Answering(implementation_type): + async def find(self, name: str, user_id: int) -> Any: + answered.set() + return user_type(name=name, user_id=user_id, address=address_type(city="Hangzhou")) + + exporter = await export(protocol, Answering(), "?shutwait=0") + request = frame(0xC2, 1, _request_body("find", "Ljava/lang/String;J", "x" * (4 * 1024 * 1024), 1)) + with socket.socket() as sock: + sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 4096) + sock.connect(("127.0.0.1", exporter.url.port)) + sock.setblocking(False) + await asyncio.get_running_loop().sock_sendall(sock, request) + await answered.wait() + await anyio.wait_all_tasks_blocked() + + started = anyio.current_time() + with anyio.CancelScope() as scope: + scope.cancel() + await protocol.aclose() + + # A graceful close would wait a second for the peer to read the response. + assert anyio.current_time() == started + + +async def test_a_oneway_request_runs_without_sending_a_response(protocol, impl, export, frame): + exporter = await export(protocol, impl) + oneway = frame(0x82, 1, _request_body("forget", "Ljava/lang/String;", "bob")) + twoway = frame(0xC2, 2, _request_body("forget", "Ljava/lang/String;", "alice")) + + async with await anyio.connect_tcp("127.0.0.1", exporter.url.port) as stream: + await stream.send(oneway) + await anyio.wait_all_tasks_blocked() + await stream.send(twoway) + reader = BufferedByteReceiveStream(stream) + header = await reader.receive_exactly(16) + _, flags, status, request_id, length = struct.unpack(">HBBqI", header) + await reader.receive_exactly(length) + + assert (flags, status, request_id) == (2, 20, 2) + assert impl.forgotten == ["bob", "alice"] + + +async def test_a_request_that_cannot_be_read_is_answered_bad_request( + protocol: DubboProtocol, impl, export, frame +) -> None: + exporter = await export(protocol, impl) + + with socket.create_connection(("127.0.0.1", exporter.url.port)) as sock: + sock.sendall(frame(0xC2, 9, hessian2.dumps_many(["not", "a", "request"]))) + sock.setblocking(False) + header = await _receive(sock, 16) + + magic, flags, status, request_id, _ = struct.unpack(">HBBqI", header) + assert (magic, flags & 0x80, status, request_id) == (0xDABB, 0, 40, 9) + + +@pytest.mark.parametrize( + ("method", "descriptor"), [("find", "Ljava/lang/String;I"), ("find", ""), ("missing", "")], ids=repr +) +async def test_a_request_whose_descriptor_matches_no_method_is_not_found( + protocol: DubboProtocol, impl, method: str, descriptor: str, export, frame +) -> None: + exporter = await export(protocol, impl) + + with socket.create_connection(("127.0.0.1", exporter.url.port)) as sock: + sock.sendall(frame(0xC2, 3, _request_body(method, descriptor, "bob", 1))) + sock.setblocking(False) + _, status, request_id, body = await _response(sock) + + assert (status, request_id) == (60, 3) + assert f"{method}({descriptor})" in hessian2.loads(body) + + +@pytest.mark.parametrize("arguments", [(1, 7), ("bob", "seven")], ids=repr) +async def test_arguments_of_other_types_are_answered_bad_request( + protocol: DubboProtocol, impl, arguments: tuple[Any, ...], export, frame +) -> None: + exporter = await export(protocol, impl) + + with socket.create_connection(("127.0.0.1", exporter.url.port)) as sock: + sock.sendall(frame(0xC2, 4, _request_body("find", "Ljava/lang/String;J", *arguments))) + sock.setblocking(False) + _, status, _, body = await _response(sock) + + assert status == 40 + assert "cannot read the request" in hessian2.loads(body) + + +async def test_a_group_that_is_no_text_is_answered_bad_request(protocol: DubboProtocol, impl, export, frame) -> None: + exporter = await export(protocol, impl) + values = ("2.0.2", "com.example.UserService", "0.0.0", "find", "Ljava/lang/String;J", "bob", 1, {"group": ["a"]}) + + with socket.create_connection(("127.0.0.1", exporter.url.port)) as sock: + sock.sendall(frame(0xC2, 6, hessian2.dumps_many(values))) + sock.setblocking(False) + _, status, _, _ = await _response(sock) + + assert status == 40 + + +@pytest.mark.parametrize( + ("path", "attachments"), [("com.example.Other", {}), ("com.example.UserService", {"group": "missing"})], ids=repr +) +async def test_echo_answers_only_for_exported_services( + protocol: DubboProtocol, impl, path: str, attachments: dict[str, str], export, frame +) -> None: + exporter = await export(protocol, impl) + values = ("2.0.2", path, "0.0.0", "$echo", "Ljava/lang/Object;", "ping", attachments) + + with socket.create_connection(("127.0.0.1", exporter.url.port)) as sock: + sock.sendall(frame(0xC2, 7, hessian2.dumps_many(values))) + sock.setblocking(False) + _, status, _, _ = await _response(sock) + + assert status == 60 + + +@pytest.mark.parametrize(("serialization_id", "name"), [(23, "fastjson2 (23)"), (30, "serialization 30")]) +async def test_a_request_in_another_serialization_is_answered_with_a_serialization_error( + protocol: DubboProtocol, impl, serialization_id: int, name: str, export, frame +) -> None: + exporter = await export(protocol, impl) + + with socket.create_connection(("127.0.0.1", exporter.url.port)) as sock: + sock.sendall(frame(0xC0 | serialization_id, 5, b"{}")) + sock.setblocking(False) + header = await _receive(sock, 16) + _, flags, status, request_id, length = struct.unpack(">HBBqI", header) + body = await _receive(sock, length) + + assert (flags & 0x1F, status, request_id) == (2, 25, 5) + assert hessian2.loads(body) == f"the request is in {name}, but this server reads hessian2 (2)" + + +async def test_a_handler_sees_an_ipv6_caller_with_its_host_in_brackets( + protocol: DubboProtocol, implementation_type, user_service +) -> None: + peers: list[str | None] = [] + + class Recording(implementation_type): + async def find(self, name: str, user_id: int) -> Any: + peers.append(dubbo.incoming().peer) + return None + + url = URL.parse("dubbo://[::1]:0/com.example.UserService") + definition = dubbo.get_definition(user_service) + exporter = await protocol.export(url, definition, ServiceInvoker.from_implementation(Recording(), url)) + caller = URL.parse(f"dubbo://[::1]:{exporter.url.port}/com.example.UserService") + users = proxy(user_service, (await protocol.refer(caller, definition)).invoke) + + await users.find("bob", hessian2.Long(1)) + + assert (peers[0] or "").startswith("[::1]:") + + +async def test_a_tls_handshake_takes_at_most_the_ssl_handshake_timeout(protocol: DubboProtocol, impl, export) -> None: + certificates = Path(__file__).resolve().parents[3] / "certificates" + query = ( + f"?ssl-enabled=true&tls-cert-file={certificates / 'localhost-cert.pem'}" + f"&tls-key-file={certificates / 'localhost-key.pem'}&ssl-handshake-timeout=100" + ) + exporter = await export(protocol, impl, query) + + # A client that never starts its handshake. + async with await anyio.connect_tcp("127.0.0.1", exporter.url.port) as stream: + with anyio.fail_after(5), pytest.raises((anyio.EndOfStream, anyio.BrokenResourceError)): + await stream.receive() + + +@pytest.mark.parametrize("types", [None, []], ids=["null-types", "no-types"]) +async def test_a_generic_call_without_arguments_may_send_null_for_them( + protocol: DubboProtocol, impl, export, frame, types +) -> None: + exporter = await export(protocol, impl) + impl.released.set() + descriptor = "Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;" + + with socket.create_connection(("127.0.0.1", exporter.url.port)) as sock: + sock.sendall(frame(0xC2, 5, _request_body("$invoke", descriptor, "sleep", types, None))) + sock.setblocking(False) + _, status, request_id, _ = await _response(sock) + + assert (status, request_id) == (20, 5) + assert impl.started.is_set() diff --git a/tests/integration/protocol/triple/builtin/test_health.py b/tests/integration/protocol/triple/builtin/test_health.py new file mode 100644 index 00000000..e0b83e95 --- /dev/null +++ b/tests/integration/protocol/triple/builtin/test_health.py @@ -0,0 +1,159 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import grpc +import pytest +from google.protobuf.wrappers_pb2 import StringValue + +import dubbo +from dubbo import RpcError, Status +from dubbo._proto.grpc.health.v1.health_pb2 import HealthCheckRequest, HealthCheckResponse, HealthListRequest +from dubbo.protocol.triple import TripleProtocol +from dubbo.protocol.triple.builtin.health import Health +from dubbo.rpc.client import proxy +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + +# grpcio calls through threads of its own and keeps its deadlines on the real clock. +_grpcio = pytest.mark.real_clock + +_HEALTH = "grpc.health.v1.Health" + + +async def test_the_health_service_is_off_by_default(protocol: TripleProtocol, impl, export) -> None: + exporter = await export(protocol, impl) + health = proxy( + Health, + ( + await protocol.refer( + URL.parse(f"tri://127.0.0.1:{exporter.url.port}/{_HEALTH}"), dubbo.get_definition(Health) + ) + ).invoke, + ) + + with pytest.raises(RpcError) as raised: + await health.check(HealthCheckRequest()) + assert raised.value.status is Status.UNIMPLEMENTED + + +@pytest.mark.parametrize("name", ["", "test.Echo", "g/test.Echo:1"], ids=["server", "interface", "service-key"]) +async def test_health_check_reports_an_exported_service_as_serving(name, protocol, impl, export): + exporter = await export(protocol, impl, "?triple.health-enabled=true&group=g&version=1") + url = URL.parse(f"tri://127.0.0.1:{exporter.url.port}/{_HEALTH}") + health = proxy(Health, (await protocol.refer(url, dubbo.get_definition(Health))).invoke) + + response = await health.check(HealthCheckRequest(service=name)) + + assert response.status == HealthCheckResponse.SERVING + + +async def test_health_check_of_an_unknown_service_is_not_found(protocol, impl, export): + exporter = await export(protocol, impl, "?triple.health-enabled=true&group=g&version=1") + url = URL.parse(f"tri://127.0.0.1:{exporter.url.port}/{_HEALTH}") + health = proxy(Health, (await protocol.refer(url, dubbo.get_definition(Health))).invoke) + + with pytest.raises(RpcError, match="NOT_FOUND") as raised: + await health.check(HealthCheckRequest(service="test.Nope")) + + assert raised.value.status is Status.NOT_FOUND + + +async def test_health_list_contains_the_server_interface_and_service_key(protocol, impl, export): + exporter = await export(protocol, impl, "?triple.health-enabled=true&group=g&version=1") + url = URL.parse(f"tri://127.0.0.1:{exporter.url.port}/{_HEALTH}") + health = proxy(Health, (await protocol.refer(url, dubbo.get_definition(Health))).invoke) + + statuses = (await health.list(HealthListRequest())).statuses + + assert {name: response.status for name, response in statuses.items()} == { + "": HealthCheckResponse.SERVING, + "test.Echo": HealthCheckResponse.SERVING, + "g/test.Echo:1": HealthCheckResponse.SERVING, + } + + +async def test_health_watch_reports_unexported_service_without_stopping_the_server(protocol, impl, export): + exporter = await export(protocol, impl, "?triple.health-enabled=true&group=g&version=1") + url = URL.parse(f"tri://127.0.0.1:{exporter.url.port}/{_HEALTH}") + health = proxy(Health, (await protocol.refer(url, dubbo.get_definition(Health))).invoke) + + async with health.watch(HealthCheckRequest(service="test.Echo")) as watch: + assert (await watch.receive()).status == HealthCheckResponse.SERVING + await exporter.aclose() + assert (await watch.receive()).status == HealthCheckResponse.NOT_SERVING + + assert (await health.check(HealthCheckRequest(service=""))).status == HealthCheckResponse.SERVING + + +async def test_closing_the_server_ends_health_watches(impl, export) -> None: + async with TripleProtocol() as serving: + exporter = await export(serving, impl, "?triple.health-enabled=true") + url = URL.parse(f"tri://127.0.0.1:{exporter.url.port}/{_HEALTH}") + async with TripleProtocol() as calling: + health = proxy(Health, (await calling.refer(url, dubbo.get_definition(Health))).invoke) + with anyio.fail_after(5): + async with health.watch(HealthCheckRequest(service="")) as watch: + assert (await watch.receive()).status == HealthCheckResponse.SERVING + await serving.aclose() + assert [response.status async for response in watch] == [HealthCheckResponse.NOT_SERVING] + + +async def test_announcing_the_shutdown_reports_not_serving_while_the_services_serve( + impl, export, serve, refer, echo_impl_type +) -> None: + async with TripleProtocol() as serving: + exporter = await export(serving, impl, "?triple.health-enabled=true") + port = exporter.url.port + async with TripleProtocol() as calling: + health = proxy( + Health, + ( + await calling.refer(URL.parse(f"tri://127.0.0.1:{port}/{_HEALTH}"), dubbo.get_definition(Health)) + ).invoke, + ) + echo = await refer(calling, exporter) + with anyio.fail_after(5): + async with health.watch(HealthCheckRequest(service="")) as watch: + assert (await watch.receive()).status == HealthCheckResponse.SERVING + serving.announce_shutdown() + assert (await watch.receive()).status == HealthCheckResponse.NOT_SERVING + + url = URL.parse(f"tri://127.0.0.1:{port}/test.Echo?version=2&triple.health-enabled=true") + await serve(serving, url, echo_impl_type()) + for name in ("", "test.Echo"): + status = (await health.check(HealthCheckRequest(service=name))).status + assert status == HealthCheckResponse.NOT_SERVING + assert [await echo.say(StringValue(value=str(i))) for i in range(3)] == [ + StringValue(value=f"{i}|-") for i in range(3) + ] + + +@_grpcio +async def test_a_grpcio_client_checks_health(protocol: TripleProtocol, impl, export) -> None: + exporter = await export(protocol, impl, "?triple.health-enabled=true") + + async with grpc.aio.insecure_channel(f"127.0.0.1:{exporter.url.port}") as channel: + check = channel.unary_unary( + f"/{_HEALTH}/Check", + request_serializer=HealthCheckRequest.SerializeToString, + response_deserializer=HealthCheckResponse.FromString, + ) + response = await check(HealthCheckRequest(service="test.Echo")) + + assert response.status == HealthCheckResponse.SERVING diff --git a/tests/integration/protocol/triple/builtin/test_reflection.py b/tests/integration/protocol/triple/builtin/test_reflection.py new file mode 100644 index 00000000..bdb5decb --- /dev/null +++ b/tests/integration/protocol/triple/builtin/test_reflection.py @@ -0,0 +1,126 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import grpc +import pytest +from google.protobuf.descriptor_pb2 import FileDescriptorProto + +from dubbo import Status +from dubbo._proto.grpc.reflection.v1 import reflection_pb2 as v1 +from dubbo._proto.grpc.reflection.v1alpha import reflection_pb2 as v1alpha + +# grpcio calls through threads of its own and keeps its deadlines on the real clock. +pytestmark = [pytest.mark.anyio, pytest.mark.real_clock] + + +async def _reflect(exporter, request, version="v1alpha"): + messages = v1 if version == "v1" else v1alpha + async with grpc.aio.insecure_channel(f"127.0.0.1:{exporter.url.port}") as channel: + info = channel.stream_stream( + f"/grpc.reflection.{version}.ServerReflection/ServerReflectionInfo", + request_serializer=messages.ServerReflectionRequest.SerializeToString, + response_deserializer=messages.ServerReflectionResponse.FromString, + ) + responses = [response async for response in info(iter([request]))] + + [response] = responses + assert response.original_request == request + return response + + +async def test_reflection_lists_exported_and_enabled_builtin_services(protocol, impl, export): + exporter = await export(protocol, impl, "?triple.reflection-enabled=true&triple.health-enabled=true") + + response = await _reflect(exporter, v1alpha.ServerReflectionRequest(host="h", list_services="")) + + assert response.valid_host == "h" + assert [service.name for service in response.list_services_response.service] == [ + "grpc.health.v1.Health", + "grpc.reflection.v1.ServerReflection", + "grpc.reflection.v1alpha.ServerReflection", + "test.Echo", + ] + + +@pytest.mark.parametrize( + ("query", "value", "files"), + [ + ("file_containing_symbol", "grpc.health.v1.Health.Check", ["grpc/health/v1/health.proto"]), + ("file_by_filename", "google/protobuf/wrappers.proto", ["google/protobuf/wrappers.proto"]), + ("file_containing_symbol", "google.rpc.Status", ["google/rpc/status.proto", "google/protobuf/any.proto"]), + ], + ids=["method-symbol", "filename", "imported-dependency"], +) +async def test_reflection_returns_the_file_holding_the_queried_symbol_or_name_with_its_imports( + query, value, files, protocol, impl, export +): + exporter = await export(protocol, impl, "?triple.reflection-enabled=true&triple.health-enabled=true") + + response = await _reflect(exporter, v1alpha.ServerReflectionRequest(**{query: value})) + + descriptors = [ + FileDescriptorProto.FromString(data) for data in response.file_descriptor_response.file_descriptor_proto + ] + assert [descriptor.name for descriptor in descriptors] == files + + +async def test_reflection_returns_the_file_that_declares_a_method(protocol, impl, export): + exporter = await export(protocol, impl, "?triple.reflection-enabled=true&triple.health-enabled=true") + + request = v1alpha.ServerReflectionRequest(file_containing_symbol="grpc.health.v1.Health.Check") + response = await _reflect(exporter, request) + + [data] = response.file_descriptor_response.file_descriptor_proto + assert [service.name for service in FileDescriptorProto.FromString(data).service] == ["Health"] + + +async def test_reflection_v1_answers_as_v1alpha(protocol, impl, export): + exporter = await export(protocol, impl, "?triple.reflection-enabled=true") + + answer = await _reflect(exporter, v1.ServerReflectionRequest(file_containing_symbol="google.rpc.Status"), "v1") + alpha = await _reflect(exporter, v1alpha.ServerReflectionRequest(file_containing_symbol="google.rpc.Status")) + + assert isinstance(answer, v1.ServerReflectionResponse) + assert answer.file_descriptor_response.file_descriptor_proto == alpha.file_descriptor_response.file_descriptor_proto + + +@pytest.mark.parametrize( + ("query", "code"), + [ + (v1alpha.ServerReflectionRequest(file_containing_symbol="test.Nope"), Status.NOT_FOUND), + (v1alpha.ServerReflectionRequest(file_containing_symbol="grpc.health.v1.Health.Nope"), Status.NOT_FOUND), + (v1alpha.ServerReflectionRequest(), Status.INVALID_ARGUMENT), + ], + ids=["missing-symbol", "missing-method", "missing-query"], +) +async def test_reflection_returns_status_for_an_unknown_or_missing_query(query, code, protocol, impl, export): + exporter = await export(protocol, impl, "?triple.reflection-enabled=true&triple.health-enabled=true") + + response = await _reflect(exporter, query) + + assert response.error_response.error_code == code + + +async def test_reflection_reports_no_extensions_for_a_type_without_them(protocol, impl, export): + exporter = await export(protocol, impl, "?triple.reflection-enabled=true") + + response = await _reflect( + exporter, v1alpha.ServerReflectionRequest(all_extension_numbers_of_type="google.protobuf.Any") + ) + + assert response.all_extension_numbers_response.base_type_name == "google.protobuf.Any" + assert list(response.all_extension_numbers_response.extension_number) == [] diff --git a/tests/integration/protocol/triple/conftest.py b/tests/integration/protocol/triple/conftest.py new file mode 100644 index 00000000..9c2401b7 --- /dev/null +++ b/tests/integration/protocol/triple/conftest.py @@ -0,0 +1,180 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import abc +import math +import typing +from collections.abc import AsyncIterator + +import anyio +import pytest +from google.protobuf.wrappers_pb2 import StringValue + +import dubbo +from dubbo import RpcError, Status +from dubbo.protocol import Exporter +from dubbo.protocol.triple import ErrorDetail, TripleError, TripleProtocol +from dubbo.rpc.client import proxy +from dubbo.rpc.server import ServiceInvoker +from dubbo.url import URL + + +@dubbo.service("test.Echo") +class Echo(typing.Protocol): + @dubbo.method("Say") + async def say(self, request: StringValue) -> StringValue: ... + + @dubbo.method("Count") + def count(self, request: StringValue) -> dubbo.ServerStream[StringValue]: ... + + @dubbo.method("Join") + def join(self) -> dubbo.ClientStream[StringValue, StringValue]: ... + + @dubbo.method("Chat") + def chat(self) -> dubbo.BidiStream[StringValue, StringValue]: ... + + +@dubbo.service("test.Echo") +class EchoServicer(abc.ABC): + @dubbo.method("Say") + @abc.abstractmethod + async def say(self, request: StringValue) -> StringValue: ... + + @dubbo.method("Count") + @abc.abstractmethod + async def count(self, request: StringValue, stream: dubbo.SendStream[StringValue]) -> None: ... + + @dubbo.method("Join") + @abc.abstractmethod + async def join(self, stream: dubbo.ReceiveStream[StringValue]) -> StringValue: ... + + @dubbo.method("Chat") + @abc.abstractmethod + async def chat(self, stream: dubbo.Stream[StringValue, StringValue]) -> None: ... + + +class EchoImpl(EchoServicer): + def __init__(self) -> None: + self.cancelled = anyio.Event() + self.release = anyio.Event() + self.started = anyio.Event() + self.peer: str | None = None + self.deadline = math.inf + + async def say(self, request: StringValue) -> StringValue: + call = dubbo.incoming() + self.peer = call.peer + call.response_attachments["Served-By"] = "echo" + for key in ("trace-bin", "tag", "token"): + call.response_attachments.extend((key, value) for value in call.attachments.getall(key, [])) + match request.value: + case "rpc": + raise RpcError(Status.ABORTED, "失败 100%") + case "details": + raise TripleError( + Status.INVALID_ARGUMENT, + "bad request", + details=[ErrorDetail.from_message(StringValue(value="value"))], + ) + case "crash": + raise ValueError("broken") + case "sleep": + try: + self.started.set() + await anyio.sleep_forever() + finally: + self.cancelled.set() + case "wait": + self.started.set() + await self.release.wait() + case "early": + # As a provider whose clock reaches the deadline of the call a moment before the caller's. + await anyio.sleep_until(anyio.current_effective_deadline() - 0.02) + raise RpcError(Status.DEADLINE_EXCEEDED, "the call ran out of time") + case "expired": + # As a provider whose own call to another service ran out of time. + raise RpcError(Status.DEADLINE_EXCEEDED, "the inventory did not answer in time") + return StringValue(value=f"{request.value}|{call.attachments.get('Tenant', '-')}") + + async def count(self, request: StringValue, stream: dubbo.SendStream[StringValue]) -> None: + dubbo.incoming().response_attachments["counted"] = request.value + for i in range(int(request.value)): + await stream.send(StringValue(value=str(i))) + if request.value == "2": + raise RpcError(Status.DATA_LOSS, "stopped after 2") + + async def join(self, stream: dubbo.ReceiveStream[StringValue]) -> StringValue: + return StringValue(value=",".join([chunk.value async for chunk in stream])) + + async def chat(self, stream: dubbo.Stream[StringValue, StringValue]) -> None: + self.deadline = anyio.current_effective_deadline() + async for question in stream: + await stream.send(StringValue(value=question.value.upper())) + + +@pytest.fixture +async def protocol() -> AsyncIterator[TripleProtocol]: + async with TripleProtocol() as protocol: + yield protocol + + +@pytest.fixture +def impl() -> EchoImpl: + return EchoImpl() + + +async def _export(protocol: TripleProtocol, impl: object, query: str = "") -> Exporter: + return await _serve(protocol, URL.parse(f"tri://127.0.0.1:0/test.Echo{query}"), impl) + + +async def _serve(protocol: TripleProtocol, url: URL, impl: object, contract: type = Echo) -> Exporter: + return await protocol.export(url, dubbo.get_definition(contract), ServiceInvoker.from_implementation(impl, url)) + + +async def _refer(protocol: TripleProtocol, exporter: Exporter, query: str = "") -> Echo: + url = URL.parse(f"tri://127.0.0.1:{exporter.url.port}/test.Echo{query}") + return proxy(Echo, (await protocol.refer(url, dubbo.get_definition(Echo))).invoke) + + +@pytest.fixture +async def echo(protocol: TripleProtocol, impl: EchoImpl) -> Echo: + return await _refer(protocol, await _export(protocol, impl)) + + +@pytest.fixture +def export(): + return _export + + +@pytest.fixture +def serve(): + return _serve + + +@pytest.fixture +def refer(): + return _refer + + +@pytest.fixture +def echo_contract(): + return Echo + + +@pytest.fixture +def echo_impl_type(): + return EchoImpl diff --git a/tests/integration/protocol/triple/grpc/test_client.py b/tests/integration/protocol/triple/grpc/test_client.py new file mode 100644 index 00000000..0dfadb65 --- /dev/null +++ b/tests/integration/protocol/triple/grpc/test_client.py @@ -0,0 +1,223 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import importlib.metadata + +import anyio +import pytest +from google.protobuf.wrappers_pb2 import StringValue + +import dubbo +from dubbo import RpcError, Status +from dubbo.protocol.triple import TripleProtocol +from dubbo.protocol.triple.grpc.framing import frame +from dubbo.protocol.triple.grpc.headers import decode_timeout +from dubbo.rpc.client import proxy +from dubbo.transport.h2 import H2Headers, H2Stream +from dubbo.transport.h2.aio import AioH2Server +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +async def _say(echo, request: StringValue) -> StringValue: + return await echo.say(request) + + +async def _join(echo, request: StringValue) -> StringValue: + async with echo.join() as stream: + await stream.send(request) + await stream.end() + return await stream.receive() + + +@pytest.mark.parametrize("call", [_say, _join]) +@pytest.mark.parametrize(("count", "problem"), [(0, "no message"), (3, "more than one message")]) +async def test_a_call_of_one_response_takes_exactly_one( + protocol: TripleProtocol, + call, + count: int, + problem: str, + echo_contract, +) -> None: + async def respond(stream: H2Stream) -> None: + await stream.receive_headers() + await stream.send_headers(((b":status", b"200"), (b"content-type", b"application/grpc+proto"))) + for _ in range(count): + await stream.send_data(frame(StringValue(value="x").SerializeToString())) + await stream.send_trailers(((b"grpc-status", b"0"),)) + + async with AioH2Server(URL(protocol="tri", host="127.0.0.1", port=0), respond) as server: + url = URL.parse(f"tri://127.0.0.1:{server.address[1]}/test.Echo") + echo = proxy(echo_contract, (await protocol.refer(url, dubbo.get_definition(echo_contract))).invoke) + + with pytest.raises(RpcError, match=f"the response has {problem}") as raised: + await call(echo, StringValue(value="x")) + # statuscodes.md:61 + assert raised.value.status is Status.UNIMPLEMENTED + + +async def test_a_call_names_the_library_in_its_user_agent(protocol: TripleProtocol, echo_contract) -> None: + received: list[dict[bytes, bytes]] = [] + + async def respond(stream: H2Stream) -> None: + received.append(dict(await stream.receive_headers())) + await stream.send_headers(((b":status", b"200"), (b"content-type", b"application/grpc+proto"))) + await stream.send_data(frame(StringValue(value="x").SerializeToString())) + await stream.send_trailers(((b"grpc-status", b"0"),)) + + async with AioH2Server(URL(protocol="tri", host="127.0.0.1", port=0), respond) as server: + url = URL.parse(f"tri://127.0.0.1:{server.address[1]}/test.Echo") + await proxy(echo_contract, (await protocol.refer(url, dubbo.get_definition(echo_contract))).invoke).say( + StringValue(value="x") + ) + + version = importlib.metadata.version("apache-dubbo") + assert received[0][b"user-agent"].startswith(f"grpc-python-dubbo/{version} (".encode()) + + +async def test_a_call_sends_its_timeout_right_after_the_pseudo_headers(protocol: TripleProtocol, echo_contract) -> None: + received: list[H2Headers] = [] + + async def respond(stream: H2Stream) -> None: + received.append(await stream.receive_headers()) + await stream.send_headers(((b":status", b"200"), (b"content-type", b"application/grpc+proto"))) + await stream.send_data(frame(StringValue(value="x").SerializeToString())) + await stream.send_trailers(((b"grpc-status", b"0"),)) + + async with AioH2Server(URL(protocol="tri", host="127.0.0.1", port=0), respond) as server: + url = URL.parse(f"tri://127.0.0.1:{server.address[1]}/test.Echo") + with anyio.fail_after(5): + await proxy(echo_contract, (await protocol.refer(url, dubbo.get_definition(echo_contract))).invoke).say( + StringValue(value="x") + ) + + # PROTOCOL-HTTP2.md:53 + names = [name for name, _ in received[0]] + pseudo = sum(1 for name in names if name.startswith(b":")) + assert names[pseudo] == b"grpc-timeout" + + +async def test_a_configured_timeout_is_the_grpc_timeout_of_the_call(protocol: TripleProtocol, echo_contract) -> None: + received: list[dict[bytes, bytes]] = [] + + async def respond(stream: H2Stream) -> None: + received.append(dict(await stream.receive_headers())) + await stream.send_headers(((b":status", b"200"), (b"content-type", b"application/grpc+proto"))) + await stream.send_data(frame(StringValue(value="x").SerializeToString())) + await stream.send_trailers(((b"grpc-status", b"0"),)) + + async with AioH2Server(URL(protocol="tri", host="127.0.0.1", port=0), respond) as server: + url = URL.parse(f"tri://127.0.0.1:{server.address[1]}/test.Echo?timeout=50") + with anyio.fail_after(5): + await proxy(echo_contract, (await protocol.refer(url, dubbo.get_definition(echo_contract))).invoke).say( + StringValue(value="x") + ) + + assert 0 < decode_timeout(received[0][b"grpc-timeout"]) <= 0.05 + + +async def test_the_grpc_timeout_is_never_above_the_configured_timeout_whatever_the_clock_reads( + protocol: TripleProtocol, echo_contract +) -> None: + received: list[dict[bytes, bytes]] = [] + + async def respond(stream: H2Stream) -> None: + received.append(dict(await stream.receive_headers())) + await stream.send_headers(((b":status", b"200"), (b"content-type", b"application/grpc+proto"))) + await stream.send_data(frame(StringValue(value="x").SerializeToString())) + await stream.send_trailers(((b"grpc-status", b"0"),)) + + # A reading where the timeout, added to it and taken away again, comes out a little larger, as it does for every + # reading from 8 to 16. + await anyio.sleep_until(8) + now = anyio.current_time() + assert (now + 0.05) - now > 0.05 + + async with AioH2Server(URL(protocol="tri", host="127.0.0.1", port=0), respond) as server: + url = URL.parse(f"tri://127.0.0.1:{server.address[1]}/test.Echo?timeout=50") + users = proxy(echo_contract, (await protocol.refer(url, dubbo.get_definition(echo_contract))).invoke) + await users.say(StringValue(value="x")) + + assert decode_timeout(received[0][b"grpc-timeout"]) <= 0.05 + + +async def test_an_explicit_grpc_status_decides_a_call_over_the_http_status( + protocol: TripleProtocol, echo_contract +) -> None: + async def respond(stream: H2Stream) -> None: + await stream.receive_headers() + await stream.send_headers( + ( + (b":status", b"500"), + (b"content-type", b"application/grpc"), + (b"grpc-status", b"10"), + (b"grpc-message", b"aborted%20by%20provider"), + ), + end_stream=True, + ) + + async with AioH2Server(URL(protocol="tri", host="127.0.0.1", port=0), respond) as server: + url = URL.parse(f"tri://127.0.0.1:{server.address[1]}/test.Echo") + echo = proxy(echo_contract, (await protocol.refer(url, dubbo.get_definition(echo_contract))).invoke) + + with pytest.raises(RpcError, match="aborted by provider") as raised: + await echo.say(StringValue(value="x")) + + assert raised.value.status is Status.ABORTED + + +async def test_a_response_that_is_not_grpc_fails_whatever_grpc_status_it_carries( + protocol: TripleProtocol, echo_contract +) -> None: + async def respond(stream: H2Stream) -> None: + await stream.receive_headers() + await stream.send_headers( + ((b":status", b"200"), (b"content-type", b"text/html"), (b"grpc-status", b"0")), end_stream=True + ) + + async with AioH2Server(URL(protocol="tri", host="127.0.0.1", port=0), respond) as server: + url = URL.parse(f"tri://127.0.0.1:{server.address[1]}/test.Echo") + echo = proxy(echo_contract, (await protocol.refer(url, dubbo.get_definition(echo_contract))).invoke) + + with pytest.raises(RpcError, match="content-type") as raised: + await echo.say(StringValue(value="x")) + + assert raised.value.status is Status.UNKNOWN + + +async def test_a_compressing_caller_names_its_encoding_and_flags_its_messages( + protocol: TripleProtocol, echo_contract +) -> None: + received: list[tuple[dict[bytes, bytes], bytes]] = [] + + async def respond(stream: H2Stream) -> None: + headers = dict(await stream.receive_headers()) + received.append((headers, await stream.receive_data_exactly(5))) + await stream.send_headers(((b":status", b"200"), (b"content-type", b"application/grpc+proto"))) + await stream.send_data(frame(StringValue(value="x").SerializeToString())) + await stream.send_trailers(((b"grpc-status", b"0"),)) + + async with AioH2Server(URL(protocol="tri", host="127.0.0.1", port=0), respond) as server: + url = URL.parse(f"tri://127.0.0.1:{server.address[1]}/test.Echo?triple.compressor=gzip") + await proxy(echo_contract, (await protocol.refer(url, dubbo.get_definition(echo_contract))).invoke).say( + StringValue(value="x") + ) + + headers, prefix = received[0] + assert headers[b"grpc-encoding"] == b"gzip" + assert prefix[0] == 1 diff --git a/tests/integration/protocol/triple/grpc/test_server.py b/tests/integration/protocol/triple/grpc/test_server.py new file mode 100644 index 00000000..ccf8bfbd --- /dev/null +++ b/tests/integration/protocol/triple/grpc/test_server.py @@ -0,0 +1,192 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import gzip + +import anyio +import grpc +import pytest +from google.protobuf.wrappers_pb2 import StringValue + +from dubbo import Status +from dubbo.protocol import Exporter +from dubbo.protocol.triple import TripleProtocol +from dubbo.protocol.triple.grpc.framing import frame +from dubbo.transport.h2 import H2Headers +from dubbo.transport.h2.aio import AioH2Client +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + +# grpcio calls through threads of its own and keeps its deadlines on the real clock. +_grpcio = pytest.mark.real_clock + + +async def _raw(exporter: Exporter, headers: H2Headers, body: bytes | None = b"") -> dict[bytes, bytes]: + url = URL(protocol="tri", host="127.0.0.1", port=exporter.url.port) + async with AioH2Client(url) as client: + stream = await client.open_stream(headers, end_stream=body is None) + async with stream: + if body is not None: + await stream.send_data(body, end_stream=True) + response = dict(await stream.receive_headers()) + trailers = await stream.receive_trailers() if b"grpc-status" not in response else None + return response | dict(trailers or ()) + + +def _request(path: bytes = b"/test.Echo/Say", **fields: bytes) -> H2Headers: + headers = { + b":method": b"POST", + b":scheme": b"http", + b":authority": b"localhost", + b":path": path, + b"content-type": b"application/grpc", + b"te": b"trailers", + } + headers |= {name.replace("_", "-").encode(): value for name, value in fields.items()} + return tuple(headers.items()) + + +@pytest.mark.parametrize( + ("headers", "body", "http_status", "status"), + [ + # PROTOCOL-HTTP2.md:64 + (_request(content_type=b"application/json"), b"", b"415", Status.INVALID_ARGUMENT), + # PROTOCOL-HTTP2.md:31-33 + (_request(grpc_timeout=b"1x"), b"", b"400", Status.INTERNAL), + # PROTOCOL-HTTP2.md:25 + (_request(**{":method": b"PUT"}), b"", b"405", Status.INTERNAL), + (_request(b"/test.Echo/Nope"), b"", b"200", Status.UNIMPLEMENTED), + (_request(content_type=b"application/grpc+json"), b"", b"200", Status.INTERNAL), + # compression.md:111-114 + (_request(grpc_encoding=b"snappy"), b"", b"200", Status.UNIMPLEMENTED), + # compression.md:122-126 + (_request(), b"\x01\x00\x00\x00\x00", b"200", Status.INTERNAL), + (_request(), (5 * 1024 * 1024).to_bytes(5, "big"), b"200", Status.RESOURCE_EXHAUSTED), + # statuscodes.md:60 + (_request(), None, b"200", Status.UNIMPLEMENTED), + (_request(), 2 * frame(StringValue(value="x").SerializeToString()), b"200", Status.UNIMPLEMENTED), + ( + _request(b"/test.Echo/Count"), + 2 * frame(StringValue(value="1").SerializeToString()), + b"200", + Status.UNIMPLEMENTED, + ), + (_request(), b"\x00\x00\x00\x00\x02\xff\xff", b"200", Status.INTERNAL), + ], + ids=[ + "content-type", + "timeout-unit", + "method", + "unknown-route", + "serialization", + "encoding", + "missing-encoding", + "message-limit", + "missing-message", + "extra-unary-message", + "extra-server-stream-message", + "malformed-protobuf", + ], +) +async def test_the_server_rejects_broken_requests( + protocol: TripleProtocol, impl, headers: H2Headers, body: bytes | None, http_status: bytes, status: Status, export +) -> None: + exporter = await export(protocol, impl) + + response = await _raw(exporter, headers, body) + + assert response[b":status"] == http_status + assert response[b"content-type"].startswith(b"application/grpc") + assert response[b"grpc-status"] == b"%d" % status + + +@pytest.mark.parametrize("cut", [3, 7]) +async def test_a_deadline_inside_a_request_message_ends_the_call_with_deadline_exceeded( + protocol: TripleProtocol, impl, cut: int, export +) -> None: + exporter = await export(protocol, impl) + url = URL(protocol="tri", host="127.0.0.1", port=exporter.url.port) + + async with AioH2Client(url) as client, await client.open_stream(_request(grpc_timeout=b"50m")) as stream: + await stream.send_data(frame(StringValue(value="hello").SerializeToString())[:cut]) + with anyio.fail_after(5): + response = dict(await stream.receive_headers()) + + assert response[b"grpc-status"] == b"%d" % Status.DEADLINE_EXCEEDED + + +async def test_an_unsupported_encoding_is_answered_with_the_supported_ones( + protocol: TripleProtocol, impl, export +) -> None: + exporter = await export(protocol, impl) + + response = await _raw(exporter, _request(grpc_encoding=b"snappy")) + + assert b"snappy" not in response[b"grpc-accept-encoding"] + assert b"gzip" in response[b"grpc-accept-encoding"] + + +@_grpcio +async def test_a_rejected_call_reports_its_status_while_the_caller_still_sends( + protocol: TripleProtocol, impl, export +) -> None: + exporter = await export(protocol, impl) + + async with grpc.aio.insecure_channel(f"127.0.0.1:{exporter.url.port}") as channel: + nope = channel.stream_stream("/test.Echo/Nope", request_serializer=StringValue.SerializeToString) + call = nope() + with pytest.raises(grpc.aio.AioRpcError) as raised: + await call.read() + + assert raised.value.code() is grpc.StatusCode.UNIMPLEMENTED + + +async def test_the_server_reads_gzip_messages(protocol: TripleProtocol, impl, export) -> None: + exporter = await export(protocol, impl) + message = gzip.compress(StringValue(value="zipped").SerializeToString()) + + response = await _raw( + exporter, _request(grpc_encoding=b"gzip"), b"\x01" + len(message).to_bytes(4, "big") + message + ) + + assert response[b"grpc-status"] == b"0" + # compression.md:38-42 leaves the response encoding to the server, which compresses only as configured. + assert b"grpc-encoding" not in response + # compression.md:53-56: a supported encoding the server has not disclosed is named in the response. + assert b"gzip" in response[b"grpc-accept-encoding"] + + +@pytest.mark.parametrize( + ("accept_encoding", "encoding"), + [ + ({"grpc_accept_encoding": b"identity, gzip"}, b"gzip"), + # compression.md:58-60 + ({"grpc_accept_encoding": b"identity"}, None), + ({}, None), + ], +) +async def test_a_compressing_server_compresses_for_callers_that_accept_it( + protocol: TripleProtocol, impl, accept_encoding: dict[str, bytes], encoding: bytes | None, export +) -> None: + exporter = await export(protocol, impl, "?triple.compressor=gzip") + message = StringValue(value="plain").SerializeToString() + + response = await _raw(exporter, _request(**accept_encoding), b"\x00" + len(message).to_bytes(4, "big") + message) + + assert response[b"grpc-status"] == b"0" + assert response.get(b"grpc-encoding") == encoding diff --git a/tests/integration/protocol/triple/test_client.py b/tests/integration/protocol/triple/test_client.py new file mode 100644 index 00000000..38316a1b --- /dev/null +++ b/tests/integration/protocol/triple/test_client.py @@ -0,0 +1,390 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import math +import socket +from collections.abc import AsyncIterator + +import anyio +import grpc +import pytest +from google.protobuf.wrappers_pb2 import StringValue + +import dubbo +from dubbo import RpcError, Status +from dubbo._proto.google.rpc.status_pb2 import Status as StatusMessage +from dubbo.protocol.triple import TripleError, TripleProtocol +from dubbo.rpc.client import proxy +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + +# grpcio calls through threads of its own and keeps its deadlines on the real clock. +_grpcio = pytest.mark.real_clock + + +async def test_unary_carries_attachments_both_ways(echo) -> None: + with dubbo.outgoing({"Tenant": "t1"}) as call: + assert await echo.say(StringValue(value="hi")) == StringValue(value="hi|t1") + + assert dict(call.response_attachments) == {"Served-By": "echo"} + + +async def test_calls_attach_the_token_of_the_provider(protocol: TripleProtocol, impl, export, refer) -> None: + guarded = await refer(protocol, await export(protocol, impl), "?token=secret") + + with dubbo.outgoing() as call: + await guarded.say(StringValue(value="hi")) + + assert call.response_attachments.getall("token") == ["secret"] + + +@pytest.mark.parametrize("query", ["?token=secret", ""], ids=["with-token", "without-token"]) +async def test_a_call_may_not_attach_a_token(protocol: TripleProtocol, impl, export, refer, query) -> None: + echo = await refer(protocol, await export(protocol, impl), query) + # Connected first, as the refused call never waits for it: a server that closes while a client connects + # leaves the socket to the garbage collector in CPython. + await echo.say(StringValue(value="hi")) + + with dubbo.outgoing({"token": "mine"}), pytest.raises(RpcError) as caught: + await echo.say(StringValue(value="hi")) + + assert caught.value.status is Status.INVALID_ARGUMENT + + +async def test_an_unknown_compressor_fails_the_reference(protocol: TripleProtocol, impl, export, refer) -> None: + exporter = await export(protocol, impl) + + with pytest.raises(ValueError, match="'compressor'"): + await refer(protocol, exporter, "?triple.compressor=snappy") + + +async def test_a_request_over_the_servers_limit_is_resource_exhausted(protocol, impl, export, refer): + echo = await refer(protocol, await export(protocol, impl, "?triple.max-receive-message-size=8")) + assert await echo.say(StringValue(value="hi")) == StringValue(value="hi|-") + + with pytest.raises(RpcError, match="larger than 8") as raised: + await echo.say(StringValue(value="longer than eight")) + + assert raised.value.status is Status.RESOURCE_EXHAUSTED + + +async def test_a_response_over_the_callers_limit_is_resource_exhausted(protocol, impl, export, refer): + exporter = await export(protocol, impl, "?triple.max-receive-message-size=8") + echo = await refer(protocol, exporter, "?triple.max-receive-message-size=4") + + with pytest.raises(RpcError, match="larger than 4") as raised: + await echo.say(StringValue(value="hi")) + + assert raised.value.status is Status.RESOURCE_EXHAUSTED + + +@pytest.mark.parametrize( + ("text", "status", "message"), + [("rpc", Status.ABORTED, "失败 100%"), ("crash", Status.UNKNOWN, "ValueError: broken")], + ids=["rpc-error", "handler-exception"], +) +async def test_handler_errors_reach_the_caller_with_status_and_message(echo, text, status, message): + with pytest.raises(RpcError, match=message) as raised: + await echo.say(StringValue(value=text)) + + assert (raised.value.status, raised.value.message) == (status, message) + + +async def test_handler_error_details_reach_the_caller(echo): + with pytest.raises(TripleError, match="bad request") as raised: + await echo.say(StringValue(value="details")) + + assert (raised.value.status, raised.value.message) == (Status.INVALID_ARGUMENT, "bad request") + assert [detail.unpack(StringValue) for detail in raised.value.details] == [StringValue(value="value")] + + +_COMPRESSIONS = pytest.mark.parametrize("compression", ["", "?triple.compressor=gzip"], ids=["plain", "gzip"]) + + +async def test_a_unary_call_round_trips_compressed(protocol, impl, export, refer): + gzip = "?triple.compressor=gzip" + echo = await refer(protocol, await export(protocol, impl, gzip), gzip) + + assert await echo.say(StringValue(value="hi")) == StringValue(value="hi|-") + + +@_COMPRESSIONS +async def test_a_server_stream_round_trips(compression, protocol, impl, export, refer): + echo = await refer(protocol, await export(protocol, impl, compression), compression) + + async with echo.count(StringValue(value="3")) as events: + assert [event.value async for event in events] == ["0", "1", "2"] + + +@_COMPRESSIONS +async def test_a_client_stream_round_trips(compression, protocol, impl, export, refer): + echo = await refer(protocol, await export(protocol, impl, compression), compression) + + async with echo.join() as upload: + for chunk in "abc": + await upload.send(StringValue(value=chunk)) + await upload.end() + assert await upload.receive() == StringValue(value="a,b,c") + + +@_COMPRESSIONS +async def test_a_bidi_stream_round_trips(compression, protocol, impl, export, refer): + echo = await refer(protocol, await export(protocol, impl, compression), compression) + + async with echo.chat() as chat: + await chat.send(StringValue(value="q")) + assert await chat.receive() == StringValue(value="Q") + await chat.end() + assert [answer async for answer in chat] == [] + + +async def test_a_stream_ends_with_the_handler_error_after_its_messages(echo) -> None: + received: list[str] = [] + + async def collect() -> None: + async with echo.count(StringValue(value="2")) as events: + while True: + received.append((await events.receive()).value) + + with dubbo.outgoing() as call, pytest.raises(RpcError, match="DATA_LOSS: stopped after 2"): + await collect() + + assert received == ["0", "1"] + assert dict(call.response_attachments) == {"counted": "2"} + + +async def test_a_stream_without_messages_ends_at_once(echo) -> None: + async with echo.count(StringValue(value="0")) as events: + assert [event async for event in events] == [] + + +async def test_the_deadline_reaches_the_server(echo, impl) -> None: + with pytest.raises(TimeoutError), anyio.fail_after(0.2): + await echo.say(StringValue(value="sleep")) + + with anyio.fail_after(5): + await impl.cancelled.wait() + + +async def test_a_call_that_its_provider_ends_at_its_deadline_ends_at_the_deadline_of_its_caller( + protocol: TripleProtocol, impl, export, refer +) -> None: + exporter = await export(protocol, impl) + bounded = await refer(protocol, exporter, "?timeout=5000") + timed = await refer(protocol, exporter, "?timeout=5000&Say.timeout=300") + + with pytest.raises(TimeoutError), anyio.fail_after(0.3): + await bounded.say(StringValue(value="early")) + with anyio.fail_after(5), pytest.raises(RpcError, match=r"Say did not complete within 0\.3 seconds"): + await timed.say(StringValue(value="early")) + + +async def test_a_deadline_that_its_provider_reached_long_before_the_caller_ends_the_call_at_once(echo) -> None: + start = anyio.current_time() + + with anyio.fail_after(5), pytest.raises(RpcError, match="the inventory did not answer in time"): + await echo.say(StringValue(value="expired")) + + assert anyio.current_time() == start + + +async def test_a_stream_takes_the_deadline_of_its_caller(echo, impl) -> None: + with anyio.fail_after(5): + async with echo.chat() as chat: + await chat.send(StringValue(value="q")) + assert await chat.receive() == StringValue(value="Q") + await chat.end() + + assert math.isfinite(impl.deadline) + + +async def test_a_unary_call_ends_after_the_timeout_of_its_method(protocol: TripleProtocol, impl, export, refer) -> None: + echo = await refer(protocol, await export(protocol, impl), "?timeout=5000&Say.timeout=50") + + with anyio.fail_after(5), pytest.raises(RpcError) as raised: + await echo.say(StringValue(value="sleep")) + + assert raised.value.status is Status.DEADLINE_EXCEEDED + with anyio.fail_after(5): + await impl.cancelled.wait() + + +# Windows refuses the connection after its own retries, in real time. +@pytest.mark.real_clock +async def test_an_invoker_is_unavailable_after_it_fails_to_connect(protocol: TripleProtocol, echo_contract) -> None: + with socket.socket() as probe: + probe.bind(("127.0.0.1", 0)) + port = probe.getsockname()[1] + # Windows takes about two seconds to refuse a connection, longer than the default timeout. + invoker = await protocol.refer( + URL.parse(f"tri://127.0.0.1:{port}/test.Echo?timeout=5000"), dubbo.get_definition(echo_contract) + ) + + with pytest.raises(RpcError, match="UNAVAILABLE"): + await proxy(echo_contract, invoker.invoke).say(StringValue(value="x")) + + assert not invoker.available + + +@pytest.fixture +async def grpc_peer(): + seen: dict[str, object] = {} + + async def say(request: StringValue, context: grpc.aio.ServicerContext) -> StringValue: + seen["metadata"] = dict(context.invocation_metadata() or ()) + seen["time_remaining"] = context.time_remaining() + if request.value == "rpc": + await context.abort(grpc.StatusCode.PERMISSION_DENIED, "失败 100%") + if request.value == "details": + status = StatusMessage(code=Status.INVALID_ARGUMENT, message="bad request") + status.details.add().Pack(StringValue(value="value")) + context.set_trailing_metadata((("grpc-status-details-bin", status.SerializeToString()),)) + await context.abort(grpc.StatusCode.INVALID_ARGUMENT, "bad request") + context.set_trailing_metadata((("served-by", "grpcio"),)) + return StringValue(value=request.value.upper()) + + async def count(request: StringValue, context: grpc.aio.ServicerContext) -> AsyncIterator[StringValue]: + for i in range(int(request.value)): + yield StringValue(value=str(i)) + + async def join(requests: AsyncIterator[StringValue], context: grpc.aio.ServicerContext) -> StringValue: + return StringValue(value=",".join([request.value async for request in requests])) + + async def chat( + requests: AsyncIterator[StringValue], context: grpc.aio.ServicerContext + ) -> AsyncIterator[StringValue]: + async for request in requests: + yield StringValue(value=request.value.upper()) + + options = {"request_deserializer": StringValue.FromString, "response_serializer": StringValue.SerializeToString} + handlers = { + "Say": grpc.unary_unary_rpc_method_handler(say, **options), + "Count": grpc.unary_stream_rpc_method_handler(count, **options), + "Join": grpc.stream_unary_rpc_method_handler(join, **options), + "Chat": grpc.stream_stream_rpc_method_handler(chat, **options), + } + server = grpc.aio.server(compression=grpc.Compression.Gzip) + server.add_generic_rpc_handlers((grpc.method_handlers_generic_handler("test.Echo", handlers),)) + port = server.add_insecure_port("127.0.0.1:0") + await server.start() + + try: + yield port, seen + finally: + await server.stop(None) + + +async def _grpc_echo(protocol: TripleProtocol, port: int, echo_contract, query: str = ""): + url = URL.parse(f"tri://127.0.0.1:{port}/test.Echo{query}") + return proxy(echo_contract, (await protocol.refer(url, dubbo.get_definition(echo_contract))).invoke) + + +@_grpcio +async def test_a_triple_unary_call_to_grpcio_carries_attachments_group_and_deadline(protocol, echo_contract, grpc_peer): + port, seen = grpc_peer + echo = await _grpc_echo(protocol, port, echo_contract, "?group=g") + + with dubbo.outgoing({"Tenant": "t1"}) as call, anyio.fail_after(5): + assert await echo.say(StringValue(value="hi")) == StringValue(value="HI") + + assert dict(call.response_attachments) == {"served-by": "grpcio"} + assert (seen["metadata"]["tenant"], seen["metadata"]["tri-service-group"]) == ("t1", "g") + assert 0 < seen["time_remaining"] <= 5 + + +@_grpcio +async def test_triple_calls_a_grpcio_server_stream(protocol, echo_contract, grpc_peer): + port, _seen = grpc_peer + echo = await _grpc_echo(protocol, port, echo_contract) + + async with echo.count(StringValue(value="3")) as events: + assert [event.value async for event in events] == ["0", "1", "2"] + + +@_grpcio +async def test_triple_calls_a_grpcio_client_stream(protocol, echo_contract, grpc_peer): + port, _seen = grpc_peer + echo = await _grpc_echo(protocol, port, echo_contract) + + async with echo.join() as upload: + await upload.send(StringValue(value="a")) + await upload.send(StringValue(value="b")) + await upload.end() + assert await upload.receive() == StringValue(value="a,b") + + +@_grpcio +async def test_triple_calls_a_grpcio_bidi_stream(protocol, echo_contract, grpc_peer): + port, _seen = grpc_peer + echo = await _grpc_echo(protocol, port, echo_contract) + + async with echo.chat() as chat: + await chat.send(StringValue(value="x")) + assert await chat.receive() == StringValue(value="X") + await chat.end() + assert [answer async for answer in chat] == [] + + +@_grpcio +async def test_triple_preserves_a_grpcio_error_status_and_message(protocol, echo_contract, grpc_peer): + port, _seen = grpc_peer + echo = await _grpc_echo(protocol, port, echo_contract) + + with pytest.raises(RpcError, match="失败 100%") as raised: + await echo.say(StringValue(value="rpc")) + + assert (raised.value.status, raised.value.message) == (Status.PERMISSION_DENIED, "失败 100%") + + +@_grpcio +async def test_triple_preserves_grpcio_error_details(protocol, echo_contract, grpc_peer): + port, _seen = grpc_peer + echo = await _grpc_echo(protocol, port, echo_contract) + + with pytest.raises(TripleError, match="bad request") as raised: + await echo.say(StringValue(value="details")) + + assert (raised.value.status, raised.value.message) == (Status.INVALID_ARGUMENT, "bad request") + assert [detail.unpack(StringValue) for detail in raised.value.details] == [StringValue(value="value")] + + +async def test_closing_an_invoker_waits_for_its_running_calls( + protocol: TripleProtocol, impl, export, echo_contract +) -> None: + exporter = await export(protocol, impl) + invoker = await protocol.refer( + URL.parse(f"tri://127.0.0.1:{exporter.url.port}/test.Echo"), dubbo.get_definition(echo_contract) + ) + echo = proxy(echo_contract, invoker.invoke) + results = [] + + async def call() -> None: + results.append(await echo.say(StringValue(value="wait"))) + + async with anyio.create_task_group() as tasks: + tasks.start_soon(call) + await impl.started.wait() + tasks.start_soon(invoker.aclose) + await anyio.wait_all_tasks_blocked() + + with pytest.raises(RpcError, match="UNAVAILABLE"): + await echo.say(StringValue(value="late")) + impl.release.set() + + assert results == [StringValue(value="wait|-")] + assert protocol._clients._shares == {} diff --git a/tests/integration/protocol/triple/test_protocol.py b/tests/integration/protocol/triple/test_protocol.py new file mode 100644 index 00000000..07e785ee --- /dev/null +++ b/tests/integration/protocol/triple/test_protocol.py @@ -0,0 +1,231 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from contextlib import aclosing + +import anyio +import pytest +from google.protobuf.wrappers_pb2 import StringValue + +import dubbo +from dubbo import RpcError, Status +from dubbo.cluster import create_cluster +from dubbo.cluster.directory import StaticDirectory +from dubbo.protocol.triple import TripleProtocol +from dubbo.rpc.client import proxy +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +async def test_export_reports_the_bound_port(protocol: TripleProtocol, impl, export) -> None: + exporter = await export(protocol, impl) + + assert exporter.url.port not in (None, 0) + assert exporter.url.path == "test.Echo" + + +async def test_group_and_version_must_match_exactly( + protocol: TripleProtocol, export, serve, refer, echo_impl_type +) -> None: + one, two = echo_impl_type(), echo_impl_type() + first = await export(protocol, one, "?group=a&version=1.0") + await serve(protocol, URL.parse(f"tri://127.0.0.1:{first.url.port}/test.Echo?group=a&version=2.0"), two) + + with dubbo.outgoing({"Tenant": "v1"}): + assert await (await refer(protocol, first, "?group=a&version=1.0")).say(StringValue(value="x")) == StringValue( + value="x|v1" + ) + with dubbo.outgoing({"Tenant": "v2"}): + assert await (await refer(protocol, first, "?group=a&version=2.0")).say(StringValue(value="x")) == StringValue( + value="x|v2" + ) + with pytest.raises(RpcError, match="UNIMPLEMENTED"): + await (await refer(protocol, first, "?group=a")).say(StringValue(value="x")) + + +@dubbo.service("test.Plain") +class _Plain(typing.Protocol): + async def say(self, text: str) -> str: ... + + +async def test_export_rejects_a_taken_route(protocol: TripleProtocol, export, serve, echo_impl_type) -> None: + exporter = await export(protocol, echo_impl_type()) + url = URL.parse(f"tri://127.0.0.1:{exporter.url.port}/test.Echo") + + with pytest.raises(ValueError, match="already exported"): + await serve(protocol, url, echo_impl_type()) + + +async def test_export_rejects_a_contract_its_serialization_cannot_carry( + protocol: TripleProtocol, export, serve, echo_impl_type +) -> None: + exporter = await export(protocol, echo_impl_type()) + url = URL.parse(f"tri://127.0.0.1:{exporter.url.port}/test.Echo") + + with pytest.raises(TypeError, match="protobuf carries messages"): + await serve(protocol, url, echo_impl_type(), _Plain) + + +async def test_a_failed_first_export_leaves_no_server_behind(protocol: TripleProtocol, serve, echo_impl_type) -> None: + with pytest.raises(TypeError, match="protobuf carries messages"): + await serve(protocol, URL.parse("tri://127.0.0.1:0/test.Echo"), echo_impl_type(), _Plain) + + # A server left behind would refuse a service asking for other settings. + url = URL.parse("tri://127.0.0.1:0/test.Echo?triple.max-receive-message-size=1024") + exporter = await serve(protocol, url, echo_impl_type()) + + assert exporter.url.port not in (None, 0) + + +async def test_closing_an_exporter_waits_for_running_calls( + protocol: TripleProtocol, impl, export, serve, refer, echo_impl_type +) -> None: + exporter = await export(protocol, impl) + echo = await refer(protocol, exporter) + other = await serve( + protocol, URL.parse(f"tri://127.0.0.1:{exporter.url.port}/test.Echo?version=2"), echo_impl_type() + ) + results: list[StringValue] = [] + + async with anyio.create_task_group() as tasks: + + async def call() -> None: + results.append(await echo.say(StringValue(value="wait"))) + + tasks.start_soon(call) + await impl.started.wait() + tasks.start_soon(exporter.aclose) + await anyio.wait_all_tasks_blocked() + + with pytest.raises(RpcError, match="UNAVAILABLE"): + await echo.say(StringValue(value="x")) + assert results == [] + impl.release.set() + + assert results == [StringValue(value="wait|-")] + assert await (await refer(protocol, other, "?version=2")).say(StringValue(value="x")) == StringValue(value="x|-") + + +async def test_calls_move_to_another_provider_while_one_is_unexported( + protocol: TripleProtocol, impl, export, refer, echo_contract, echo_impl_type +) -> None: + leaving = await export(protocol, impl) + async with TripleProtocol() as other: + staying = await export(other, echo_impl_type()) + url = URL.parse("tri://127.0.0.1/test.Echo") + invokers = [ + await protocol.refer(url.replace(port=exporter.url.port), dubbo.get_definition(echo_contract)) + for exporter in (leaving, staying) + ] + async with aclosing(await create_cluster(url, StaticDirectory(invokers))) as cluster: + echo = proxy(echo_contract, cluster.invoke) + direct = await refer(protocol, leaving) + replies: list[StringValue] = [] + + async with anyio.create_task_group() as tasks: + tasks.start_soon(direct.say, StringValue(value="wait")) + await impl.started.wait() + tasks.start_soon(leaving.aclose) + await anyio.wait_all_tasks_blocked() + + replies = [await echo.say(StringValue(value=str(i))) for i in range(20)] + impl.release.set() + + assert replies == [StringValue(value=f"{i}|-") for i in range(20)] + + +async def test_closing_an_exporter_cancels_the_calls_still_running_after_shutwait( + protocol: TripleProtocol, impl, export, refer +) -> None: + exporter = await export(protocol, impl, "?shutwait=50") + echo = await refer(protocol, exporter) + errors: list[RpcError] = [] + + async with anyio.create_task_group() as tasks: + + async def call() -> None: + with pytest.raises(RpcError) as raised: + await echo.say(StringValue(value="sleep")) + errors.append(raised.value) + + tasks.start_soon(call) + await impl.started.wait() + with anyio.fail_after(2): + await exporter.aclose() + + assert impl.cancelled.is_set() + assert [error.status for error in errors] == [Status.CANCELLED] + + +async def test_an_export_to_a_served_address_asks_for_the_settings_of_its_server( + protocol: TripleProtocol, export, serve, echo_impl_type +) -> None: + exporter = await export(protocol, echo_impl_type()) + address = f"tri://127.0.0.1:{exporter.url.port}/test.Echo" + + with pytest.raises(ValueError, match="runs with other max-receive-message-size, shutwait"): + await serve(protocol, URL.parse(f"{address}?triple.max-receive-message-size=8&shutwait=1"), echo_impl_type()) + + +async def test_services_of_one_server_may_differ_in_service_parameters( + protocol: TripleProtocol, export, serve, echo_impl_type +) -> None: + exporter = await export(protocol, echo_impl_type()) + address = f"tri://127.0.0.1:{exporter.url.port}/test.Echo" + + await serve( + protocol, URL.parse(f"{address}?version=2&timeout=100&say.timeout=50&application=other"), echo_impl_type() + ) + await serve(protocol, URL.parse(f"{address}?version=3&weight=10&warmup=1000&dubbo.tag=gray"), echo_impl_type()) + + +# Windows refuses the connection after its own retries, in real time. +@pytest.mark.real_clock +async def test_the_server_listens_until_the_protocol_closes(impl, export, refer, echo_contract) -> None: + async with TripleProtocol() as protocol: + exporter = await export(protocol, impl) + await exporter.aclose() + port = exporter.url.port + + with pytest.raises(RpcError, match=r"UNAVAILABLE: .* is no longer served here"): + await (await refer(protocol, exporter)).say(StringValue(value="x")) + + # Windows takes about two seconds to refuse a connection, longer than the default timeout. + url = URL.parse(f"tri://127.0.0.1:{port}/test.Echo?timeout=5000") + async with TripleProtocol() as caller: + with pytest.raises(RpcError, match="UNAVAILABLE"): + await proxy(echo_contract, (await caller.refer(url, dubbo.get_definition(echo_contract))).invoke).say( + StringValue(value="x") + ) + + +async def test_an_invoker_that_cannot_be_created_gives_its_connection_back( + protocol: TripleProtocol, impl, export, echo_contract +) -> None: + exporter = await export(protocol, impl) + url = URL.parse(f"tri://127.0.0.1:{exporter.url.port}/test.Echo") + invoker = await protocol.refer(url, dubbo.get_definition(echo_contract)) + + with pytest.raises(ValueError, match="compressor"): + await protocol.refer( + url.update_parameters({"triple.compressor": "missing"}), dubbo.get_definition(echo_contract) + ) + await invoker.aclose() + + assert protocol._clients._shares == {} diff --git a/tests/integration/protocol/triple/test_pure_python_protobuf.py b/tests/integration/protocol/triple/test_pure_python_protobuf.py new file mode 100644 index 00000000..52abb407 --- /dev/null +++ b/tests/integration/protocol/triple/test_pure_python_protobuf.py @@ -0,0 +1,42 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import os +import subprocess +import sys + +_ROUND_TRIP = """ +from google.protobuf.wrappers_pb2 import StringValue +from dubbo import Status +from dubbo.protocol.triple import ErrorDetail, TripleError +from dubbo.protocol.triple.grpc.status import status_headers, trailer_error + +detail = ErrorDetail.from_message(StringValue(value="name")) +error = trailer_error(dict(status_headers(TripleError(Status.INVALID_ARGUMENT, "bad", details=[detail])))) +assert error.details == (detail,), error +""" + + +def test_error_details_travel_with_the_pure_python_protobuf_runtime(): + # Free-threaded builds of Python have only this runtime. + environment = {**os.environ, "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "python"} + + result = subprocess.run( + [sys.executable, "-c", _ROUND_TRIP], capture_output=True, text=True, timeout=10, env=environment + ) + + assert result.returncode == 0, result.stderr diff --git a/tests/integration/protocol/triple/test_server.py b/tests/integration/protocol/triple/test_server.py new file mode 100644 index 00000000..526b46b8 --- /dev/null +++ b/tests/integration/protocol/triple/test_server.py @@ -0,0 +1,207 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import grpc +import pytest +from google.protobuf.wrappers_pb2 import StringValue + +import dubbo +from dubbo import RpcError, Status +from dubbo._proto.google.rpc.status_pb2 import Status as StatusMessage +from dubbo.protocol import Exporter +from dubbo.protocol.triple import TripleProtocol +from dubbo.rpc import Invocation +from dubbo.rpc.server import ServiceInvoker +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + +# grpcio calls through threads of its own and keeps its deadlines on the real clock. +_grpcio = pytest.mark.real_clock + + +class _Broken(ServiceInvoker): + async def invoke(self, invocation: Invocation): + raise RuntimeError("broken") + + +async def test_an_invoker_that_raises_answers_internal(protocol: TripleProtocol, impl, refer, echo_contract) -> None: + url = URL.parse("tri://127.0.0.1:0/test.Echo") + exporter = await protocol.export(url, dubbo.get_definition(echo_contract), _Broken.from_implementation(impl, url)) + echo = await refer(protocol, exporter) + + with pytest.raises(RpcError, match=r"^INTERNAL: RuntimeError: broken$") as caught: + await echo.say(StringValue(value="hi")) + + assert caught.value.status is Status.INTERNAL + + +async def test_a_handler_sees_the_caller_address(echo, impl) -> None: + await echo.say(StringValue(value="hi")) + + assert impl.peer is not None + host, _, port = impl.peer.rpartition(":") + assert host == "127.0.0.1" + assert int(port) > 0 + + +async def test_a_handler_is_cancelled_when_the_caller_leaves( + protocol: TripleProtocol, export, refer, echo_impl_type +) -> None: + seen: list[BaseException] = [] + finished = anyio.Event() + + class Impl(echo_impl_type): + async def chat(self, stream: dubbo.Stream[StringValue, StringValue]) -> None: + await stream.send(await stream.receive()) + try: + await stream.receive() + except BaseException as error: + seen.append(error) + raise + finally: + finished.set() + + echo = await refer(protocol, await export(protocol, Impl())) + async with echo.chat() as chat: + await chat.send(StringValue(value="x")) + assert await chat.receive() == StringValue(value="x") + + with anyio.fail_after(5): + await finished.wait() + assert isinstance(seen[0], anyio.get_cancelled_exc_class()) + + +_MESSAGES = {"request_serializer": StringValue.SerializeToString, "response_deserializer": StringValue.FromString} + + +def _channel(exporter: Exporter) -> grpc.aio.Channel: + return grpc.aio.insecure_channel(f"127.0.0.1:{exporter.url.port}") + + +async def _grpcio_error( + exporter: Exporter, method: str, text: str, timeout: float | None = None +) -> grpc.aio.AioRpcError: + async with _channel(exporter) as channel: + call = channel.unary_unary(f"/test.Echo/{method}", request_serializer=StringValue.SerializeToString) + with pytest.raises(grpc.aio.AioRpcError) as raised: + await call(StringValue(value=text), timeout=timeout) + + return raised.value + + +@_grpcio +async def test_a_grpcio_unary_call_carries_metadata_both_ways_compressed(protocol, impl, export): + exporter = await export(protocol, impl) + metadata = ( + ("tenant", "t1"), + ("tri-header-convert", '{"tenant":"Tenant"}'), + ("trace-bin", b"\x00\xff"), + ("tag", "a"), + ("tag", "b"), + ) + + async with _channel(exporter) as channel: + say = channel.unary_unary("/test.Echo/Say", **_MESSAGES) + call = say(StringValue(value="hi"), metadata=metadata, compression=grpc.Compression.Gzip) + assert await call == StringValue(value="hi|t1") + trailers = tuple(await call.trailing_metadata()) + + assert ("served-by", "echo") in trailers + assert ("trace-bin", b"\x00\xff") in trailers + assert [value for key, value in trailers if key == "tag"] == ["a", "b"] + + +@_grpcio +async def test_a_grpcio_client_calls_a_triple_server_stream(protocol, impl, export): + exporter = await export(protocol, impl) + + async with _channel(exporter) as channel: + count = channel.unary_stream("/test.Echo/Count", **_MESSAGES) + assert [event.value async for event in count(StringValue(value="3"))] == ["0", "1", "2"] + + +@_grpcio +async def test_a_grpcio_client_calls_a_triple_client_stream(protocol, impl, export): + exporter = await export(protocol, impl) + + async with _channel(exporter) as channel: + join = channel.stream_unary("/test.Echo/Join", **_MESSAGES) + assert await join(iter([StringValue(value="a"), StringValue(value="b")])) == StringValue(value="a,b") + + +@_grpcio +async def test_a_grpcio_client_calls_a_triple_bidi_stream(protocol, impl, export): + exporter = await export(protocol, impl) + + async with _channel(exporter) as channel: + chat = channel.stream_stream("/test.Echo/Chat", **_MESSAGES) + answers = [answer.value async for answer in chat(iter([StringValue(value="x"), StringValue(value="y")]))] + + assert answers == ["X", "Y"] + + +@_grpcio +async def test_a_grpcio_client_receives_a_triple_rpc_error_with_its_message(protocol, impl, export): + error = await _grpcio_error(await export(protocol, impl), "Say", "rpc") + + assert (error.code(), error.details()) == (grpc.StatusCode.ABORTED, "失败 100%") + + +@_grpcio +async def test_a_grpcio_client_receives_triple_error_details(protocol, impl, export): + error = await _grpcio_error(await export(protocol, impl), "Say", "details") + + assert error.code() is grpc.StatusCode.INVALID_ARGUMENT + details = StatusMessage.FromString(dict(error.trailing_metadata())["grpc-status-details-bin"]) + assert (details.code, details.message) == (Status.INVALID_ARGUMENT, "bad request") + assert [detail.value for detail in details.details] == [StringValue(value="value").SerializeToString()] + + +@_grpcio +async def test_a_grpcio_client_calling_an_unknown_method_receives_unimplemented(protocol, impl, export): + error = await _grpcio_error(await export(protocol, impl), "Nope", "x") + + assert error.code() is grpc.StatusCode.UNIMPLEMENTED + + +@_grpcio +async def test_a_triple_handler_whose_caller_gives_up_finishes_its_shielded_work_first(protocol, impl, export): + committed = anyio.Event() + + class Committing(type(impl)): + async def say(self, request: StringValue) -> StringValue: + with anyio.CancelScope(shield=True): + await anyio.sleep(0.2) + committed.set() + await anyio.sleep_forever() + return request + + error = await _grpcio_error(await export(protocol, Committing()), "Say", "commit", timeout=0.05) + + assert error.code() is grpc.StatusCode.DEADLINE_EXCEEDED + with anyio.fail_after(2): + await committed.wait() + + +@_grpcio +async def test_a_grpcio_deadline_ends_and_cancels_the_triple_handler(protocol, impl, export): + error = await _grpcio_error(await export(protocol, impl), "Say", "sleep", timeout=0.2) + + assert error.code() is grpc.StatusCode.DEADLINE_EXCEEDED + await impl.cancelled.wait() diff --git a/tests/integration/protocol/triple/test_wrapper.py b/tests/integration/protocol/triple/test_wrapper.py new file mode 100644 index 00000000..987ee9de --- /dev/null +++ b/tests/integration/protocol/triple/test_wrapper.py @@ -0,0 +1,157 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import abc +import typing +from collections.abc import AsyncIterator +from typing import Any + +import pytest +from google.protobuf.wrappers_pb2 import StringValue +from hessian2 import HessianObject + +import dubbo +from dubbo._proto.org.apache.dubbo.triple.triple_wrapper_pb2 import TripleResponseWrapper +from dubbo.exceptions import RemoteError +from dubbo.protocol.triple import TripleProtocol +from dubbo.protocol.triple.grpc.framing import frame +from dubbo.rpc.client import GenericService, proxy +from dubbo.rpc.definition import Service +from dubbo.rpc.server import ServiceInvoker +from dubbo.serialization.hessian2 import Hessian2Serialization +from dubbo.transport.h2 import H2Stream +from dubbo.transport.h2.aio import AioH2Server +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +@pytest.fixture +def hessian2() -> Hessian2Serialization: + return Hessian2Serialization(URL(protocol="tri")) + + +@dubbo.service("test.Users") +class Users(typing.Protocol): + @dubbo.method("greet") + async def greet(self, name: str, times: int) -> str: ... + + +@dubbo.service("test.Users") +class UsersServicer(abc.ABC): + @dubbo.method("greet") + @abc.abstractmethod + async def greet(self, name: str, times: int) -> str: ... + + @dubbo.method("$invoke") + @abc.abstractmethod + async def echo_generic_call( + self, method: str, types: tuple[str, ...] | None, arguments: tuple[Any, ...] + ) -> Any: ... + + +class UsersImpl(UsersServicer): + async def greet(self, name: str, times: int) -> str: + return " ".join([f"hi {name}"] * times) + + async def echo_generic_call(self, method: str, types: tuple[str, ...] | None, arguments: tuple[Any, ...]) -> Any: + return {"method": method, "types": types, "arguments": arguments, **dubbo.incoming().attachments} + + +@pytest.fixture +async def port() -> AsyncIterator[tuple[TripleProtocol, int]]: + async with TripleProtocol() as protocol: + url = URL.parse("tri://127.0.0.1:0/test.Users?serialization=hessian2") + invoker = ServiceInvoker.from_implementation(UsersImpl(), url) + exporter = await protocol.export(url, dubbo.get_definition(UsersServicer), invoker) + yield protocol, exporter.url.port or 0 + + +async def test_a_java_format_travels_wrapped_with_all_its_parameters(port: tuple[TripleProtocol, int]) -> None: + protocol, number = port + url = URL.parse(f"tri://127.0.0.1:{number}/test.Users?serialization=hessian2") + + users = proxy(Users, (await protocol.refer(url, dubbo.get_definition(Users))).invoke) + + assert await users.greet("bob", 2) == "hi bob hi bob" + + +async def test_a_generic_call_travels_as_wrapped_invoke_whatever_the_format(port: tuple[TripleProtocol, int]) -> None: + protocol, number = port + url = URL.parse(f"tri://127.0.0.1:{number}/test.Users?serialization=protobuf") + invoker = await protocol.refer(url, Service(interface="test.Users", methods=())) + users = GenericService("test.Users", invoker.invoke) + + received = await users.call("find", "bob", 7) + typed = await users.call("find", "bob", 7, types=["java.lang.String", "long"]) + + assert received["method"] == "find" + assert received["types"] is None + assert received["arguments"] == ["bob", 7] + assert received["generic"] == "true" + assert typed["types"] == ["java.lang.String", "long"] + + +async def test_a_response_flagged_as_an_exception_is_the_error_of_the_call(hessian2: Hessian2Serialization) -> None: + thrown = HessianObject("java.lang.IllegalStateException", {"detailMessage": "broken"}) + message = TripleResponseWrapper( + serializeType="hessian4", data=hessian2.codec((Any,)).encode((thrown,)) + ).SerializeToString() + + async def respond(stream: H2Stream) -> None: + await stream.receive_headers() + await stream.send_headers( + ((b":status", b"200"), (b"content-type", b"application/grpc+proto"), (b"tri-exception-code", b"3")) + ) + await stream.send_data(frame(message)) + await stream.send_trailers(((b"grpc-status", b"0"),)) + + async with ( + TripleProtocol() as protocol, + AioH2Server(URL(protocol="tri", host="127.0.0.1", port=0), respond) as server, + ): + url = URL.parse(f"tri://127.0.0.1:{server.address[1]}/test.Users?serialization=hessian2") + users = proxy(Users, (await protocol.refer(url, dubbo.get_definition(Users))).invoke) + + with pytest.raises(RemoteError) as raised: + await users.greet("bob", 1) + + assert raised.value.class_name == "java.lang.IllegalStateException" + assert raised.value.message == "broken" + + +@dubbo.service("test.Echo") +class Echo(typing.Protocol): + @dubbo.method("Say") + async def say(self, request: StringValue) -> StringValue: ... + + +class EchoImpl(Echo): + async def say(self, request: StringValue) -> StringValue: + return StringValue(value=request.value.upper()) + + +async def test_protobuf_messages_travel_as_themselves_where_the_service_names_a_java_format() -> None: + async with TripleProtocol() as protocol: + served = URL.parse("tri://127.0.0.1:0/test.Echo?serialization=hessian2") + invoker = ServiceInvoker.from_implementation(EchoImpl(), served) + exporter = await protocol.export(served, dubbo.get_definition(Echo), invoker) + # A consumer of protobuf, as a gRPC client or a Java consumer of the proto file calls. + called = URL.parse(f"tri://127.0.0.1:{exporter.url.port}/test.Echo") + echo = proxy(Echo, (await protocol.refer(called, dubbo.get_definition(Echo))).invoke) + + assert (await echo.say(StringValue(value="bob"))).value == "BOB" diff --git a/tests/integration/registry/conftest.py b/tests/integration/registry/conftest.py new file mode 100644 index 00000000..9fa46443 --- /dev/null +++ b/tests/integration/registry/conftest.py @@ -0,0 +1,225 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +import uuid +from collections.abc import Sequence +from typing import Any, Self +from urllib.parse import parse_qsl, urlencode + +import anyio +import pytest +from google.protobuf.wrappers_pb2 import StringValue + +import dubbo +from dubbo import Dubbo, Invocation, Invoker +from dubbo.cluster import Router +from dubbo.config import ( + ApplicationConfig, + ConfigCenterConfig, + ConsumerConfig, + MetadataReportConfig, + ProtocolConfig, + ProviderConfig, + ReferenceConfig, + RegistryConfig, + RegistryMode, + ShutdownConfig, +) +from dubbo.extension import extensions +from dubbo.url import URL + + +@dubbo.service("test.registry.Greeter") +class _Greeter(typing.Protocol): + @dubbo.method("Greet") + async def greet(self, request: StringValue) -> StringValue: ... + + +@dubbo.service("test.registry.Echo") +class _Echo(typing.Protocol): + @dubbo.method("Echo") + async def echo(self, request: StringValue) -> StringValue: ... + + +class _EchoImpl(_Echo): + async def echo(self, request: StringValue) -> StringValue: + return request + + +class _GreeterImpl(_Greeter): + def __init__(self, name: str = "a") -> None: + self.name = name + + async def greet(self, request: StringValue) -> StringValue: + return StringValue(value=f"{self.name}: hello {request.value}") + + +def _registry_config(address: str, **fields: Any) -> RegistryConfig: + """Return the registry at ``address``, its ``group`` query parameter set as the field.""" + base, _, query = address.partition("?") + parameters = dict(parse_qsl(query)) + group = parameters.pop("group", None) + return RegistryConfig(address=base + (f"?{urlencode(parameters)}" if parameters else ""), group=group, **fields) + + +def _provider( + address: str, + mode: RegistryMode, + *, + name: str = "greeter-app", + settings: ProviderConfig | None = None, + shutdown: ShutdownConfig | None = None, + config_center: ConfigCenterConfig | None = None, + metadata_report: MetadataReportConfig | None = None, + **application, +) -> Dubbo: + return Dubbo( + application=ApplicationConfig(name=name, **application), + registries={"zk": _registry_config(address, mode=mode)}, + protocols={"tri": ProtocolConfig(name="tri", host="127.0.0.1", port=0)}, + provider=settings, + shutdown=shutdown or ShutdownConfig(unregister_wait=0), + config_center=config_center, + metadata_report=metadata_report, + env_prefix=None, + ) + + +def _config_center(address: str) -> ConfigCenterConfig: + """Return the configuration center on the ZooKeeper of the registry at ``address``, under its root.""" + base, _, query = address.partition("?") + parameters = dict(parse_qsl(query)) + client = f"?client={parameters['client']}" if "client" in parameters else "" + return ConfigCenterConfig(address=base + client, namespace=parameters["group"], check=False) + + +def _consumer(address: str, mode: RegistryMode, **reference) -> Dubbo: + return Dubbo( + application=ApplicationConfig(name="caller-app"), + registries={"zk": _registry_config(address, mode=mode)}, + consumer=ConsumerConfig(references={"test.registry.Greeter": ReferenceConfig(**reference)}) + if reference + else None, + env_prefix=None, + ) + + +@pytest.fixture(params=["memory", pytest.param("kazoo", marks=pytest.mark.zookeeper)]) +async def registry_address(request, delete_tree, zk): + root = f"test-{uuid.uuid4().hex}" + if request.param == "memory": + request.getfixturevalue("memory_zookeeper") + yield f"zookeeper://127.0.0.1:2181?client=memory&group={root}" + else: + address = request.getfixturevalue("zookeeper") + yield f"zookeeper://{address}?group={root}" + async with zk(f"zookeeper://{address}") as client: + await delete_tree(client, f"/{root}") + + +@pytest.fixture +async def real_registry_address(zookeeper, delete_tree, zk): + root = f"test-{uuid.uuid4().hex}" + yield f"zookeeper://{zookeeper}?group={root}" + async with zk(f"zookeeper://{zookeeper}") as client: + await delete_tree(client, f"/{root}") + + +class _ConsumerUpdates: + def __init__(self): + self.snapshots = [] + self.changed = anyio.Event() + + def publish(self, urls): + self.snapshots.append(urls) + self.changed.set() + self.changed = anyio.Event() + + async def wait_for(self, predicate, *, since=0): + with anyio.fail_after(5): + while True: + changed = self.changed + for snapshot in self.snapshots[since:]: + if predicate(snapshot): + return snapshot + await changed.wait() + + +@pytest.fixture +def consumer_updates(isolated_extensions) -> _ConsumerUpdates: + """The providers of each reference whose routers include ``updates``, each time its directory takes them.""" + updates = _ConsumerUpdates() + + class Updates(Router): + def __init__(self, url: URL) -> None: + pass + + async def __aenter__(self) -> Self: + return self + + async def aclose(self) -> None: + pass + + def notify(self, invokers: Sequence[Invoker]) -> None: + updates.publish([invoker.url for invoker in invokers]) + + def route(self, invokers: Sequence[Invoker], invocation: Invocation) -> Sequence[Invoker]: + return invokers + + extensions.register(Router, "updates", Updates) + return updates + + +@pytest.fixture +def greeter_contract(): + return _Greeter + + +@pytest.fixture +def greeter_impl_type(): + return _GreeterImpl + + +@pytest.fixture +def echo_contract(): + return _Echo + + +@pytest.fixture +def echo_impl_type(): + return _EchoImpl + + +@pytest.fixture +def registry_config(): + return _registry_config + + +@pytest.fixture +def provider(): + return _provider + + +@pytest.fixture +def config_center(): + return _config_center + + +@pytest.fixture +def consumer(): + return _consumer diff --git a/tests/integration/registry/nacos/conftest.py b/tests/integration/registry/nacos/conftest.py new file mode 100644 index 00000000..3cea585f --- /dev/null +++ b/tests/integration/registry/nacos/conftest.py @@ -0,0 +1,64 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import uuid +from contextlib import AsyncExitStack + +import pytest + +from dubbo.extension import ApplicationScope +from dubbo.url import APPLICATION_SCOPE, URL + + +@pytest.fixture +def group(): + return f"dubbo-test-{uuid.uuid4().hex}" + + +@pytest.fixture +def provider_url(): + interface = f"org.example.Users${uuid.uuid4().hex}" + return URL.parse(f"tri://10.0.0.1:50051/{interface}?interface={interface}&version=1.0.0&group=blue&side=provider") + + +@pytest.fixture +async def opened(nacos): + async with AsyncExitStack() as stack: + + async def open_registry(cls, query=""): + scope = await stack.enter_async_context(ApplicationScope()) + url = URL.parse(f"nacos://{nacos}?{query}").replace(attributes={APPLICATION_SCOPE: scope}) + return await stack.enter_async_context(cls(url)) + + yield open_registry + + +@pytest.fixture +async def register(opened): + """Keep a URL or instance registered with a registry until the test ends, or the function returned releases it.""" + kept = [] + + async def register_url(registry, url): + stack = AsyncExitStack() + await stack.enter_async_context(registry.register(url)) + kept.append(stack) + return stack.aclose + + yield register_url + + for stack in reversed(kept): + await stack.aclose() diff --git a/tests/integration/registry/nacos/test_application.py b/tests/integration/registry/nacos/test_application.py new file mode 100644 index 00000000..dc68f1e8 --- /dev/null +++ b/tests/integration/registry/nacos/test_application.py @@ -0,0 +1,60 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +import uuid + +import pytest +from google.protobuf.wrappers_pb2 import StringValue + +import dubbo +from dubbo import Dubbo +from dubbo.config import ApplicationConfig, ProtocolConfig, RegistryConfig, RegistryMode, ShutdownConfig + +pytestmark = [pytest.mark.anyio, pytest.mark.nacos] + + +@dubbo.service("test.nacos.Greeter") +class Greeter(typing.Protocol): + @dubbo.method("Greet") + async def greet(self, request: StringValue) -> StringValue: ... + + +class GreeterImpl(Greeter): + async def greet(self, request: StringValue) -> StringValue: + return StringValue(value=f"hello {request.value}") + + +@pytest.mark.parametrize("mode", [RegistryMode.INTERFACE, RegistryMode.INSTANCE]) +async def test_a_consumer_calls_a_provider_found_in_nacos(mode, nacos): + group = f"test-{uuid.uuid4().hex}" + registry = RegistryConfig(address=f"nacos://{nacos}", group=group, mode=mode) + app = Dubbo( + application=ApplicationConfig(name=f"greeter-{group}"), + registries={"nacos": registry}, + protocols={"tri": ProtocolConfig(name="tri", host="127.0.0.1", port=0)}, + shutdown=ShutdownConfig(unregister_wait=0), + env_prefix=None, + ) + app.export(GreeterImpl()) + caller = Dubbo( + application=ApplicationConfig(name=f"caller-{group}"), registries={"nacos": registry}, env_prefix=None + ) + greeter = caller.refer(Greeter) + + async with app, caller: + assert await greeter.greet(StringValue(value="nacos")) == StringValue(value="hello nacos") diff --git a/tests/integration/registry/nacos/test_instance.py b/tests/integration/registry/nacos/test_instance.py new file mode 100644 index 00000000..b15b31b3 --- /dev/null +++ b/tests/integration/registry/nacos/test_instance.py @@ -0,0 +1,68 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import uuid + +import anyio +import pytest + +from dubbo.registry import ServiceInstance +from dubbo.registry.nacos import NacosInstanceRegistry +from dubbo.transport.nacos import DEFAULT_GROUP, NacosInstance, get_nacos_naming_client + +pytestmark = [pytest.mark.anyio, pytest.mark.nacos] + + +@pytest.mark.parametrize( + "query", ["", "group", "nacos-group"], ids=["default-group", "registry-group", "nacos-group-overrides"] +) +async def test_application_instances_use_the_application_service_and_selected_nacos_group( + opened, register, group, query +): + parameters, expected_group = { + "": ("", DEFAULT_GROUP), + "group": (f"group={group}", group), + "nacos-group": (f"group=other&nacos.group={group}", group), + }[query] + registry = await opened(NacosInstanceRegistry, parameters) + instance = ServiceInstance( + app=f"orders-{uuid.uuid4().hex}", host="10.0.0.2", port=50051, metadata={"dubbo.metadata.revision": "a1"} + ) + client = await get_nacos_naming_client(registry.url) + raw = NacosInstance(host=instance.host, port=instance.port, metadata=instance.metadata) + + with anyio.fail_after(10): + async with ( + registry.subscribe(instance.app) as snapshots, + client.watch(instance.app, expected_group) as raw_snapshots, + ): + assert await anext(snapshots) == [] + release = await register(registry, instance) + async for instances in snapshots: + if instances: + break + assert instances == [instance] + async for instances in raw_snapshots: + if instances: + break + assert instances == [raw] + + await release() + async for instances in snapshots: + if not instances: + break + assert instances == [] diff --git a/tests/integration/registry/nacos/test_interface.py b/tests/integration/registry/nacos/test_interface.py new file mode 100644 index 00000000..18cdc284 --- /dev/null +++ b/tests/integration/registry/nacos/test_interface.py @@ -0,0 +1,191 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from contextlib import AsyncExitStack + +import anyio +import pytest + +from dubbo.registry.nacos import NacosInterfaceRegistry +from dubbo.transport.nacos import DEFAULT_GROUP, NacosInstance, get_nacos_naming_client +from dubbo.url import URL + +pytestmark = [pytest.mark.anyio, pytest.mark.nacos] + + +async def _snapshot(registry, service, group, expected): + client = await get_nacos_naming_client(registry.url) + async with client.watch(service, group) as snapshots: + with anyio.fail_after(10): + async for instances in snapshots: + if set(instances) == set(expected): + return sorted(instances, key=lambda instance: (instance.host, instance.port)) + pytest.fail("the naming watch ended before the expected instances") + + +async def test_provider_registration_uses_category_interface_version_and_group(opened, register, provider_url, group): + registry = await opened(NacosInterfaceRegistry, f"group={group}") + expected = NacosInstance( + host="10.0.0.1", + port=50051, + metadata={**provider_url.parameters, "category": "providers", "protocol": "tri", "path": provider_url.path}, + ) + service = f"providers:{provider_url.path}:1.0.0:blue" + + release = await register(registry, provider_url) + + assert await _snapshot(registry, service, group, [expected]) == [expected] + await release() + assert await _snapshot(registry, service, group, []) == [] + + +async def test_missing_version_and_group_use_empty_service_segments_and_the_default_nacos_group( + opened, register, provider_url +): + registry = await opened(NacosInterfaceRegistry) + url = provider_url.replace(parameters={"interface": provider_url.path}) + expected = NacosInstance( + host=url.host, + port=url.port, + metadata={**url.parameters, "category": "providers", "protocol": "tri", "path": url.path}, + ) + + await register(registry, url) + + assert await _snapshot(registry, f"providers:{url.path}::", DEFAULT_GROUP, [expected]) == [expected] + + +async def _register_a_consumer(opened, register, provider_url, group, query): + """Register a consumer URL, as a reference has it with no port, then a provider; return the registry and the consumer URL. + + The provider registers after the consumer on the same connection, so once it shows, so has the consumer. + """ + registry = await opened(NacosInterfaceRegistry, f"group={group}{query}") + url = provider_url.replace(protocol="consumer", port=None).update_parameters( + {"category": "consumers", "side": "consumer"} + ) + sentinel = NacosInstance( + host=provider_url.host, + port=provider_url.port, + metadata={**provider_url.parameters, "category": "providers", "protocol": "tri", "path": provider_url.path}, + ) + + await register(registry, url) + await register(registry, provider_url) + await _snapshot(registry, f"providers:{url.path}:1.0.0:blue", group, [sentinel]) + return registry, url + + +async def test_consumers_are_not_registered_by_default(opened, register, provider_url, group): + registry, url = await _register_a_consumer(opened, register, provider_url, group, "") + + assert await _snapshot(registry, f"consumers:{url.path}:1.0.0:blue", group, []) == [] + + +async def test_a_consumer_registers_with_port_0_when_requested(opened, register, provider_url, group): + registry, url = await _register_a_consumer(opened, register, provider_url, group, "®ister-consumer-url=true") + expected = [ + NacosInstance(host=url.host, port=0, metadata={**url.parameters, "protocol": "consumer", "path": url.path}) + ] + + assert await _snapshot(registry, f"consumers:{url.path}:1.0.0:blue", group, expected) == expected + + +async def test_subscribers_receive_provider_urls_after_registration_changes(opened, register, provider_url, group): + registry = await opened(NacosInterfaceRegistry, f"group={group}") + other = provider_url.replace(host="10.0.0.2") + first = provider_url.update_parameters({"category": "providers"}) + second = other.update_parameters({"category": "providers"}) + + with anyio.fail_after(10): + async with registry.subscribe(provider_url.path, group="blue", version="1.0.0") as snapshots: + assert await anext(snapshots) == [] + await register(registry, provider_url) + async for urls in snapshots: + if urls: + break + assert urls == [first] + await register(registry, other) + async for urls in snapshots: + if any(url.host == other.host for url in urls): + break + assert set(urls) == {first, second} + + +async def test_unregistering_one_address_of_a_service_keeps_the_others(opened, register, provider_url, group): + registry = await opened(NacosInterfaceRegistry, f"group={group}") + other = provider_url.replace(host="10.0.0.2") + release = await register(registry, provider_url) + await register(registry, other) + service = f"providers:{provider_url.path}:1.0.0:blue" + expected = NacosInstance( + host=other.host, + port=other.port, + metadata={**other.parameters, "category": "providers", "protocol": "tri", "path": other.path}, + ) + + await release() + + assert await _snapshot(registry, service, group, [expected]) == [expected] + + +async def test_subscribers_combine_providers_from_each_requested_group(opened, register, provider_url, group): + registry = await opened(NacosInterfaceRegistry, f"group={group}") + green = provider_url.replace(host="10.0.0.2").update_parameters({"group": "green"}) + await register(registry, provider_url) + await register(registry, green) + + with anyio.fail_after(10): + async with registry.subscribe(provider_url.path, group="blue,green", version="1.0.0") as snapshots: + async for urls in snapshots: + if len(urls) == 2: + break + + assert set(urls) == { + provider_url.update_parameters({"category": "providers"}), + green.update_parameters({"category": "providers"}), + } + + +@pytest.mark.parametrize(("wanted_group", "version"), [("*", "1.0.0"), ("blue", "*")], ids=["any-group", "any-version"]) +async def test_subscribers_must_name_their_groups_and_version(opened, provider_url, group, wanted_group, version): + registry = await opened(NacosInterfaceRegistry, f"group={group}") + + with pytest.raises(ValueError, match="cannot watch any group or version"): + async with registry.subscribe(provider_url.path, group=wanted_group, version=version): + pass + + +async def test_subscribers_skip_protocol_less_instances_and_accept_a_missing_path(opened, provider_url, group): + registry = await opened(NacosInterfaceRegistry, f"group={group}") + client = await get_nacos_naming_client(registry.url) + other = await opened(NacosInterfaceRegistry, f"group={group}") + other_client = await get_nacos_naming_client(other.url) + service = f"providers:{provider_url.path}::" + good = NacosInstance(host="10.0.0.1", port=50051, metadata={"protocol": "tri", "interface": provider_url.path}) + bad = NacosInstance(host="10.0.0.1", port=50052, metadata={"interface": provider_url.path}) + + async with AsyncExitStack() as registered: + await registered.enter_async_context(client.keep_registered(service, group, good)) + await registered.enter_async_context(other_client.keep_registered(service, group, bad)) + await _snapshot(registry, service, group, [good, bad]) + + with anyio.fail_after(10): + async with registry.subscribe(provider_url.path, group=None, version=None) as snapshots: + urls = await anext(snapshots) + + assert urls == [URL(protocol="tri", host=good.host, port=good.port, parameters={"interface": provider_url.path})] diff --git a/tests/integration/registry/test_application.py b/tests/integration/registry/test_application.py new file mode 100644 index 00000000..15d59c41 --- /dev/null +++ b/tests/integration/registry/test_application.py @@ -0,0 +1,1228 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import itertools +import json +import logging +import socket +import typing +from contextlib import AsyncExitStack, asynccontextmanager +from pathlib import Path +from urllib.parse import parse_qsl, unquote_plus, urlencode + +import anyio +import pytest +from google.protobuf.wrappers_pb2 import StringValue + +import dubbo +from dubbo import Dubbo, RpcError, Status +from dubbo.config import ( + ApplicationConfig, + ConfigError, + ConsumerConfig, + MetadataReportConfig, + MetadataType, + MethodConfig, + ProtocolConfig, + ProviderConfig, + ReferenceConfig, + RegistryMode, + ServiceConfig, + ShutdownConfig, + TLSConfig, + TripleConfig, +) +from dubbo.constants import DEFAULT_ROUTERS +from dubbo.extension import ExtensionError +from dubbo.metadata.service.server import MetadataStore +from dubbo.protocol.served import ServedExporter +from dubbo.protocol.triple import TripleProtocol +from dubbo.protocol.triple.invoker import TripleInvoker +from dubbo.registry.zookeeper import ZookeeperInstanceRegistry +from dubbo.registry.zookeeper.interface import ZookeeperInterfaceRegistry, _parse_full_string +from dubbo.transport.h2.aio import AioH2Client +from dubbo.url import URL + +pytestmark = pytest.mark.anyio +# The routers of references that consumer_updates follows. +_UPDATES = (*DEFAULT_ROUTERS, "updates") + + +async def test_a_consumer_calls_a_provider_found_by_interface( + registry_address, greeter_contract, greeter_impl_type, consumer, provider, zk +): + app = provider(registry_address, RegistryMode.INTERFACE) + app.export(greeter_impl_type()) + caller = consumer(registry_address, RegistryMode.INTERFACE) + greeter = caller.refer(greeter_contract) + + async with app, caller: + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + + async with zk(registry_address) as client: + root = "/" + URL.parse(registry_address).parameters["group"] + providers = await client.children(f"{root}/test.registry.Greeter/providers") + consumers = await client.children(f"{root}/test.registry.Greeter/consumers") + assert await client.children(f"{root}/test.registry.Greeter") == ["consumers", "providers"] + + [node] = providers + url = _parse_full_string(unquote_plus(node)) + assert (url.protocol, url.host, url.path) == ("tri", "127.0.0.1", "test.registry.Greeter") + assert {key: url.parameters[key] for key in ("application", "interface", "methods", "side", "dubbo")} == { + "application": "greeter-app", + "interface": "test.registry.Greeter", + "methods": "Greet", + "side": "provider", + "dubbo": "2.0.2", + } + [node] = consumers + url = _parse_full_string(unquote_plus(node)) + assert (url.protocol, url.host, url.parameters["category"], url.parameters["side"]) == ( + "consumer", + "127.0.0.1", + "consumers", + "consumer", + ) + + +async def test_a_provider_whose_filters_cannot_load_is_left_out_and_its_invoker_closed( + registry_address, monkeypatch, greeter_contract, greeter_impl_type, consumer, provider +): + closed = anyio.Event() + aclose = TripleInvoker.aclose + + async def recording(invoker): + await aclose(invoker) + closed.set() + + monkeypatch.setattr(TripleInvoker, "aclose", recording) + app = provider(registry_address, RegistryMode.INTERFACE) + app.export(greeter_impl_type()) + caller = consumer(registry_address, RegistryMode.INTERFACE, check=False, attempt_filters=("missing",)) + greeter = caller.refer(greeter_contract) + + with anyio.fail_after(5): + async with app, caller: + await closed.wait() + with pytest.raises(RpcError, match="UNAVAILABLE"): + await greeter.greet(StringValue(value="b")) + + +async def test_a_simplified_registry_gets_only_what_consumers_need( + registry_address, greeter_contract, greeter_impl_type, consumer, provider, zk +): + address = f"{registry_address}&simplified=true&extra-keys=timestamp" + app = provider(address, RegistryMode.INTERFACE) + app.export(greeter_impl_type()) + caller = consumer(address, RegistryMode.INTERFACE) + greeter = caller.refer(greeter_contract) + + async with app, caller: + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + + async with zk(registry_address) as client: + root = "/" + URL.parse(registry_address).parameters["group"] + [provider_node] = await client.children(f"{root}/test.registry.Greeter/providers") + [consumer_node] = await client.children(f"{root}/test.registry.Greeter/consumers") + + url = _parse_full_string(unquote_plus(provider_node)) + assert set(url.parameters) == {"application", "dubbo", "release", "side", "timestamp"} + url = _parse_full_string(unquote_plus(consumer_node)) + assert set(url.parameters) == {"application", "dubbo", "release", "category", "check"} + + +async def test_the_tags_of_services_and_references_are_registered( + registry_address, greeter_contract, greeter_impl_type, consumer, provider, zk +): + app = provider(registry_address, RegistryMode.INTERFACE, settings=ProviderConfig(tag="gray")) + app.export(greeter_impl_type()) + caller = consumer(registry_address, RegistryMode.INTERFACE, tag="blue") + caller.refer(greeter_contract) + + async with app, caller, zk(registry_address) as client: + root = "/" + URL.parse(registry_address).parameters["group"] + [provider_node] = await client.children(f"{root}/test.registry.Greeter/providers") + [consumer_node] = await client.children(f"{root}/test.registry.Greeter/consumers") + + assert _parse_full_string(unquote_plus(provider_node)).parameters["dubbo.tag"] == "gray" + assert _parse_full_string(unquote_plus(consumer_node)).parameters["dubbo.tag"] == "blue" + + +async def test_a_reference_of_a_forced_tag_calls_only_the_providers_found_with_that_tag( + registry_address, greeter_contract, greeter_impl_type, consumer, provider +): + plain = provider(registry_address, RegistryMode.INTERFACE) + plain.export(greeter_impl_type("plain")) + blue = provider(registry_address, RegistryMode.INTERFACE, settings=ProviderConfig(tag="blue")) + blue.export(greeter_impl_type("blue")) + tagged = consumer( + registry_address, + RegistryMode.INTERFACE, + tag="blue", + loadbalance="roundrobin", + parameters={"dubbo.force.tag": "true"}, + ) + untagged = consumer(registry_address, RegistryMode.INTERFACE) + tagged_greeter, untagged_greeter = tagged.refer(greeter_contract), untagged.refer(greeter_contract) + + async with plain, blue, tagged, untagged: + answers = [(await tagged_greeter.greet(StringValue(value="b"))).value for _ in range(4)] + assert (await untagged_greeter.greet(StringValue(value="b"))).value == "plain: hello b" + + assert answers == ["blue: hello b"] * 4 + + +async def test_an_application_that_does_not_register_leaves_the_registry_alone( + registry_address, greeter_contract, greeter_impl_type, registry_config, zk +): + registries = {"zk": registry_config(registry_address, mode=RegistryMode.INTERFACE, register=False)} + app = Dubbo( + application=ApplicationConfig(name="greeter-app"), + registries=registries, + protocols={"tri": ProtocolConfig(name="tri", host="127.0.0.1", port=0)}, + env_prefix=None, + ) + app.export(greeter_impl_type()) + caller = Dubbo( + application=ApplicationConfig(name="caller-app"), + registries=registries, + consumer=ConsumerConfig(references={"test.registry.Greeter": ReferenceConfig(check=False)}), + env_prefix=None, + ) + caller.refer(greeter_contract) + + async with app, caller, zk(registry_address) as client: + root = "/" + URL.parse(registry_address).parameters["group"] + assert await client.children(f"{root}/test.registry.Greeter") == [] + + +async def test_startup_fails_when_a_reference_subscribes_to_none_of_its_registries( + registry_address, greeter_contract, registry_config +): + caller = Dubbo( + application=ApplicationConfig(name="caller-app"), + registries={"zk": registry_config(registry_address, subscribe=False)}, + env_prefix=None, + ) + caller.refer(greeter_contract) + + with pytest.raises(ConfigError, match="subscribes to none of its registries"): + async with caller: + pass + + +async def test_a_reference_calls_the_providers_it_names_besides_those_of_its_registries( + registry_address, exported_urls, greeter_contract, greeter_impl_type, consumer, provider +): + registered = provider(registry_address, RegistryMode.INTERFACE) + registered.export(greeter_impl_type("registered")) + named = Dubbo(protocols={"tri": ProtocolConfig(name="tri", host="127.0.0.1", port=0)}, env_prefix=None) + named.export(greeter_impl_type("named")) + + async with registered, named: + url = exported_urls[-1] + caller = consumer( + registry_address, RegistryMode.INTERFACE, urls=(str(url),), registries=("zk",), loadbalance="roundrobin" + ) + greeter = caller.refer(greeter_contract) + async with caller: + answers = [(await greeter.greet(StringValue(value="b"))).value for _ in range(2)] + + assert set(answers) == {"registered: hello b", "named: hello b"} + + +async def test_providers_leave_the_registry_when_they_stop( + registry_address, consumer_updates, greeter_contract, greeter_impl_type, consumer, provider +): + app = provider(registry_address, RegistryMode.INTERFACE) + app.export(greeter_impl_type()) + caller = consumer(registry_address, RegistryMode.INTERFACE, routers=_UPDATES, check=False) + greeter = caller.refer(greeter_contract) + + async with caller: + since = len(consumer_updates.snapshots) + async with app: + await consumer_updates.wait_for(bool, since=since) + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + since = len(consumer_updates.snapshots) + + await consumer_updates.wait_for(lambda urls: not urls, since=since) + with pytest.raises(RpcError, match="UNAVAILABLE"): + await greeter.greet(StringValue(value="b")) + + +async def test_a_stopping_provider_announces_it_then_waits_after_leaving_the_registry( + registry_address, monkeypatch, greeter_impl_type, provider +): + events = [] + announce, register, unexport = ( + TripleProtocol.announce_shutdown, + ZookeeperInterfaceRegistry.register, + ServedExporter.aclose, + ) + + def announce_shutdown(protocol): + events.append(("announce", anyio.current_time())) + announce(protocol) + + @asynccontextmanager + async def registered(registry, url): + async with register(registry, url): + yield + events.append(("unregister", anyio.current_time())) + + async def close_exporter(exporter): + events.append(("unexport", anyio.current_time())) + await unexport(exporter) + + monkeypatch.setattr(TripleProtocol, "announce_shutdown", announce_shutdown) + monkeypatch.setattr(ZookeeperInterfaceRegistry, "register", registered) + monkeypatch.setattr(ServedExporter, "aclose", close_exporter) + app = provider(registry_address, RegistryMode.INTERFACE, shutdown=ShutdownConfig(unregister_wait=0.05)) + app.export(greeter_impl_type()) + + with anyio.fail_after(5): + async with app: + pass + + assert [name for name, _ in events] == ["announce", "unregister", "unexport"] + # To the nanosecond: exactly the wait on the virtual clock, at least it against a real ZooKeeper. + assert round(events[2][1] - events[1][1], 9) >= 0.05 + + +@pytest.mark.parametrize( + ("timeout", "methods", "registered"), + [ + (0.05, {}, ("50", None)), + (5, {"Greet": MethodConfig(timeout=0.05)}, ("5000", "50")), + ], + ids=["service-timeout", "method-timeout"], +) +async def test_a_consumer_takes_the_provider_timeout_and_its_identity( + registry_address, timeout, methods, registered, greeter_contract, consumer, provider, zk +): + release = anyio.Event() + settings = ServiceConfig(group="g", version="1", timeout=timeout, methods=methods) + + class Slow(greeter_contract): + async def greet(self, request): + await release.wait() + return request + + app = provider( + registry_address, RegistryMode.INTERFACE, settings=ProviderConfig(services={"test.registry.Greeter": settings}) + ) + app.export(Slow()) + caller = consumer(registry_address, RegistryMode.INTERFACE, group="*", version="1", retries=0) + greeter = caller.refer(greeter_contract) + + async with app, caller: + root = "/" + URL.parse(registry_address).parameters["group"] + async with zk(registry_address) as client: + [node] = await client.children(f"{root}/test.registry.Greeter/providers") + with anyio.fail_after(5), pytest.raises(RpcError, match="DEADLINE_EXCEEDED"): + await greeter.greet(StringValue(value="b")) + release.set() + + parameters = _parse_full_string(unquote_plus(node)).parameters + assert (parameters["group"], parameters["version"]) == ("g", "1") + assert (parameters["timeout"], parameters.get("Greet.timeout")) == registered + + +@pytest.mark.parametrize("mode", [RegistryMode.INTERFACE, RegistryMode.INSTANCE], ids=["interface", "instance"]) +async def test_consumers_attach_the_token_a_provider_registers_and_hear_what_it_deprecates( + registry_address, mode, caplog, exported_urls, greeter_contract, greeter_impl_type, consumer, provider +): + service = ServiceConfig(token=True, methods={"Greet": MethodConfig(deprecated=True)}) + app = provider(registry_address, mode, settings=ProviderConfig(services={"test.registry.Greeter": service})) + app.export(greeter_impl_type()) + caller = consumer(registry_address, mode) + greeter = caller.refer(greeter_contract) + + with caplog.at_level(logging.WARNING, logger="dubbo.filter.deprecated"): + async with app, caller: + url = next(url for url in exported_urls if url.path == "test.registry.Greeter") + direct = Dubbo(env_prefix=None) + stranger = direct.refer(greeter_contract, url=str(url.replace(parameters={}))) + async with direct: + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + with pytest.raises(RpcError, match="PERMISSION_DENIED"): + await stranger.greet(StringValue(value="b")) + + assert [record.getMessage() for record in caplog.records] == [ + f"Calling test.registry.Greeter.Greet, which its provider at 127.0.0.1:{url.port} deprecates" + ] + + +async def test_providers_that_leave_give_their_connections_back( + registry_address, monkeypatch, greeter_contract, greeter_impl_type, consumer, provider, zk +): + closed = anyio.Event() + addresses = [] + close = AioH2Client.aclose + + async def recording(client): + await close(client) + addresses.append((client.url.host, client.url.port)) + closed.set() + + monkeypatch.setattr(AioH2Client, "aclose", recording) + app = provider(registry_address, RegistryMode.INTERFACE) + app.export(greeter_impl_type()) + caller = consumer(registry_address, RegistryMode.INTERFACE) + greeter = caller.refer(greeter_contract) + + async with app, caller: + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + root = "/" + URL.parse(registry_address).parameters["group"] + async with zk(registry_address) as client: + parent = f"{root}/test.registry.Greeter/providers" + [node] = await client.children(parent) + await client.delete(f"{parent}/{node}") + + with anyio.fail_after(5): + await closed.wait() + url = _parse_full_string(unquote_plus(node)) + assert addresses == [(url.host, url.port)] + + +async def test_a_call_running_when_its_provider_stops_still_completes( + registry_address, consumer_updates, monkeypatch, greeter_contract, consumer, provider, zk +): + started, release, ready, stop, closing = anyio.Event(), anyio.Event(), anyio.Event(), anyio.Event(), anyio.Event() + results = [] + close = ServedExporter.aclose + + async def observe(exporter): + closing.set() + await close(exporter) + + monkeypatch.setattr(ServedExporter, "aclose", observe) + + class Held(greeter_contract): + async def greet(self, request): + started.set() + await release.wait() + return StringValue(value=f"held {request.value}") + + app = provider(registry_address, RegistryMode.INTERFACE) + app.export(Held()) + caller = consumer(registry_address, RegistryMode.INTERFACE, routers=_UPDATES, check=False, timeout=5.0) + greeter = caller.refer(greeter_contract) + + async def serve(): + async with app: + ready.set() + await stop.wait() + + async def call(): + results.append(await greeter.greet(StringValue(value="hold"))) + + with anyio.fail_after(5): + async with caller, anyio.create_task_group() as tasks: + since = len(consumer_updates.snapshots) + tasks.start_soon(serve) + await ready.wait() + await consumer_updates.wait_for(bool, since=since) + tasks.start_soon(call) + await started.wait() + root = "/" + URL.parse(registry_address).parameters["group"] + async with ( + zk(registry_address) as client, + client.watch_children(f"{root}/test.registry.Greeter/providers") as nodes, + ): + assert await anext(nodes) + stop.set() + await _until(nodes, lambda children: children == []) + await closing.wait() + release.set() + + assert results == [StringValue(value="held hold")] + + +# Windows refuses the connection after its own retries, in real time. +@pytest.mark.real_clock +async def test_a_cancelled_application_still_stops_serving_and_leaves_the_registry( + registry_address, greeter_impl_type, provider, zk +): + app = provider(registry_address, RegistryMode.INTERFACE) + app.export(greeter_impl_type()) + parent = "/" + URL.parse(registry_address).parameters["group"] + "/test.registry.Greeter/providers" + + with anyio.CancelScope() as cancelled: + async with app: + async with zk(registry_address) as client: + [node] = await client.children(parent) + address = _parse_full_string(unquote_plus(node)) + cancelled.cancel() + await anyio.sleep_forever() + + with pytest.raises(OSError, match="connection attempts failed"): + async with await anyio.connect_tcp(address.host, address.port): + pass + async with zk(registry_address) as client: + assert await client.children(parent) == [] + + +async def test_a_protocol_first_used_after_start_closes_with_the_application( + registry_address, monkeypatch, consumer_updates, greeter_contract, greeter_impl_type, consumer, provider +): + opened, closed = set(), set() + init, close = TripleProtocol.__init__, TripleProtocol.aclose + + def recording_init(protocol, **kwargs): + opened.add(id(protocol)) + init(protocol, **kwargs) + + async def recording_close(protocol): + await close(protocol) + closed.add(id(protocol)) + + monkeypatch.setattr(TripleProtocol, "__init__", recording_init) + monkeypatch.setattr(TripleProtocol, "aclose", recording_close) + caller = consumer(registry_address, RegistryMode.INTERFACE, routers=_UPDATES, check=False) + greeter = caller.refer(greeter_contract) + app = provider(registry_address, RegistryMode.INTERFACE) + app.export(greeter_impl_type()) + + async with caller: + assert opened == set() + since = len(consumer_updates.snapshots) + async with app: + await consumer_updates.wait_for(bool, since=since) + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + + assert len(opened) == 2 + assert closed == opened + + +@pytest.mark.parametrize("mode", [RegistryMode.INTERFACE, RegistryMode.INSTANCE], ids=["interface", "instance"]) +async def test_the_override_rules_of_providers_change_what_they_register( + registry_address, mode, greeter_impl_type, config_center, provider, zk +): + root = "/" + URL.parse(registry_address).parameters["group"] + rule = f"{root}/config/dubbo/greeter-app.configurators" + app = provider( + registry_address, mode, config_center=config_center(registry_address), metadata_type=MetadataType.REMOTE + ) + app.export(greeter_impl_type()) + + async with app, zk(registry_address) as client, _registered_weights(client, root, mode) as weights: + assert await anext(weights) is None + await client.set( + rule, + b"scope: application\nkey: greeter-app\nconfigs:\n - {side: provider, addresses: ['127.0.0.1'], parameters: {weight: 50}}\n - {side: provider, addresses: ['10.9.9.9'], parameters: {weight: 1}}\n - {side: consumer, parameters: {weight: 2}}\n", + ) + assert await _until(weights, lambda value: value == "50") == "50" + await client.delete(rule) + assert await _until(weights, lambda value: value is None) is None + + +@pytest.mark.parametrize("mode", [RegistryMode.INTERFACE, RegistryMode.INSTANCE], ids=["interface", "instance"]) +@pytest.mark.parametrize("side", ["provider", "consumer"]) +async def test_calls_keep_succeeding_while_override_rules_swap_the_weights_of_providers( + registry_address, + mode, + side, + greeter_contract, + greeter_impl_type, + config_center, + registry_config, + consumer_updates, + zk, +): + # A rule for the providers belongs to their application, one for consumers to that of the consumer. + owner = "greeter-app" if side == "provider" else "caller-app" + rule = "/" + URL.parse(registry_address).parameters["group"] + f"/config/dubbo/{owner}.configurators" + ports = _free_ports(4) + apps = [ + Dubbo( + application=ApplicationConfig(name="greeter-app"), + registries={"zk": registry_config(registry_address, mode=mode)}, + protocols={"tri": ProtocolConfig(name="tri", host="127.0.0.1", port=port)}, + config_center=config_center(registry_address), + shutdown=ShutdownConfig(unregister_wait=0), + env_prefix=None, + ) + for port in ports + ] + for app in apps: + app.export(greeter_impl_type()) + caller = Dubbo( + application=ApplicationConfig(name="caller-app"), + registries={"zk": registry_config(registry_address, mode=mode)}, + config_center=config_center(registry_address), + consumer=ConsumerConfig(references={"test.registry.Greeter": ReferenceConfig(routers=_UPDATES, check=False)}), + env_prefix=None, + ) + greeter = caller.refer(greeter_contract) + stop = anyio.Event() + calls, errors = [0], [] + + async def call(): + while not stop.is_set(): + try: + await greeter.greet(StringValue(value="b")) + except RpcError as error: + errors.append(error) + calls[0] += 1 + + def weights(urls): + return {url.port: url.parameters.get("weight") for url in urls} + + with anyio.fail_after(30): + async with AsyncExitStack() as stack: + for app in apps: + await stack.enter_async_context(app) + await stack.enter_async_context(caller) + client = await stack.enter_async_context(zk(registry_address)) + await consumer_updates.wait_for(lambda urls: len(urls) == len(ports)) + since = len(consumer_updates.snapshots) + async with anyio.create_task_group() as tasks: + for _ in range(16): + tasks.start_soon(call) + for idle in (ports[0::2], ports[1::2]) * 4: + changed = len(consumer_updates.snapshots) + addresses = ", ".join(f"'127.0.0.1:{port}'" for port in idle) + await client.set( + rule, + f"scope: application\nkey: {owner}\nconfigs: [{{side: {side}, providerAddresses: [{addresses}], parameters: {{weight: 0}}}}]\n".encode(), + ) + expected = {port: "0" if port in idle else None for port in ports} + await consumer_updates.wait_for( + lambda urls, expected=expected: weights(urls) == expected, since=changed + ) + # Calls go on under the new weights before they swap again. + until = calls[0] + 64 + while calls[0] < until: + await anyio.sleep(0) + stop.set() + seen = consumer_updates.snapshots[since:] + + assert [len(urls) for urls in seen if len(urls) != len(ports)] == [] + assert calls[0] > 0 + assert errors == [] + + +def _free_ports(count): + sockets = [socket.socket() for _ in range(count)] + try: + for each in sockets: + each.bind(("127.0.0.1", 0)) + return [each.getsockname()[1] for each in sockets] + finally: + for each in sockets: + each.close() + + +async def test_the_override_rules_of_providers_change_the_filters_they_serve_through( + registry_address, caplog, greeter_contract, greeter_impl_type, consumer, provider, zk +): + root = "/" + URL.parse(registry_address).parameters["group"] + rule = f"{root}/config/dubbo/greeter-app.configurators" + app = provider(registry_address, RegistryMode.INTERFACE) + app.export(greeter_impl_type()) + caller = consumer(registry_address, RegistryMode.INTERFACE, retries=0) + greeter = caller.refer(greeter_contract) + + async with ( + app, + caller, + zk(registry_address) as client, + client.watch_children(f"{root}/test.registry.Greeter/providers") as nodes, + ): + + async def registered_tps(value): + return await _until( + nodes, + lambda values: ( + len(values) == 1 and _parse_full_string(unquote_plus(values[0])).parameters.get("tps") == value + ), + ) + + async def configure(parameters): + await client.set(rule, b"scope: application\nkey: greeter-app\nconfigs:\n" + parameters) + + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + await configure(b" - {side: provider, parameters: {tps: 1, tps.interval: 60000}}\n") + await registered_tps("1") + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + with pytest.raises(RpcError, match="UNAVAILABLE"): + await greeter.greet(StringValue(value="b")) + + await client.delete(rule) + await registered_tps(None) + assert [await greeter.greet(StringValue(value="b")) for _ in range(2)] == [StringValue(value="a: hello b")] * 2 + + with caplog.at_level(logging.WARNING, logger="dubbo.application"): + await configure(b" - {side: provider, parameters: {tps: many}}\n") + await registered_tps("many") + + assert any("Cannot apply the override rules" in record.getMessage() for record in caplog.records) + assert [await greeter.greet(StringValue(value="b")) for _ in range(2)] == [StringValue(value="a: hello b")] * 2 + + +async def test_local_metadata_serves_only_the_revision_the_instance_registers( + registry_address, greeter_impl_type, config_center, provider, zk +): + from dubbo.metadata.service.v2 import MetadataRequest, MetadataServiceV2 + + root = "/" + URL.parse(registry_address).parameters["group"] + app = provider( + registry_address, RegistryMode.INSTANCE, config_center=config_center(registry_address), metadata_type="local" + ) + app.export(greeter_impl_type()) + + async with app, zk(registry_address) as registry: + [instance_id] = await registry.children(f"{root}/greeter-app") + path = f"{root}/greeter-app/{instance_id}" + # The MetadataService follows the services it describes. + greeter_url, _, url = app.exported_urls + assert (greeter_url.path, url.path) == ("test.registry.Greeter", "org.apache.dubbo.metadata.MetadataServiceV2") + client = Dubbo(env_prefix=None) + service = client.refer(MetadataServiceV2, url=str(url)) + + async with client, registry.watch(path) as snapshots: + with anyio.fail_after(5): + first = json.loads(await anext(snapshots))["payload"]["metadata"]["dubbo.metadata.revision"] + assert (await service.get_metadata_info(MetadataRequest(revision=first))).version == first + + await registry.set( + f"{root}/config/dubbo/greeter-app.configurators", + b"scope: application\nkey: greeter-app\nconfigs: [{side: provider, parameters: {weight: 50}}]\n", + ) + data = await _until( + snapshots, + lambda data: ( + bool(data) and json.loads(data)["payload"]["metadata"]["dubbo.metadata.revision"] != first + ), + ) + current = json.loads(data)["payload"]["metadata"]["dubbo.metadata.revision"] + await anyio.wait_all_tasks_blocked() + + assert (await service.get_metadata_info(MetadataRequest(revision=current))).version == current + + async def read_first_until_dropped() -> None: + while True: + await service.get_metadata_info(MetadataRequest(revision=first)) + await anyio.sleep(0.01) + + # The provider drops the old revision once the registration that replaced it returns. + with pytest.raises(RpcError, match="NOT_FOUND"): + await read_first_until_dropped() + + +async def test_local_metadata_over_tri_also_serves_the_version_older_consumers_know( + registry_address, greeter_impl_type, provider, zk +): + from dubbo.metadata.service.v1 import MetadataServiceV1 + + root = "/" + URL.parse(registry_address).parameters["group"] + app = provider(registry_address, RegistryMode.INSTANCE, metadata_type="local") + app.export(greeter_impl_type()) + + async with app, zk(registry_address) as registry: + [instance_id] = await registry.children(f"{root}/greeter-app") + async with registry.watch(f"{root}/greeter-app/{instance_id}") as snapshots: + node = json.loads(await anext(snapshots))["payload"]["metadata"] + published = json.loads(node["dubbo.metadata-service.url-params"]) + + # A consumer that knows MetadataServiceV2 learns it from meta-v; one that does not calls what is published. + assert node["meta-v"] == "2.0.0" + paths = [url.path for url in app.exported_urls[1:]] + assert paths == ["org.apache.dubbo.metadata.MetadataService", "org.apache.dubbo.metadata.MetadataServiceV2"] + assert (published["protocol"], published["version"]) == ("tri", "1.0.0") + client = Dubbo(env_prefix=None) + service = client.refer(MetadataServiceV1, url=str(app.exported_urls[1])) + async with client: + info = await service.get_metadata_info(node["dubbo.metadata.revision"]) + + assert info is not None + assert [each.name for each in (info.services or {}).values()] == ["test.registry.Greeter"] + + +async def test_a_failure_to_register_what_the_rules_change_is_tried_again( + registry_address, monkeypatch, caplog, greeter_impl_type, config_center, provider, zk +): + root = "/" + URL.parse(registry_address).parameters["group"] + register = ZookeeperInterfaceRegistry.register + calls = 0 + + @asynccontextmanager + async def failing_once(registry, url): + nonlocal calls + calls += 1 + if calls == 2: + raise OSError("registry unreachable") + async with register(registry, url): + yield + + monkeypatch.setattr(ZookeeperInterfaceRegistry, "register", failing_once) + monkeypatch.setattr(dubbo.registry.provider, "backoff", lambda: itertools.repeat(0)) + app = provider(registry_address, RegistryMode.INTERFACE, config_center=config_center(registry_address)) + app.export(greeter_impl_type()) + + async with ( + app, + zk(registry_address) as client, + _registered_weights(client, root, RegistryMode.INTERFACE) as weights, + ): + assert await anext(weights) is None + await client.set( + f"{root}/config/dubbo/greeter-app.configurators", + b"scope: application\nkey: greeter-app\nconfigs: [{side: provider, parameters: {weight: 50}}]\n", + ) + assert await _until(weights, lambda value: value == "50") == "50" + + assert calls == 3 + assert "Cannot register the services as their override rules changed" in caplog.text + + +@pytest.mark.parametrize( + ("metadata_type", "metadata_service"), + [(MetadataType.LOCAL, ("2.0.0", "tri")), (MetadataType.REMOTE, (None, None))], + ids=["local", "remote"], +) +async def test_a_consumer_calls_a_provider_found_by_application( + registry_address, metadata_type, metadata_service, greeter_contract, greeter_impl_type, consumer, provider, zk +): + app = provider(registry_address, RegistryMode.INSTANCE, metadata_type=metadata_type) + app.export(greeter_impl_type()) + caller = consumer(registry_address, RegistryMode.INSTANCE) + greeter = caller.refer(greeter_contract) + + async with app, caller: + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + + root = "/" + URL.parse(registry_address).parameters["group"] + async with zk(registry_address) as client: + [instance_id] = await client.children(f"{root}/greeter-app") + node = json.loads(await client.get(f"{root}/greeter-app/{instance_id}") or b"") + mapping = await client.get(f"{root}/mapping/test.registry.Greeter") + assert await client.children(f"{root}/test.registry.Greeter") == [] + + metadata = node["payload"]["metadata"] + assert instance_id == f"127.0.0.1:{node['port']}" + assert mapping == b"greeter-app" + assert metadata["dubbo.metadata.storage-type"] == str(metadata_type) + assert json.loads(metadata["dubbo.endpoints"]) == [{"port": node["port"], "protocol": "tri"}] + service_params = json.loads(metadata.get("dubbo.metadata-service.url-params", "{}")) + assert (metadata.get("meta-v"), service_params.get("protocol")) == metadata_service + + +@dubbo.service("test.registry.Hello") +class _Hello(typing.Protocol): + async def hello(self, name: str) -> str: ... + + +class _HelloImpl(_Hello): + async def hello(self, name: str) -> str: + return f"hello {name}" + + +@pytest.fixture +def instance_app(registry_config): + def create(address: str, name: str, *, protocols=None, tls: TLSConfig | None = None) -> Dubbo: + return Dubbo( + application=ApplicationConfig(name=name, metadata_type=MetadataType.LOCAL), + registries={"zk": registry_config(address, mode=RegistryMode.INSTANCE)}, + protocols=protocols, + tls=tls, + shutdown=ShutdownConfig(unregister_wait=0), + env_prefix=None, + ) + + return create + + +@pytest.fixture +def instance_metadata(zk): + async def read(address: str, app: str) -> dict[str, str]: + root = "/" + URL.parse(address).parameters["group"] + async with zk(address) as client: + [instance_id] = await client.children(f"{root}/{app}") + return json.loads(await client.get(f"{root}/{app}/{instance_id}") or b"")["payload"]["metadata"] + + return read + + +async def test_a_provider_served_only_over_dubbo_serves_its_metadata_through_the_metadata_service_1_0_0( + registry_address, + instance_app, + instance_metadata, +): + app = instance_app( + registry_address, "hello-app", protocols={"dubbo": ProtocolConfig(name="dubbo", host="127.0.0.1", port=0)} + ) + app.export(_HelloImpl()) + caller = instance_app(registry_address, "caller-app") + hello = caller.refer(_Hello) + + async with app, caller: + assert await hello.hello("b") == "hello b" + metadata = await instance_metadata(registry_address, "hello-app") + + assert metadata["meta-v"] == "1.0.0" + assert json.loads(metadata["dubbo.metadata-service.url-params"])["protocol"] == "dubbo" + + +async def test_local_metadata_shares_a_triple_server_tuned_by_its_protocol( + registry_address, greeter_contract, greeter_impl_type, instance_app, consumer +): + tuned = TripleConfig(max_receive_message_size=8 << 20, max_concurrent_streams=50) + app = instance_app( + registry_address, + "greeter-app", + protocols={"tri": ProtocolConfig(name="tri", host="127.0.0.1", port=0, triple=tuned)}, + ) + app.export(greeter_impl_type()) + caller = consumer(registry_address, RegistryMode.INSTANCE) + greeter = caller.refer(greeter_contract) + + async with app, caller: + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + + +async def test_a_consumer_reads_local_metadata_over_tls_as_it_calls( + registry_address, greeter_contract, greeter_impl_type, instance_app +): + certificates = Path(__file__).resolve().parents[2] / "certificates" + server = TLSConfig(certfile=certificates / "localhost-cert.pem", keyfile=certificates / "localhost-key.pem") + client = TLSConfig(cafile=certificates / "localhost-cert.pem", server_hostname="localhost") + app = instance_app( + registry_address, + "greeter-app", + protocols={"tri": ProtocolConfig(name="tri", host="127.0.0.1", port=0)}, + tls=server, + ) + app.export(greeter_impl_type()) + caller = instance_app(registry_address, "caller-app", tls=client) + greeter = caller.refer(greeter_contract) + + async with app, caller: + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + + +async def test_all_registers_both_ways_and_consumers_discover_instances( + registry_address, greeter_contract, greeter_impl_type, consumer, provider, zk +): + app = provider(registry_address, RegistryMode.ALL) + app.export(greeter_impl_type()) + caller = consumer(registry_address, RegistryMode.ALL) + greeter = caller.refer(greeter_contract) + + async with app, caller: + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + + root = "/" + URL.parse(registry_address).parameters["group"] + async with zk(registry_address) as client: + assert len(await client.children(f"{root}/test.registry.Greeter/providers")) == 1 + assert len(await client.children(f"{root}/greeter-app")) == 1 + + +async def test_an_all_consumer_also_calls_providers_registered_by_interface_only( + registry_address, greeter_contract, greeter_impl_type, consumer, provider +): + app = provider(registry_address, RegistryMode.INTERFACE) + app.export(greeter_impl_type()) + caller = consumer(registry_address, RegistryMode.ALL) + greeter = caller.refer(greeter_contract) + + async with app, caller: + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + + +async def test_references_share_the_watch_and_the_metadata_of_an_application( + registry_address, + monkeypatch, + echo_contract, + echo_impl_type, + greeter_contract, + greeter_impl_type, + consumer, + provider, +): + subscribed: list[str] = [] + read: list[str] = [] + subscribe, get = ZookeeperInstanceRegistry.subscribe, MetadataStore.get + + def recording_subscribe(self: ZookeeperInstanceRegistry, app: str) -> typing.Any: + subscribed.append(app) + return subscribe(self, app) + + def recording_get(self: MetadataStore, revision: str) -> typing.Any: + read.append(revision) + return get(self, revision) + + monkeypatch.setattr(ZookeeperInstanceRegistry, "subscribe", recording_subscribe) + monkeypatch.setattr(MetadataStore, "get", recording_get) + app = provider(registry_address, RegistryMode.INSTANCE) + app.export(greeter_impl_type()) + app.export(echo_impl_type()) + caller = consumer(registry_address, RegistryMode.INSTANCE) + greeter, echo = caller.refer(greeter_contract), caller.refer(echo_contract) + + async with app, caller: + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + assert await echo.echo(StringValue(value="b")) == StringValue(value="b") + + assert subscribed == ["greeter-app"] + assert len(read) == 1 + + +async def test_an_instance_whose_metadata_cannot_be_read_leaves_the_others_callable( + registry_address, greeter_contract, greeter_impl_type, consumer, provider, zk +): + good = provider(registry_address, RegistryMode.INSTANCE, name="good-app") + good.export(greeter_impl_type("good")) + bad = provider(registry_address, RegistryMode.INSTANCE, name="bad-app") + bad.export(greeter_impl_type("bad")) + caller = consumer(registry_address, RegistryMode.INSTANCE) + greeter = caller.refer(greeter_contract) + + async with good, bad: + root = "/" + URL.parse(registry_address).parameters["group"] + async with zk(registry_address) as client: + [instance_id] = await client.children(f"{root}/bad-app") + path = f"{root}/bad-app/{instance_id}" + node = json.loads(await client.get(path) or b"") + node["payload"]["metadata"]["dubbo.metadata-service.url-params"] = "[]" + await client.set(path, json.dumps(node).encode()) + + async with caller: + answers = {(await greeter.greet(StringValue(value="b"))).value for _ in range(20)} + + assert answers == {"good: hello b"} + + +async def test_a_metadata_report_apart_from_the_registry_holds_the_metadata_and_the_mapping( + registry_address, greeter_contract, greeter_impl_type, provider, registry_config, zk +): + base, _, query = registry_address.partition("?") + parameters = dict(parse_qsl(query)) + root = "/" + parameters.pop("group") + report = MetadataReportConfig( + address=base + (f"?{urlencode(parameters)}" if parameters else ""), group=f"{root}/report" + ) + app = provider(registry_address, RegistryMode.INSTANCE, metadata_report=report, metadata_type=MetadataType.REMOTE) + app.export(greeter_impl_type()) + caller = Dubbo( + application=ApplicationConfig(name="caller-app"), + registries={"zk": registry_config(registry_address, mode=RegistryMode.INSTANCE)}, + metadata_report=report, + env_prefix=None, + ) + greeter = caller.refer(greeter_contract) + + async with app, caller: + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + + async with zk(registry_address) as client: + assert len(await client.children(f"{root}/report/metadata/greeter-app")) == 1 + assert await client.get(f"{root}/report/mapping/test.registry.Greeter") is not None + assert not {"metadata", "mapping"} & set(await client.children(root)) + + +async def test_consumers_follow_the_applications_mapped_to_an_interface( + registry_address, consumer_updates, greeter_contract, greeter_impl_type, consumer, provider +): + first = provider(registry_address, RegistryMode.INSTANCE, name="first-app") + first.export(greeter_impl_type("first")) + second = provider(registry_address, RegistryMode.INSTANCE, name="second-app") + second.export(greeter_impl_type("second")) + caller = consumer(registry_address, RegistryMode.INSTANCE, routers=_UPDATES, loadbalance="roundrobin") + greeter = caller.refer(greeter_contract) + + async with first, caller: + assert await greeter.greet(StringValue(value="b")) == StringValue(value="first: hello b") + since = len(consumer_updates.snapshots) + async with second: + await consumer_updates.wait_for(lambda urls: len(urls) == 2, since=since) + answers = [(await greeter.greet(StringValue(value="b"))).value for _ in range(2)] + assert set(answers) == {"first: hello b", "second: hello b"} + + +async def test_provided_by_skips_the_mapping( + registry_address, greeter_contract, greeter_impl_type, consumer, provider, zk +): + app = provider(registry_address, RegistryMode.INSTANCE) + app.export(greeter_impl_type()) + caller = consumer(registry_address, RegistryMode.INSTANCE, provided_by=("greeter-app",)) + greeter = caller.refer(greeter_contract) + + async with app: + root = "/" + URL.parse(registry_address).parameters["group"] + async with zk(registry_address) as client: + await client.delete(f"{root}/mapping/test.registry.Greeter") + + async with caller: + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + + +async def test_a_reference_without_providers_fails_its_calls_as_unavailable( + registry_address, greeter_contract, consumer +): + caller = consumer(registry_address, RegistryMode.ALL, check=False) + greeter = caller.refer(greeter_contract) + + async with caller: + with pytest.raises(RpcError, match="UNAVAILABLE") as raised: + await greeter.greet(StringValue(value="b")) + + assert raised.value.status is Status.UNAVAILABLE + + +async def test_startup_fails_when_a_reference_that_checks_has_no_provider( + registry_address, monkeypatch, greeter_contract, consumer +): + monkeypatch.setattr("dubbo.application._CHECK_GRACE", 0.1) + caller = consumer(registry_address, RegistryMode.INTERFACE) + caller.refer(greeter_contract) + + with pytest.raises(RpcError, match="UNAVAILABLE") as raised: + async with caller: + pass + + assert raised.value.status is Status.UNAVAILABLE + assert "test.registry.Greeter" in str(raised.value) + + +@pytest.mark.parametrize("mode", list(RegistryMode)) +async def test_startup_fails_on_a_registry_scheme_without_an_implementation( + mode, greeter_contract, greeter_impl_type, consumer, provider +): + caller = consumer("etcd://127.0.0.1:2379", mode) + caller.refer(greeter_contract) + app = provider("etcd://127.0.0.1:2379", mode) + app.export(greeter_impl_type()) + + for application in (caller, app): + with pytest.raises(ExtensionError, match="unknown extension 'etcd'"): + async with application: + pass + + +async def test_a_reference_finds_the_provider_its_own_application_registers( + registry_address, greeter_contract, greeter_impl_type, provider +): + app = provider(registry_address, RegistryMode.INTERFACE) + app.export(greeter_impl_type()) + greeter = app.refer(greeter_contract) + + async with app: + assert await greeter.greet(StringValue(value="b")) == StringValue(value="a: hello b") + + +async def test_an_all_consumer_calls_the_providers_found_by_instance_while_there_are_any( + registry_address, greeter_contract, greeter_impl_type, consumer, provider +): + by_instance = provider(registry_address, RegistryMode.INSTANCE, name="instance-app") + by_instance.export(greeter_impl_type("instance")) + by_interface = provider(registry_address, RegistryMode.INTERFACE, name="interface-app") + by_interface.export(greeter_impl_type("interface")) + caller = consumer(registry_address, RegistryMode.ALL) + greeter = caller.refer(greeter_contract) + + async with by_instance, by_interface, caller: + answers = {(await greeter.greet(StringValue(value="b"))).value for _ in range(20)} + + assert answers == {"instance: hello b"} + + +async def test_a_reference_of_several_registries_calls_the_preferred_one( + registry_address, greeter_contract, greeter_impl_type, provider, registry_config +): + root = URL.parse(registry_address).parameters["group"] + other_address = registry_address.replace(f"group={root}", f"group={root}/other") + + def serving(address: str, name: str) -> Dubbo: + app = provider(address, RegistryMode.INTERFACE, name=name) + app.export(greeter_impl_type(name)) + return app + + caller = Dubbo( + application=ApplicationConfig(name="caller-app"), + registries={ + "one": registry_config(registry_address, mode=RegistryMode.INTERFACE), + "two": registry_config(other_address, mode=RegistryMode.INTERFACE, preferred=True), + }, + env_prefix=None, + ) + greeter = caller.refer(greeter_contract) + + async with serving(registry_address, "one"), serving(other_address, "two"), caller: + # The providers of the preferred registry take the calls once they are connected. + with anyio.fail_after(5): + while (await greeter.greet(StringValue(value="b"))).value != "two: hello b": + await anyio.sleep(0.01) + answers = {(await greeter.greet(StringValue(value="b"))).value for _ in range(20)} + + assert answers == {"two: hello b"} + + +async def _until(values, predicate): + with anyio.fail_after(5): + async for value in values: + if predicate(value): + return value + pytest.fail("the watch ended before the expected change") + + +@asynccontextmanager +async def _registered_weights(client, root, mode): + if mode is RegistryMode.INTERFACE: + async with client.watch_children(f"{root}/test.registry.Greeter/providers") as snapshots: + + async def weights(): + async for nodes in snapshots: + if len(nodes) == 1: + yield _parse_full_string(unquote_plus(nodes[0])).parameters.get("weight") + + yield weights() + else: + [instance] = await client.children(f"{root}/greeter-app") + async with client.watch(f"{root}/greeter-app/{instance}") as snapshots: + + async def weights(): + async for data in snapshots: + if data: + revision = json.loads(data)["payload"]["metadata"]["dubbo.metadata.revision"] + metadata = json.loads(await client.get(f"{root}/metadata/greeter-app/{revision}")) + [service] = metadata["services"].values() + yield service["params"].get("weight") + + yield weights() + + +async def test_an_instance_publishes_the_advertised_port_of_its_protocol_over_that_of_the_application( + registry_address, registry_config, greeter_impl_type, instance_metadata +): + app = Dubbo( + application=ApplicationConfig(name="greeter-app", metadata_type=MetadataType.LOCAL, advertised_port=40000), + registries={"zk": registry_config(registry_address, mode=RegistryMode.INSTANCE)}, + protocols={"tri": ProtocolConfig(name="tri", host="127.0.0.1", port=0, advertised_port=30051)}, + shutdown=ShutdownConfig(unregister_wait=0), + env_prefix=None, + ) + app.export(greeter_impl_type()) + + async with app: + metadata = await instance_metadata(registry_address, "greeter-app") + + assert json.loads(metadata["dubbo.endpoints"]) == [{"port": 30051, "protocol": "tri"}] + assert json.loads(metadata["dubbo.metadata-service.url-params"])["port"] == "30051" diff --git a/tests/integration/registry/zookeeper/test_instance.py b/tests/integration/registry/zookeeper/test_instance.py new file mode 100644 index 00000000..36b5de83 --- /dev/null +++ b/tests/integration/registry/zookeeper/test_instance.py @@ -0,0 +1,59 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import json + +import pytest + +from dubbo.extension import ApplicationScope +from dubbo.registry import ServiceInstance +from dubbo.registry.zookeeper import ZookeeperInstanceRegistry +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = [pytest.mark.anyio, pytest.mark.zookeeper] + + +async def test_instance_registration_writes_the_curator_service_instance_format(real_registry_address, monkeypatch, zk): + monkeypatch.setattr("time.time_ns", lambda: 1700000000000000000) + instance = ServiceInstance(app="demo", host="10.0.0.5", port=50051, metadata={"dubbo.metadata.revision": "r1"}) + root = URL.parse(real_registry_address).parameters["group"] + + async with ApplicationScope() as scope: + url = URL.parse(real_registry_address).replace(attributes={APPLICATION_SCOPE: scope}) + async with ( + ZookeeperInstanceRegistry(url) as registry, + zk(real_registry_address) as client, + registry.register(instance), + ): + data = await client.get(f"/{root}/demo/10.0.0.5:50051") + + assert json.loads(data) == { + "name": "demo", + "id": "10.0.0.5:50051", + "address": "10.0.0.5", + "port": 50051, + "sslPort": None, + "payload": { + "@class": "org.apache.dubbo.registry.zookeeper.ZookeeperInstance", + "id": "10.0.0.5:50051", + "name": "demo", + "metadata": {"dubbo.metadata.revision": "r1"}, + }, + "registrationTimeUTC": 1700000000000, + "serviceType": "DYNAMIC", + "uriSpec": None, + } diff --git a/tests/integration/registry/zookeeper/test_interface.py b/tests/integration/registry/zookeeper/test_interface.py new file mode 100644 index 00000000..23e6cd38 --- /dev/null +++ b/tests/integration/registry/zookeeper/test_interface.py @@ -0,0 +1,83 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import pytest + +from dubbo.extension import ApplicationScope +from dubbo.registry.zookeeper import ZookeeperInterfaceRegistry +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = [pytest.mark.anyio, pytest.mark.zookeeper] + + +@pytest.mark.parametrize( + ("text", "node"), + [ + ( + "tri://10.0.0.5:50051/com.example.Greeter?methods=a%2Cb&interface=com.example.Greeter", + "tri%3A%2F%2F10.0.0.5%3A50051%2Fcom.example.Greeter%3Finterface%3Dcom.example.Greeter%26methods%3Da%2Cb", + ), + ( + "tri://alice:secret@10.0.0.5:50051/com.example.Greeter?side=provider", + "tri%3A%2F%2Falice%3Asecret%4010.0.0.5%3A50051%2Fcom.example.Greeter%3Fside%3Dprovider", + ), + ], + ids=["raw-comma-and-sorted-parameters", "credentials"], +) +async def test_registered_nodes_form_encode_the_full_unescaped_dubbo_url(real_registry_address, text, node, zk): + root = URL.parse(real_registry_address).parameters["group"] + async with ApplicationScope() as scope: + url = URL.parse(real_registry_address).replace(attributes={APPLICATION_SCOPE: scope}) + async with ( + ZookeeperInterfaceRegistry(url) as registry, + zk(real_registry_address) as client, + registry.register(URL.parse(text)), + ): + assert await client.children(f"/{root}/com.example.Greeter/providers") == [node] + + +async def test_subscribers_decode_a_java_style_registry_node(real_registry_address, zk): + interface = "org.apache.dubbo.demo.DemoService" + node = ( + "dubbo%3A%2F%2F192.168.1.7%3A20880%2Forg.apache.dubbo.demo.DemoService%3Fanyhost%3Dtrue" + "%26application%3Ddemo-provider%26interface%3Dorg.apache.dubbo.demo.DemoService" + "%26methods%3DsayHello%2CsayHelloAsync%26side%3Dprovider%26timestamp%3D1700000000000" + ) + root = URL.parse(real_registry_address).parameters["group"] + async with ApplicationScope() as scope: + url = URL.parse(real_registry_address).replace(attributes={APPLICATION_SCOPE: scope}) + async with ZookeeperInterfaceRegistry(url) as registry, zk(real_registry_address) as client: + await client.create(f"/{root}/{interface}/providers/{node}") + with anyio.fail_after(5): + async with registry.subscribe(interface, group=None, version=None) as urls: + assert await anext(urls) == [ + URL( + protocol="dubbo", + host="192.168.1.7", + port=20880, + path=interface, + parameters={ + "anyhost": "true", + "application": "demo-provider", + "interface": interface, + "methods": "sayHello,sayHelloAsync", + "side": "provider", + "timestamp": "1700000000000", + }, + ) + ] diff --git a/tests/integration/rpc/test_client.py b/tests/integration/rpc/test_client.py new file mode 100644 index 00000000..b30a80c2 --- /dev/null +++ b/tests/integration/rpc/test_client.py @@ -0,0 +1,354 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import abc +import enum +import typing +from collections.abc import AsyncIterator +from contextlib import AsyncExitStack, asynccontextmanager +from typing import Any + +import anyio +import attrs +import hessian2 +import pytest + +import dubbo +from dubbo import RemoteError, RpcError, Status +from dubbo.protocol import Protocol +from dubbo.protocol.dubbo import DubboProtocol +from dubbo.protocol.triple import TripleProtocol +from dubbo.rpc.client import GenericService, proxy +from dubbo.rpc.definition import Service +from dubbo.rpc.invocation import Invocation +from dubbo.rpc.server import ServiceInvoker +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + +_INTERFACE = "com.example.UserService" + + +@hessian2.java_class("com.example.Color") +class Color(enum.Enum): + RED = "r" + + +@hessian2.java_class("com.example.Address") +@attrs.define(kw_only=True) +class Address: + city: str + + +@hessian2.java_class("com.example.User") +@attrs.define(kw_only=True) +class User: + name: str + user_id: hessian2.Long + address: Address | None + color: Color | None + tags: tuple[str, ...] + + +@hessian2.java_class("java.lang.IllegalStateException") +@attrs.define(kw_only=True) +class IllegalState(Exception): + detail_message: str = "" + + +@dubbo.service(_INTERFACE) +class UserService(abc.ABC): + @dubbo.method("find") + @abc.abstractmethod + async def find(self, name: str, user_id: hessian2.Long) -> User | None: ... + + @dubbo.method("save") + @abc.abstractmethod + async def save(self, user: User) -> str: ... + + @dubbo.method("fail") + @abc.abstractmethod + async def fail(self, how: str) -> str: ... + + +class UserServiceImpl(UserService): + async def find(self, name: str, user_id: int) -> User | None: + if name == "nobody": + return None + + return User(name=name, user_id=user_id, address=Address(city="Hangzhou"), color=Color.RED, tags=("a",)) + + async def save(self, user: User) -> str: + return f"{user.name} {user.user_id} {user.address} {user.color} {user.tags}" + + async def fail(self, how: str) -> str: + if how == "rpc": + raise RpcError(Status.NOT_FOUND, "no such user") + + raise IllegalState(detail_message="not now") + + +def _user(name: str) -> dict[str, Any]: + return { + "class": "com.example.User", + "name": name, + "userId": 7, + "address": {"class": "com.example.Address", "city": "Hangzhou"}, + "color": "RED", + "tags": ["a"], + } + + +@asynccontextmanager +async def _serve(name: str) -> AsyncIterator[tuple[Protocol, URL, AsyncExitStack]]: + protocol: Protocol = DubboProtocol() if name == "dubbo" else TripleProtocol() + + with anyio.fail_after(3): + async with protocol, AsyncExitStack() as resources: + url = URL.parse(f"{name}://127.0.0.1:0/{_INTERFACE}?serialization=hessian2") + invoker = ServiceInvoker.from_implementation(UserServiceImpl(), url) + exporter = await protocol.export(url, dubbo.get_definition(UserService), invoker) + yield protocol, exporter.url, resources + + +@pytest.fixture(params=["dubbo", "tri"]) +async def provider(request: pytest.FixtureRequest): + async with _serve(request.param) as served: + yield served + + +async def _generic(provider, generic: str = "true") -> GenericService: + protocol, url, resources = provider + invoker = await protocol.refer(url, Service(interface=_INTERFACE, methods=())) + resources.push_async_callback(invoker.aclose) + + return GenericService(_INTERFACE, invoker.invoke, generic=generic) + + +async def test_generic_calls_realize_class_maps_and_generalize_returned_objects(provider): + users = await _generic(provider) + + saved = await users.call("save", _user("bob")) + found = await users.call("find", "bob", 7, types=["java.lang.String", "long"]) + missing = await users.call("find", "nobody", 7) + + assert (saved, found, missing) == ("bob 7 Address(city='Hangzhou') Color.RED ('a',)", _user("bob"), None) + + +async def test_generic_calls_preserve_the_java_exception_class_and_message(provider): + users = await _generic(provider) + + with pytest.raises(RemoteError, match="not now") as thrown: + await users.call("fail", "declared") + + assert (thrown.value.class_name, thrown.value.message) == ("java.lang.IllegalStateException", "not now") + + +@pytest.mark.parametrize( + ("provider", "status"), + [("dubbo", Status.UNKNOWN), ("tri", Status.NOT_FOUND)], + ids=["dubbo", "tri"], + indirect=["provider"], +) +async def test_generic_calls_report_the_provider_failure_in_the_protocols_error_form(provider, status): + users = await _generic(provider) + + with pytest.raises(RpcError, match="no such user") as raised: + await users.call("fail", "rpc") + + assert (raised.value.status, raised.value.message) == (status, "no such user") + + +@pytest.mark.parametrize( + ("provider", "generic", "method", "arguments", "message", "status"), + [ + ("dubbo", "gson", "find", ('"bob"', "7"), "the mode 'gson' are not served", Status.UNIMPLEMENTED), + ("dubbo", "true", "missing", (), "has no unary method 'missing'", Status.UNIMPLEMENTED), + ("dubbo", "true", "save", ("bob", 7), "the arguments of save", Status.UNKNOWN), + ("dubbo", "true", "save", ("bob",), "the arguments of save", Status.UNKNOWN), + ("tri", "gson", "find", ('"bob"', "7"), "the mode 'gson' are not served", Status.UNIMPLEMENTED), + ("tri", "true", "missing", (), "has no unary method 'missing'", Status.UNIMPLEMENTED), + ("tri", "true", "save", ("bob", 7), "the arguments of save", Status.INVALID_ARGUMENT), + ("tri", "true", "save", ("bob",), "the arguments of save", Status.INVALID_ARGUMENT), + ], + ids=[ + f"{protocol}-{case}" + for protocol in ("dubbo", "tri") + for case in ("unsupported-mode", "unknown-method", "wrong-arity", "wrong-type") + ], + indirect=["provider"], +) +async def test_generic_calls_fail_when_the_provider_cannot_serve_them( + provider, generic, method, arguments, message, status +): + users = await _generic(provider, generic) + + with pytest.raises(RpcError, match=message) as raised: + await users.call(method, *arguments) + + assert raised.value.status is status + + +async def test_triple_preserves_a_declared_java_exception_separately_from_a_status(): + async with _serve("tri") as (protocol, url, resources): + invoker = await protocol.refer(url, dubbo.get_definition(UserService)) + resources.push_async_callback(invoker.aclose) + users = proxy(UserService, invoker.invoke) + + with pytest.raises(RemoteError, match="not now") as thrown: + await users.fail("declared") + with pytest.raises(RpcError, match="no such user") as status: + await users.fail("rpc") + + assert (thrown.value.class_name, thrown.value.message) == ("java.lang.IllegalStateException", "not now") + assert not isinstance(status.value, RemoteError) + assert status.value.status is Status.NOT_FOUND + + +async def test_echo_returns_the_argument_without_calling_a_service_method(provider): + protocol, url, resources = provider + echo = dubbo.Method(name="$echo", request=(dubbo.Parameter(name="value", type=Any),), response=Any) + invoker = await protocol.refer(url, Service(interface=_INTERFACE, methods=(echo,))) + resources.push_async_callback(invoker.aclose) + call = Invocation(interface=_INTERFACE, method="$echo", definition=echo, arguments=({"k": [1]},)) + + result = await invoker.invoke(call) + + assert (result.value, result.error) == ({"k": [1]}, None) + + +@dubbo.service("test.RpcStreams") +class Streams(typing.Protocol): + def watch(self, query: str) -> dubbo.ServerStream[int]: ... + def upload(self) -> dubbo.ClientStream[bytes, int]: ... + def chat(self) -> dubbo.BidiStream[str, str]: ... + + +@dubbo.service("test.RpcStreams") +class StreamService: + def __init__(self) -> None: + self.started = anyio.Event() + self.cancelled = anyio.Event() + + async def watch(self, query: str, events: dubbo.SendStream[int]) -> None: + self.started.set() + try: + await events.send(0) + await anyio.sleep_forever() + finally: + self.cancelled.set() + + async def upload(self, chunks: dubbo.ReceiveStream[bytes]) -> int: + total = sum([len(chunk) async for chunk in chunks]) + if not total: + raise RpcError(Status.INVALID_ARGUMENT, "nothing uploaded") + + return total + + async def chat(self, stream: dubbo.Stream[str, str]) -> None: + async for question in stream: + if question == "fail": + raise RpcError(Status.ABORTED, "asked to fail") + + await stream.send(question.upper()) + + +@pytest.fixture +async def stream_provider(): + implementation = StreamService() + + with anyio.fail_after(3): + async with TripleProtocol() as protocol, AsyncExitStack() as resources: + url = URL.parse("tri://127.0.0.1:0/test.RpcStreams?serialization=hessian2") + exporter = await protocol.export( + url, dubbo.get_definition(Streams), ServiceInvoker.from_implementation(implementation, url) + ) + yield protocol, exporter.url, resources, implementation + + +@pytest.fixture +async def streams(stream_provider): + protocol, url, resources, _ = stream_provider + invoker = await protocol.refer(url, dubbo.get_definition(Streams)) + resources.push_async_callback(invoker.aclose) + + return proxy(Streams, invoker.invoke) + + +async def test_client_stream_receive_raises_the_handler_error(streams): + async with streams.upload() as stream: + await stream.end() + + with pytest.raises(RpcError, match="INVALID_ARGUMENT: nothing uploaded"): + await stream.receive() + + +async def test_bidi_stream_receive_raises_the_handler_error(streams): + async with streams.chat() as stream: + await stream.send("fail") + + with pytest.raises(RpcError, match="ABORTED: asked to fail"): + await stream.receive() + + +async def test_bidi_stream_receive_ends_when_the_handler_returns(streams): + async with streams.chat() as stream: + await stream.end() + + with pytest.raises(dubbo.EndOfStream): + await stream.receive() + + +async def test_bidi_stream_send_repeats_the_handler_error_already_received(streams): + async with streams.chat() as stream: + await stream.send("fail") + with pytest.raises(RpcError, match="ABORTED: asked to fail"): + await stream.receive() + + with pytest.raises(RpcError, match="ABORTED: asked to fail"): + await stream.send("more") + + +async def test_a_stream_deadline_cancels_the_provider_handler(streams, stream_provider): + implementation = stream_provider[3] + + async def watch() -> None: + with anyio.fail_after(None) as deadline: + async with streams.watch("wait") as events: + assert await events.receive() == 0 + deadline.deadline = anyio.current_time() + await events.receive() + + with pytest.raises(TimeoutError): + await watch() + with anyio.fail_after(5): + await implementation.cancelled.wait() + + assert implementation.started.is_set() + + +async def test_generic_calls_cannot_invoke_a_streaming_method(stream_provider): + protocol, url, resources, implementation = stream_provider + invoker = await protocol.refer(url, Service(interface="test.RpcStreams", methods=())) + resources.push_async_callback(invoker.aclose) + generic = GenericService("test.RpcStreams", invoker.invoke) + + with pytest.raises(RpcError, match="has no unary method 'watch'") as raised: + await generic.call("watch", "wait") + + assert raised.value.status is Status.UNIMPLEMENTED + assert not implementation.started.is_set() diff --git a/tests/integration/test_application.py b/tests/integration/test_application.py new file mode 100644 index 00000000..198a68ce --- /dev/null +++ b/tests/integration/test_application.py @@ -0,0 +1,751 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import errno +import socket +import typing +from contextlib import asynccontextmanager + +import anyio +import pytest +from google.protobuf.wrappers_pb2 import StringValue + +import dubbo +import dubbo.application as application_module +from dubbo import Dubbo, DubboError, RpcError, Status +from dubbo.cluster import Router +from dubbo.config import ConsumerConfig, ProtocolConfig, ProviderConfig, ReferenceConfig, ShutdownConfig, TripleConfig +from dubbo.extension import extensions +from dubbo.filter import Filter +from dubbo.protocol.served import ServedExporter +from dubbo.rpc.invocation import Result + +pytestmark = pytest.mark.anyio + +APP = {"application": {"name": "orders"}} + + +@dubbo.service("com.example.UserService") +class UserService(typing.Protocol): + @dubbo.method("getUser") + async def get_user(self, id: StringValue) -> StringValue: ... + + +class UserServiceImpl(UserService): + async def get_user(self, id: StringValue) -> StringValue: + return StringValue(value="user " + id.value) + + +class Holding(UserService): + """Answers with its prefix, holding the calls for the id ``hold`` until ``release`` is set.""" + + def __init__(self, prefix: str, entered: anyio.Event, release: anyio.Event) -> None: + self._prefix = prefix + self._entered = entered + self._release = release + + async def get_user(self, id: StringValue) -> StringValue: + if id.value == "hold": + self._entered.set() + await self._release.wait() + return StringValue(value=f"{self._prefix} {id.value}") + + +class Prefixed(UserService): + def __init__(self, prefix: str) -> None: + self._prefix = prefix + + async def get_user(self, id: StringValue) -> StringValue: + return StringValue(value=f"{self._prefix} {id.value}") + + +@dubbo.service("com.example.OrderService") +class OrderService(typing.Protocol): + async def place(self, user: StringValue) -> StringValue: ... + + +def _protocols(**triple): + return {"tri": ProtocolConfig(name="tri", host="127.0.0.1", port=0, triple=TripleConfig(**triple))} + + +@asynccontextmanager +async def _provider(exported_urls, implementation=None, **options): + app = Dubbo(APP, protocols=_protocols(), env_prefix=None, **options) + app.export(UserServiceImpl() if implementation is None else implementation) + async with app: + yield exported_urls[-1] + + +def _client(urls, **settings): + reference = ReferenceConfig(urls=tuple(str(url) for url in urls), **settings) + return Dubbo(APP, consumer=ConsumerConfig(references={"com.example.UserService": reference}), env_prefix=None) + + +async def test_a_reference_calls_the_service_of_its_group_in_another_application(exported_urls): + async with _provider(exported_urls, provider=ProviderConfig(group="blue")) as url: + client = _client([url.replace(parameters={})], group="blue") + users = client.refer(UserService) + + async with client: + assert await users.get_user(StringValue(value="2")) == StringValue(value="user 2") + + +async def test_a_reference_of_another_group_finds_no_such_service(exported_urls): + async with _provider(exported_urls, provider=ProviderConfig(group="blue")) as url: + client = _client([url.replace(parameters={})], group="red") + users = client.refer(UserService) + + async with client: + with pytest.raises(RpcError, match="UNIMPLEMENTED"): + await users.get_user(StringValue(value="2")) + + +@pytest.fixture +def default_port_zero(monkeypatch): + # The default Triple port is fixed; tests running at the same time each need their own. + monkeypatch.setattr("dubbo.protocol.triple.protocol.DEFAULT_TRIPLE_PORT", 0) + + +async def test_exported_services_use_triple_when_no_protocol_is_configured(exported_urls, default_port_zero): + app = Dubbo(APP, env_prefix=None) + app.export(UserServiceImpl()) + + async with app: + assert app.config.protocols == {"tri": ProtocolConfig(name="tri")} + (url,) = exported_urls + async with await anyio.connect_tcp("127.0.0.1", url.port): + pass + + +# Windows refuses the connection after its own retries, in real time. +@pytest.mark.real_clock +async def test_the_default_server_closes_when_the_application_stops(exported_urls, default_port_zero): + app = Dubbo(APP, env_prefix=None) + app.export(UserServiceImpl()) + + async with app: + (url,) = exported_urls + + with pytest.raises(OSError, match="connection attempts failed"): + await anyio.connect_tcp("127.0.0.1", url.port) + + +async def test_the_exported_urls_tell_the_bound_ports_while_the_application_runs(default_port_zero): + app = Dubbo(APP, env_prefix=None) + app.export(UserServiceImpl()) + with pytest.raises(RuntimeError, match="while the application runs"): + _ = app.exported_urls + + async with app: + (url,) = app.exported_urls + assert (url.path, url.port != 0) == ("com.example.UserService", True) + async with await anyio.connect_tcp("127.0.0.1", url.port): + pass + + with pytest.raises(RuntimeError, match="while the application runs"): + _ = app.exported_urls + + +async def test_a_port_in_use_fails_the_start_with_an_os_error(): + with socket.socket() as busy: + busy.bind(("127.0.0.1", 0)) + busy.listen() + port = busy.getsockname()[1] + app = Dubbo(APP, protocols={"tri": ProtocolConfig(name="tri", host="127.0.0.1", port=port)}, env_prefix=None) + app.export(UserServiceImpl()) + + with pytest.raises(OSError, match=str(port)) as raised: + async with app: + pass + + assert raised.value.errno == errno.EADDRINUSE + + +async def test_an_application_without_services_exports_nothing(exported_urls, default_port_zero): + async with Dubbo(APP, env_prefix=None): + assert exported_urls == [] + + +async def _filtered_calls(exported_urls, attempt_filters): + """Return where the filters ``recording`` ran on a call retried once, with ``attempt_filters`` on each attempt, and the provider URL.""" + calls = [] + attempts = 0 + + class Recording: + def __init__(self, url): + # A reference filter sees the reference, an attempt filter the provider it calls. + self.side = f"tri:{url.port}" if url.protocol == "tri" else url.protocol + + async def invoke(self, call_next, invocation): + calls.append((self.side, invocation.method)) + return await call_next(invocation) + + class BusyOnce: + def __init__(self, url): + pass + + async def invoke(self, call_next, invocation): + nonlocal attempts + attempts += 1 + calls.append(("service", invocation.method)) + if attempts == 1: + return Result(error=RpcError(Status.UNAVAILABLE, "busy")) + return await call_next(invocation) + + extensions.register(Filter, "recording", Recording) + extensions.register(Filter, "busy-once", BusyOnce) + + async with _provider(exported_urls, provider=ProviderConfig(filters=("busy-once",))) as url: + client = _client([url], retries=1, filters=("recording",), attempt_filters=attempt_filters) + users = client.refer(UserService) + + async with client: + assert await users.get_user(StringValue(value="1")) == StringValue(value="user 1") + + return calls, url + + +async def test_a_service_filter_that_raises_is_logged_and_its_caller_receives_internal( + exported_urls, isolated_extensions, caplog +): + class Broken: + def __init__(self, url): + pass + + async def invoke(self, call_next, invocation): + raise RuntimeError("a bug in the filter") + + extensions.register(Filter, "broken", Broken) + + async with _provider(exported_urls, provider=ProviderConfig(filters=("broken",))) as url: + client = _client([url], retries=0) + users = client.refer(UserService) + async with client: + with pytest.raises(RpcError) as caught: + await users.get_user(StringValue(value="1")) + + assert caught.value.status is Status.INTERNAL + [record] = [record for record in caplog.records if "raised instead of returning a result" in record.getMessage()] + assert (record.levelname, str(record.exc_info[1])) == ("ERROR", "a bug in the filter") + + +async def test_a_reference_filter_runs_once_around_a_call_and_a_service_filter_on_each_attempt( + exported_urls, isolated_extensions +): + calls, _ = await _filtered_calls(exported_urls, ()) + + assert calls == [("consumer", "getUser"), ("service", "getUser"), ("service", "getUser")] + + +async def test_an_attempt_filter_runs_on_each_attempt_with_the_provider_it_calls(exported_urls, isolated_extensions): + calls, url = await _filtered_calls(exported_urls, ("recording",)) + + attempt, service = (f"tri:{url.port}", "getUser"), ("service", "getUser") + assert calls == [("consumer", "getUser"), attempt, service, attempt, service] + + +async def test_a_reference_calls_only_the_providers_its_router_keeps(exported_urls, isolated_extensions): + notified = [] + selected = [] + + class KeepLast: + def __init__(self, url): + self.url = url + + async def __aenter__(self): + return self + + async def __aexit__(self, *_): + pass + + async def aclose(self): + pass + + def notify(self, invokers): + notified.append(tuple(invoker.url.port for invoker in invokers)) + + def route(self, invokers, invocation): + selected.append(self.url.scope) + return invokers[-1:] + + extensions.register(Router, "keep-last", KeepLast) + + async with ( + _provider(exported_urls, Prefixed("dropped")) as first, + _provider(exported_urls, Prefixed("kept")) as second, + ): + client = _client([first, second], routers=("keep-last",)) + users = client.refer(UserService) + + async with client: + assert await users.get_user(StringValue(value="1")) == StringValue(value="kept 1") + + assert notified == [(first.port, second.port)] + assert len(selected) == 1 + + +async def test_round_robin_configuration_alternates_between_providers(exported_urls): + async with ( + _provider(exported_urls, Prefixed("first")) as first, + _provider(exported_urls, Prefixed("second")) as second, + ): + client = _client([first, second], loadbalance="roundrobin") + users = client.refer(UserService) + + async with client: + answers = [(await users.get_user(StringValue(value="1"))).value for _ in range(4)] + + assert answers == ["first 1", "second 1"] * 2 + + +@pytest.mark.parametrize("delay", [0, 0.05], ids=["at-once", "after-a-lifespan"]) +async def test_a_reference_that_checks_fails_the_start_when_its_provider_refuses_whatever_the_timing( + monkeypatch, delay +): + monkeypatch.setattr(application_module, "_CHECK_GRACE", 0.5) + + @asynccontextmanager + async def lifespan(app): + await anyio.sleep(delay) + yield + + # Nothing listens on port 1, so every attempt to connect is refused. + client = Dubbo( + APP, + consumer=ConsumerConfig(references={"com.example.UserService": ReferenceConfig(urls=("tri://127.0.0.1:1",))}), + lifespan=lifespan, + env_prefix=None, + ) + client.refer(UserService) + + with pytest.raises(RpcError, match=r"no provider of com\.example\.UserService is available"): + async with client: + pass + + +async def test_a_provider_whose_host_answers_no_connection_does_not_hold_up_calls(exported_urls): + async with _provider(exported_urls, Prefixed("live")) as live: + # A documentation address, which no network routes, stands for a provider whose host is gone. Its + # connect timeout outlasts the calls, so that only an attempt the calls do not cancel can end. + gone = live.replace(host="192.0.2.1", parameters={**live.parameters, "triple.connect-timeout": "400"}) + client = _client([gone, live], timeout=0.2) + users = client.refer(UserService) + + async with client: + # Both connect in the background from the start; the attempt to the gone one has failed by now. + await anyio.sleep(0.6) + with anyio.fail_after(5): + answers = [(await users.get_user(StringValue(value="1"))).value for _ in range(10)] + + assert answers == ["live 1"] * 10 + + +async def test_a_reference_of_a_tag_calls_only_the_providers_of_that_tag(exported_urls): + async with ( + _provider(exported_urls, Prefixed("plain")) as plain, + _provider(exported_urls, Prefixed("blue"), provider=ProviderConfig(tag="blue")) as blue, + ): + client = _client([plain, blue], loadbalance="roundrobin", tag="blue") + users = client.refer(UserService) + + async with client: + answers = [(await users.get_user(StringValue(value="1"))).value for _ in range(4)] + + assert answers == ["blue 1"] * 4 + + +async def test_least_active_configuration_avoids_a_provider_with_an_inflight_call(exported_urls): + entered, release = anyio.Event(), anyio.Event() + async with ( + _provider(exported_urls, Holding("first", entered, release)) as first, + _provider(exported_urls, Holding("second", entered, release)) as second, + ): + client = _client([first, second], loadbalance="leastactive") + users = client.refer(UserService) + held = [] + + async def hold(): + held.append((await users.get_user(StringValue(value="hold"))).value) + + with anyio.fail_after(5): + async with client, anyio.create_task_group() as tasks: + tasks.start_soon(hold) + await entered.wait() + answers = [(await users.get_user(StringValue(value="1"))).value for _ in range(2)] + release.set() + + prefix = "second" if held == ["first hold"] else "first" + assert held in (["first hold"], ["second hold"]) + assert answers == [f"{prefix} 1"] * 2 + + +# Windows refuses the connection after its own retries, in real time. +@pytest.mark.real_clock +async def test_export_failure_releases_the_servers_already_opened(exported_urls, isolated_extensions): + from dubbo.transport.h2 import H2Server + from dubbo.transport.h2.aio import AioH2Server + + class RefuseSecond(AioH2Server): + async def __aenter__(self): + if exported_urls: + raise DubboError("cannot bind the second server") from OSError("address unavailable") + return await super().__aenter__() + + extensions.register(H2Server, "refuse-second", RefuseSecond) + protocols = { + "first": ProtocolConfig(name="tri", host="127.0.0.1", port=0), + "second": ProtocolConfig( + name="tri", host="127.0.0.2", port=0, triple=TripleConfig(parameters={"server": "refuse-second"}) + ), + } + app = Dubbo(APP, protocols=protocols, env_prefix=None) + app.export(UserServiceImpl()) + + with pytest.raises(DubboError, match="cannot bind the second server") as caught: + await app.__aenter__() + + assert isinstance(caught.value.__cause__, OSError) + (url,) = exported_urls + with pytest.raises(OSError, match="connection attempts failed"): + await anyio.connect_tcp(url.host, url.port) + + +@dubbo.service("com.example.Echo") +class Echo(typing.Protocol): + async def echo(self, text: str) -> str: ... + + +class EchoImpl(Echo): + async def echo(self, text: str) -> str: + return text + + +@pytest.fixture +def event_loop_told_in_tasks_only(monkeypatch): + """Let AnyIO tell the event loop only inside a task, as it does where sniffio is installed.""" + + def current_async_library() -> str | None: + return "asyncio" if asyncio.current_task() is not None else None + + monkeypatch.setattr("anyio._core._eventloop.current_async_library", current_async_library) + + +@pytest.mark.parametrize("protocol", ["tri", "dubbo"]) +async def test_servers_answer_where_anyio_tells_the_event_loop_only_inside_tasks( + protocol, event_loop_told_in_tasks_only +): + server = Dubbo( + APP, + protocols={protocol: ProtocolConfig(host="127.0.0.1", port=0)}, + provider=ProviderConfig(serialization="hessian2"), + env_prefix=None, + ) + server.export(EchoImpl()) + + async with server: + (url,) = (url for url in server.exported_urls if url.path == "com.example.Echo") + client = Dubbo(APP, env_prefix=None) + echo = client.refer(Echo, url=str(url)) + async with client: + assert await echo.echo("hi") == "hi" + + +async def test_protocol_settings_limit_requests_on_the_server(exported_urls): + app = Dubbo(APP, protocols=_protocols(max_receive_message_size=8), env_prefix=None) + app.export(UserServiceImpl()) + + async with app: + client = _client([exported_urls[-1]]) + users = client.refer(UserService) + async with client: + assert await users.get_user(StringValue(value="1")) == StringValue(value="user 1") + with pytest.raises(RpcError, match="RESOURCE_EXHAUSTED"): + await users.get_user(StringValue(value="x" * 32)) + + +def _limited_client(url, query_limit, consumer_limit, reference_limit): + parameters = {"triple.max-receive-message-size": str(query_limit)} if query_limit else {} + reference = ReferenceConfig( + urls=(str(url.replace(parameters=parameters)),), + triple=TripleConfig(max_receive_message_size=reference_limit), + ) + return Dubbo( + APP, + consumer=ConsumerConfig( + triple=TripleConfig(max_receive_message_size=consumer_limit), + references={"com.example.UserService": reference}, + ), + env_prefix=None, + ) + + +@pytest.mark.parametrize(("query_limit", "consumer_limit"), [(8, None), (None, 8)], ids=["query", "consumer"]) +async def test_a_receive_limit_of_the_url_or_the_consumer_refuses_a_larger_response( + exported_urls, query_limit, consumer_limit +): + async with _provider(exported_urls) as url: + client = _limited_client(url, query_limit, consumer_limit, None) + users = client.refer(UserService) + + async with client: + with pytest.raises(RpcError, match="RESOURCE_EXHAUSTED"): + await users.get_user(StringValue(value="x" * 32)) + + +@pytest.mark.parametrize(("query_limit", "consumer_limit"), [(8, None), (None, 8)], ids=["over-query", "over-consumer"]) +async def test_the_receive_limit_of_a_reference_overrides_those_of_the_url_and_the_consumer( + exported_urls, query_limit, consumer_limit +): + async with _provider(exported_urls) as url: + client = _limited_client(url, query_limit, consumer_limit, 1024) + users = client.refer(UserService) + + async with client: + assert await users.get_user(StringValue(value="x" * 32)) == StringValue(value="user " + "x" * 32) + + +async def test_configured_timeouts_end_a_unary_call(exported_urls): + release = anyio.Event() + + class Slow(UserService): + async def get_user(self, id): + await release.wait() + return id + + async with _provider(exported_urls, Slow()) as url: + client = _client([url], timeout=0.05) + users = client.refer(UserService) + async with client: + with anyio.fail_after(5), pytest.raises(RpcError, match="DEADLINE_EXCEEDED"): + await users.get_user(StringValue(value="1")) + release.set() + + +async def test_stopping_services_can_finish_calls_using_their_application_references(exported_urls, monkeypatch): + entered, release, closing = anyio.Event(), anyio.Event(), anyio.Event() + close = ServedExporter.aclose + + async def observe(exporter): + closing.set() + await close(exporter) + + monkeypatch.setattr(ServedExporter, "aclose", observe) + async with _provider(exported_urls) as users_url: + + class Orders(OrderService): + async def place(self, user): + entered.set() + await release.wait() + found = await users.get_user(user) + return StringValue(value="order for " + found.value) + + orders_app = Dubbo( + APP, + protocols=_protocols(), + consumer=ConsumerConfig(references={"com.example.UserService": ReferenceConfig(urls=(str(users_url),))}), + env_prefix=None, + ) + users = orders_app.refer(UserService) + orders_app.export(Orders()) + ready, stop, answered = anyio.Event(), anyio.Event(), anyio.Event() + answers = [] + + async def serve(): + async with orders_app: + ready.set() + await stop.wait() + + async def place(orders): + answers.append(await orders.place(StringValue(value="3"))) + answered.set() + + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + tasks.start_soon(serve) + await ready.wait() + orders_url = exported_urls[-1] + client = Dubbo(APP, env_prefix=None) + orders = client.refer(OrderService, url=str(orders_url)) + async with client: + tasks.start_soon(place, orders) + await entered.wait() + stop.set() + await closing.wait() + release.set() + await answered.wait() + + assert answers == [StringValue(value="order for user 3")] + + +async def test_cancelling_an_application_cancels_its_running_calls(exported_urls): + entered = anyio.Event() + + class Orders(OrderService): + async def place(self, user): + entered.set() + await anyio.sleep_forever() + + app = Dubbo(APP, protocols=_protocols(), env_prefix=None) + app.export(Orders()) + ready, stop, cancelled = anyio.Event(), anyio.Event(), anyio.Event() + + async def serve(): + with anyio.CancelScope() as owner: + async with app: + ready.set() + await stop.wait() + owner.cancel() + await anyio.sleep_forever() + + async def place(orders): + with pytest.raises(RpcError, match="CANCELLED: the HTTP/2 stream"): + await orders.place(StringValue(value="3")) + cancelled.set() + + with anyio.fail_after(2): + async with anyio.create_task_group() as tasks: + tasks.start_soon(serve) + await ready.wait() + client = Dubbo(APP, env_prefix=None) + orders = client.refer(OrderService, url=str(exported_urls[-1])) + async with client: + tasks.start_soon(place, orders) + await entered.wait() + stop.set() + await cancelled.wait() + + +async def test_the_lifespan_holds_what_the_services_use_from_before_they_serve_until_they_drain(exported_urls): + state, entered, release = {"resource": "none", "served": None}, anyio.Event(), anyio.Event() + + @asynccontextmanager + async def lifespan(app): + state["served"] = list(exported_urls) + state["resource"] = "open" + yield + state["resource"] = "closed" + + class Users(UserService): + async def get_user(self, id): + entered.set() + await release.wait() + return StringValue(value=state["resource"]) + + app = Dubbo(APP, protocols=_protocols(), lifespan=lifespan, env_prefix=None) + app.export(Users()) + ready, stop = anyio.Event(), anyio.Event() + answers = [] + + async def serve(): + async with app: + ready.set() + await stop.wait() + + async def call(users): + answers.append((await users.get_user(StringValue(value="1"))).value) + + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + tasks.start_soon(serve) + await ready.wait() + client = Dubbo(APP, env_prefix=None) + users = client.refer(UserService, url=str(exported_urls[-1])) + async with client, anyio.create_task_group() as calls: + calls.start_soon(call, users) + await entered.wait() + stop.set() + await anyio.wait_all_tasks_blocked() + release.set() + + assert state["served"] == [] + assert answers == ["open"] + assert state["resource"] == "closed" + + +async def test_cancelling_the_task_of_an_application_with_asyncio_stops_it_at_once(exported_urls): + entered = anyio.Event() + + class Orders(OrderService): + async def place(self, user): + entered.set() + await anyio.sleep_forever() + + app = Dubbo(APP, protocols=_protocols(), shutdown=ShutdownConfig(grace=30), env_prefix=None) + app.export(Orders()) + ready = anyio.Event() + + async def serve(): + async with app: + ready.set() + await anyio.sleep_forever() + + async def place(orders): + with pytest.raises(RpcError, match="CANCELLED"): + await orders.place(StringValue(value="3")) + + with anyio.fail_after(2): + serving = asyncio.create_task(serve()) + await ready.wait() + client = Dubbo(APP, env_prefix=None) + orders = client.refer(OrderService, url=str(exported_urls[-1])) + async with client, anyio.create_task_group() as tasks: + tasks.start_soon(place, orders) + await entered.wait() + serving.cancel() + with pytest.raises(asyncio.CancelledError): + await serving + + +def _generic_client(): + reference = ReferenceConfig(methods={"anyMethod": dubbo.config.MethodConfig(timeout=1)}) + return Dubbo(APP, consumer=ConsumerConfig(references={"com.example.UserService": reference}), env_prefix=None) + + +async def test_a_generic_reference_sends_invoke_calls_to_its_provider(exported_urls): + async with _provider(exported_urls) as url: + client = _generic_client() + generic = client.refer_generic("com.example.UserService", url=str(url)) + + async with client: + with pytest.raises(RpcError, match="UNIMPLEMENTED") as caught: + await generic.call("getUser", {"value": "x"}) + + assert "/com.example.UserService/$invoke" in caught.value.message + + +async def test_a_generic_reference_beside_a_reference_with_the_contract_leaves_its_calls_as_they_are(exported_urls): + async with _provider(exported_urls) as url: + client = _generic_client() + users = client.refer(UserService, url=str(url)) + generic = client.refer_generic("com.example.UserService", url=str(url)) + + async with client: + assert await users.get_user(StringValue(value="x")) == StringValue(value="user x") + with pytest.raises(RpcError, match="UNIMPLEMENTED") as caught: + await generic.call("getUser", {"value": "x"}) + + assert "/com.example.UserService/$invoke" in caught.value.message + + +async def test_an_unconfigured_application_calls_the_url_given_in_code(exported_urls): + async with _provider(exported_urls) as url: + client = Dubbo(env_prefix=None) + users = client.refer(UserService, url=str(url)) + + async with client: + assert await users.get_user(StringValue(value="x")) == StringValue(value="user x") diff --git a/tests/integration/test_application_imports.py b/tests/integration/test_application_imports.py new file mode 100644 index 00000000..05e87f08 --- /dev/null +++ b/tests/integration/test_application_imports.py @@ -0,0 +1,37 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import subprocess +import sys + +import pytest + + +@pytest.mark.parametrize( + "modules", + [ + "dubbo.extension, dubbo.config, dubbo", + "dubbo.config_center, dubbo", + "dubbo.transport.zookeeper, dubbo", + "dubbo.config, dubbo", + "dubbo", + ], +) +def test_packages_import_in_any_order(modules): + result = subprocess.run([sys.executable, "-c", f"import {modules}"], capture_output=True, text=True, timeout=10) + + assert result.returncode == 0, result.stderr diff --git a/tests/integration/test_application_signals.py b/tests/integration/test_application_signals.py new file mode 100644 index 00000000..576dc834 --- /dev/null +++ b/tests/integration/test_application_signals.py @@ -0,0 +1,92 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import os +import signal +import sys +import threading +from collections.abc import AsyncIterator +from contextlib import asynccontextmanager + +import anyio +import pytest + +from dubbo import Dubbo + +pytestmark = pytest.mark.anyio +APP = {"application": {"name": "orders"}} + + +@pytest.mark.skipif(sys.platform == "win32", reason="signals are not received on Windows") +async def test_serve_forever_returns_on_sigterm(): + async def terminate() -> None: + await anyio.wait_all_tasks_blocked() + os.kill(os.getpid(), signal.SIGTERM) + + async with Dubbo(APP, env_prefix=None) as app: + with anyio.fail_after(5): + async with anyio.create_task_group() as task_group: + task_group.start_soon(terminate) + await app.serve_forever() + + +@pytest.mark.skipif(sys.platform == "win32", reason="signals are not received on Windows") +async def test_a_second_signal_while_stopping_stops_at_once(): + async def terminate() -> None: + await anyio.wait_all_tasks_blocked() + os.kill(os.getpid(), signal.SIGTERM) + + @asynccontextmanager + async def stalls(app: Dubbo) -> AsyncIterator[None]: + yield + os.kill(os.getpid(), signal.SIGINT) + await anyio.sleep_forever() + + with anyio.fail_after(5): + async with ( + Dubbo({**APP, "shutdown": {"grace": 60}}, lifespan=stalls, env_prefix=None) as app, + anyio.create_task_group() as task_group, + ): + task_group.start_soon(terminate) + await app.serve_forever() + + assert signal.getsignal(signal.SIGINT) is signal.default_int_handler + + +@pytest.mark.parametrize("loop", ["asyncio", "uvloop"]) +def test_serve_forever_outside_the_main_thread_serves_until_cancelled(loop): + if loop == "uvloop": + pytest.importorskip("uvloop") + outcome = [] + + async def serve() -> None: + async with Dubbo(APP, env_prefix=None) as app: + with anyio.move_on_after(0.1) as scope: + await app.serve_forever() + outcome.append(scope.cancelled_caught) + + def run() -> None: + try: + anyio.run(serve, backend_options={"use_uvloop": loop == "uvloop"}) + except BaseException as error: + outcome.append(error) + + thread = threading.Thread(target=run) + thread.start() + thread.join(5) + + assert outcome == [True] diff --git a/tests/integration/test_samples.py b/tests/integration/test_samples.py new file mode 100644 index 00000000..15800ab6 --- /dev/null +++ b/tests/integration/test_samples.py @@ -0,0 +1,552 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""The samples run as their READMEs say and print what they show.""" + +import json +import os +import re +import shutil +import signal +import socket +import subprocess +import sys +import time +import urllib.error +import urllib.request +from collections.abc import Iterator +from contextlib import contextmanager +from pathlib import Path + +import pytest + +# Samples show the API, whatever the platform; CI runs them on Linux. +pytestmark = pytest.mark.samples + +SAMPLES = Path(__file__).parents[2] / "samples" + +_TIMEOUT = 20 + + +@contextmanager +def _serving( + directory: Path, + port: int, + *args: str, + env: dict[str, str] | None = None, + executable: str = sys.executable, + stopped_code: int = 0, +) -> Iterator[tuple[subprocess.Popen[str], list[str]]]: + """Run a server of a sample once its port accepts, and stop it as Ctrl+C does. + + Yields the process, and the lines of its output that remain unread once it + has stopped, with ``stopped_code``. + """ + process = subprocess.Popen( + [executable, *args], + cwd=directory, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + text=True, + env={**os.environ, "PYTHONUNBUFFERED": "1", **(env or {})}, + ) + output: list[str] = [] + try: + _wait_for_port(process, port) + yield process, output + finally: + if sys.platform == "win32": + process.terminate() + else: + process.send_signal(signal.SIGINT) + out, _ = process.communicate(timeout=_TIMEOUT) + output.extend(out.splitlines()) + + assert process.returncode == stopped_code or sys.platform == "win32", out + + +def _wait_for_port(process: subprocess.Popen[str], port: int) -> None: + deadline = time.monotonic() + _TIMEOUT + while time.monotonic() < deadline: + if process.poll() is not None: + raise AssertionError(process.communicate()[0]) + try: + socket.create_connection(("127.0.0.1", port), timeout=0.2).close() + except OSError: + time.sleep(0.1) + else: + return + raise AssertionError(f"nothing listens on port {port}") + + +def _run(directory: Path, *args: str, env: dict[str, str] | None = None) -> str: + result = subprocess.run( + [sys.executable, *args], + cwd=directory, + capture_output=True, + text=True, + timeout=_TIMEOUT, + env={**os.environ, **(env or {})}, + check=False, + ) + assert result.returncode == 0, result.stderr + return result.stdout + + +@pytest.mark.parametrize( + ("sample", "port", "server", "client", "printed"), + [ + pytest.param( + "basics/01_hello_world", + 20880, + "server.py", + "client.py", + "Hello, Alice!\nHello, Bob!\n", + id="hello-world", + ), + pytest.param("basics/02_protobuf", 50051, "server.py", "client.py", "Hello, Dubbo!\n", id="protobuf"), + pytest.param( + "basics/03_streaming", + 50051, + "server.py", + "client.py", + "Server streaming:\n" + " Hello #1, Alice!\n" + " Hello #2, Alice!\n" + " Hello #3, Alice!\n" + "Client streaming:\n" + " Hello, Alice, Bob, Carol!\n" + "Bidirectional streaming:\n" + " Nice to meet you, Alice\n" + " Nice to meet you, Bob\n", + id="streaming", + ), + pytest.param( + "basics/08_errors_and_timeouts", + 50051, + "server.py", + "client.py", + "User 1: Alice\n" + "User 2: Bob\n" + "No user 42\n" + "Failed: INVALID_ARGUMENT: a user ID is not negative: -1\n" + "Exported 2 users\n" + "Gave up exporting after 1 second\n", + id="errors-and-timeouts", + ), + pytest.param( + "basics/14_filters", + 20880, + "server.py", + "client.py", + "With the key: Hello, Alice!\nWithout: PERMISSION_DENIED: a valid API key is required\n", + id="filters", + ), + pytest.param( + "basics/17_generic", + 20880, + "server.py", + "client.py", + "{'id': 1, 'name': 'Alice', 'email': 'alice@example.com'}\n['Alice']\nUNKNOWN: no user has ID 42\n", + id="generic", + ), + pytest.param( + "interop/grpc", 50051, "dubbo_server.py", "grpc_client.py", "Hello, gRPC, from Dubbo!\n", id="grpc-to-dubbo" + ), + pytest.param( + "interop/grpc", 50052, "grpc_server.py", "dubbo_client.py", "Hello, Dubbo, from gRPC!\n", id="dubbo-to-grpc" + ), + ], +) +def test_the_client_of_a_sample_prints_the_replies_of_its_server(sample, port, server, client, printed): + directory = SAMPLES / sample + + with _serving(directory, port, server): + output = _run(directory, client) + + assert output == printed + + +def test_the_context_sample_passes_attachments_along_its_chain_of_services(): + directory = SAMPLES / "basics/09_context" + + with ( + _serving(directory, 20881, "inventory_server.py") as (_, inventory_output), + _serving(directory, 20880, "order_server.py") as (_, order_output), + ): + output = _run(directory, "client.py") + + assert output == "Ordered 2 x book\nServed by order-server\n" + assert order_output[-1].startswith("[trace 4bf92f35] Order from alice at 127.0.0.1:") + assert inventory_output[-1] == "[trace 4bf92f35] Reserving 2 x book for alice" + + +def test_the_load_balancing_sample_spreads_and_fails_over_as_each_setting_says(): + directory = SAMPLES / "basics/11_load_balancing" + + with _serving(directory, 20882, "server.py"): + output = _run(directory, "client.py").splitlines() + + leastactive = dict(item.split(" ") for item in output[1].removeprefix("leastactive: ").split(", ")) + assert [output[0], output[2], output[3]] == [ + "roundrobin: fast 3, slow 3", + "failover: fast 6", + "failfast: UNAVAILABLE 3, fast 3", + ] + assert int(leastactive["fast"]) > int(leastactive["slow"]) + + +@pytest.mark.parametrize( + "registry", + [pytest.param("zookeeper", marks=pytest.mark.zookeeper), pytest.param("nacos", marks=pytest.mark.nacos)], +) +def test_the_registry_sample_finds_its_server_through_the_registry(registry, request): + directory = SAMPLES / "basics/04_registry" + env = {"DUBBO__REGISTRIES__DEFAULT__ADDRESS": f"{registry}://{request.getfixturevalue(registry)}"} + + with _serving(directory, 20880, "server.py", env=env): + output = _run(directory, "client.py", env=env) + + assert re.fullmatch(r"(Hello, \w+! \(from server \d+\)\n){4}", output), output + + +@pytest.mark.zookeeper +def test_the_configuration_sample_calls_with_the_settings_of_its_files(zookeeper): + directory = SAMPLES / "basics/05_configuration" + env = {"DUBBO__REGISTRIES__ZOOKEEPER__ADDRESS": f"zookeeper://{zookeeper}"} + + with _serving(directory, 20880, "server.py", env=env) as (_, server_output): + output = _run(directory, "client.py", env=env) + + assert output == "Hello, Alice!\nHello... Bob!\n" + assert [line.split(" OK ")[0] for line in server_output if "dubbo.accesslog" in line] == [ + "INFO dubbo.accesslog: org.apache.dubbo.samples.Greeter greet", + "INFO dubbo.accesslog: org.apache.dubbo.samples.Greeter greet_slowly", + ] + + +@pytest.mark.parametrize("args", [(), ("--structlog",)], ids=["json", "structlog"]) +def test_the_logging_sample_logs_each_call_as_a_json_line_with_its_trace_id(args): + if args: + pytest.importorskip("structlog") + directory = SAMPLES / "basics/06_logging" + + with _serving(directory, 20880, "server.py", *args) as (_, server_output): + output = _run(directory, "client.py") + + assert output == "Hello, Alice!\nHello, Bob!\n" + calls = [line for line in map(json.loads, server_output) if line["logger"] == "dubbo.accesslog"] + assert [(line["method"], line["status"], line["trace_id"]) for line in calls] == [ + ("greet", "OK", "4bf92f35"), + ("greet", "OK", "a3ce929d"), + ] + + +@pytest.mark.zookeeper +def test_the_group_version_sample_calls_the_version_its_client_names(zookeeper): + directory = SAMPLES / "basics/10_group_version" + env = {"DUBBO__REGISTRIES__DEFAULT__ADDRESS": f"zookeeper://{zookeeper}"} + + with _serving(directory, 20880, "server_v1.py", env=env), _serving(directory, 20881, "server_v2.py", env=env): + outputs = [_run(directory, "client.py", env=env), _run(directory, "client.py", "2.0.0", env=env)] + + assert outputs == ["Version 1.0.0: Hello, Alice!\n", "Version 2.0.0: Good to see you, Alice!\n"] + + +@pytest.mark.zookeeper +def test_the_config_center_sample_lets_a_rule_lengthen_the_timeout_of_running_calls(zookeeper): + if zookeeper != "127.0.0.1:2181": + pytest.skip("the sample uses the ZooKeeper at 127.0.0.1:2181") + directory = SAMPLES / "basics/12_config_center" + _run(directory, "publish.py", "config") + + try: + with _serving(directory, 20880, "server.py"): + client = subprocess.Popen( + [sys.executable, "client.py"], + cwd=directory, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + text=True, + env={**os.environ, "PYTHONUNBUFFERED": "1"}, + ) + assert client.stdout.readline().startswith("DEADLINE_EXCEEDED: ") + _run(directory, "publish.py", "rule") + output, _ = client.communicate(timeout=_TIMEOUT) + finally: + _run(directory, "publish.py", "clear") + + assert output.splitlines()[-3:] == ["Hello, Alice!"] * 3 + + +@pytest.mark.zookeeper +def test_the_routing_sample_routes_by_tags_and_conditions_as_rules_change(zookeeper): + if zookeeper != "127.0.0.1:2181": + pytest.skip("the sample uses the ZooKeeper at 127.0.0.1:2181") + directory = SAMPLES / "basics/13_routing" + + try: + with _serving(directory, 20882, "server.py"): + outputs = [_run(directory, "client.py")] + for rule in ("condition", "tag"): + _run(directory, "publish.py", rule) + outputs.append(_run(directory, "client.py")) + finally: + _run(directory, "publish.py", "clear") + + assert [output.splitlines() for output in outputs] == [ + [ + "Bob: stable-1, stable-2", + "Alice: stable-1, stable-2", + "Bob, tagged gray: gray", + "Bob, tagged canary: stable-1, stable-2", + ], + [ + "Bob: stable-1, stable-2", + "Alice: stable-1", + "Bob, tagged gray: gray", + "Bob, tagged canary: stable-1, stable-2", + ], + ["Bob: stable-1", "Alice: stable-1", "Bob, tagged gray: gray", "Bob, tagged canary: stable-2"], + ] + + +@pytest.mark.skipif(sys.platform == "win32", reason="Ctrl+C cannot be sent to one process on Windows") +def test_the_graceful_shutdown_sample_finishes_the_call_it_is_stopped_in(): + directory = SAMPLES / "basics/07_graceful_shutdown" + + with _serving(directory, 20880, "server.py") as (server, server_output): + client = subprocess.Popen( + [sys.executable, "client.py"], cwd=directory, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True + ) + # The call takes 5 seconds; the server is stopped once it has started. + for line in server.stdout: + if line == "Greeting Watson...\n": + break + client_output, _ = client.communicate(timeout=_TIMEOUT) + + assert client_output.splitlines()[-1] == "Hello, Dr. Watson!" + assert server_output == [ + "Stopping; running calls finish first", + "Greeted Watson", + "Database closed", + "Stopped", + ] + + +def test_the_extensions_sample_reads_its_configuration_with_the_installed_plugin(): + pytest.importorskip("dubbo_toml", reason="pip install -e samples/basics/15_extensions/dubbo-toml") + directory = SAMPLES / "basics/15_extensions" + + with _serving(directory, 20880, "server.py") as (_, server_output): + output = _run(directory, "client.py") + + assert output == "Hello, Alice!\nHello, Bob!\n" + assert server_output[-1] == "extensions-server serving on port 20880; press Ctrl+C to stop" + + +def test_the_tls_sample_serves_only_clients_with_a_certificate(): + pytest.importorskip("trustme") + directory = SAMPLES / "basics/16_tls" + _run(directory, "make_certificates.py") + + with _serving(directory, 50051, "server.py"): + output = _run(directory, "client.py") + + assert output == ( + "With a client certificate: Hello, Alice, over TLS!\nWithout: UNAVAILABLE: the HTTP/2 connection is closed\n" + ) + + +@pytest.mark.zookeeper +def test_the_fastapi_sample_answers_each_order_with_the_status_of_its_calls(zookeeper): + pytest.importorskip("fastapi") + pytest.importorskip("uvicorn") + directory = SAMPLES / "integrations/fastapi" + env = {"DUBBO__REGISTRIES__ZOOKEEPER__ADDRESS": f"zookeeper://{zookeeper}"} + + def order(user_id: int, item: str, quantity: int) -> tuple[int, dict[str, object]]: + body = json.dumps({"user_id": user_id, "item": item, "quantity": quantity}).encode() + request = urllib.request.Request( + "http://127.0.0.1:8000/orders", data=body, headers={"content-type": "application/json"} + ) + try: + with urllib.request.urlopen(request, timeout=_TIMEOUT) as response: + return response.status, json.load(response) + except urllib.error.HTTPError as error: + return error.code, json.load(error) + + with ( + _serving(directory, 50051, "backend.py", env=env) as (_, backend_output), + _serving(directory, 50052, "orders.py", env=env), + _serving(directory, 8000, "-m", "uvicorn", "app:app", env=env), + ): + answers = [order(1, "book", 2), order(9, "book", 1), order(1, "lamp", 5), order(2, "piano", 1)] + + assert answers == [ + (200, {"id": 1, "user": "Alice", "item": "book", "quantity": 2, "total": 25.0}), + (404, {"detail": "no user has ID 9"}), + (409, {"detail": "only 2 lamp left"}), + (504, {"detail": "get_item did not complete within 1.0 seconds"}), + ] + # The trace id of each order reaches the services that the orders service calls. + traced = [line.split()[0] for line in backend_output if line.startswith("[")] + assert len(traced) == 8 + assert len(set(traced)) == 4 + + +@pytest.mark.parametrize( + ("answer", "printed", "calls"), + [ + ("y", "Drafted PO-0001", ["draft", "low_stock", "predict", "quotes"]), + ("n", "Nothing drafted", ["low_stock", "predict", "quotes"]), + ], + ids=["agreed", "declined"], +) +def test_the_pydantic_ai_sample_plans_with_the_services_as_tools_and_drafts_only_once_agreed(answer, printed, calls): + pytest.importorskip("pydantic_ai") + directory = SAMPLES / "integrations/pydantic_ai" + # The test model of Pydantic AI calls each tool once, with arguments it makes up, and needs no API key. + env = {**os.environ, "MODEL": "test", "PYDANTIC_AI_NO_BANNER": "1"} + + with _serving(directory, 20880, "services.py") as (_, served): + planned = subprocess.run( + [sys.executable, "planner.py"], + cwd=directory, + input=f"{answer}\n", + capture_output=True, + text=True, + timeout=_TIMEOUT, + env=env, + check=False, + ) + + assert planned.returncode == 0, planned.stderr + assert printed in planned.stdout + assert sorted(line.split("(")[0] for line in served if "(" in line) == calls + + +def _traced(output: list[str]) -> list[str]: + """The lines of ``output`` that a server of an interoperability sample prints for each call, with its trace id.""" + return [line for line in output if re.match(r"\[[\w-]+\] \w+\(", line)] + + +_MAVEN = shutil.which("mvn") + + +@pytest.mark.nacos +@pytest.mark.skipif(_MAVEN is None, reason="needs Maven and a JDK") +def test_the_java_sample_calls_java_from_python_and_python_from_java_through_nacos(nacos): + if nacos != "127.0.0.1:8848": + pytest.skip("the sample uses the Nacos at 127.0.0.1:8848") + assert _MAVEN is not None + directory = SAMPLES / "interop/java" + maven = ["-q", "-f", "java/pom.xml"] + subprocess.run([_MAVEN, *maven, "compile"], cwd=directory, check=True, timeout=600) + + with _serving( + directory, + 50052, + *maven, + "exec:java", + "-Dexec.mainClass=org.apache.dubbo.samples.JavaServer", + executable=_MAVEN, + stopped_code=130, + ) as (_, java_server): + from_python = _run(directory, "python_client.py") + with _serving(directory, 50051, "python_server.py") as (_, python_server): + java = subprocess.run( + [_MAVEN, *maven, "exec:java", "-Dexec.mainClass=org.apache.dubbo.samples.JavaClient"], + cwd=directory, + capture_output=True, + text=True, + timeout=60, + check=True, + ) + # Newer JDKs warn on the output about the libraries of the client. + from_java = [line for line in java.stdout.splitlines() if not line.startswith("WARNING: ")] + + assert from_python.splitlines() == [ + "Hello, Alice, from Java!", + "Hello #1, Bob, from Java!", + "Hello #2, Bob, from Java!", + "Hello #3, Bob, from Java!", + "User(id=1, name='Alice', email='alice@example.com')", + "java.lang.IllegalArgumentException: no user has ID 42", + ] + assert from_java == [ + "Hello, Alice, from Python!", + "Hello #1, Bob, from Python!", + "Hello #2, Bob, from Python!", + "Hello #3, Bob, from Python!", + "User(id=1, name=Alice, email=alice@example.com)", + "java.lang.IllegalArgumentException: no user has ID 42", + ] + # Each server prints the trace id that the client of the other language attached. + assert _traced(java_server) == [ + "[py-4bf9] sayHello(Alice)", + "[py-4bf9] getUser(1)", + "[py-4bf9] getUser(42)", + ] + assert _traced(python_server) == [ + "[java-7f3a] say_hello(Alice)", + "[java-7f3a] get_user(1)", + "[None] get_user(42)", + ] + + +_GO = shutil.which("go") + + +@pytest.mark.nacos +@pytest.mark.skipif(_GO is None, reason="needs Go") +def test_the_go_sample_calls_go_from_python_and_python_from_go_through_nacos(nacos, tmp_path): + if nacos != "127.0.0.1:8848": + pytest.skip("the sample uses the Nacos at 127.0.0.1:8848") + assert _GO is not None + directory = SAMPLES / "interop/go" + # Built rather than run with go run, which leaves the server running when it is stopped alone. + server = tmp_path / "server" + subprocess.run([_GO, "-C", "go", "build", "-o", str(server), "./server"], cwd=directory, check=True, timeout=600) + + with _serving(directory, 50052, executable=str(server)) as (_, go_server): + from_python = _run(directory, "python_client.py") + with _serving(directory, 50051, "python_server.py") as (_, python_server): + from_go = subprocess.run( + [_GO, "-C", "go", "run", "./client"], + cwd=directory, + capture_output=True, + text=True, + timeout=120, + check=True, + ).stdout + + assert from_python.splitlines() == [ + "Hello, Alice, from Go!", + "Hello #1, Bob, from Go!", + "Hello #2, Bob, from Go!", + "Hello #3, Bob, from Go!", + "INVALID_ARGUMENT: a name is required", + ] + assert from_go.splitlines() == [ + "Hello, Alice, from Python!", + "Hello #1, Bob, from Python!", + "Hello #2, Bob, from Python!", + "Hello #3, Bob, from Python!", + ] + # Each server prints the trace id that the client of the other language attached. + assert _traced(go_server) == ["[py-4bf9] SayHello(Alice)", "[py-4bf9] SayHello()"] + assert _traced(python_server) == ["[go-1c9d] say_hello(Alice)"] diff --git a/tests/integration/transport/h2/aio/conftest.py b/tests/integration/transport/h2/aio/conftest.py new file mode 100644 index 00000000..c51c7802 --- /dev/null +++ b/tests/integration/transport/h2/aio/conftest.py @@ -0,0 +1,57 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from pathlib import Path + +import pytest + +_CERTIFICATES = Path(__file__).resolve().parents[4] / "certificates" + + +_SERVER_TLS = { + "ssl_enabled": "true", + "tls_cert_file": str(_CERTIFICATES / "localhost-cert.pem"), + "tls_key_file": str(_CERTIFICATES / "localhost-key.pem"), +} + + +_CLIENT_TLS = {"ssl_enabled": "true", "ca_cert_file": str(_CERTIFICATES / "localhost-cert.pem")} + + +@pytest.fixture +def server_tls(): + return _SERVER_TLS + + +@pytest.fixture +def client_tls(): + return _CLIENT_TLS + + +@pytest.fixture +def certificates(): + return _CERTIFICATES + + +@pytest.fixture +def path_headers(request_headers): + """Return a function that gives the request headers with another ``:path``.""" + + def path_headers(path: bytes) -> tuple[tuple[bytes, bytes], ...]: + return tuple((name, path if name == b":path" else value) for name, value in request_headers) + + return path_headers diff --git a/tests/integration/transport/h2/aio/test_bdp.py b/tests/integration/transport/h2/aio/test_bdp.py new file mode 100644 index 00000000..c74dda31 --- /dev/null +++ b/tests/integration/transport/h2/aio/test_bdp.py @@ -0,0 +1,91 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import ngh2 +import pytest +from anyio.streams.buffered import BufferedByteReceiveStream + +from dubbo.transport.h2.aio import AioH2Client +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +async def _download(parameters): + consumed, grown = anyio.Event(), anyio.Event() + windows, pings = [], [] + body = b"x" * 800_000 + + async def peer(stream): + engine = ngh2.Connection(ngh2.Role.SERVER) + engine.initiate_connection() + async with stream: + await stream.send(engine.data_to_send()) + reader = BufferedByteReceiveStream(stream) + engine.receive_data(await reader.receive_exactly(24)) + while True: + header = await reader.receive_exactly(9) + payload = await reader.receive_exactly(int.from_bytes(header[:3], "big")) + engine.receive_data(header + payload) + for event in engine.events(): + if isinstance(event, ngh2.RequestReceived): + engine.send_response(event.stream_id, ((b":status", b"200"),)) + engine.send_data(event.stream_id, body, end_stream=True) + elif isinstance(event, ngh2.SettingsReceived): + window = event.settings.get(ngh2.Setting.INITIAL_WINDOW_SIZE) + if window is not None: + windows.append(window) + if window == 1605632: + grown.set() + if header[3] == 6 and header[4] == 0: + pings.append(payload) + await consumed.wait() + if outgoing := engine.data_to_send(): + await stream.send(outgoing) + + async with await anyio.create_tcp_listener(local_host="127.0.0.1") as listener, anyio.create_task_group() as tasks: + tasks.start_soon(listener.serve, peer) + port = listener.extra(anyio.abc.SocketAttribute.local_port) + async with AioH2Client(URL(protocol="tri", host="127.0.0.1", port=port, parameters=parameters)) as client: + request = ((b":method", b"GET"), (b":scheme", b"http"), (b":authority", b"bdp"), (b":path", b"/")) + async with await client.open_stream(request, end_stream=True) as stream: + await stream.receive_headers() + assert await stream.receive_data_exactly(len(body)) == body + consumed.set() + if not parameters: + await grown.wait() + async with await client.open_stream(request, end_stream=True) as stream: + await stream.receive_headers() + assert await stream.receive_data_exactly(len(body)) == body + tasks.cancel_scope.cancel() + + return windows, pings + + +async def test_an_unset_stream_window_grows_by_settings_when_a_probe_asks(): + windows, pings = await _download({}) + + assert windows == [1048576, 1605632] + assert b"\xff" * 8 in pings + + +async def test_a_set_stream_window_is_fixed(): + windows, pings = await _download({"initial-window-size": "65535"}) + + assert windows == [65535] + assert pings == [] diff --git a/tests/integration/transport/h2/aio/test_client.py b/tests/integration/transport/h2/aio/test_client.py new file mode 100644 index 00000000..3719e9b6 --- /dev/null +++ b/tests/integration/transport/h2/aio/test_client.py @@ -0,0 +1,161 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import gc + +import anyio +import pytest + +import dubbo.utils.async_ as async_module +from dubbo.transport.h2 import ( + H2ConnectionError, +) +from dubbo.transport.h2.aio import AioH2Client, AioH2Server + +pytestmark = pytest.mark.anyio + + +async def test_connect_timeout_bounds_a_stalled_handshake_and_waiting_callers_share_its_failure( + request_headers, client_tls, h2_url +) -> None: + accepted: list[anyio.abc.SocketStream] = [] + + async def withhold_handshake(stream: anyio.abc.SocketStream) -> None: + accepted.append(stream) + async with stream: + await anyio.sleep_forever() + + listener = await anyio.create_tcp_listener(local_host="127.0.0.1") + port = listener.extra(anyio.abc.SocketAttribute.local_port) + client = AioH2Client(h2_url("127.0.0.1", port, connect_timeout="100", **client_tls)) + + async def open_stream() -> None: + with pytest.raises(H2ConnectionError, match="failed to connect"): + await client.open_stream(request_headers, end_stream=True) + + async with listener, anyio.create_task_group() as server: + server.start_soon(listener.serve, withhold_handshake) + with anyio.fail_after(5): + async with anyio.create_task_group() as callers: + callers.start_soon(open_stream) + callers.start_soon(open_stream) + + assert len(accepted) == 1 + assert not client.available + await client.aclose() + server.cancel_scope.cancel() + + +async def test_client_closed_while_connecting_releases_its_socket(h2_url) -> None: + listener = await anyio.create_tcp_listener(local_host="127.0.0.1") + port = listener.extra(anyio.abc.SocketAttribute.local_port) + + async with listener: + # The attempt is cancelled at each step it can reach before the close. + for steps in range(20): + client = await AioH2Client(h2_url("127.0.0.1", port)).__aenter__() + for _ in range(steps % 5): + await anyio.sleep(0) + await client.aclose() + + # A socket left open warns as it is collected, which fails the test. + gc.collect() + + +async def test_cancelling_a_client_close_aborts_its_connections_at_once(request_headers, h2_url) -> None: + async def handler(stream) -> None: + await stream.receive_headers() + await anyio.sleep_forever() + + async with AioH2Server(h2_url("127.0.0.1", 0, shutwait="0"), handler) as server: + host, port = server.address + client = AioH2Client(h2_url(host, port)) + stream = await client.open_stream(request_headers) + connection = client._active_connection + assert connection is not None + + started = anyio.current_time() + with anyio.move_on_after(0.02): + await client.aclose() + + # The open stream would hold a graceful close for its grace period of a second. + assert anyio.current_time() - started == pytest.approx(0.02) + assert connection.closed + with pytest.raises(H2ConnectionError): + await stream.receive_headers() + + +async def test_client_close_waits_for_its_connections_together( + monkeypatch: pytest.MonkeyPatch, request_headers, response_headers, h2_url +) -> None: + monkeypatch.setattr(async_module, "_CLOSE_GRACE", 0.2) + + async def handler(stream) -> None: + await stream.receive_headers() + # The client reads the GOAWAY before these headers, so its next stream opens another connection. + server.announce_shutdown() + await stream.send_headers(response_headers) + await anyio.sleep_forever() + + async with AioH2Server(h2_url("127.0.0.1", 0, shutwait="0"), handler) as server: + host, port = server.address + client = AioH2Client(h2_url(host, port)) + streams = [] + for _ in range(3): + streams.append(await client.open_stream(request_headers)) + await streams[-1].receive_headers() + # Two draining after a GOAWAY, and the active one. + assert len(client._draining_connections) == 2 + + started = anyio.current_time() + await client.aclose() + + # One after another, the three open streams would hold the close for three grace periods. + assert anyio.current_time() - started == pytest.approx(0.2) + + +async def test_client_replaces_a_connection_draining_after_goaway(response_headers, h2_url, path_headers) -> None: + release_old_stream = anyio.Event() + peers: dict[bytes, str | None] = {} + + async def handler(stream) -> None: + headers = await stream.receive_headers() + path = dict(headers)[b":path"] + peers[path] = stream.peer + if path == b"/old": + server.announce_shutdown() + # The client reads the GOAWAY before these headers, which follow it on the connection. + await stream.send_headers(response_headers) + await release_old_stream.wait() + await stream.end() + return + + await stream.send_headers(response_headers, end_stream=True) + + async with AioH2Server(h2_url("127.0.0.1", 0), handler) as server: + host, port = server.address + async with AioH2Client(h2_url(host, port)) as client: + old_stream = await client.open_stream(path_headers(b"/old"), end_stream=True) + assert await old_stream.receive_headers() == response_headers + + new_stream = await client.open_stream(path_headers(b"/new"), end_stream=True) + assert await new_stream.receive_headers() == response_headers + assert new_stream.stream_id == 1 + + release_old_stream.set() + assert await old_stream.receive_data() == b"" + assert peers[b"/old"] != peers[b"/new"] diff --git a/tests/integration/transport/h2/aio/test_connection.py b/tests/integration/transport/h2/aio/test_connection.py new file mode 100644 index 00000000..d150560a --- /dev/null +++ b/tests/integration/transport/h2/aio/test_connection.py @@ -0,0 +1,423 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import socket +import ssl +from collections.abc import AsyncIterator, Awaitable, Callable +from contextlib import asynccontextmanager + +import anyio +import ngh2 +import pytest +from anyio.streams.buffered import BufferedByteReceiveStream + +from dubbo.transport.h2 import ( + H2ConnectionError, +) +from dubbo.transport.h2.aio import AioH2Client, AioH2Server +from dubbo.url import SSL_CONTEXT, URL + +pytestmark = pytest.mark.anyio + + +async def test_tls_round_trip_negotiates_h2_for_a_domain_name( + request_headers, response_headers, server_tls, client_tls, h2_url +) -> None: + async def handler(stream) -> None: + assert await stream.receive_headers() == request_headers + await stream.send_headers(response_headers, end_stream=True) + + async with AioH2Server(h2_url("127.0.0.1", 0, **server_tls), handler) as server: + _, port = server.address + async with AioH2Client(h2_url("localhost", port, **client_tls)) as client: + stream = await client.open_stream(request_headers, end_stream=True) + assert await stream.receive_headers() == response_headers + + +async def test_a_given_server_context_without_h2_alpn_fails_the_connection_unchanged( + request_headers, client_tls, certificates, h2_url +) -> None: + async def handler(stream) -> None: + await stream.reset() + + context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) + context.load_cert_chain(certificates / "localhost-cert.pem", certificates / "localhost-key.pem") + url = h2_url("127.0.0.1", 0, ssl_enabled="true").replace(attributes={SSL_CONTEXT: context}) + + async with AioH2Server(url, handler) as server: + _, port = server.address + async with AioH2Client(h2_url("localhost", port, **client_tls)) as client: + with pytest.raises(H2ConnectionError, match="ALPN"): + await client.open_stream(request_headers, end_stream=True) + + assert context.minimum_version == ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER).minimum_version + + +def test_tls_round_trip_runs_on_uvloop(request_headers, response_headers, server_tls, client_tls, h2_url) -> None: + uvloop = pytest.importorskip("uvloop") + + async def handler(stream) -> None: + assert await stream.receive_headers() == request_headers + await stream.send_headers(response_headers, end_stream=True) + + async def round_trip() -> None: + async with AioH2Server(h2_url("127.0.0.1", 0, **server_tls), handler) as server: + _, port = server.address + async with AioH2Client(h2_url("localhost", port, **client_tls)) as client: + stream = await client.open_stream(request_headers, end_stream=True) + assert await stream.receive_headers() == response_headers + + with asyncio.Runner(loop_factory=uvloop.new_event_loop) as runner: + runner.run(asyncio.wait_for(round_trip(), 10)) + + +async def test_tls_certificate_failure_maps_to_h2_connection_error(request_headers, server_tls, h2_url) -> None: + async def handler(stream) -> None: + await stream.reset() + + async with AioH2Server(h2_url("127.0.0.1", 0, **server_tls), handler) as server: + _, port = server.address + async with AioH2Client(h2_url("localhost", port, ssl_enabled="true")) as client: + with pytest.raises(H2ConnectionError) as raised: + await client.open_stream(request_headers, end_stream=True) + + assert isinstance(raised.value.__cause__, ssl.SSLCertVerificationError) + + +@pytest.mark.skipif(not socket.has_ipv6, reason="IPv6 is unavailable") +async def test_h2c_round_trip_over_ipv6(request_headers, response_headers, h2_url) -> None: + async def handler(stream) -> None: + assert await stream.receive_headers() == request_headers + await stream.send_headers(response_headers, end_stream=True) + + async with AioH2Server(h2_url("::1", 0), handler) as server: + host, port = server.address + async with AioH2Client(h2_url(host, port)) as client: + stream = await client.open_stream(request_headers, end_stream=True) + assert await stream.receive_headers() == response_headers + + +async def test_keep_alive_ping_is_acknowledged_on_an_idle_connection(request_headers, response_headers, h2_url): + acknowledged = anyio.Event() + + async def handler(stream): + await stream.receive_headers() + await stream.send_headers(response_headers, end_stream=True) + + async with AioH2Server(h2_url("127.0.0.1", 0), handler) as server: + host, port = server.address + + async def proxy(stream): + async def relay(source, target, preface=False): + reader = BufferedByteReceiveStream(source) + if preface: + await target.send(await reader.receive_exactly(24)) + while True: + header = await reader.receive_exactly(9) + payload = await reader.receive_exactly(int.from_bytes(header[:3], "big")) + await target.send(header + payload) + if not preface and header[3:5] == b"\x06\x01" and payload == (1).to_bytes(8, "big"): + acknowledged.set() + + async with stream, await anyio.connect_tcp(host, port) as upstream, anyio.create_task_group() as pipes: + pipes.start_soon(relay, stream, upstream, True) + pipes.start_soon(relay, upstream, stream) + + async with await anyio.create_tcp_listener(local_host="127.0.0.1") as listener: + proxy_port = listener.extra(anyio.abc.SocketAttribute.local_port) + async with ( + AioH2Client(h2_url(host, proxy_port, keep_alive_interval="10", keep_alive_timeout="1000")) as client, + anyio.create_task_group() as tasks, + ): + tasks.start_soon(listener.serve, proxy) + stream = await client.open_stream(request_headers, end_stream=True) + assert await stream.receive_headers() == response_headers + + await acknowledged.wait() + + next_stream = await client.open_stream(request_headers, end_stream=True) + assert await next_stream.receive_headers() == response_headers + assert next_stream.stream_id == stream.stream_id + 2 + tasks.cancel_scope.cancel() + + +async def test_a_response_finished_after_the_peer_goaway_is_written_before_the_socket_closes( + request_headers, response_headers, h2_url +) -> None: + async def handler(stream) -> None: + await stream.receive_headers() + # The request ends after the client's GOAWAY, so the server reads that GOAWAY first. + assert await stream.receive_data() == b"" + await stream.send_headers(response_headers) + await stream.send_data(b"last", end_stream=True) + + async with AioH2Server(h2_url("127.0.0.1", 0), handler) as server: + host, port = server.address + client = AioH2Client(h2_url(host, port)) + stream = await client.open_stream(request_headers) + async with anyio.create_task_group() as task_group: + # Closing the client sends GOAWAY while its stream still waits for the response. + task_group.start_soon(client.aclose) + await anyio.wait_all_tasks_blocked() + await stream.end() + + # Writing the last response also closes the server's last stream. + assert await stream.receive_headers() == response_headers + assert await stream.receive_data() == b"last" + + +async def test_completed_stream_remains_readable_after_final_goaway(request_headers, response_headers) -> None: + async def respond(engine: ngh2.Connection, request: ngh2.RequestReceived, peer: anyio.abc.SocketStream) -> None: + engine.send_shutdown_notice() + engine.send_goaway(last_stream_id=request.stream_id) + engine.send_response(request.stream_id, response_headers) + engine.send_data(request.stream_id, b"payload", end_stream=True) + + async with _raw_server(respond) as (url, client_closed), AioH2Client(url) as client: + stream = await client.open_stream(request_headers, end_stream=True) + assert await stream.receive_headers() == response_headers + # The client closes its socket once the GOAWAY has ended its last stream. + await client_closed.wait() + + assert await stream.receive_data() == b"payload" + assert await stream.receive_data() == b"" + + +async def test_socket_failure_maps_to_h2_connection_error(request_headers, h2_url) -> None: + class AbortOnData(asyncio.Protocol): + def connection_made(self, transport: asyncio.BaseTransport) -> None: + self.transport = transport + + def data_received(self, data: bytes) -> None: + self.transport.abort() + + async def open_then_receive(client: AioH2Client) -> None: + stream = await client.open_stream(request_headers, end_stream=True) + await stream.receive_headers() + + loop = asyncio.get_running_loop() + async with await loop.create_server(AbortOnData, "127.0.0.1", 0) as server: + address = server.sockets[0].getsockname() + async with AioH2Client(h2_url(address[0], address[1])) as client: + with pytest.raises(H2ConnectionError): + await open_then_receive(client) + + +async def test_a_stream_above_the_goaway_last_stream_id_fails_with_the_connection( + response_headers, path_headers +) -> None: + release_first = anyio.Event() + first_ids: list[int] = [] + + async def respond(engine: ngh2.Connection, request: ngh2.RequestReceived, peer: anyio.abc.SocketStream) -> None: + if (b":path", b"/first") in request.headers: + first_ids.append(request.stream_id) + return + + engine.send_goaway(last_stream_id=request.stream_id - 2) + await peer.send(engine.data_to_send()) + await release_first.wait() + engine.send_response(first_ids[0], response_headers, end_stream=True) + + async with _raw_server(respond) as (url, _), AioH2Client(url) as client: + first = await client.open_stream(path_headers(b"/first"), end_stream=True) + second = await client.open_stream(path_headers(b"/second"), end_stream=True) + + with anyio.fail_after(5), pytest.raises(H2ConnectionError, match="draining"): + await second.receive_headers() + + release_first.set() + assert await first.receive_headers() == response_headers + + +@asynccontextmanager +async def _raw_server( + respond: Callable[[ngh2.Connection, ngh2.RequestReceived, anyio.abc.SocketStream], Awaitable[None]], + settings: dict[ngh2.Setting, int] | None = None, +) -> AsyncIterator[tuple[URL, anyio.Event]]: + """Serve one client from a bare ngh2 engine that ``respond`` drives for each request, announcing ``settings``. + + Yield the URL to connect to and an event set once the client closes its socket. + """ + client_closed = anyio.Event() + + async def serve(peer: anyio.abc.SocketStream) -> None: + engine = ngh2.Connection(ngh2.Role.SERVER) + engine.initiate_connection(settings) + async with peer: + await peer.send(engine.data_to_send()) + async for data in peer: + # A terminated engine reads nothing more, but the client may still write before closing. + if not engine.want_read: + continue + engine.receive_data(data) + for event in engine.events(): + if isinstance(event, ngh2.RequestReceived): + await respond(engine, event, peer) + if outgoing := engine.data_to_send(): + await peer.send(outgoing) + client_closed.set() + + async with await anyio.create_tcp_listener(local_host="127.0.0.1") as listener, anyio.create_task_group() as tasks: + tasks.start_soon(listener.serve, serve) + port = listener.extra(anyio.abc.SocketAttribute.local_port) + yield URL(protocol="tri", host="127.0.0.1", port=port), client_closed + tasks.cancel_scope.cancel() + + +@asynccontextmanager +async def _one_stream_at_a_time( + h2_url, response_headers +) -> AsyncIterator[tuple[AioH2Client, list[bytes], anyio.Event]]: + """Yield a client of a server that serves one stream at a time, the paths it served, and what ends ``/held``.""" + served: list[bytes] = [] + release = anyio.Event() + + async def handler(stream) -> None: + path = dict(await stream.receive_headers())[b":path"] + served.append(path) + if path == b"/held": + await release.wait() + await stream.send_headers(response_headers) + await stream.send_data(b"", end_stream=True) + + async with AioH2Server(h2_url("127.0.0.1", 0, max_concurrent_streams="1"), handler) as server: + _, port = server.address + async with AioH2Client(h2_url("127.0.0.1", port)) as client: + yield client, served, release + + +async def test_streams_open_in_the_order_they_waited_for_room(path_headers, response_headers, h2_url) -> None: + async with _one_stream_at_a_time(h2_url, response_headers) as (client, served, release): + held = await client.open_stream(path_headers(b"/held"), end_stream=True) + await anyio.wait_all_tasks_blocked() + + async def call(path: bytes) -> None: + stream = await client.open_stream(path_headers(path), end_stream=True) + await stream.receive_headers() + await stream.receive_data() + + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + tasks.start_soon(call, b"/waited") + await anyio.wait_all_tasks_blocked() + release.set() + await held.receive_headers() + await held.receive_data() + # Arriving once the held stream closes, it still comes after the one that waited. + await call(b"/later") + + assert served == [b"/held", b"/waited", b"/later"] + + +@pytest.mark.parametrize("settings", [{ngh2.Setting.MAX_CONCURRENT_STREAMS: 3}, {}], ids=["announced", "unlimited"]) +async def test_a_client_opens_as_many_streams_as_the_server_allows(path_headers, settings) -> None: + held: list[int] = [] + + async def respond(engine: ngh2.Connection, request: ngh2.RequestReceived, peer: anyio.abc.SocketStream) -> None: + held.append(request.stream_id) + + # Its own limit is what the server may open towards it, not what it opens. + async with ( + _raw_server(respond, settings) as (url, _), + AioH2Client(url.update_parameters({"max-concurrent-streams": "1"})) as client, + ): + with anyio.fail_after(5): + streams = [await client.open_stream(path_headers(b"/held"), end_stream=True) for _ in range(3)] + while len(held) < 3: + await anyio.sleep(0.01) + + assert len(streams) == 3 + + +async def test_streams_open_in_the_order_they_waited_when_the_peer_lowers_its_limit(path_headers) -> None: + held: list[int] = [] + served: list[bytes] = [] + release = anyio.Event() + + async def respond(engine: ngh2.Connection, request: ngh2.RequestReceived, peer: anyio.abc.SocketStream) -> None: + if len(held) == 2: + served.append(dict(request.headers)[b":path"]) + engine.send_response(request.stream_id, ((b":status", b"200"),), end_stream=True) + return + + held.append(request.stream_id) + if len(held) == 2: + await release.wait() + # Both held streams end, then the limit falls to one, in one write. + for stream_id in held: + engine.send_response(stream_id, ((b":status", b"200"),), end_stream=True) + responses = engine.data_to_send() + engine.update_settings({ngh2.Setting.MAX_CONCURRENT_STREAMS: 1}) + await peer.send(responses + engine.data_to_send()) + + async def call(path: bytes) -> None: + stream = await client.open_stream(path_headers(path), end_stream=True) + await stream.receive_headers() + + async with ( + _raw_server(respond, {ngh2.Setting.MAX_CONCURRENT_STREAMS: 2}) as (url, _), + AioH2Client(url) as client, + ): + streams = [await client.open_stream(path_headers(b"/held"), end_stream=True) for _ in range(2)] + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + tasks.start_soon(call, b"/first") + await anyio.wait_all_tasks_blocked() + tasks.start_soon(call, b"/second") + await anyio.wait_all_tasks_blocked() + release.set() + for stream in streams: + await stream.receive_headers() + + assert served == [b"/first", b"/second"] + + +async def test_a_waiter_cancelled_before_its_turn_leaves_the_room_to_the_next( + path_headers, response_headers, h2_url +) -> None: + async with _one_stream_at_a_time(h2_url, response_headers) as (client, served, release): + held = await client.open_stream(path_headers(b"/held"), end_stream=True) + await anyio.wait_all_tasks_blocked() + opened: list[bytes] = [] + + async def call(path: bytes) -> None: + stream = await client.open_stream(path_headers(path), end_stream=True) + opened.append(path) + await stream.receive_headers() + await stream.receive_data() + + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + first = anyio.CancelScope() + + async def cancellable() -> None: + with first: + await call(b"/cancelled") + + tasks.start_soon(cancellable) + await anyio.wait_all_tasks_blocked() + tasks.start_soon(call, b"/next") + await anyio.wait_all_tasks_blocked() + first.cancel() + release.set() + await held.receive_headers() + await held.receive_data() + + assert opened == [b"/next"] + assert served == [b"/held", b"/next"] diff --git a/tests/integration/transport/h2/aio/test_server.py b/tests/integration/transport/h2/aio/test_server.py new file mode 100644 index 00000000..c5630730 --- /dev/null +++ b/tests/integration/transport/h2/aio/test_server.py @@ -0,0 +1,396 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import ssl +from contextlib import ExitStack + +import anyio +import ngh2 +import pytest + +from dubbo.transport.h2 import ( + H2ConnectionError, + H2Error, + H2StreamResetError, +) +from dubbo.transport.h2.aio import AioH2Client, AioH2Server + +pytestmark = pytest.mark.anyio + + +async def test_closing_the_server_writes_the_responses_its_handlers_queued( + request_headers, response_headers, h2_url +) -> None: + response = b"r" * (100 * 1024) + handled = anyio.Event() + + async def handler(stream) -> None: + await stream.receive_headers() + await stream.send_headers(response_headers) + # Part of the response stays queued behind the client's window. + await stream.send_data(response) + await stream.send_trailers(((b"grpc-status", b"0"),)) + handled.set() + + async with AioH2Server(h2_url("127.0.0.1", 0), handler) as server: + host, port = server.address + async with AioH2Client(h2_url(host, port, initial_window_size="65535")) as client: + stream = await client.open_stream(request_headers, end_stream=True) + async with stream, anyio.create_task_group() as task_group: + await handled.wait() + task_group.start_soon(server.aclose) + + with anyio.fail_after(5): + assert await stream.receive_headers() == response_headers + assert await stream.receive_data_exactly(len(response)) == response + assert await stream.receive_trailers() == ((b"grpc-status", b"0"),) + + +async def test_a_handler_is_cancelled_when_the_peer_resets_its_stream(request_headers, h2_url) -> None: + started = anyio.Event() + cancelled = anyio.Event() + + async def handler(stream) -> None: + await stream.receive_headers() + started.set() + with ExitStack() as stack: + stack.callback(cancelled.set) + await anyio.sleep_forever() + + async with AioH2Server(h2_url("127.0.0.1", 0), handler) as server: + host, port = server.address + async with AioH2Client(h2_url(host, port)) as client: + stream = await client.open_stream(request_headers) + await started.wait() + await stream.reset() + + await cancelled.wait() + + +async def test_a_handler_is_cancelled_when_its_connection_fails(request_headers, h2_url) -> None: + started = anyio.Event() + cancelled = anyio.Event() + + async def handler(stream) -> None: + await stream.receive_headers() + started.set() + with ExitStack() as stack: + stack.callback(cancelled.set) + await anyio.sleep_forever() + + async with AioH2Server(h2_url("127.0.0.1", 0), handler) as server: + host, port = server.address + engine = ngh2.Connection(ngh2.Role.CLIENT) + engine.initiate_connection() + engine.send_request(request_headers, end_stream=False) + async with await anyio.connect_tcp(host, port) as peer: + await peer.send(engine.data_to_send()) + await started.wait() + + await cancelled.wait() + + +async def test_handler_failure_resets_only_its_stream(response_headers, h2_url, path_headers) -> None: + async def handler(stream) -> None: + headers = await stream.receive_headers() + if (b":path", b"/fail") in headers: + raise RuntimeError("handler failed") + await stream.send_headers(response_headers, end_stream=True) + + async with AioH2Server(h2_url("127.0.0.1", 0), handler) as server: + host, port = server.address + async with AioH2Client(h2_url(host, port)) as client: + failed = await client.open_stream(path_headers(b"/fail"), end_stream=True) + with pytest.raises(H2StreamResetError, match="reset"): + await failed.receive_headers() + + healthy = await client.open_stream(path_headers(b"/healthy"), end_stream=True) + assert await healthy.receive_headers() == response_headers + assert healthy.stream_id == failed.stream_id + 2 + + +async def test_server_reports_its_address_only_while_listening(h2_url) -> None: + async def handler(stream) -> None: + raise AssertionError("no stream is opened") + + server = AioH2Server(h2_url("127.0.0.1", 0), handler) + with pytest.raises(RuntimeError, match="not listening"): + _ = server.address + + async with server: + host, port = server.address + assert host == "127.0.0.1" + assert port != 0 + with pytest.raises(RuntimeError, match="started once"): + await server.__aenter__() + + with pytest.raises(RuntimeError, match="not listening"): + _ = server.address + + +async def test_server_close_lets_running_handlers_finish_and_accepts_no_new_work( + request_headers, response_headers, h2_url +) -> None: + started = anyio.Event() + release = anyio.Event() + + async def handler(stream) -> None: + await stream.receive_headers() + started.set() + await release.wait() + await stream.send_headers(response_headers, end_stream=True) + + async with AioH2Server(h2_url("127.0.0.1", 0, max_concurrent_streams="1"), handler) as server: + host, port = server.address + # The running stream fills the connection, so the next one waits until the GOAWAY frees it. + async with AioH2Client(h2_url(host, port)) as client: + running = await client.open_stream(request_headers, end_stream=True) + await started.wait() + + async with anyio.create_task_group() as task_group: + task_group.start_soon(server.aclose) + # The shutdown GOAWAY stops the client opening streams on this connection. + with pytest.raises(H2ConnectionError, match="failed to connect"): + await client.open_stream(request_headers, end_stream=True) + release.set() + + assert await running.receive_headers() == response_headers + + assert not server._connections + assert not server._handlers + + +async def test_server_announcing_its_shutdown_sends_goaway_and_keeps_serving( + response_headers, h2_url, path_headers +) -> None: + async def handler(stream) -> None: + if (b":path", b"/announce") in await stream.receive_headers(): + server.announce_shutdown() + # After an announcement, the client reads the GOAWAY before these headers, which follow it. + await stream.send_headers(response_headers, end_stream=True) + + async with AioH2Server(h2_url("127.0.0.1", 0), handler) as server: + host, port = server.address + async with AioH2Client(h2_url(host, port)) as client: + stream = await client.open_stream(path_headers(b"/announce"), end_stream=True) + assert await stream.receive_headers() == response_headers + + # The next streams go to a new connection, which the server serves without a notice. + stream_ids = [] + for _ in range(3): + stream = await client.open_stream(path_headers(b"/serve"), end_stream=True) + assert await stream.receive_headers() == response_headers + stream_ids.append(stream.stream_id) + assert stream_ids == [1, 3, 5] + + +async def test_server_close_cancels_handlers_still_running_after_the_grace_period(request_headers, h2_url) -> None: + started = anyio.Event() + cancelled = anyio.Event() + + async def handler(stream) -> None: + await stream.receive_headers() + started.set() + with ExitStack() as stack: + stack.callback(cancelled.set) + await anyio.sleep_forever() + + async with AioH2Server(h2_url("127.0.0.1", 0, shutwait="10"), handler) as server: + host, port = server.address + async with AioH2Client(h2_url(host, port)) as client: + stream = await client.open_stream(request_headers) + await started.wait() + await server.aclose() + with pytest.raises(H2Error): + await stream.receive_headers() + + assert cancelled.is_set() + assert not server._connections + + +async def test_tls_server_bounds_a_stalled_handshake(server_tls, h2_url) -> None: + async def handler(stream) -> None: + raise AssertionError("TLS never reached HTTP/2") + + server = AioH2Server(h2_url("127.0.0.1", 0, ssl_handshake_timeout="50", **server_tls), handler) + async with server: + host, port = server.address + async with await anyio.connect_tcp(host, port) as raw_stream: + # The server stays open, so only the handshake timeout ends the connection. + with anyio.fail_after(5), pytest.raises(anyio.EndOfStream): + await raw_stream.receive() + + assert not server._connections + + assert not server._connections + + +async def test_tls_server_discards_an_invalid_handshake_without_registering_h2(server_tls, h2_url) -> None: + async def handler(stream) -> None: + raise AssertionError("invalid TLS never reached HTTP/2") + + server = AioH2Server(h2_url("127.0.0.1", 0, ssl_handshake_timeout="200", **server_tls), handler) + async with server: + host, port = server.address + raw_stream = await anyio.connect_tcp(host, port) + await raw_stream.send(b"not TLS") + + with anyio.fail_after(5): + with pytest.raises(anyio.EndOfStream): + await raw_stream.receive() + assert not server._connections + + await raw_stream.aclose() + + +async def test_tls_server_aborts_an_established_peer_that_withholds_close_notify( + server_tls, h2_url, certificates +) -> None: + async def handler(stream) -> None: + raise AssertionError("the peer did not send an HTTP/2 request") + + async with AioH2Server(h2_url("127.0.0.1", 0, **server_tls), handler) as server: + host, port = server.address + context = ssl.create_default_context(cafile=certificates / "localhost-cert.pem") + context.set_alpn_protocols(["h2"]) + reader, writer = await asyncio.open_connection( + host, + port, + ssl=context, + server_hostname="localhost", + ) + # The server writes its SETTINGS once it owns the connection. + await reader.readexactly(9) + + writer.transport.pause_reading() + with anyio.fail_after(2): + await server.aclose() + writer.transport.abort() + + assert not server._connections + + +async def test_cancelling_server_start_closes_its_listener(monkeypatch, h2_url): + listeners = [] + started = anyio.Event() + start_serving = asyncio.base_events.Server.start_serving + + async def start_and_wait(listener): + listeners.append(listener) + await start_serving(listener) + started.set() + await anyio.sleep_forever() + + async def handler(stream): + raise AssertionError("no request is sent") + + monkeypatch.setattr(asyncio.base_events.Server, "start_serving", start_and_wait) + scopes = [] + + async def start(): + with anyio.CancelScope() as scope: + scopes.append(scope) + await AioH2Server(h2_url("127.0.0.1", 0), handler).__aenter__() + + async with anyio.create_task_group() as tasks: + tasks.start_soon(start) + await started.wait() + scopes[0].cancel() + + assert len(listeners) == 1 + assert not listeners[0].is_serving() + + +async def test_cancelling_a_server_close_finishes_the_close_first(request_headers, h2_url) -> None: + started = anyio.Event() + + async def handler(stream) -> None: + await stream.receive_headers() + started.set() + await anyio.sleep_forever() + + async with AioH2Server(h2_url("127.0.0.1", 0, shutwait="10000"), handler) as server: + host, port = server.address + async with AioH2Client(h2_url(host, port)) as client: + await client.open_stream(request_headers) + await started.wait() + + closing = asyncio.get_running_loop().create_task(server.aclose()) + # While the close waits out the handlers' grace period. + await anyio.wait_all_tasks_blocked() + closing.cancel() + with pytest.raises(asyncio.CancelledError): + await closing + + assert not server._handlers + assert not server._connections + + +async def test_cancelling_the_server_owner_closes_its_connections(request_headers, h2_url) -> None: + handler_started = anyio.Event() + + async def handler(stream) -> None: + await stream.receive_headers() + handler_started.set() + await stream.receive_data() + + server = AioH2Server(h2_url("127.0.0.1", 0, shutwait="0"), handler) + client: AioH2Client | None = None + with anyio.CancelScope() as scope: + async with server: + host, port = server.address + client = AioH2Client(h2_url(host, port)) + await client.open_stream(request_headers) + await handler_started.wait() + scope.cancel() + await anyio.sleep_forever() + + assert client is not None + await client.aclose() + assert not server._connections + + +async def test_a_task_cancelled_while_it_holds_the_server_stops_it_at_once(request_headers, h2_url) -> None: + started = anyio.Event() + + async def handler(stream) -> None: + await stream.receive_headers() + started.set() + await anyio.sleep_forever() + + listening = anyio.Event() + + async def serve(server: AioH2Server) -> None: + async with server: + listening.set() + await anyio.sleep_forever() + + server = AioH2Server(h2_url("127.0.0.1", 0, shutwait="3000"), handler) + task = asyncio.get_running_loop().create_task(serve(server)) + await listening.wait() + # The client stays connected, so that only the server's close can end the handler. + async with AioH2Client(h2_url(*server.address)) as client: + await client.open_stream(request_headers) + await started.wait() + stopping = anyio.current_time() + task.cancel() + with pytest.raises(asyncio.CancelledError): + await task + + # A graceful close would wait three seconds for the handler. + assert anyio.current_time() == stopping diff --git a/tests/integration/transport/h2/aio/test_stream.py b/tests/integration/transport/h2/aio/test_stream.py new file mode 100644 index 00000000..787aa553 --- /dev/null +++ b/tests/integration/transport/h2/aio/test_stream.py @@ -0,0 +1,254 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import pytest + +from dubbo.transport.h2 import ( + H2ErrorCode, + H2StreamResetError, +) +from dubbo.transport.h2.aio import AioH2Client, AioH2Server + +pytestmark = pytest.mark.anyio + + +@pytest.mark.parametrize( + ("body", "parameters"), + [(b"answer", {}), (b"r" * (100 * 1024), {"initial_window_size": "65535"})], + ids=["unbuffered", "flow-controlled"], +) +async def test_completing_a_response_preserves_its_body_and_stops_the_request( + body, parameters, request_headers, response_headers, h2_url +): + async def handler(stream): + await stream.receive_headers() + await stream.send_headers(response_headers) + await stream.send_data(body) + await stream.send_trailers(((b"grpc-status", b"0"),)) + + async with AioH2Server(h2_url("127.0.0.1", 0), handler) as server: + host, port = server.address + async with ( + AioH2Client(h2_url(host, port, **parameters)) as client, + await client.open_stream(request_headers) as stream, + ): + assert await stream.receive_headers() == response_headers + assert await stream.receive_data_exactly(len(body)) == body + assert await stream.receive_trailers() == ((b"grpc-status", b"0"),) + + async def send_until_reset(): + while True: + await stream.send_data(b"more") + await anyio.wait_all_tasks_blocked() + + with pytest.raises(H2StreamResetError, match="reset") as raised: + await send_until_reset() + + assert raised.value.error_code == H2ErrorCode.NO_ERROR + + +async def test_a_request_outliving_a_flow_controlled_response_still_reaches_its_end( + request_headers, response_headers, h2_url +) -> None: + # The client's window holds part of the response when the handler returns. + response = b"r" * (100 * 1024) + + async def handler(stream) -> None: + await stream.receive_headers() + await stream.send_headers(response_headers) + await stream.send_data(response) + await stream.send_trailers(((b"grpc-status", b"0"),)) + + async with AioH2Server(h2_url("127.0.0.1", 0, initial_window_size="65535"), handler) as server: + host, port = server.address + async with AioH2Client(h2_url(host, port, initial_window_size="65535")) as client: + stream = await client.open_stream(request_headers) + async with stream: + assert await stream.receive_headers() == response_headers + + # More than the server's stream window, which no handler reads anymore. + with anyio.fail_after(5): + await stream.send_data(b"q" * (256 * 1024), end_stream=True) + + assert await stream.receive_data_exactly(len(response)) == response + assert await stream.receive_trailers() == ((b"grpc-status", b"0"),) + + +async def test_a_send_blocked_when_a_complete_response_stops_the_request_raises( + request_headers, response_headers, h2_url +) -> None: + # RFC 9113 section 8.1: the request bytes still queued are discarded, so the send must not succeed. + async def handler(stream) -> None: + await stream.receive_headers() + await stream.send_headers(response_headers) + await stream.send_data(b"answer") + await stream.send_trailers(((b"grpc-status", b"0"),)) + + async with AioH2Server(h2_url("127.0.0.1", 0, initial_window_size="65535"), handler) as server: + host, port = server.address + async with AioH2Client(h2_url(host, port)) as client: + stream = await client.open_stream(request_headers) + async with stream: + # More than the server's stream window and the local send buffer together. + with anyio.fail_after(5), pytest.raises(H2StreamResetError) as raised: + await stream.send_data(b"q" * (512 * 1024)) + assert raised.value.error_code == H2ErrorCode.NO_ERROR + + assert await stream.receive_headers() == response_headers + assert await stream.receive_data_exactly(6) == b"answer" + + +async def test_h2c_round_trip_applies_flow_control_when_application_consumes_data( + request_headers, response_headers, h2_url +) -> None: + body = bytes(range(256)) * 1024 + prefix = b"\x00" + len(body).to_bytes(4, "big") + + async def handler(stream) -> None: + assert await stream.receive_headers() == request_headers + request_prefix = await stream.receive_data_exactly(5) + request_body = await stream.receive_data_exactly(int.from_bytes(request_prefix[1:], "big")) + assert await stream.receive_data() == b"" + + await stream.send_headers(response_headers) + await stream.send_data(request_prefix[:2]) + await stream.send_data(request_prefix[2:] + request_body, end_stream=True) + + async with AioH2Server(h2_url("127.0.0.1", 0), handler) as server: + host, port = server.address + async with ( + AioH2Client(h2_url(host, port)) as client, + await client.open_stream(request_headers) as stream, + ): + await stream.send_data(prefix[:2]) + await stream.send_data(prefix[2:] + body, end_stream=True) + + assert await stream.receive_headers() == response_headers + response_prefix = await stream.receive_data_exactly(5) + response_body = await stream.receive_data_exactly(int.from_bytes(response_prefix[1:], "big")) + assert response_prefix == prefix + assert response_body == body + assert await stream.receive_data() == b"" + + +async def test_receive_data_exactly_returns_what_is_left_when_the_peer_ends( + response_headers, h2_url, path_headers +) -> None: + async def handler(stream) -> None: + headers = await stream.receive_headers() + if (b":path", b"/empty") in headers: + await stream.send_headers(response_headers, end_stream=True) + return + + await stream.send_headers(response_headers) + await stream.send_data(b"abc", end_stream=True) + + async with AioH2Server(h2_url("127.0.0.1", 0), handler) as server: + host, port = server.address + async with AioH2Client(h2_url(host, port)) as client: + empty = await client.open_stream(path_headers(b"/empty"), end_stream=True) + assert await empty.receive_headers() == response_headers + assert await empty.receive_data_exactly(1) == b"" + + partial = await client.open_stream(path_headers(b"/partial"), end_stream=True) + assert await partial.receive_headers() == response_headers + assert await partial.receive_data_exactly(5) == b"abc" + assert await partial.receive_data_exactly(5) == b"" + + +async def test_stream_reset_does_not_close_the_connection( + request_headers, response_headers, h2_url, path_headers +) -> None: + async def handler(stream) -> None: + headers = await stream.receive_headers() + if (b":path", b"/reset") in headers: + await stream.reset() + else: + await stream.send_headers(response_headers, end_stream=True) + + async with AioH2Server(h2_url("127.0.0.1", 0), handler) as server: + host, port = server.address + async with AioH2Client(h2_url(host, port)) as client: + reset_stream = await client.open_stream(path_headers(b"/reset"), end_stream=True) + with pytest.raises(H2StreamResetError) as raised: + await reset_stream.receive_headers() + assert raised.value.error_code == H2ErrorCode.CANCEL + + stream = await client.open_stream(request_headers, end_stream=True) + assert await stream.receive_headers() == response_headers + assert await stream.receive_data() == b"" + assert stream.stream_id == reset_stream.stream_id + 2 + + +async def test_reset_returns_unread_data_to_the_connection_window( + request_headers, response_headers, h2_url, path_headers +) -> None: + body = b"x" * 40_000 + + async def handler(stream) -> None: + headers = await stream.receive_headers() + if (b":path", b"/reset") in headers: + # Waiting for the end of the request leaves its body unread. + assert await stream.receive_trailers() is None + await stream.reset() + return + + assert await stream.receive_data_exactly(30_000) == b"y" * 30_000 + await stream.send_headers(response_headers, end_stream=True) + + # Smaller than both requests together, so the second needs the credit the reset returns. + async with AioH2Server(h2_url("127.0.0.1", 0, connection_initial_window_size="65535"), handler) as server: + host, port = server.address + async with AioH2Client(h2_url(host, port)) as client: + first = await client.open_stream(path_headers(b"/reset")) + await first.send_data(body, end_stream=True) + with pytest.raises(H2StreamResetError): + await first.receive_headers() + + second = await client.open_stream(request_headers) + await second.send_data(b"y" * 30_000, end_stream=True) + assert await second.receive_headers() == response_headers + + +async def test_stream_context_releases_unread_response_data( + request_headers, response_headers, h2_url, path_headers +) -> None: + async def handler(stream) -> None: + headers = await stream.receive_headers() + await stream.send_headers(response_headers) + if (b":path", b"/full-window") in headers: + await stream.send_data(b"x" * (64 * 1024 - 1), end_stream=True) + else: + await stream.send_data(b"y", end_stream=True) + + async with AioH2Server(h2_url("127.0.0.1", 0), handler) as server: + host, port = server.address + # The protocol's smallest windows, which the first response fills. + url = h2_url(host, port, initial_window_size="65535", connection_initial_window_size="65535") + async with AioH2Client(url) as client: + async with await client.open_stream( + path_headers(b"/full-window"), + end_stream=True, + ) as first: + assert await first.receive_headers() == response_headers + # Waiting for the end of the response leaves its body unread. + assert await first.receive_trailers() is None + + second = await client.open_stream(request_headers, end_stream=True) + assert await second.receive_headers() == response_headers + assert await second.receive_data() == b"y" diff --git a/tests/integration/transport/h2/test_base.py b/tests/integration/transport/h2/test_base.py new file mode 100644 index 00000000..639f75d6 --- /dev/null +++ b/tests/integration/transport/h2/test_base.py @@ -0,0 +1,35 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import subprocess +import sys + + +def test_h2_contract_import_does_not_load_aio_plugin() -> None: + script = """ +import sys +import dubbo.transport.h2 as h2 +from typing import get_type_hints + +assert "ngh2" not in sys.modules +assert "dubbo.transport.h2.aio" not in sys.modules +assert not hasattr(h2, "AioH2Client") +get_type_hints(h2.H2Client.open_stream) +assert "ngh2" not in sys.modules +assert "dubbo.transport.h2.aio" not in sys.modules +""" + subprocess.run([sys.executable, "-c", script], check=True) diff --git a/tests/integration/transport/test_kazoo.py b/tests/integration/transport/test_kazoo.py new file mode 100644 index 00000000..91e37d2b --- /dev/null +++ b/tests/integration/transport/test_kazoo.py @@ -0,0 +1,176 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import uuid +from collections.abc import AsyncIterator +from typing import Any + +import anyio +import pytest +from kazoo.client import KazooClient +from kazoo.exceptions import NoAuthError + +from dubbo.transport.zookeeper import ZookeeperClient, ZookeeperError +from dubbo.transport.zookeeper.kazoo import KazooZookeeperClient +from dubbo.url import URL + +pytestmark = [pytest.mark.anyio, pytest.mark.zookeeper] + + +@pytest.fixture +async def client(zookeeper: str, zk) -> AsyncIterator[Any]: + async with zk(f"zookeeper://{zookeeper}?timeout=5000") as client: + yield client + + +async def test_leaving_watches_of_an_idle_node_keeps_none_of_their_callbacks(connected) -> None: + client, root = connected + path = f"{root}/rules" + kazoo = client._kazoo + listeners = len(kazoo.state_listeners) + await client.set(path, b"rules") + + for _ in range(3): + async with client.watch(path) as values, client.watch_children(path) as children: + with anyio.fail_after(5): + assert await anext(values) == b"rules" + assert await anext(children) == [] + + # Kazoo shows its registered watchers only through these attributes. + assert len(kazoo.state_listeners) == listeners + assert not kazoo._data_watchers.get(path) + assert not kazoo._child_watchers.get(path) + + +@pytest.fixture +async def connected(client, delete_tree): + root = f"/dubbo-python-test/{uuid.uuid4().hex}" + yield client, root + await delete_tree(client, root) + + +async def _next(values: AsyncIterator[object]) -> object: + with anyio.fail_after(5): + return await anext(values) + + +async def _until(values: AsyncIterator[object], expected: object) -> None: + with anyio.fail_after(5): + async for value in values: + if value == expected: + return + pytest.fail("the watch ended before the expected value") + + +async def test_watches_resume_after_the_session_expires(connected, zookeeper): + client, root = connected + data, providers = f"{root}/config", f"{root}/providers" + await client.set(data, b"v1") + await client.create(f"{providers}/a") + + async with client.watch(data) as values, client.watch_children(providers) as names: + assert await _next(values) == b"v1" + assert await _next(names) == ["a"] + + await _expire_session(client, zookeeper) + + await client.set(data, b"v2") + await _until(values, b"v2") + await client.delete(f"{providers}/a") + await _until(names, []) + + +async def test_kept_ephemeral_nodes_return_after_the_session_expires_until_their_keepers_exit(connected, zookeeper): + client, root = connected + kept, left = f"{root}/providers/a", f"{root}/providers/b" + async with client.keep_ephemeral(kept, b"a"): + async with client.keep_ephemeral(left, b"b"): + pass + + await _expire_session(client, zookeeper) + + async with client.watch(kept) as values: + await _until(values, b"a") + assert await client.get(left) is None + + +async def test_a_later_keeper_changes_the_data_of_the_node_in_place(connected): + client, root = connected + path = f"{root}/instances/a" + + def created() -> int: + return client._kazoo.exists(path).czxid + + async with client.keep_ephemeral(path, b"old"): + first = await anyio.to_thread.run_sync(created) + async with client.keep_ephemeral(path, b"new"): + # Watchers would see the node missing if it were deleted and created again. + assert await anyio.to_thread.run_sync(created) == first + assert await client.get(path) == b"new" + + +async def _expire_session(client: ZookeeperClient, zookeeper: str) -> None: + """Expire the session of ``client`` and wait until it has a new one.""" + # ZooKeeper expires a session that another client opens and closes. + assert isinstance(client, KazooZookeeperClient) + kazoo = client._kazoo + expired = kazoo.client_id + session = KazooClient(hosts=zookeeper, client_id=expired) + + def expire() -> None: + session.start() + session.stop() + session.close() + + connected = anyio.Event() + token = anyio.lowlevel.current_token() + + def changed(state): + if state == "CONNECTED" and kazoo.client_id != expired: + anyio.from_thread.run_sync(connected.set, token=token) + + kazoo.add_listener(changed) + with anyio.fail_after(10): + await anyio.to_thread.run_sync(expire) + await connected.wait() + kazoo.remove_listener(changed) + + +async def test_created_nodes_are_unreadable_to_other_users(client, zookeeper): + path = f"/dubbo-python-test-acl-{uuid.uuid4().hex}" + + async with ( + KazooZookeeperClient(URL.parse(f"zookeeper://test-{uuid.uuid4().hex}:secret@{zookeeper}")) as owner, + owner.keep_ephemeral(path, b"owned"), + ): + assert await owner.get(path) == b"owned" + + with pytest.raises(ZookeeperError, match="cannot get") as caught: + await client.get(path) + assert isinstance(caught.value.__cause__, NoAuthError) + + +async def test_created_nodes_without_a_user_are_readable_to_all(client, zookeeper): + path = f"/dubbo-python-test-acl-{uuid.uuid4().hex}" + + async with ( + KazooZookeeperClient(URL.parse(f"zookeeper://{zookeeper}")) as owner, + owner.keep_ephemeral(path, b"owned"), + ): + assert await owner.get(path) == b"owned" + + assert await client.get(path) == b"owned" diff --git a/tests/integration/transport/test_nacos_sdk.py b/tests/integration/transport/test_nacos_sdk.py new file mode 100644 index 00000000..dfd4718a --- /dev/null +++ b/tests/integration/transport/test_nacos_sdk.py @@ -0,0 +1,142 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import uuid +from collections.abc import AsyncIterator, Callable +from contextlib import AsyncExitStack +from typing import Any + +import anyio +import pytest +from v2.nacos import ConfigParam + +from dubbo.extension import ApplicationScope +from dubbo.transport.nacos import ( + NacosInstance, + get_nacos_config_client, + get_nacos_naming_client, +) +from dubbo.transport.nacos.sdk.config import SdkNacosConfigClient +from dubbo.transport.nacos.sdk.naming import SdkNacosNamingClient +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = pytest.mark.anyio + + +# The SDK connects through the threads of grpcio. +@pytest.mark.real_clock +@pytest.mark.parametrize("client_type", [SdkNacosConfigClient, SdkNacosNamingClient], ids=["config", "naming"]) +async def test_a_cancelled_connection_leaves_no_task_of_the_sdk(client_type: type) -> None: + before = asyncio.all_tasks() + + with anyio.move_on_after(0.2): + await client_type(URL.parse("nacos://127.0.0.1:1")).__aenter__() + started = asyncio.all_tasks() - before - {asyncio.current_task()} + # The SDK starts some tasks without keeping them, such as reading its disk cache; they end by themselves. + with anyio.move_on_after(1): + for task in started: + await asyncio.wait((task,)) + + assert [task for task in started if not task.done()] == [] + + +async def _until(values: AsyncIterator[Any], expected: Callable[[Any], bool]) -> Any: + with anyio.fail_after(10): + async for value in values: + if expected(value): + return value + raise AssertionError("the values ended") + + +@pytest.mark.nacos +async def test_sdk_watches_instances_until_none_are_left(nacos): + service, group = f"providers:test.Nacos$Inner{uuid.uuid4().hex}::", "dubbo-test" + instance = NacosInstance(host="10.9.9.9", port=1234, metadata={"side": "provider"}) + + async with ApplicationScope() as scope: + client = await get_nacos_naming_client( + URL.parse(f"nacos://{nacos}").replace(attributes={APPLICATION_SCOPE: scope}) + ) + async with client.watch(service, group) as snapshots: + assert await _until(snapshots, lambda instances: instances == []) == [] + async with client.keep_registered(service, group, instance): + await _until(snapshots, lambda instances: instances == [instance]) + await _until(snapshots, lambda instances: instances == []) + + +@pytest.mark.nacos +async def test_sdk_keeps_an_instance_kept_again_when_the_keeper_it_replaced_exits(nacos): + service, group = f"providers:test.Nacos{uuid.uuid4().hex}::", "dubbo-test" + old = NacosInstance(host="10.9.9.9", port=1234, metadata={"weight": "100"}) + new = NacosInstance(host="10.9.9.9", port=1234, metadata={"weight": "53"}) + + async with ApplicationScope() as scope: + client = await get_nacos_naming_client( + URL.parse(f"nacos://{nacos}").replace(attributes={APPLICATION_SCOPE: scope}) + ) + async with client.watch(service, group) as snapshots: + async with AsyncExitStack() as stack: + earlier = AsyncExitStack() + await earlier.enter_async_context(client.keep_registered(service, group, old)) + await _until(snapshots, lambda instances: instances == [old]) + await stack.enter_async_context(client.keep_registered(service, group, new)) + await earlier.aclose() + await _until(snapshots, lambda instances: instances == [new]) + await _until(snapshots, lambda instances: instances == []) + + +@pytest.fixture +async def config(nacos): + data_id, group = f"test/{uuid.uuid4().hex}$x", "dubbo-test" + async with ApplicationScope() as scope: + client = await get_nacos_config_client( + URL.parse(f"nacos://{nacos}").replace(attributes={APPLICATION_SCOPE: scope}) + ) + yield client, data_id, group + + # The framework has no configuration deletion API. + assert isinstance(client, SdkNacosConfigClient) + await client._connected().remove_config( + ConfigParam(data_id=data_id.replace("$", "___").replace("/", "-"), group=group) + ) + + +@pytest.mark.nacos +async def test_sdk_writes_configurations_by_compare_and_set_and_watches_them(config): + client, data_id, group = config + + async with client.watch(data_id, group) as contents: + assert await _until(contents, lambda content: content is None) is None + await client.update(data_id, group, lambda content: (content or "") + "a") + await _until(contents, lambda content: content == "a") + await client.update(data_id, group, lambda content: f"{content}b") + await _until(contents, lambda content: content == "ab") + + assert await client.get(data_id, group) == "ab" + + +@pytest.mark.nacos +async def test_a_config_client_disconnects_without_waiting_for_its_listen_task(nacos): + client = SdkNacosConfigClient(URL.parse(f"nacos://{nacos}")) + await client.__aenter__() + # As in a client that has run a while: the listen task waits for work. + await anyio.wait_all_tasks_blocked() + + # The listen task of the SDK sees that it stops only every five seconds, unless cancelled. + with anyio.fail_after(2): + await client.aclose() diff --git a/tests/integration/transport/test_zookeeper.py b/tests/integration/transport/test_zookeeper.py new file mode 100644 index 00000000..fb5a1c0e --- /dev/null +++ b/tests/integration/transport/test_zookeeper.py @@ -0,0 +1,30 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.transport.zookeeper import ZookeeperError + +pytestmark = pytest.mark.anyio + + +# The client connects in threads of its own. +@pytest.mark.real_clock +async def test_unreachable_ensemble_fails_to_connect(zk): + with pytest.raises(ZookeeperError, match=r"cannot connect on ZooKeeper 127\.0\.0\.1:1"): + async with zk("zookeeper://127.0.0.1:1?timeout=500"): + pass diff --git a/tests/integration/transport/test_zookeeper_client.py b/tests/integration/transport/test_zookeeper_client.py new file mode 100644 index 00000000..30b78d5d --- /dev/null +++ b/tests/integration/transport/test_zookeeper_client.py @@ -0,0 +1,144 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""The contract of ``ZookeeperClient``, held by the in-memory fake the unit tests use and by the kazoo client. + +The tests arrange nodes with the operations that `zk` adds to the contract. +""" + +import uuid +from collections.abc import AsyncIterator +from contextlib import AsyncExitStack +from typing import Any + +import anyio +import pytest + +pytestmark = pytest.mark.anyio + + +@pytest.fixture(params=["memory", pytest.param("kazoo", marks=pytest.mark.zookeeper)]) +def address(request) -> str: + if request.param == "memory": + request.getfixturevalue("memory_zookeeper") + return "zookeeper://127.0.0.1:2181?client=memory&timeout=5000" + return f"zookeeper://{request.getfixturevalue('zookeeper')}?timeout=5000" + + +@pytest.fixture +async def connected(address, delete_tree, zk) -> AsyncIterator[tuple[Any, str]]: + root = f"/dubbo-python-test/{uuid.uuid4().hex}" + async with zk(address) as client: + yield client, root + await delete_tree(client, root) + + +async def _next(values: AsyncIterator[object]) -> object: + with anyio.fail_after(5): + return await anext(values) + + +async def _until(values: AsyncIterator[object], expected: object) -> None: + with anyio.fail_after(5): + async for value in values: + if value == expected: + return + pytest.fail("the watch ended before the expected value") + + +async def test_a_missing_node_has_no_data(connected): + client, root = connected + + assert await client.get(f"{root}/missing") is None + + +async def test_a_kept_ephemeral_node_replaces_one_that_exists_and_stays_as_its_earlier_keeper_exits(connected): + client, root = connected + await client.set(f"{root}/a/config", b"two") + + async with AsyncExitStack() as later: + async with client.keep_ephemeral(f"{root}/a/provider"): + await later.enter_async_context(client.keep_ephemeral(f"{root}/a/provider", b"replaced")) + + assert await client.get(f"{root}/a/provider") == b"replaced" + assert sorted(await client.children(f"{root}/a")) == ["config", "provider"] + assert await client.children(f"{root}/a") == ["config"] + + +async def test_data_watch_yields_the_current_data_then_changes(connected): + client, root = connected + path = f"{root}/rules" + + async with client.watch(path) as values: + assert await _next(values) is None + + await client.set(path, b"one") + assert await _next(values) == b"one" + + await client.delete(path) + assert await _next(values) is None + + +async def test_children_watch_follows_the_node_as_it_is_deleted_and_created_again(connected): + client, root = connected + path = f"{root}/providers" + + async with client.watch_children(path) as values: + assert await _next(values) == [] + assert await client.get(path) is None + + # Creating a child creates the node first, which may show no names. + await client.create(f"{path}/a") + await _until(values, ["a"]) + + await client.delete(f"{path}/a") + await client.delete(path) + assert await _next(values) == [] + + await client.create(f"{path}/b") + await _until(values, ["b"]) + + +async def test_update_changes_the_data_it_reads_and_creates_a_missing_node(connected): + client, root = connected + path = f"{root}/a/counter" + seen = [] + + def increment(data: bytes | None) -> bytes: + seen.append(data) + return b"1" if data is None else str(int(data) + 1).encode() + + await client.update(path, increment) + await client.update(path, increment) + + assert seen == [None, b"1"] + assert await client.get(path) == b"2" + + +async def test_closing_a_client_deletes_its_ephemeral_nodes(connected, address, zk): + client, root = connected + await client.set(f"{root}/kept", b"") + + # A keeper whose client closes before it exits. + async with zk(address) as other: + keeper = other.keep_ephemeral(f"{root}/provider") + await keeper.__aenter__() + assert sorted(await client.children(root)) == ["kept", "provider"] + + async with client.watch_children(root) as children: + await _until(children, ["kept"]) + await keeper.__aexit__(None, None, None) diff --git a/tests/test_url.py b/tests/test_url.py deleted file mode 100644 index e0f538be..00000000 --- a/tests/test_url.py +++ /dev/null @@ -1,76 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from dubbo.url import URL, create_url - - -def test_str_to_url(): - url_0 = create_url("http://www.facebook.com/friends?param1=value1¶m2=value2") - assert url_0.scheme == "http" - assert url_0.host == "www.facebook.com" - assert url_0.port is None - assert url_0.path == "friends" - assert url_0.parameters["param1"] == "value1" - assert url_0.parameters["param2"] == "value2" - - url_1 = create_url("ftp://username:password@192.168.1.7:21/1/read.txt") - assert url_1.scheme == "ftp" - assert url_1.username == "username" - assert url_1.password == "password" - assert url_1.host == "192.168.1.7" - assert url_1.port == 21 - assert url_1.location == "192.168.1.7:21" - assert url_1.path == "1/read.txt" - - url_2 = create_url("file:///home/user1/router.js?type=script") - assert url_2.scheme == "file" - assert url_2.path == "home/user1/router.js" - - url_3 = create_url( - "http%3A//www.facebook.com/friends%3Fparam1%3Dvalue1%26param2%3Dvalue2", - encoded=True, - ) - assert url_3.scheme == "http" - assert url_3.host == "www.facebook.com" - assert url_3.port is None - assert url_3.path == "friends" - assert url_3.parameters["param1"] == "value1" - assert url_3.parameters["param2"] == "value2" - - -def test_url_to_str(): - url_0 = URL( - scheme="tri", - host="127.0.0.1", - port=12, - username="username", - password="password", - path="path", - parameters={"type": "a"}, - ) - assert url_0.to_str() == "tri://username:password@127.0.0.1:12/path?type=a" - - url_1 = URL( - scheme="tri", - host="127.0.0.1", - port=12, - path="path", - parameters={"type": "a"}, - ) - assert url_1.to_str() == "tri://127.0.0.1:12/path?type=a" - - url_2 = URL(scheme="tri", host="127.0.0.1", port=12, parameters={"type": "a"}) - assert url_2.to_str() == "tri://127.0.0.1:12?type=a" diff --git a/tests/unit/cluster/conftest.py b/tests/unit/cluster/conftest.py new file mode 100644 index 00000000..835ae8f0 --- /dev/null +++ b/tests/unit/cluster/conftest.py @@ -0,0 +1,105 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import AsyncIterator +from contextlib import aclosing, asynccontextmanager + +import anyio +import attrs +import pytest + +from dubbo import Invocation, Invoker, Method, Parameter, Result, RpcError, RpcType, Status +from dubbo.cluster import Cluster, StaticDirectory, create_cluster +from dubbo.url import URL + + +@attrs.define(kw_only=True) +class _Provider(Invoker): + url: URL + results: tuple[Result, ...] + up: bool = True + calls: int = 0 + closed: bool = False + + @property + def available(self) -> bool: + return self.up + + async def invoke(self, invocation: Invocation) -> Result: + self.calls += 1 + + return self.results[min(self.calls, len(self.results)) - 1] + + async def aclose(self) -> None: + self.closed = True + + +@pytest.fixture +def provider(): + def create(host: str, *results: Result, query: str = "", port: int = 20880, up: bool = True): + return _Provider( + url=URL.parse(f"tri://127.0.0.1:{port}/test.Greeter?{query}").replace(host=host), + results=results or (Result(value=host),), + up=up, + ) + + return create + + +@pytest.fixture +def invocation(): + def create(method: str = "greet", *, arguments: tuple = (), **attachments: str) -> Invocation: + return Invocation( + interface="test.Greeter", + method=method, + definition=Method(name=method, request=(), response=None), + arguments=arguments, + attachments=attachments, + ) + + return create + + +@pytest.fixture +def call(invocation) -> Invocation: + return invocation() + + +@pytest.fixture +def streaming_call() -> Invocation: + method = Method( + name="greet", rpc_type=RpcType.SERVER_STREAM, request=(Parameter(name="name", type=str),), response=str + ) + + return Invocation(interface="test.Greeter", method="greet", definition=method, arguments=("hi",)) + + +@pytest.fixture +def unavailable() -> Result: + return Result(error=RpcError(Status.UNAVAILABLE, "down")) + + +@pytest.fixture +def open_cluster(): + @asynccontextmanager + async def open_(strategy: str, *providers: Invoker, query: str = "") -> AsyncIterator[Cluster]: + url = URL.parse(f"consumer://127.0.0.1/test.Greeter?cluster={strategy}&loadbalance=roundrobin&{query}") + with anyio.fail_after(5): + async with aclosing(await create_cluster(url, StaticDirectory(providers))) as cluster: + yield cluster + + return open_ diff --git a/tests/unit/cluster/directory/test_dynamic.py b/tests/unit/cluster/directory/test_dynamic.py new file mode 100644 index 00000000..bcc9c0a6 --- /dev/null +++ b/tests/unit/cluster/directory/test_dynamic.py @@ -0,0 +1,277 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import itertools +from contextlib import asynccontextmanager + +import anyio +import attrs +import pytest + +from dubbo.cluster import Router +from dubbo.cluster.directory import DynamicDirectory +from dubbo.rpc.definition import Method +from dubbo.rpc.invocation import Invocation, Invoker, Result +from dubbo.url import PROVIDER_URL, URL +from dubbo.utils import Latest + +pytestmark = pytest.mark.anyio +CALL = Invocation(interface="test.Greeter", method="greet", definition=Method(name="greet", request=(), response=None)) + + +@attrs.define(kw_only=False) +class _Invoker(Invoker): + url: URL + closed: bool = False + closing: anyio.Event = attrs.field(factory=anyio.Event) + + async def invoke(self, invocation): + return Result() + + async def aclose(self): + self.closed = True + self.closing.set() + + +@asynccontextmanager +async def _fixed(urls): + async def snapshots(): + yield urls + await anyio.sleep_forever() + + yield snapshots() + + +async def test_different_service_groups_at_one_address_keep_distinct_invokers(): + urls = [ + URL.parse(f"tri://10.0.0.5:50051/test.Greeter?group={group}&version={version}") + for group, version in (("a", "1"), ("b", "2")) + ] + + async def refer(url): + return _Invoker(url) + + async with DynamicDirectory(lambda: _fixed(urls), refer, "test.Greeter") as directory: + assert [invoker.url for invoker in directory.candidates(CALL)] == urls + + +@pytest.mark.parametrize("error", [TypeError, ValueError, OSError]) +async def test_a_provider_that_cannot_be_called_is_left_out_of_the_others(error): + unfit, fit = URL.parse("dubbo://a:1/test.Greeter"), URL.parse("tri://b:1/test.Greeter") + + async def refer(url): + if url is unfit: + raise error("the protocol cannot carry the methods") + return _Invoker(url) + + with anyio.fail_after(5): + async with DynamicDirectory(lambda: _fixed([unfit, fit]), refer, "test.Greeter") as directory: + assert [invoker.url for invoker in directory.candidates(CALL)] == [fit] + + +async def test_an_unchanged_provider_keeps_its_invoker_whatever_the_protocol_adds_to_its_url(): + first, second = URL.parse("dubbo://a:1/test.Greeter"), URL.parse("dubbo://b:1/test.Greeter") + snapshots = Latest() + snapshots.publish([first]) + referred = [] + + async def refer(url): + # As a protocol that fills in its defaults. + invoker = _Invoker(url.update_parameters({"serialization": "hessian2"})) + referred.append(invoker) + return invoker + + @asynccontextmanager + async def changing(): + yield aiter(snapshots) + + with anyio.fail_after(5): + async with DynamicDirectory(changing, refer, "test.Greeter") as directory: + snapshots.publish([first, second]) + while len(directory.candidates(CALL)) < 2: + await anyio.sleep(0.001) + + assert len(referred) == 2 + assert not referred[0].closed + + +async def test_removed_providers_close_while_unchanged_providers_keep_their_invokers(): + first, second = URL.parse("tri://a:1/test.Greeter"), URL.parse("tri://b:1/test.Greeter") + snapshots = Latest() + snapshots.publish([first, second]) + referred = [] + + async def refer(url): + invoker = _Invoker(url) + referred.append(invoker) + return invoker + + @asynccontextmanager + async def changing(): + yield aiter(snapshots) + + with anyio.fail_after(5): + async with DynamicDirectory(changing, refer, "test.Greeter") as directory: + snapshots.publish([second]) + await referred[0].closing.wait() + + assert directory.candidates(CALL) == (referred[1],) + assert [invoker.closed for invoker in referred] == [True, False] + + assert [invoker.closed for invoker in referred] == [True, True] + + +async def test_a_provider_that_publishes_new_parameters_gets_a_new_invoker_for_the_same_call_url(): + published = URL.parse("tri://a:1/test.Greeter?zone=east") + calls = URL.parse("tri://a:1/test.Greeter") + snapshots = Latest() + snapshots.publish([calls.replace(attributes={PROVIDER_URL: published})]) + referred = [] + + async def refer(url): + invoker = _Invoker(url) + referred.append(invoker) + return invoker + + @asynccontextmanager + async def changing(): + yield aiter(snapshots) + + with anyio.fail_after(5): + async with DynamicDirectory(changing, refer, "test.Greeter") as directory: + snapshots.publish([calls.replace(attributes={PROVIDER_URL: published.update_parameters({"zone": "west"})})]) + await referred[0].closing.wait() + + assert directory.candidates(CALL) == (referred[1],) + assert referred[1].url.attributes[PROVIDER_URL].parameters["zone"] == "west" + + +async def test_a_router_that_fails_to_take_the_providers_leaves_each_invoker_closed(): + first, second = URL.parse("tri://a:1/test.Greeter"), URL.parse("tri://b:1/test.Greeter") + snapshots = Latest() + snapshots.publish([first]) + referred = [] + + async def refer(url): + invoker = _Invoker(url) + referred.append(invoker) + return invoker + + @asynccontextmanager + async def changing(): + yield aiter(snapshots) + + class Failing(Router): + def __init__(self): + self.notified = 0 + + def notify(self, invokers): + self.notified += 1 + if self.notified > 1: + raise ValueError("cannot take the providers") + + def route(self, invokers, invocation): + return invokers + + directory = DynamicDirectory(changing, refer, "test.Greeter", [Failing()]) + with anyio.fail_after(5): + await directory.__aenter__() + snapshots.publish([second]) + await referred[0].closing.wait() + with pytest.raises(ValueError, match="cannot take the providers"): + await directory.aclose() + + assert [invoker.closed for invoker in referred] == [True, True] + + +async def test_cancelling_an_update_closes_each_invoker_it_already_created(): + first, second = URL.parse("tri://a:1/test.Greeter"), URL.parse("tri://b:1/test.Greeter") + entering = anyio.Event() + referred = [] + + async def refer(url): + if url == second: + entering.set() + await anyio.sleep_forever() + invoker = _Invoker(url) + referred.append(invoker) + return invoker + + async def open_directory(): + async with DynamicDirectory(lambda: _fixed([first, second]), refer, "test.Greeter"): + pytest.fail("the update finished before cancellation") + + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + tasks.start_soon(open_directory) + await entering.wait() + tasks.cancel_scope.cancel() + + assert [(invoker.url, invoker.closed) for invoker in referred] == [(first, True)] + + +async def test_ended_subscriptions_resume_without_recreating_unchanged_invokers(monkeypatch): + monkeypatch.setattr("dubbo.utils.async_.backoff", lambda: itertools.repeat(0)) + first, second = URL.parse("tri://a:1/test.Greeter"), URL.parse("tri://b:1/test.Greeter") + subscriptions = 0 + referred = [] + resumed = anyio.Event() + + @asynccontextmanager + async def subscribe(): + nonlocal subscriptions + subscriptions += 1 + + async def snapshots(): + yield [first] if subscriptions == 1 else [first, second] + if subscriptions > 1: + resumed.set() + await anyio.sleep_forever() + + yield snapshots() + + async def refer(url): + invoker = _Invoker(url) + referred.append(invoker) + return invoker + + with anyio.fail_after(5): + async with DynamicDirectory(subscribe, refer, "test.Greeter") as directory: + await resumed.wait() + assert directory.candidates(CALL) == tuple(referred) + assert [invoker.url for invoker in referred] == [first, second] + assert not any(invoker.closed for invoker in referred) + + assert subscriptions == 2 + + +async def test_the_first_subscription_failure_reaches_the_caller_unchanged(): + failure = ConnectionError("unreachable") + + @asynccontextmanager + async def subscribe(): + raise failure + yield + + async def refer(url): + return _Invoker(url) + + with pytest.raises(ConnectionError, match="unreachable") as caught: + async with DynamicDirectory(subscribe, refer, "test.Greeter"): + pass + + assert caught.value is failure diff --git a/tests/unit/cluster/directory/test_static.py b/tests/unit/cluster/directory/test_static.py new file mode 100644 index 00000000..8790a70e --- /dev/null +++ b/tests/unit/cluster/directory/test_static.py @@ -0,0 +1,62 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import pytest + +from dubbo import Invocation, Invoker, Result +from dubbo.cluster import StaticDirectory +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +async def test_a_static_directory_closes_every_invoker_when_closing_one_is_cancelled(provider): + first, last = provider("a"), provider("b") + + class Cancelling(Invoker): + url = URL(protocol="tri", host="cancelling") + + async def invoke(self, invocation: Invocation) -> Result: + return Result() + + async def aclose(self) -> None: + scope.cancel() + await anyio.sleep_forever() + + with anyio.fail_after(5), anyio.CancelScope() as scope: + await StaticDirectory([first, Cancelling(), last]).aclose() + + assert (first.closed, last.closed) == (True, True) + + +async def test_a_static_directory_closes_every_invoker_when_closing_one_raises(provider): + first, last = provider("a"), provider("b") + + class Failing(Invoker): + url = URL(protocol="tri", host="failing") + + async def invoke(self, invocation: Invocation) -> Result: + return Result() + + async def aclose(self) -> None: + raise OSError("cannot close") + + with pytest.raises(OSError, match="cannot close"): + await StaticDirectory([first, Failing(), last]).aclose() + + assert (first.closed, last.closed) == (True, True) diff --git a/tests/unit/cluster/loadbalance/conftest.py b/tests/unit/cluster/loadbalance/conftest.py new file mode 100644 index 00000000..1cf70e46 --- /dev/null +++ b/tests/unit/cluster/loadbalance/conftest.py @@ -0,0 +1,39 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import random + +import pytest + + +@pytest.fixture +def invokers(provider): + def create(*queries: str, port: int = 50051): + return tuple( + provider(f"10.0.0.{index}", query=query.removeprefix("?"), port=port) + for index, query in enumerate(queries, 1) + ) + + return create + + +@pytest.fixture(autouse=True) +def random_state(): + state = random.getstate() + random.seed(7) + yield + random.setstate(state) diff --git a/tests/unit/cluster/loadbalance/data/consistenthash.json b/tests/unit/cluster/loadbalance/data/consistenthash.json new file mode 100644 index 00000000..f0e1b78d --- /dev/null +++ b/tests/unit/cluster/loadbalance/data/consistenthash.json @@ -0,0 +1,26 @@ +{ + "": { + "alice": "1", + "bob": "1", + "carol": "2", + "dave": "1", + "erin": "3", + "frank": "3", + "42": "2", + "7": "3", + "x": "2", + "": "1" + }, + "?hash.nodes=8": { + "alice": "1", + "bob": "2", + "carol": "3", + "dave": "1", + "erin": "1", + "frank": "1", + "42": "2", + "7": "3", + "x": "3", + "": "2" + } +} diff --git a/tests/unit/cluster/loadbalance/data/consistenthash.md b/tests/unit/cluster/loadbalance/data/consistenthash.md new file mode 100644 index 00000000..3ae4eddf --- /dev/null +++ b/tests/unit/cluster/loadbalance/data/consistenthash.md @@ -0,0 +1,13 @@ +# Consistent-hash assignments + +Migrated unchanged from `tests/test_loadbalance.py` at the `baseline` commit. +That test records Dubbo for Go's +`cluster/loadbalance/consistenthashing/selector.go` as the generator. +The baseline does not record a peer version or generation command; neither +has been reconstructed here. These are recorded regression assignments, +not evidence of a newly executed Go or Java interoperability run. + +Provider addresses: `10.0.0.1:20880`, `10.0.0.2:20880`, `10.0.0.3:20880`. +Arguments consisting only of digits are integers; the other arguments are +strings. The empty key is the empty string. Queries select the default +160 ring points per provider or eight points per provider. diff --git a/tests/unit/cluster/loadbalance/test_base.py b/tests/unit/cluster/loadbalance/test_base.py new file mode 100644 index 00000000..b890d83f --- /dev/null +++ b/tests/unit/cluster/loadbalance/test_base.py @@ -0,0 +1,144 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +from types import SimpleNamespace + +import pytest + +from dubbo.cluster import LoadBalance +from dubbo.cluster.loadbalance import base +from dubbo.cluster.loadbalance.base import PerSequence, Weights +from dubbo.cluster.loadbalance.consistenthash import ConsistentHashLoadBalance +from dubbo.cluster.loadbalance.leastactive import LeastActiveLoadBalance +from dubbo.cluster.loadbalance.random import RandomLoadBalance +from dubbo.cluster.loadbalance.roundrobin import RoundRobinLoadBalance +from dubbo.extension import extensions +from dubbo.url import URL + + +@pytest.mark.parametrize( + ("name", "implementation"), + [ + ("random", RandomLoadBalance), + ("roundrobin", RoundRobinLoadBalance), + ("leastactive", LeastActiveLoadBalance), + ("consistenthash", ConsistentHashLoadBalance), + ], + ids=["random", "roundrobin", "leastactive", "consistenthash"], +) +def test_load_balances_are_installed(name, implementation): + assert extensions.get(LoadBalance, name) is implementation + + +def test_per_sequence_keeps_what_it_derived_for_the_last_four_sequences_used(invokers): + derived: list[tuple[int, str]] = [] + + def derive(sequence, method): + derived.append((len(sequence), method)) + return len(derived) + + kept = PerSequence(derive) + sequences = [invokers(*[""] * size) for size in range(1, 6)] + + firsts = [kept.get(sequence, "greet") for sequence in sequences[:4]] + again = [kept.get(sequence, "greet") for sequence in reversed(sequences[:4])] + kept.get(sequences[4], "greet") + evicted = kept.get(sequences[3], "greet") + other = kept.get(sequences[0], "other") + + assert (firsts, again) == ([1, 2, 3, 4], [4, 3, 2, 1]) + assert (evicted, other) == (6, 7) + assert derived[4:] == [(5, "greet"), (4, "greet"), (1, "other")] + + +@pytest.mark.parametrize( + ("query", "now", "expected"), + [ + ("?timestamp=1000&warmup=10000", 6.0, [50]), + ("?timestamp=1000&warmup=10000&weight=10", 1.5, [1]), + ("?timestamp=9000", 1.0, [1]), + ("?timestamp=1000&warmup=10000", 11.0, [100]), + ("", 6.0, [100]), + ("?timestamp=9000&warmup=0", 1.0, [100]), + ], + ids=["half-warm", "at-least-one", "clock-behind", "warmup-finished", "no-timestamp", "no-warmup-clock-behind"], +) +def test_weights_increase_with_uptime_until_warmup_finishes(query, now, expected, monkeypatch, invokers): + monkeypatch.setattr(base, "time", SimpleNamespace(time=lambda: now)) + + assert Weights().get(invokers(query), "greet") == expected + + +def test_invalid_weights_use_the_default_and_log_a_warning(invokers, caplog): + values = Weights().get(invokers("?weight=heavy", "?weight=100"), "greet") + + assert values == [100, 100] + assert [(record.name, record.levelno) for record in caplog.records] == [ + ("dubbo.cluster.loadbalance.base", logging.WARNING) + ] + + +def test_weights_reuse_the_same_list_until_the_provider_sequence_changes(invokers): + weights = Weights() + first, second = invokers("?weight=1", "?weight=2"), invokers("?weight=1", "?weight=2") + + initial = weights.get(first, "greet") + assert weights.get(first, "greet") is initial + changed = weights.get(second, "greet") + + assert initial == changed == [1, 2] + assert changed is not initial + assert weights.get(second, "greet") is changed + + +def test_weights_are_recomputed_for_the_same_providers_while_they_warm_up(monkeypatch, invokers): + now = [1.0] + monkeypatch.setattr(base, "time", SimpleNamespace(time=lambda: now[0])) + weights = Weights() + providers = invokers("?timestamp=1000&warmup=10000", "") + initial = weights.get(providers, "greet") + + now[0] = 6.0 + warming = weights.get(providers, "greet") + now[0] = 11.0 + warmed = weights.get(providers, "greet") + + assert (initial, warming, warmed) == ([1, 100], [50, 100], [100, 100]) + assert weights.get(providers, "greet") is warmed + + +def test_a_warming_provider_reads_its_settings_once_for_the_same_providers(monkeypatch, invokers): + now = [1.0] + monkeypatch.setattr(base, "time", SimpleNamespace(time=lambda: now[0])) + read: list[str] = [] + get_parameter = URL.get_parameter + + def counted(self, key, *args): + read.append(key) + return get_parameter(self, key, *args) + + monkeypatch.setattr(URL, "get_parameter", counted) + weights = Weights() + providers = invokers("?timestamp=1000&warmup=10000") + weights.get(providers, "greet") + first = len(read) + + now[0] = 6.0 + warming = weights.get(providers, "greet") + + assert (warming, len(read)) == ([50], first) diff --git a/tests/unit/cluster/loadbalance/test_consistenthash.py b/tests/unit/cluster/loadbalance/test_consistenthash.py new file mode 100644 index 00000000..a77120da --- /dev/null +++ b/tests/unit/cluster/loadbalance/test_consistenthash.py @@ -0,0 +1,94 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import json +from pathlib import Path + +import attrs +import pytest + +from dubbo.cluster import LoadBalance +from dubbo.cluster.loadbalance.consistenthash import ConsistentHashLoadBalance +from dubbo.rpc.invocation import Invoker +from dubbo.url import URL + + +@pytest.fixture +def providers(invokers): + return invokers("", "", "", port=20880) + + +@pytest.fixture +def hashed(providers, call): + def select(load_balance: LoadBalance, *arguments: object, candidates: tuple[Invoker, ...] = providers) -> str: + chosen = load_balance.select(candidates, attrs.evolve(call, arguments=arguments)) + + return str(chosen.url.host)[-1] + + return select + + +@pytest.mark.parametrize("query", ["", "?hash.nodes=8"], ids=["default-nodes", "eight-nodes"]) +def test_consistent_hash_preserves_the_recorded_dubbo_key_assignments(query, hashed): + cases = json.loads((Path(__file__).parent / "data" / "consistenthash.json").read_text())[query] + load_balance = ConsistentHashLoadBalance(URL.parse(f"consumer://h/test.Greeter{query}")) + + chosen = {argument: hashed(load_balance, int(argument) if argument.isdigit() else argument) for argument in cases} + + assert chosen == cases + + +@pytest.mark.parametrize( + ("query", "arguments", "key"), + [ + ("?hash.arguments=1", ("ignored", "alice"), ("alice",)), + ("?hash.arguments=0,1,5", ("al", "ice"), ("alice",)), + ("?greet.hash.arguments=1", ("x", "bob"), ("bob",)), + ("?hash.arguments=-1", ("alice",), ()), + ("", (None,), ("null",)), + ("", (True,), ("true",)), + ], + ids=["second-argument", "joined-and-out-of-range", "method-override", "negative-index", "null", "boolean"], +) +def test_consistent_hash_builds_the_key_from_the_selected_arguments(query, arguments, key, hashed): + selected = ConsistentHashLoadBalance(URL.parse(f"consumer://h/test.Greeter{query}")) + default = ConsistentHashLoadBalance(URL(protocol="consumer")) + + assert hashed(selected, *arguments) == hashed(default, *key) + + +def test_consistent_hash_moves_only_the_keys_of_a_provider_that_leaves(hashed, providers): + load_balance = ConsistentHashLoadBalance(URL(protocol="consumer")) + keys = [f"key{index}" for index in range(300)] + before = {key: hashed(load_balance, key) for key in keys} + + after = {key: hashed(load_balance, key, candidates=providers[:2]) for key in keys} + + assert {key: host for key, host in before.items() if host != "3"} == { + key: host for key, host in after.items() if before[key] != "3" + } + assert set(after.values()) == {"1", "2"} + + +@pytest.mark.parametrize( + ("query", "message"), + [("?hash.nodes=3", "at least 4"), ("?greet.hash.nodes=0", "at least 4"), ("?hash.arguments=first", "first")], + ids=["too-few-nodes", "method-nodes", "non-integer-index"], +) +def test_consistent_hash_refuses_invalid_settings(query, message): + with pytest.raises(ValueError, match=message): + ConsistentHashLoadBalance(URL.parse(f"consumer://h/test.Greeter{query}")) diff --git a/tests/unit/cluster/loadbalance/test_leastactive.py b/tests/unit/cluster/loadbalance/test_leastactive.py new file mode 100644 index 00000000..41b353d1 --- /dev/null +++ b/tests/unit/cluster/loadbalance/test_leastactive.py @@ -0,0 +1,81 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections import Counter +from contextlib import ExitStack + +import pytest + +from dubbo.cluster.loadbalance.leastactive import LeastActiveLoadBalance +from dubbo.extension import ApplicationScope +from dubbo.filter.activecount import ActiveCounts +from dubbo.rpc.invocation import Invoker +from dubbo.url import APPLICATION_SCOPE, URL + + +def _least_active(counts: ActiveCounts) -> LeastActiveLoadBalance: + scope = ApplicationScope() + scope.state[ActiveCounts] = counts + return LeastActiveLoadBalance(URL(protocol="consumer", attributes={APPLICATION_SCOPE: scope})) + + +def _busy(stack: ExitStack, counts: ActiveCounts, provider: Invoker, calls: int, method: str = "greet") -> None: + for _ in range(calls): + stack.enter_context(counts.counting(provider.url, method)) + + +def test_least_active_chooses_the_provider_with_the_fewest_calls_under_way_whatever_the_weights(invokers, call): + with ExitStack() as stack: + counts = ActiveCounts() + providers = a, b, c = invokers("?weight=300", "?weight=100", "?weight=100") + _busy(stack, counts, a, 5) + _busy(stack, counts, b, 2) + _busy(stack, counts, c, 3) + _busy(stack, counts, b, 9, "other") + + assert _least_active(counts).select(providers, call) is b + _busy(stack, counts, b, 2) + assert _least_active(counts).select(providers, call) is c + + +def test_least_active_chooses_among_equally_busy_providers_in_proportion_to_their_weights(invokers, call): + with ExitStack() as stack: + counts = ActiveCounts() + providers = a, b, _, d = invokers("?weight=100", "?weight=300", "?weight=0", "?weight=100") + _busy(stack, counts, a, 2) + _busy(stack, counts, b, 2) + _busy(stack, counts, d, 3) + load_balance = _least_active(counts) + + chosen = Counter(load_balance.select(providers, call).url.host for _ in range(4000)) + + assert set(chosen) == {"10.0.0.1", "10.0.0.2"} + assert chosen["10.0.0.2"] / 4000 == pytest.approx(0.75, abs=0.03) + + +def test_least_active_chooses_among_providers_that_all_weigh_zero(invokers, call): + with ExitStack() as stack: + counts = ActiveCounts() + providers = a, b = invokers("?weight=0", "?weight=0") + _busy(stack, counts, a, 1) + + assert _least_active(counts).select(providers, call) is b + + +def test_least_active_needs_the_application_that_keeps_the_counts(): + with pytest.raises(RuntimeError, match="belongs to no application"): + LeastActiveLoadBalance(URL(protocol="consumer")) diff --git a/tests/unit/cluster/loadbalance/test_random.py b/tests/unit/cluster/loadbalance/test_random.py new file mode 100644 index 00000000..3994f0ca --- /dev/null +++ b/tests/unit/cluster/loadbalance/test_random.py @@ -0,0 +1,70 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections import Counter + +import pytest + +from dubbo.cluster.loadbalance.random import RandomLoadBalance +from dubbo.url import URL + + +def test_random_returns_a_single_provider_without_reading_its_weight(invokers, call, caplog): + providers = invokers("?weight=heavy") + + chosen = RandomLoadBalance(URL(protocol="consumer")).select(providers, call) + + assert chosen is providers[0] + assert caplog.records == [] + + +def test_random_uses_the_weight_of_the_called_method(invokers, call, invocation): + providers = invokers("?weight=100&greet.weight=0", "?weight=100") + load_balance = RandomLoadBalance(URL(protocol="consumer")) + + assert {load_balance.select(providers, call).url.host for _ in range(200)} == {"10.0.0.2"} + assert {load_balance.select(providers, invocation("other")).url.host for _ in range(200)} == { + "10.0.0.1", + "10.0.0.2", + } + + +@pytest.mark.parametrize( + ("queries", "share"), + [ + (("?weight=100", "?weight=300"), 0.75), + (("", "?weight=100"), 0.5), + (("?weight=0", "?weight=0"), 0.5), + ], + ids=["weighted", "equal-default", "all-zero"], +) +def test_random_selects_providers_in_proportion_to_their_weights(queries, share, invokers, call): + providers = invokers(*queries) + load_balance = RandomLoadBalance(URL(protocol="consumer")) + + counts = Counter(load_balance.select(providers, call).url.host for _ in range(4000)) + + assert counts["10.0.0.2"] / 4000 == pytest.approx(share, abs=0.03) + + +def test_random_never_selects_a_provider_of_weight_zero_beside_a_weighted_one(invokers, call): + providers = invokers("?weight=0", "") + load_balance = RandomLoadBalance(URL(protocol="consumer")) + + counts = Counter(load_balance.select(providers, call).url.host for _ in range(4000)) + + assert counts == {"10.0.0.2": 4000} diff --git a/tests/unit/cluster/loadbalance/test_roundrobin.py b/tests/unit/cluster/loadbalance/test_roundrobin.py new file mode 100644 index 00000000..21795af4 --- /dev/null +++ b/tests/unit/cluster/loadbalance/test_roundrobin.py @@ -0,0 +1,68 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.cluster import LoadBalance +from dubbo.cluster.loadbalance.roundrobin import RoundRobinLoadBalance +from dubbo.rpc.invocation import Invocation, Invoker +from dubbo.url import URL + + +def _turns(load_balance: LoadBalance, providers: tuple[Invoker, ...], times: int, call: Invocation) -> str: + # The provider at 10.0.0.1 is a, the one at 10.0.0.2 is b, and so on. + return "".join("abcdefgh"[int(str(load_balance.select(providers, call).url.host)[-1]) - 1] for _ in range(times)) + + +def test_round_robin_spreads_the_turns_of_heavier_providers_as_nginx_does(invokers, call): + providers = invokers("?weight=5", "?weight=1", "?weight=1") + + assert _turns(RoundRobinLoadBalance(URL(protocol="consumer")), providers, 14, call) == "aabacaa" * 2 + + +@pytest.mark.parametrize( + ("queries", "turns"), + [ + (("", "", ""), "abcabc"), + (("?weight=0", "", "?greet.weight=0"), "bbbbbb"), + (("?weight=0", "?weight=0"), "ababab"), + ], + ids=["equal-default-weights", "zero-method-and-provider-weights", "all-zero-weights"], +) +def test_round_robin_skips_providers_of_weight_zero_unless_all_weigh_zero(queries, turns, invokers, call): + load_balance = RoundRobinLoadBalance(URL(protocol="consumer")) + + assert _turns(load_balance, invokers(*queries), len(turns), call) == turns + + +def test_round_robin_keeps_the_turns_of_providers_while_the_invokers_change(invokers, call): + a, b, c = invokers("?weight=2", "?weight=1", "?weight=1") + load_balance = RoundRobinLoadBalance(URL(protocol="consumer")) + + assert _turns(load_balance, (a, b), 2, call) == "ab" + # a and b keep what they gained, 1 and -1, and c starts at none. + assert _turns(load_balance, (b, a, c), 4, call) == "acab" + + +def test_round_robin_spreads_each_set_of_providers_that_routing_alternates_between(invokers, call): + a, b, c, d = invokers("", "", "", "") + load_balance = RoundRobinLoadBalance(URL(protocol="consumer")) + sets = ((a, c), (b, d)) + + chosen = [load_balance.select(sets[index % 2], call) for index in range(8)] + + assert chosen == [a, b, c, d] * 2 diff --git a/tests/unit/cluster/router/conftest.py b/tests/unit/cluster/router/conftest.py new file mode 100644 index 00000000..826caabc --- /dev/null +++ b/tests/unit/cluster/router/conftest.py @@ -0,0 +1,55 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import AsyncIterator +from contextlib import asynccontextmanager + +import anyio +import pytest + +from dubbo.extension import ApplicationScope +from dubbo.url import APPLICATION_SCOPE, CONFIG_CENTER_URL, URL + + +@pytest.fixture +def provider(provider): + def create(host: str, query: str = "", port: int = 20880, app: str = "greeter"): + return provider(host, query=f"remote.application={app}&{query}", port=port) + + return create + + +@pytest.fixture +def routed(): + @asynccontextmanager + async def open_( + router: type, + consumer: str = "consumer://10.0.0.1/test.Greeter?application=web&version=1.0", + *, + center: bool = True, + ) -> AsyncIterator: + with anyio.fail_after(5): + async with ApplicationScope() as scope: + attributes: dict[str, object] = {APPLICATION_SCOPE: scope} + if center: + attributes[CONFIG_CENTER_URL] = URL(protocol="memory", attributes={APPLICATION_SCOPE: scope}) + url = URL.parse(consumer).replace(attributes=attributes) + + async with router(url) as routing: + yield routing + + return open_ diff --git a/tests/unit/cluster/router/test_chain.py b/tests/unit/cluster/router/test_chain.py new file mode 100644 index 00000000..a4a4e521 --- /dev/null +++ b/tests/unit/cluster/router/test_chain.py @@ -0,0 +1,93 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Sequence + +import attrs +import pytest + +from dubbo import Invocation, Invoker +from dubbo.cluster.router import RouterChain +from dubbo.extension import Resource + +pytestmark = pytest.mark.anyio + + +@attrs.define(kw_only=True) +class _Keeping(Resource): + hosts: set[str] + events: list[str] + name: str + told: list[tuple[str | None, ...]] = attrs.field(factory=list) + routed: list[tuple[str | None, ...]] = attrs.field(factory=list) + + def notify(self, invokers: Sequence[Invoker]) -> None: + self.told.append(tuple(invoker.url.host for invoker in invokers)) + + def route(self, invokers: Sequence[Invoker], invocation: Invocation) -> Sequence[Invoker]: + self.routed.append(tuple(invoker.url.host for invoker in invokers)) + kept = [invoker for invoker in invokers if invoker.url.host in self.hosts] + + return invokers if len(kept) == len(invokers) else kept + + async def aclose(self) -> None: + self.events.append(f"close {self.name}") + + async def __aenter__(self): + self.events.append(f"open {self.name}") + + return self + + +async def test_a_nested_router_chain_notifies_every_router_and_routes_in_order(provider, call): + a, b, c = provider("a"), provider("b"), provider("c") + first = _Keeping(hosts={"a", "b"}, events=[], name="first") + second = _Keeping(hosts={"b", "c"}, events=[], name="second") + + async with RouterChain([RouterChain([first]), second]) as chain: + chain.notify((a, b, c)) + result = chain.route((a, b, c), call) + + assert result == [b] + assert (first.told, second.told, first.routed, second.routed) == ( + [("a", "b", "c")], + [("a", "b", "c")], + [("a", "b", "c")], + [("a", "b")], + ) + + +async def test_a_router_chain_opens_in_order_and_closes_in_reverse(): + events = [] + first = _Keeping(hosts=set(), events=events, name="first") + second = _Keeping(hosts=set(), events=events, name="second") + + async with RouterChain([first, second]): + assert events == ["open first", "open second"] + + assert events == ["open first", "open second", "close second", "close first"] + + +@pytest.mark.parametrize("has_router", [False, True], ids=["empty-chain", "unchanged-by-router"]) +async def test_a_router_chain_preserves_the_candidate_sequence_when_no_provider_is_removed(has_router, provider, call): + providers = (provider("a"), provider("b")) + routers = [_Keeping(hosts={"a", "b"}, events=[], name="all")] if has_router else [] + + async with RouterChain(routers) as chain: + chain.notify(providers) + + assert chain.route(providers, call) is providers diff --git a/tests/unit/cluster/router/test_condition.py b/tests/unit/cluster/router/test_condition.py new file mode 100644 index 00000000..70068910 --- /dev/null +++ b/tests/unit/cluster/router/test_condition.py @@ -0,0 +1,268 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import json +import logging +import re + +import anyio +import attrs +import pytest + +from dubbo import Method, Parameter +from dubbo.cluster.router.condition import ConditionRouter +from dubbo.url import PROVIDER_URL, URL + +pytestmark = pytest.mark.anyio + +CONSUMER = "consumer://10.0.0.1/test.Greeter?application=web&version=1.0" + + +async def test_condition_rules_of_the_service_and_the_consumer_apply_in_turn( + config_store, provider, invocation, routed +): + a, b, c = provider("10.0.0.1"), provider("10.0.0.2", "zone=x"), provider("10.0.0.3", "zone=x") + providers = (a, b, c) + config_store.put("test.Greeter:1.0:.condition-router", "conditions: ['method = greet => zone = x']") + config_store.put("web.condition-router", "conditions: ['=> host != 10.0.0.3']") + + async with routed(ConditionRouter) as router: + router.notify(providers) + + assert router.route(providers, invocation()) == [b] + assert router.route(providers, invocation("other")) == [a, b] + + +async def test_a_condition_routes_to_the_same_sequence_while_the_providers_do_not_change( + config_store, provider, invocation, routed +): + a, b, c = provider("10.0.0.1"), provider("10.0.0.2", "zone=x"), provider("10.0.0.3", "zone=x") + providers = (a, b, c) + config_store.put("test.Greeter:1.0:.condition-router", "conditions: ['method = greet => zone = x']") + + async with routed(ConditionRouter) as router: + router.notify(providers) + first = router.route(providers, invocation()) + other = router.route(providers, invocation("other")) + again = router.route(providers, invocation()) + changed = (a, b) + router.notify(changed) + after = router.route(changed, invocation()) + + assert (first, other, after) == ([b, c], providers, [b]) + assert again is first + + +async def test_a_condition_without_then_blocks_and_one_matching_nothing_keeps_unless_forced( + config_store, provider, invocation, routed +): + a = provider("10.0.0.1", "zone=x") + key = "test.Greeter:1.0:.condition-router" + config_store.put(key, "conditions: ['host = 10.0.0.1 => ', 'method = greet => zone = y']") + + async with routed(ConditionRouter) as router: + assert router.route((a,), invocation()) == () + + config_store.put(key, "conditions: ['method = greet => zone = y']") + await anyio.wait_all_tasks_blocked() + assert router.route((a,), invocation()) == (a,) + + config_store.put(key, "force: true\nconditions: ['method = greet => zone = y']") + await anyio.wait_all_tasks_blocked() + assert router.route((a,), invocation()) == () + + +async def test_a_condition_rule_of_the_provider_application_follows_the_providers( + config_store, provider, invocation, routed +): + a, b = provider("10.0.0.1"), provider("10.0.0.2", "version=1.0") + config_store.put("greeter.condition-router", "conditions: ['=> version = $version & provider.host = 10.0.0.*']") + + async with routed(ConditionRouter) as router: + router.notify((a, b)) + await anyio.wait_all_tasks_blocked() + + assert router.route((a, b), invocation()) == [b] + + +async def test_the_rules_of_provider_applications_route_to_the_same_sequence_while_the_providers_do_not_change( + config_store, provider, invocation, routed +): + a, b, c = provider("10.0.0.1"), provider("10.0.0.2", "zone=x"), provider("10.0.0.3", app="other") + providers = (a, b, c) + config_store.put("greeter.condition-router", "conditions: ['=> zone = x']") + + async with routed(ConditionRouter) as router: + router.notify(providers) + await anyio.wait_all_tasks_blocked() + first = router.route(providers, invocation()) + again = router.route(providers, invocation()) + + assert first == [b, c] + assert again is first + + +async def test_the_condition_rule_of_each_provider_application_routes_its_own_providers( + config_store, provider, invocation, routed +): + a1, a2 = provider("10.0.0.1"), provider("10.0.0.2") + b1, b2 = provider("10.0.0.3", app="other"), provider("10.0.0.4", app="other") + c1 = provider("10.0.0.5", app="third") + providers = (a1, a2, b1, b2, c1) + config_store.put("greeter.condition-router", "conditions: ['=> host = 10.0.0.1']") + config_store.put("other.condition-router", "conditions: ['=> host = 10.0.0.4']") + + async with routed(ConditionRouter) as router: + router.notify(providers) + await anyio.wait_all_tasks_blocked() + + assert router.route(providers, invocation()) == [a1, b2, c1] + + # Another order of the same providers keeps the rules, even before anything is read. + router.notify(providers[::-1]) + assert router.route(providers, invocation()) == [a1, b2, c1] + + # The rules of an application without providers stop applying. + router.notify((b1, b2)) + await anyio.wait_all_tasks_blocked() + assert router.route(providers, invocation()) == [a1, a2, b2, c1] + + +async def test_a_v3_1_condition_goes_to_one_destination_by_weight(config_store, provider, invocation, routed): + a, b = provider("10.0.0.1", "zone=x"), provider("10.0.0.2", "zone=y") + config_store.put( + "web.condition-router", + "configVersion: v3.1\nconditions:\n" + " - from: {match: 'attachments[user] = 1~9'}\n" + " to: [{match: 'zone = x', weight: 1}, {match: 'zone = z'}]\n" + " - from: {match: 'method = block'}\n" + " to: []\n", + ) + + async with routed(ConditionRouter) as router: + assert router.route((a, b), invocation(user="5")) == [a] + assert router.route((a, b), invocation(user="10")) == (a, b) + assert router.route((a, b), invocation("block")) == () + + +async def test_condition_values_match_as_dubbo_globs_ranges_values_of_the_reference_and_argument_text( + config_store, provider, invocation, routed +): + a, b, c = provider("10.0.0.1", "zone=x1"), provider("10.0.0.2", "zone=y1"), provider("10.0.0.3", "zone=u[12]") + providers = (a, b, c) + key = "test.Greeter:1.0:.condition-router" + long_number = attrs.evolve( + invocation(), + definition=Method(name="greet", request=(Parameter(name="number", type=str),), response=None), + arguments=("9" * 5000,), + ) + + async with routed(ConditionRouter, f"{CONSUMER}&zone=x*") as router: + for condition, call, routed in [ + ("=> zone = $zone", invocation(), [a]), + ("=> zone = u[12]", invocation(), [c]), + ("=> zone = *1", invocation(), [a, b]), + ("host = $host => zone = y1", invocation(), providers), + ("arguments[0] = 1~9 => zone = y1", long_number, providers), + ("arguments[0] = true => zone = y1", invocation(arguments=(True,)), [b]), + ("arguments[0] = null => zone = y1", invocation(arguments=(None,)), [b]), + ]: + config_store.put(key, f"force: true\nconditions: ['{condition}']") + await anyio.wait_all_tasks_blocked() + assert list(router.route(providers, call)) == list(routed), condition + + +async def test_a_condition_names_providers_by_what_they_published_not_by_the_settings_of_the_calls( + config_store, provider, invocation, routed +): + def called(host: str, zone: str): + # The URL a consumer of zone hz calls with, whose parameters replace those the provider published. + published = URL.parse(f"tri://{host}:20880/test.Greeter?zone={zone}") + remote = provider(host) + remote.url = published.update_parameters({"zone": "hz"}).replace(attributes={PROVIDER_URL: published}) + + return remote + + near, far = called("10.0.0.1", "hz"), called("10.0.0.2", "sh") + config_store.put("test.Greeter:1.0:.condition-router", "force: true\nconditions: ['=> zone = $zone']") + + async with routed(ConditionRouter, f"{CONSUMER}&zone=hz") as router: + assert list(router.route((near, far), invocation())) == [near] + + +@pytest.mark.parametrize( + ("data", "message"), + [ + ({"conditions": ["= 1 => zone = x"]}, "cannot read '= 1'"), + ({"conditions": ["host = 1 => &"]}, "cannot read ''"), + ({"conditions": ["=> zone = x,,y"]}, "cannot read 'zone = x,,y'"), + ({"conditions": ["=> port = ~"]}, "has no bound"), + ({"conditions": [{"to": [{"match": "zone = x", "weight": 0}]}]}, "must be positive"), + ({"conditions": ["=> zone = x", " "]}, "must not be blank"), + ], + ids=[ + "missing-match-key", + "empty-provider-clause", + "empty-alternative", + "unbounded-range", + "nonpositive-destination-weight", + "blank-condition", + ], +) +async def test_condition_router_logs_malformed_rules_and_keeps_the_previous_rule( + data, message, config_store, provider, invocation, routed, caplog +): + key = "test.Greeter:1.0:.condition-router" + a, b = provider("10.0.0.1"), provider("10.0.0.2") + config_store.put(key, "force: true\nconditions: ['=> host = 10.0.0.1']") + + async with routed(ConditionRouter) as router: + config_store.put(key, json.dumps(data)) + await anyio.wait_all_tasks_blocked() + result = router.route((a, b), invocation()) + + assert result == [a] + [record] = caplog.records + assert (record.name, record.levelno, record.args[0], record.exc_info) == ( + "dubbo.cluster.rule", + logging.WARNING, + key, + None, + ) + assert re.search(message, str(record.args[1])) + + +@pytest.mark.parametrize( + "data", + [ + {"enabled": False, "conditions": ["=> zone = x"]}, + {"enabled": False, "conditions": ["host = => zone = x"]}, + {"conditions": []}, + ], + ids=["disabled", "disabled-malformed", "empty"], +) +async def test_disabled_or_empty_condition_rules_leave_all_candidates( + data, config_store, provider, invocation, routed, caplog +): + config_store.put("test.Greeter:1.0:.condition-router", json.dumps(data)) + providers = (provider("10.0.0.1"),) + + async with routed(ConditionRouter) as router: + result = router.route(providers, invocation()) + + assert result is providers + assert caplog.records == [] diff --git a/tests/unit/cluster/router/test_tag.py b/tests/unit/cluster/router/test_tag.py new file mode 100644 index 00000000..e7440e25 --- /dev/null +++ b/tests/unit/cluster/router/test_tag.py @@ -0,0 +1,269 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging + +import anyio +import attrs +import pytest + +from dubbo.cluster.router.tag import TagRouter +from dubbo.constants import FORCE_TAG_KEY, TAG_KEY +from dubbo.url import PROVIDER_URL, URL + +pytestmark = pytest.mark.anyio + +CONSUMER = "consumer://10.0.0.1/test.Greeter?application=web&version=1.0" + + +async def test_a_tag_goes_to_its_providers_and_else_to_the_untagged(provider, invocation, routed): + gray, plain, blue = provider("a", f"{TAG_KEY}=gray"), provider("b"), provider("c", f"{TAG_KEY}=blue") + providers = (gray, plain, blue) + + async with routed(TagRouter, center=False) as router: + router.notify(providers) + + assert router.route(providers, invocation(**{TAG_KEY: "gray"})) == [gray] + assert router.route(providers, invocation()) == [plain] + assert router.route(providers, invocation(**{TAG_KEY: "red"})) == [plain] + assert router.route(providers, invocation(**{TAG_KEY: "red", FORCE_TAG_KEY: "true"})) == [] + assert router.route(providers, invocation(**{TAG_KEY: "*"})) is providers + + async with routed(TagRouter, f"{CONSUMER}&{TAG_KEY}=blue", center=False) as router: + assert router.route(providers, invocation()) == [blue] + + +async def test_a_tag_routes_to_the_same_sequence_until_the_providers_or_the_rules_change( + config_store, provider, invocation, routed +): + a, b, c = provider("10.0.0.1", f"{TAG_KEY}=gray"), provider("10.0.0.2"), provider("10.0.0.3") + providers = (a, b, c) + + async with routed(TagRouter) as router: + router.notify(providers) + await anyio.wait_all_tasks_blocked() + gray = router.route(providers, invocation(**{TAG_KEY: "gray"})) + again = router.route(providers, invocation(**{TAG_KEY: "gray"})) + untagged = router.route(providers, invocation()) + + config_store.put("greeter.tag-router", "tags: [{name: gray, addresses: ['10.0.0.2']}]") + await anyio.wait_all_tasks_blocked() + ruled = router.route(providers, invocation(**{TAG_KEY: "gray"})) + moved = router.route(list(providers), invocation()) + + assert again is gray + assert (gray, untagged, ruled, moved) == ([a], [b, c], [b], [c]) + + +async def test_a_tag_rule_of_the_provider_application_tags_providers_by_address( + config_store, provider, invocation, routed +): + a, b, c = provider("10.0.0.1"), provider("10.0.0.2"), provider("10.0.0.3", port=20881) + providers = (a, b, c) + config_store.put( + "greeter.tag-router", + "force: false\ntags:\n" + " - {name: gray, addresses: ['10.0.0.1:20880']}\n" + " - {name: gray|canary, addresses: ['10.0.0.2-3']}\n", + ) + + async with routed(TagRouter) as router: + router.notify(providers) + await anyio.wait_all_tasks_blocked() + + assert router.route(providers, invocation(**{TAG_KEY: "gray"})) == [a] + assert router.route(providers, invocation(**{TAG_KEY: "gray|canary|x"})) == [b, c] + # Providers a rule tags are not untagged. + assert router.route(providers, invocation()) == [] + + config_store.put("greeter.tag-router", None) + await anyio.wait_all_tasks_blocked() + assert router.route(providers, invocation()) is providers + + +async def test_the_tag_rules_of_several_applications_tag_their_own_providers_and_route_together( + config_store, provider, invocation, routed +): + a1, a2 = provider("10.0.0.1"), provider("10.0.0.2") + b1, b2 = provider("10.0.0.3", app="other"), provider("10.0.0.4", app="other") + providers = (a1, a2, b1, b2) + # The address of b2 in the rule of greeter tags no provider of other. + config_store.put("greeter.tag-router", "tags: [{name: gray, addresses: ['10.0.0.1:20880', '10.0.0.4:20880']}]") + config_store.put( + "other.tag-router", + "force: true\ntags: [{name: gray, addresses: ['10.0.0.3']}, {name: blue, addresses: ['10.0.0.9']}]", + ) + + async with routed(TagRouter) as router: + router.notify(providers) + await anyio.wait_all_tasks_blocked() + + assert router.route(providers, invocation(**{TAG_KEY: "gray"})) == [a1, b1] + assert router.route(providers, invocation()) == [a2, b2] + # A tag of a forced rule that tags no provider keeps its calls. + assert router.route(providers, invocation(**{TAG_KEY: "blue"})) == [] + + +async def test_a_v3_tag_rule_tags_providers_by_parameters_and_a_forced_rule_keeps_its_tag( + config_store, provider, invocation, routed +): + a, b = provider("10.0.0.1", "env=gray"), provider("10.0.0.2", "env=prod") + config_store.put( + "greeter.tag-router", + "configVersion: v3.0\nforce: true\ntags:\n" + " - {name: gray, match: [{key: env, value: {exact: gray}}]}\n" + " - {name: blue, addresses: ['192.168.0.0/16']}\n", + ) + + async with routed(TagRouter) as router: + router.notify((a, b)) + await anyio.wait_all_tasks_blocked() + + assert router.route((a, b), invocation(**{TAG_KEY: "gray"})) == [a] + assert router.route((a, b), invocation(**{TAG_KEY: "blue"})) == [] + assert router.route((a, b), invocation()) == [b] + + +async def test_an_unreadable_rule_is_logged_and_the_one_before_stays( + config_store, caplog, provider, invocation, routed +): + a, b = provider("10.0.0.1"), provider("10.0.0.2") + config_store.put("greeter.tag-router", "tags: [{name: gray, addresses: ['10.0.0.1']}]") + + async with routed(TagRouter) as router: + router.notify((a, b)) + await anyio.wait_all_tasks_blocked() + with caplog.at_level(logging.WARNING): + config_store.put("greeter.tag-router", "tags: [{addresses: ['10.0.0.2']}]") + await anyio.wait_all_tasks_blocked() + + assert router.route((a, b), invocation(**{TAG_KEY: "gray"})) == [a] + [record] = caplog.records + assert (record.name, record.levelno, record.args[0], record.exc_info) == ( + "dubbo.cluster.rule", + logging.WARNING, + "greeter.tag-router", + None, + ) + assert "needs a name" in str(record.args[1]) + + +async def test_tag_rules_select_the_providers_their_addresses_match(config_store, provider, invocation, routed): + inside, outside = provider("10.0.9.3"), provider("10.0.9.6") + config_store.put("greeter.tag-router", "force: true\ntags: [{name: gray, addresses: ['10.0.*.1-5']}]") + + async with routed(TagRouter) as router: + router.notify((inside, outside)) + await anyio.wait_all_tasks_blocked() + + assert router.route((inside, outside), invocation(**{TAG_KEY: "gray"})) == [inside] + + +async def test_tag_rules_list_providers_by_exact_addresses_as_by_any_pattern( + config_store, provider, invocation, routed +): + providers = ( + provider("10.0.0.1"), + provider("10.0.0.1", port=20881), + provider("10.0.0.2"), + provider("fe80::1"), + provider("fe80::1", port=20881), + ) + patterns = ["10.0.0.1", "10.0.0.1:20881", "10.0.0.2:020880", "[fe80::1]:20881", "fe80:0::1", "10.0.0.1-1"] + tags = ", ".join(f"{{name: t{index}, addresses: ['{pattern}']}}" for index, pattern in enumerate(patterns)) + config_store.put("greeter.tag-router", f"force: true\ntags: [{tags}]") + + async with routed(TagRouter) as router: + router.notify(providers) + await anyio.wait_all_tasks_blocked() + routed_by = [ + list(router.route(providers, invocation(**{TAG_KEY: f"t{index}"}))) for index in range(len(patterns)) + ] + + assert routed_by == [ + [providers[0], providers[1]], + [providers[1]], + [], + [providers[4]], + [providers[3], providers[4]], + [providers[0], providers[1]], + ] + + +async def test_a_malformed_tag_address_is_logged_and_leaves_the_provider_untagged( + config_store, provider, invocation, routed, caplog +): + remote = provider("10.0.0.1", port=1) + config_store.put("greeter.tag-router", "force: true\ntags: [{name: gray, addresses: ['10.0.*']}]") + + async with routed(TagRouter) as router: + router.notify((remote,)) + await anyio.wait_all_tasks_blocked() + selected = router.route((remote,), invocation(**{TAG_KEY: "gray"})) + assert router.route((remote,), invocation()) == (remote,) + + assert selected == [] + assert [(record.name, record.levelno) for record in caplog.records] == [ + ("dubbo.cluster.router.tag", logging.WARNING) + ] + + +@pytest.mark.parametrize("center", [False, True], ids=["by-parameter", "by-rules"]) +async def test_a_provider_has_the_tag_it_publishes_whatever_its_calls_set( + config_store, provider, invocation, routed, center +): + def calling(published: URL, **parameters: str): + return attrs.evolve( + provider("10.0.0.1"), + url=published.update_parameters(parameters).replace(attributes={PROVIDER_URL: published}), + ) + + plain = calling(URL.parse("tri://10.0.0.1:20880/test.Greeter?remote.application=greeter"), **{TAG_KEY: "blue"}) + blue = calling(URL.parse(f"tri://10.0.0.2:20880/test.Greeter?remote.application=greeter&{TAG_KEY}=blue")) + if center: + config_store.put("greeter.tag-router", "tags: [{name: red, addresses: ['10.0.0.9']}]") + + async with routed(TagRouter, center=center) as router: + router.notify((plain, blue)) + await anyio.wait_all_tasks_blocked() + + assert router.route((plain, blue), invocation(**{TAG_KEY: "blue", FORCE_TAG_KEY: "true"})) == [blue] + assert router.route((plain, blue), invocation()) == [plain] + + +async def test_a_v3_tag_rule_matches_the_parameters_a_provider_publishes(config_store, provider, invocation, routed): + published = URL.parse("tri://10.0.0.1:20880/test.Greeter?remote.application=greeter&application=greeter") + a = attrs.evolve( + provider("10.0.0.1"), + url=published.update_parameters({"application": "web"}).replace(attributes={PROVIDER_URL: published}), + ) + b = provider("10.0.0.2") + config_store.put( + "greeter.tag-router", + "configVersion: v3.0\ntags: [{name: gray, match: [{key: application, value: {exact: greeter}}]}]\n", + ) + + async with routed(TagRouter) as router: + router.notify((a, b)) + await anyio.wait_all_tasks_blocked() + + assert router.route((a, b), invocation(**{TAG_KEY: "gray"})) == [a] + + +def test_a_tag_router_refuses_a_force_of_the_reference_that_is_not_a_boolean(): + with pytest.raises(ValueError, match=FORCE_TAG_KEY): + TagRouter(URL.parse(f"{CONSUMER}&{FORCE_TAG_KEY}=maybe")) diff --git a/tests/unit/cluster/test_available.py b/tests/unit/cluster/test_available.py new file mode 100644 index 00000000..8073a3a6 --- /dev/null +++ b/tests/unit/cluster/test_available.py @@ -0,0 +1,50 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo import RpcError, Status + +pytestmark = pytest.mark.anyio + + +async def test_available_calls_only_the_first_available_provider(provider, open_cluster, call): + down, first, second = provider("down", up=False), provider("first"), provider("second") + + async with open_cluster("available", down, first, second) as cluster: + results = [await cluster.invoke(call) for _ in range(2)] + + assert ([result.value for result in results], down.calls, first.calls, second.calls) == ( + ["first", "first"], + 0, + 2, + 0, + ) + + +async def test_available_refuses_to_call_unavailable_providers(provider, open_cluster, call): + down = provider("down", up=False) + + async with open_cluster("available", down) as cluster: + result = await cluster.invoke(call) + + assert isinstance(result.error, RpcError) + assert (result.error.status, result.error.message, down.calls) == ( + Status.UNAVAILABLE, + "no provider of test.Greeter is available", + 0, + ) diff --git a/tests/unit/cluster/test_base.py b/tests/unit/cluster/test_base.py new file mode 100644 index 00000000..21c95c7b --- /dev/null +++ b/tests/unit/cluster/test_base.py @@ -0,0 +1,230 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Sequence +from contextlib import aclosing + +import attrs +import pytest + +from dubbo import Invocation, Invoker, Result, RpcError, Status +from dubbo.cluster import Cluster, LoadBalance, StaticDirectory, create_cluster +from dubbo.cluster.available import AvailableCluster +from dubbo.cluster.broadcast import BroadcastCluster +from dubbo.cluster.failback import FailbackCluster +from dubbo.cluster.failfast import FailfastCluster +from dubbo.cluster.failover import FailoverCluster +from dubbo.cluster.failsafe import FailsafeCluster +from dubbo.cluster.forking import ForkingCluster +from dubbo.extension import ExtensionError, extensions +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +@pytest.mark.parametrize("strategy", ["failfast", "failover"]) +async def test_a_cluster_without_providers_returns_unavailable(strategy, open_cluster, call): + async with open_cluster(strategy) as cluster: + result = await cluster.invoke(call) + + assert isinstance(result.error, RpcError) + assert (result.error.status, result.error.message) == ( + Status.UNAVAILABLE, + "no provider of test.Greeter is available", + ) + + +@pytest.mark.parametrize( + ("name", "implementation"), + [ + ("failfast", FailfastCluster), + ("failover", FailoverCluster), + ("available", AvailableCluster), + ("broadcast", BroadcastCluster), + ("failback", FailbackCluster), + ("failsafe", FailsafeCluster), + ("forking", ForkingCluster), + ], + ids=["failfast", "failover", "available", "broadcast", "failback", "failsafe", "forking"], +) +def test_cluster_strategies_are_installed(name, implementation): + assert extensions.get(Cluster, name) is implementation + + +async def test_closing_a_cluster_closes_its_directory_providers(provider, open_cluster): + first, second = provider("a"), provider("b") + + async with open_cluster("failfast", first, second): + assert (first.closed, second.closed) == (False, False) + + assert (first.closed, second.closed) == (True, True) + + +async def test_a_cluster_can_call_and_close_another_cluster(provider, unavailable, call): + down, up = provider("a", unavailable), provider("b", Result(value="ok")) + inner = await create_cluster(URL.parse("consumer://h/test.Greeter?cluster=failfast"), StaticDirectory([down])) + + async with aclosing( + await create_cluster( + URL.parse("consumer://h/test.Greeter?cluster=failover&loadbalance=roundrobin"), StaticDirectory([inner, up]) + ) + ) as outer: + result = await outer.invoke(call) + + assert (result, down.calls, up.calls, down.closed, up.closed) == (Result(value="ok"), 1, 1, True, True) + + +@pytest.mark.parametrize("strategy", ["failfast", "failover"]) +async def test_a_cluster_calls_an_available_provider_before_an_unavailable_one(strategy, provider, open_cluster, call): + down, up = provider("down", up=False), provider("up") + + async with open_cluster(strategy, down, up) as cluster: + result = await cluster.invoke(call) + + assert (result.value, down.calls, up.calls) == ("up", 0, 1) + + +@pytest.mark.parametrize("strategy", ["failfast", "failover"]) +async def test_a_cluster_calls_an_unavailable_provider_when_none_is_available(strategy, provider, open_cluster, call): + first, second = provider("first", up=False), provider("second", up=False) + + async with open_cluster(strategy, first, second) as cluster: + result = await cluster.invoke(call) + + assert (result.value, first.calls, second.calls) == ("first", 1, 0) + + +async def test_a_cluster_asks_only_the_provider_it_chooses_whether_it_is_available(provider, open_cluster, call): + asked: list[str] = [] + + class Asked(type(provider("a"))): + @property + def available(self) -> bool: + asked.append(self.url.host) + return self.up + + providers = [Asked(url=provider(host).url, results=(Result(value=host),)) for host in "abcd"] + + async with open_cluster("failfast", *providers) as cluster: + result = await cluster.invoke(call) + + assert asked == [result.value] + + +async def test_a_cluster_passes_unchanged_candidates_to_its_load_balance(isolated_extensions, provider, call): + seen: list[Sequence[Invoker]] = [] + + class Recording: + def __init__(self, url: URL) -> None: + pass + + def select(self, invokers: Sequence[Invoker], invocation: Invocation) -> Invoker: + seen.append(invokers) + return invokers[0] + + extensions.register(LoadBalance, "recording", Recording) + directory = StaticDirectory([provider("a"), provider("b")]) + + async with aclosing( + await create_cluster(URL.parse("consumer://h/test.Greeter?cluster=failfast&loadbalance=recording"), directory) + ) as cluster: + await cluster.invoke(call) + await cluster.invoke(call) + + assert seen[0] is seen[1] is directory.candidates(call) + + +async def test_a_cluster_reports_the_availability_of_its_directory(provider, open_cluster): + remote = provider("a") + + async with open_cluster("failfast", remote) as cluster: + assert cluster.available is True + remote.up = False + assert cluster.available is False + + +async def test_create_cluster_opens_the_strategy_named_by_the_url(provider): + remote = provider("a") + + async with aclosing( + await create_cluster(URL.parse("consumer://h/test.Greeter?cluster=failfast"), StaticDirectory([remote])) + ) as cluster: + assert isinstance(cluster, FailfastCluster) + assert remote.closed is False + + assert remote.closed is True + + +async def test_create_cluster_closes_its_directory_when_the_strategy_cannot_be_loaded(provider): + orphaned = provider("a") + + with pytest.raises(ExtensionError, match="'nope'"): + await create_cluster(URL.parse("consumer://h/test.Greeter?cluster=nope"), StaticDirectory([orphaned])) + + assert orphaned.closed is True + + +async def test_a_method_uses_its_own_load_balance(isolated_extensions, provider, open_cluster, call, invocation): + @attrs.define(kw_only=True) + class Picking: + index: int + + def select(self, invokers: Sequence[Invoker], invocation: Invocation) -> Invoker: + return invokers[self.index] + + extensions.register(LoadBalance, "first", lambda url: Picking(index=0)) + extensions.register(LoadBalance, "last", lambda url: Picking(index=-1)) + first, last = provider("a"), provider("b") + + async with open_cluster("failfast", first, last, query="loadbalance=first&greet.loadbalance=last") as cluster: + await cluster.invoke(call) + await cluster.invoke(invocation("other")) + + assert (first.calls, last.calls) == (1, 1) + + +async def test_a_sticky_reference_calls_the_provider_it_called_last(provider, open_cluster, call): + first, second = provider("a"), provider("b") + + async with open_cluster("failfast", first, second, query="sticky=true") as cluster: + for _ in range(3): + await cluster.invoke(call) + + assert (first.calls, second.calls) == (3, 0) + + +async def test_a_sticky_reference_moves_on_when_its_provider_becomes_unavailable(provider, open_cluster, call): + first, second = provider("a"), provider("b") + + async with open_cluster("failfast", first, second, query="sticky=true") as cluster: + await cluster.invoke(call) + first.up = False + await cluster.invoke(call) + first.up = True + await cluster.invoke(call) + + assert (first.calls, second.calls) == (1, 2) + + +async def test_a_method_is_sticky_on_its_own(provider, open_cluster, call, invocation): + first, second = provider("a"), provider("b") + + async with open_cluster("failfast", first, second, query="greet.sticky=true") as cluster: + results = [(await cluster.invoke(call)).value for _ in range(2)] + others = [(await cluster.invoke(invocation("other"))).value for _ in range(2)] + + assert (results, sorted(others)) == (["a", "a"], ["a", "b"]) diff --git a/tests/unit/cluster/test_broadcast.py b/tests/unit/cluster/test_broadcast.py new file mode 100644 index 00000000..8f3529f4 --- /dev/null +++ b/tests/unit/cluster/test_broadcast.py @@ -0,0 +1,73 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo import Result, RpcError, Status + +pytestmark = pytest.mark.anyio + + +async def test_broadcast_calls_every_provider_and_returns_the_last_result(provider, open_cluster, call): + first, middle, last = provider("a"), provider("b"), provider("c") + + async with open_cluster("broadcast", first, middle, last) as cluster: + result = await cluster.invoke(call) + + assert (result, first.calls, middle.calls, last.calls) == (Result(value="c"), 1, 1, 1) + + +async def test_broadcast_calls_every_provider_and_returns_the_last_failure(provider, open_cluster, call): + failed = Result(error=RpcError(Status.INVALID_ARGUMENT, "bad")) + first = provider("a", Result(error=RpcError(Status.UNAVAILABLE, "down"))) + middle, last = provider("b", failed), provider("c") + + async with open_cluster("broadcast", first, middle, last) as cluster: + result = await cluster.invoke(call) + + assert (result, first.calls, middle.calls, last.calls) == (failed, 1, 1, 1) + + +@pytest.mark.parametrize( + ("percent", "calls"), + [("50", [1, 1, 0, 0]), ("0", [1, 1, 1, 1]), ("100", [1, 1, 1, 1])], + ids=["half", "zero-means-all", "all"], +) +async def test_broadcast_stops_when_the_configured_share_of_providers_has_failed( + percent, calls, provider, unavailable, open_cluster, call +): + providers = [provider(host, unavailable) for host in "abcd"] + + async with open_cluster("broadcast", *providers, query=f"broadcast.fail.percent={percent}") as cluster: + result = await cluster.invoke(call) + + assert (result, [remote.calls for remote in providers]) == (unavailable, calls) + + +async def test_broadcast_refuses_a_failure_share_above_one_hundred(open_cluster): + with pytest.raises(ValueError, match="between 0 and 100"): + async with open_cluster("broadcast", query="broadcast.fail.percent=101"): + pass + + +async def test_broadcast_opens_a_stream_on_one_provider(provider, open_cluster, streaming_call): + first, second = provider("a"), provider("b") + + async with open_cluster("broadcast", first, second) as cluster: + result = await cluster.invoke(streaming_call) + + assert (result, first.calls, second.calls) == (Result(value="a"), 1, 0) diff --git a/tests/unit/cluster/test_configurator.py b/tests/unit/cluster/test_configurator.py new file mode 100644 index 00000000..6db4a34c --- /dev/null +++ b/tests/unit/cluster/test_configurator.py @@ -0,0 +1,289 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import json +import logging +import re +from collections.abc import AsyncIterator +from contextlib import asynccontextmanager + +import anyio +import pytest + +from dubbo.cluster.configurator import Overrides +from dubbo.extension import ApplicationScope +from dubbo.registry.consumer import Consumer +from dubbo.url import APPLICATION_SCOPE, CONFIG_CENTER_URL, URL + +pytestmark = pytest.mark.anyio + +REFERENCE = "consumer://10.0.0.9/test.Greeter?application=web&version=1.0" +A = URL.parse("tri://10.0.0.1:20880/test.Greeter?application=web&version=1.0&timeout=1000") +B = URL.parse("tri://10.0.0.2:20880/test.Greeter?application=web&version=1.0&timeout=1000") + + +@asynccontextmanager +async def _reference() -> AsyncIterator[URL]: + with anyio.fail_after(5): + async with ApplicationScope() as scope: + center = URL(protocol="memory", attributes={APPLICATION_SCOPE: scope}) + yield URL.parse(REFERENCE).replace(attributes={APPLICATION_SCOPE: scope, CONFIG_CENTER_URL: center}) + + +_MATCH = { + "address": "{cird: '10.0.0.0/24'}", + "providerAddress": "{wildcard: '10.0.0.2*'}", + "service": "{oneof: [{exact: 'test.Greeter:1.0'}]}", + "application": "{oneof: [{prefix: 'we'}]}", + "param": "[{key: timeout, value: {exact: '1000'}}]", +} + + +def _timeouts(urls: list[URL]) -> list[str | None]: + return [url.parameters.get("timeout") for url in urls] + + +async def test_overrides_of_the_service_win_over_those_of_the_application_and_specific_hosts_over_any(config_store): + config_store.put( + "web.configurators", + "scope: application\nkey: web\nconfigs:\n" + " - {side: consumer, addresses: ['10.0.0.9'], parameters: {timeout: 3000}}\n" + " - {side: consumer, addresses: ['0.0.0.0'], parameters: {timeout: 2000, retries: 5}}\n" + " - {side: provider, parameters: {weight: 1}}\n", + ) + config_store.put( + "test.Greeter:1.0:.configurators", + "scope: service\nkey: test.Greeter:1.0\nconfigs:\n" + " - {side: consumer, providerAddresses: ['10.0.0.2:20880'], parameters: {timeout: 4000}}\n", + ) + + async with _reference() as url, Overrides(url, "consumer") as overrides: + a, b = overrides.configure([A, B]) + + assert (a.parameters["timeout"], a.parameters["retries"], b.parameters["timeout"]) == ("3000", "5", "4000") + assert "weight" not in a.parameters + + +async def test_overrides_for_other_consumers_services_or_applications_change_nothing(config_store): + config_store.put( + "web.configurators", + "scope: application\nkey: web\nconfigs:\n" + " - {side: consumer, addresses: ['10.0.0.8'], parameters: {timeout: 1}}\n" + " - {side: consumer, services: [test.Other], parameters: {timeout: 2}}\n", + ) + config_store.put( + "test.Greeter:1.0:.configurators", + "scope: service\nkey: test.Greeter:1.0\nenabled: true\nconfigs:\n" + " - {side: consumer, applications: [mobile], parameters: {timeout: 3}}\n", + ) + + async with _reference() as url, Overrides(url, "consumer") as overrides: + assert _timeouts(overrides.configure([A, B])) == ["1000", "1000"] + + +async def test_a_reference_calls_its_providers_again_with_the_overrides_that_change(config_store): + @asynccontextmanager + async def fixed() -> AsyncIterator[AsyncIterator[list[URL]]]: + async def snapshots() -> AsyncIterator[list[URL]]: + yield [A] + await anyio.sleep_forever() + + yield snapshots() + + consumer = Consumer(interface="test.Greeter", group=None, version="1.0", parameters={"application": "web"}) + async with _reference() as url, consumer.watch(fixed(), url) as watched: + assert _timeouts(await anext(watched)) == ["1000"] + + config_store.put( + "web.configurators", "scope: application\nkey: web\nconfigs: [{side: consumer, parameters: {timeout: 9}}]" + ) + with anyio.fail_after(5): + assert _timeouts(await anext(watched)) == ["9"] + + +def _match_rule(match: dict[str, str]) -> str: + return ( + "configVersion: v3.0\nscope: service\nkey: test.Greeter:1.0\nconfigs:\n" + " - side: consumer\n parameters: {timeout: 5}\n match:\n" + + "".join(f" {name}: {value}\n" for name, value in match.items()) + ) + + +async def test_a_config_applies_to_the_urls_its_match_takes_in(config_store): + config_store.put("test.Greeter:1.0:.configurators", _match_rule(_MATCH)) + + async with _reference() as url, Overrides(url, "consumer") as overrides: + assert _timeouts(overrides.configure([A, B])) == ["1000", "5"] + + +@pytest.mark.parametrize( + "mismatch", + [ + {"address": "{exact: '10.0.0.8'}"}, + {"service": "{oneof: [{exact: test.Other}]}"}, + {"app": "{oneof: [{exact: mobile}]}"}, + {"param": "[{key: timeout, value: {exact: '9'}}]"}, + ], + ids=["different-consumer-address", "different-service", "different-application", "different-parameter"], +) +async def test_a_config_leaves_out_the_urls_one_part_of_its_match_does_not_take_in(config_store, mismatch): + config_store.put("test.Greeter:1.0:.configurators", _match_rule({**_MATCH, **mismatch})) + + async with _reference() as url, Overrides(url, "consumer") as overrides: + assert _timeouts(overrides.configure([A, B])) == ["1000", "1000"] + + +async def test_an_empty_match_takes_in_every_url(config_store): + config_store.put( + "web.configurators", + "configVersion: v3.0\nscope: application\nkey: web\nconfigs:\n" + " - {side: consumer, match: {}, parameters: {timeout: 7}}\n", + ) + + async with _reference() as url, Overrides(url, "consumer") as overrides: + assert _timeouts(overrides.configure([A, B])) == ["7", "7"] + + +async def test_overrides_disable_providers_and_enable_those_registered_disabled(config_store): + off = URL.parse("tri://10.0.0.3:20880/test.Greeter?version=1.0&disabled=true") + plain = URL.parse("tri://10.0.0.4:20880/test.Greeter?version=1.0&disabled=false&enabled=false") + + @asynccontextmanager + async def fixed() -> AsyncIterator[AsyncIterator[list[URL]]]: + async def snapshots() -> AsyncIterator[list[URL]]: + yield [A, B, off, plain] + await anyio.sleep_forever() + + yield snapshots() + + consumer = Consumer(interface="test.Greeter", group=None, version="1.0", parameters={"application": "web"}) + async with _reference() as url, consumer.watch(fixed(), url) as watched: + # disabled, when set, wins over enabled. + assert [found.host for found in await anext(watched)] == ["10.0.0.1", "10.0.0.2", "10.0.0.4"] + + config_store.put( + "web.configurators", + "scope: application\nkey: web\nconfigs:\n" + " - {side: consumer, providerAddresses: ['10.0.0.1:20880'], parameters: {disabled: true}}\n" + " - {side: consumer, providerAddresses: ['10.0.0.3'], parameters: {disabled: false}}\n", + ) + with anyio.fail_after(5): + assert [found.host for found in await anext(watched)] == ["10.0.0.2", "10.0.0.3", "10.0.0.4"] + + +@pytest.mark.parametrize( + ("address", "timeouts"), + [("[::1]:20880", ["9", "1000"]), ("[::1]", ["9", "9"]), ("0.0.0.0:20880", ["9", "1000"]), ("*", ["9", "9"])], + ids=["ipv6-port", "ipv6", "any-host", "any"], +) +async def test_overrides_apply_to_the_provider_addresses_they_list(address, timeouts, config_store): + v6 = URL.parse("tri://[::1]:20880/test.Greeter?application=web&version=1.0&timeout=1000") + config_store.put( + "web.configurators", + "scope: application\nkey: web\n" + f"configs: [{{side: consumer, providerAddresses: ['{address}'], parameters: {{timeout: 9}}}}]", + ) + + async with _reference() as url, Overrides(url, "consumer") as overrides: + configured = overrides.configure([v6, v6.replace(port=20881)]) + + assert _timeouts(configured) == timeouts + + +async def test_provider_overrides_apply_to_the_url_a_provider_registers_at_its_host(config_store): + config_store.put( + "web.configurators", + "scope: application\nkey: web\nconfigs:\n" + " - {side: provider, addresses: ['10.0.0.1'], parameters: {weight: 50}}\n" + " - {side: consumer, parameters: {timeout: 1}}\n", + ) + + async with _reference() as reference: + for provider, weight in ((A, "50"), (B, None)): + url = provider.replace(attributes=reference.attributes) + async with Overrides(url, "provider") as overrides: + (configured,) = overrides.configure([url]) + assert (configured.parameters.get("weight"), configured.parameters["timeout"]) == (weight, "1000") + + +@pytest.mark.parametrize( + ("data", "message"), + [ + ({"configs": []}, "needs a key"), + ({"key": "web", "configs": [{"side": "consumer"}]}, "needs parameters"), + ( + {"key": "web", "configs": [{"side": "consumer", "match": {"address": "*"}, "parameters": {"a": 1}}]}, + "address", + ), + ( + { + "key": "web", + "configs": [{"side": "consumer", "match": {"param": [{"value": {}}]}, "parameters": {"a": 1}}], + }, + "needs a key", + ), + ], + ids=["missing-rule-key", "missing-parameters", "nonmapping-address-match", "missing-parameter-match-key"], +) +async def test_overrides_log_malformed_rules_and_keep_the_previous_parameters(data, message, config_store, caplog): + config_store.put( + "web.configurators", "scope: application\nkey: web\nconfigs: [{side: consumer, parameters: {timeout: 7}}]" + ) + + async with _reference() as url, Overrides(url, "consumer") as overrides: + config_store.put("web.configurators", json.dumps(data)) + await anyio.wait_all_tasks_blocked() + configured = overrides.configure([A, B]) + + assert _timeouts(configured) == ["7", "7"] + [record] = caplog.records + assert (record.name, record.levelno, record.args[0], record.exc_info) == ( + "dubbo.cluster.rule", + logging.WARNING, + "web.configurators", + None, + ) + assert re.search(message, str(record.args[1])) + + +async def test_overrides_log_an_unparsable_rule_without_its_text(config_store, caplog): + async with _reference() as url, Overrides(url, "consumer") as overrides: + config_store.put("web.configurators", "key: web\nconfigs: [{parameters: {token: rv08demo}") + await anyio.wait_all_tasks_blocked() + configured = overrides.configure([A]) + + assert configured == [A] + assert [(record.levelno, record.exc_info) for record in caplog.records] == [(logging.WARNING, None)] + assert "rv08demo" not in caplog.text + + +@pytest.mark.parametrize( + ("side", "data"), + [ + ("consumer", {"enabled": False, "configs": [{"side": "consumer", "parameters": {"timeout": 1}}]}), + ("consumer", {"configs": [{"side": "provider", "parameters": {"weight": 1}}]}), + ("provider", {"configs": [{"side": "consumer", "parameters": {"timeout": 1}}]}), + ], + ids=["disabled", "provider-rule-at-consumer", "consumer-rule-at-provider"], +) +async def test_disabled_rules_and_rules_for_the_other_side_leave_urls_unchanged(side, data, config_store): + config_store.put("web.configurators", json.dumps({"scope": "application", "key": "web", **data})) + + async with _reference() as url, Overrides(url, side) as overrides: + configured = overrides.configure([A, B]) + + assert configured == [A, B] diff --git a/tests/unit/cluster/test_failback.py b/tests/unit/cluster/test_failback.py new file mode 100644 index 00000000..7e438362 --- /dev/null +++ b/tests/unit/cluster/test_failback.py @@ -0,0 +1,117 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging + +import anyio +import pytest + +from dubbo import RemoteError, Result +from dubbo.cluster import failback + +pytestmark = pytest.mark.anyio + + +@pytest.fixture +def retry_timer(monkeypatch): + monkeypatch.setattr(failback, "_RETRY_INTERVAL", 0) + + +async def test_failback_returns_nothing_and_retries_until_the_first_success( + retry_timer, provider, unavailable, open_cluster, call, caplog +): + remote = provider("a", unavailable, unavailable, Result(value="ok"), unavailable) + + async with open_cluster("failback", remote) as cluster: + assert await cluster.invoke(call) == Result() + await anyio.wait_all_tasks_blocked() + + assert remote.calls == 3 + assert [(record.name, record.levelno, record.exc_info[1]) for record in caplog.records] == [ + ("dubbo.cluster.failback", logging.WARNING, unavailable.error) + ] + + +async def test_failback_retries_on_a_different_candidate_than_the_last( + retry_timer, provider, unavailable, open_cluster, call +): + down, up = provider("a", unavailable), provider("b", Result(value="ok")) + + async with open_cluster("failback", down, up) as cluster: + result = await cluster.invoke(call) + await anyio.wait_all_tasks_blocked() + + assert (result, down.calls, up.calls) == (Result(), 1, 1) + + +@pytest.mark.parametrize( + ("query", "calls", "levels"), + [ + ("", 4, [logging.WARNING, logging.ERROR]), + ("retries=1", 2, [logging.WARNING, logging.ERROR]), + ("retries=0", 1, [logging.WARNING]), + ], + ids=["default", "one-retry", "no-retry"], +) +async def test_failback_drops_a_call_after_its_retry_budget( + retry_timer, query, calls, levels, provider, unavailable, open_cluster, call, caplog +): + remote = provider("a", unavailable) + + async with open_cluster("failback", remote, query=query) as cluster: + assert await cluster.invoke(call) == Result() + await anyio.wait_all_tasks_blocked() + + assert remote.calls == calls + assert [record.levelno for record in caplog.records] == levels + + +@pytest.mark.parametrize("streaming", [False, True], ids=["remote-exception", "failed-stream-opening"]) +async def test_failback_does_not_retry_a_method_exception_or_stream_opening( + streaming, provider, unavailable, open_cluster, call, streaming_call +): + failed = unavailable if streaming else Result(error=RemoteError("java.lang.IllegalStateException", "bad")) + remote = provider("a", failed) + + async with open_cluster("failback", remote) as cluster: + result = await cluster.invoke(streaming_call if streaming else call) + await anyio.wait_all_tasks_blocked() + + assert (result, remote.calls) == (failed, 1) + + +async def test_failback_drops_overflow_and_cancels_queued_retries_when_closed( + provider, unavailable, open_cluster, call, caplog +): + remote = provider("a", unavailable) + + async with open_cluster("failback", remote, query="failbacktasks=1") as cluster: + assert await cluster.invoke(call) == Result() + assert await cluster.invoke(call) == Result() + + assert (remote.calls, remote.closed) == (2, True) + assert [(record.name, record.levelno) for record in caplog.records] == [ + ("dubbo.cluster.failback", logging.WARNING), + ("dubbo.cluster.failback", logging.ERROR), + ] + + +@pytest.mark.parametrize("query", ["retries=-1", "failbacktasks=0"], ids=["negative-retries", "no-queue-capacity"]) +async def test_failback_refuses_invalid_retry_settings(query, open_cluster): + with pytest.raises(ValueError, match="retries must not be negative and failbacktasks must be positive"): + async with open_cluster("failback", query=query): + pass diff --git a/tests/unit/cluster/test_failfast.py b/tests/unit/cluster/test_failfast.py new file mode 100644 index 00000000..861a9072 --- /dev/null +++ b/tests/unit/cluster/test_failfast.py @@ -0,0 +1,29 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +pytestmark = pytest.mark.anyio + + +async def test_failfast_returns_the_failure_without_retrying(provider, unavailable, open_cluster, call): + failed = provider("a", unavailable) + + async with open_cluster("failfast", failed) as cluster: + result = await cluster.invoke(call) + + assert (result, failed.calls) == (unavailable, 1) diff --git a/tests/unit/cluster/test_failover.py b/tests/unit/cluster/test_failover.py new file mode 100644 index 00000000..d1e99209 --- /dev/null +++ b/tests/unit/cluster/test_failover.py @@ -0,0 +1,115 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import Sequence + +import attrs +import pytest + +from dubbo import Invocation, Invoker, Result, RpcError, Status +from dubbo.cluster.directory import Directory +from dubbo.cluster.failover import FailoverCluster +from dubbo.exceptions import RemoteError +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +async def test_failover_retries_an_unavailable_call_on_an_untried_provider(provider, unavailable, open_cluster, call): + down, up = provider("a", unavailable), provider("b", Result(value="ok")) + + async with open_cluster("failover", down, up) as cluster: + result = await cluster.invoke(call) + + assert (result, down.calls, up.calls) == (Result(value="ok"), 1, 1) + + +@pytest.mark.parametrize( + "error", + [ + RpcError(Status.INVALID_ARGUMENT, "bad"), + RemoteError("org.apache.dubbo.rpc.RpcException", "down", status=Status.UNAVAILABLE), + ], + ids=["invalid-argument", "remote-exception"], +) +async def test_failover_returns_non_retryable_errors_once(error, provider, open_cluster, call): + failed = Result(error=error) + remote = provider("a", failed, Result(value="ok")) + + async with open_cluster("failover", remote) as cluster: + result = await cluster.invoke(call) + + assert (result, remote.calls) == (failed, 1) + + +@pytest.mark.parametrize( + ("query", "attempts"), + [("", 3), ("retries=0", 1), ("retries=4&greet.retries=1", 2)], + ids=["default", "no-retry", "method-override"], +) +async def test_failover_makes_retries_plus_one_attempts(query, attempts, provider, unavailable, open_cluster, call): + remote = provider("a", unavailable) + + async with open_cluster("failover", remote, query=query) as cluster: + result = await cluster.invoke(call) + + assert (result, remote.calls) == (unavailable, attempts) + + +async def test_failover_does_not_retry_opening_a_stream(provider, unavailable, open_cluster, streaming_call): + remote = provider("a", unavailable) + + async with open_cluster("failover", remote) as cluster: + result = await cluster.invoke(streaming_call) + + assert (result, remote.calls) == (unavailable, 1) + + +@attrs.define(kw_only=True) +class _Changing(Directory): + snapshots: tuple[tuple[Invoker, ...], ...] + asked: int = 0 + + def candidates(self, invocation: Invocation) -> Sequence[Invoker]: + self.asked += 1 + + return self.snapshots[min(self.asked, len(self.snapshots)) - 1] + + async def aclose(self) -> None: + for snapshot in self.snapshots: + for provider in snapshot: + await provider.aclose() + + +async def test_failover_retries_on_a_provider_that_joined_after_the_first_attempt(provider, unavailable, call): + down, joined = provider("a", unavailable), provider("b", Result(value="ok")) + cluster = FailoverCluster(URL(protocol="consumer"), _Changing(snapshots=((down,), (joined,)))) + + async with cluster: + result = await cluster.invoke(call) + + assert (result, down.calls, joined.calls) == (Result(value="ok"), 1, 1) + + +async def test_failover_returns_the_last_failure_when_every_provider_left_before_the_retry(provider, unavailable, call): + down = provider("a", unavailable) + cluster = FailoverCluster(URL(protocol="consumer"), _Changing(snapshots=((down,), ()))) + + async with cluster: + result = await cluster.invoke(call) + + assert (result, down.calls) == (unavailable, 1) diff --git a/tests/unit/cluster/test_failsafe.py b/tests/unit/cluster/test_failsafe.py new file mode 100644 index 00000000..fda3176e --- /dev/null +++ b/tests/unit/cluster/test_failsafe.py @@ -0,0 +1,51 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging + +import pytest + +from dubbo import RemoteError, Result, RpcError, Status + +pytestmark = pytest.mark.anyio + + +@pytest.mark.parametrize( + "error", + [RpcError(Status.UNAVAILABLE, "down"), RemoteError("java.lang.IllegalStateException", "bad")], + ids=["unavailable", "remote-exception"], +) +async def test_failsafe_logs_the_failure_and_returns_nothing(error, provider, open_cluster, call, caplog): + async with open_cluster("failsafe", provider("a", Result(error=error))) as cluster: + result = await cluster.invoke(call) + + assert result == Result() + assert [(record.name, record.levelno, record.exc_info[1]) for record in caplog.records] == [ + ("dubbo.cluster.failsafe", logging.WARNING, error) + ] + + +@pytest.mark.parametrize("streaming", [False, True], ids=["successful-unary", "failed-stream-opening"]) +async def test_failsafe_preserves_successes_and_stream_opening_failures( + streaming, provider, unavailable, open_cluster, call, streaming_call +): + expected = unavailable if streaming else Result(value="ok") + + async with open_cluster("failsafe", provider("a", expected)) as cluster: + result = await cluster.invoke(streaming_call if streaming else call) + + assert result is expected diff --git a/tests/unit/cluster/test_forking.py b/tests/unit/cluster/test_forking.py new file mode 100644 index 00000000..69df14d2 --- /dev/null +++ b/tests/unit/cluster/test_forking.py @@ -0,0 +1,124 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from contextlib import aclosing + +import anyio +import pytest + +from dubbo import Invocation, Invoker, RemoteError, Result, RpcError, Status +from dubbo.cluster import StaticDirectory, create_cluster +from dubbo.extension import ApplicationScope +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = pytest.mark.anyio + + +@pytest.mark.parametrize( + "answer", + [Result(value="ok"), Result(error=RemoteError("java.lang.IllegalStateException", "bad"))], + ids=["value", "remote-exception"], +) +async def test_forking_returns_the_first_answer_and_cancels_unanswered_calls( + answer, provider, unavailable, open_cluster, call +): + started, cancelled = anyio.Event(), anyio.Event() + + class Hanging(Invoker): + url = URL(protocol="tri", host="hanging") + + async def invoke(self, invocation: Invocation) -> Result: + started.set() + try: + await anyio.sleep_forever() + finally: + cancelled.set() + + async def aclose(self) -> None: + pass + + class Answering(Invoker): + url = URL(protocol="tri", host="answering") + + async def invoke(self, invocation: Invocation) -> Result: + await started.wait() + return answer + + async def aclose(self) -> None: + pass + + async with open_cluster( + "forking", Hanging(), provider("failed", unavailable), Answering(), query="forks=3" + ) as cluster: + result = await cluster.invoke(call) + + assert result is answer + assert cancelled.is_set() + + +async def test_forking_returns_the_last_failure_when_no_provider_answers(provider, unavailable, open_cluster, call): + failed = Result(error=RpcError(Status.INVALID_ARGUMENT, "bad")) + + async with open_cluster("forking", provider("a", unavailable), provider("b", failed)) as cluster: + result = await cluster.invoke(call) + + assert result is failed + + +@pytest.mark.parametrize( + ("query", "calls"), + [("", 2), ("forks=2", 2), ("forks=1", 1), ("forks=0", 4), ("forks=9", 4)], + ids=["default", "two", "one", "zero-means-all", "above-provider-count"], +) +async def test_forking_calls_the_configured_number_of_distinct_providers( + query, calls, provider, unavailable, open_cluster, call +): + providers = [provider(host, unavailable) for host in "abcd"] + + async with open_cluster("forking", *providers, query=query) as cluster: + result = await cluster.invoke(call) + + assert result is unavailable + assert sorted(remote.calls for remote in providers) == [0] * (4 - calls) + [1] * calls + + +async def test_forking_opens_a_stream_on_one_provider(provider, open_cluster, streaming_call): + first, second = provider("a"), provider("b") + + async with open_cluster("forking", first, second) as cluster: + result = await cluster.invoke(streaming_call) + + assert (result, first.calls, second.calls) == (Result(value="a"), 1, 0) + + +@pytest.mark.parametrize("load_balance", ["random", "roundrobin", "leastactive", "consistenthash"]) +async def test_forking_calls_distinct_providers_on_every_call_whatever_the_load_balance( + load_balance, provider, unavailable, call +): + providers = [ + provider(host, unavailable, query=f"weight={weight}") for host, weight in (("a", 1), ("b", 2), ("c", 3)) + ] + query = f"cluster=forking&forks=2&loadbalance={load_balance}" + + with anyio.fail_after(5): + async with ApplicationScope() as scope: + url = URL.parse(f"consumer://127.0.0.1/test.Greeter?{query}").replace(attributes={APPLICATION_SCOPE: scope}) + async with aclosing(await create_cluster(url, StaticDirectory(providers))) as cluster: + results = [await cluster.invoke(call) for _ in range(3)] + + assert results == [unavailable] * 3 + assert sum(remote.calls for remote in providers) == 6 diff --git a/tests/unit/cluster/test_zoneaware.py b/tests/unit/cluster/test_zoneaware.py new file mode 100644 index 00000000..85ff5199 --- /dev/null +++ b/tests/unit/cluster/test_zoneaware.py @@ -0,0 +1,87 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo import RpcError, Status + +pytestmark = pytest.mark.anyio + + +async def test_zone_aware_uses_the_preferred_registry_until_it_becomes_unavailable(provider, open_cluster, call): + other, preferred = provider("a"), provider("b", query="registry.preferred=true") + + async with open_cluster("zone-aware", other, preferred) as cluster: + assert (await cluster.invoke(call)).value == "b" + preferred.up = False + result = await cluster.invoke(call) + + assert (result.value, other.calls, preferred.calls) == ("a", 1, 1) + + +async def test_zone_aware_uses_the_registry_in_the_requested_zone(provider, open_cluster, invocation): + east, west = provider("east", query="registry.zone=east"), provider("west", query="registry.zone=west") + + async with open_cluster("zone-aware", east, west) as cluster: + result = await cluster.invoke(invocation(**{"registry.zone": "west"})) + + assert (result.value, east.calls, west.calls) == ("west", 0, 1) + + +async def test_zone_aware_falls_back_from_a_missing_zone(provider, open_cluster, invocation): + east = provider("east", query="registry.zone=east") + call = invocation(**{"registry.zone": "west", "registry.zone.force": "false"}) + + async with open_cluster("zone-aware", east) as cluster: + result = await cluster.invoke(call) + + assert (result.value, result.error, east.calls) == ("east", None, 1) + + +async def test_zone_aware_reports_a_missing_forced_zone_as_unavailable(provider, open_cluster, invocation): + east = provider("east", query="registry.zone=east") + call = invocation(**{"registry.zone": "west", "registry.zone.force": "true"}) + + async with open_cluster("zone-aware", east) as cluster: + result = await cluster.invoke(call) + + assert isinstance(result.error, RpcError) + assert (result.error.status, result.error.message, east.calls) == ( + Status.UNAVAILABLE, + "no provider of test.Greeter is available in zone west", + 0, + ) + + +async def test_zone_aware_skips_zero_weight_and_unavailable_registries(provider, open_cluster, call): + heavy, light, empty = provider("heavy"), provider("light", query="weight=0"), provider("empty", up=False) + + async with open_cluster("zone-aware", heavy, light, empty) as cluster: + results = [await cluster.invoke(call) for _ in range(3)] + + assert ([result.value for result in results], heavy.calls, light.calls, empty.calls) == (["heavy"] * 3, 3, 0, 0) + + +async def test_zone_aware_returns_unavailable_when_every_registry_is_empty(provider, open_cluster, call): + async with open_cluster("zone-aware", provider("a", up=False)) as cluster: + result = await cluster.invoke(call) + + assert isinstance(result.error, RpcError) + assert (result.error.status, result.error.message) == ( + Status.UNAVAILABLE, + "no provider of test.Greeter is available", + ) diff --git a/tests/unit/compression/test_base.py b/tests/unit/compression/test_base.py new file mode 100644 index 00000000..d7a6f9df --- /dev/null +++ b/tests/unit/compression/test_base.py @@ -0,0 +1,120 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import bz2 +import gzip +import os +import time +import zlib +from collections.abc import Callable + +import pytest + +from dubbo.compression import Compressor +from dubbo.compression.bzip2 import Bzip2Compressor +from dubbo.compression.deflate import DeflateCompressor +from dubbo.compression.gzip import GzipCompressor +from dubbo.extension import extensions +from dubbo.url import URL + +_URL = URL(protocol="tri") + + +_ROUND_TRIPS = [ + pytest.param(GzipCompressor, gzip.compress, gzip.decompress, id="gzip"), + pytest.param(DeflateCompressor, zlib.compress, zlib.decompress, id="deflate"), + pytest.param(Bzip2Compressor, bz2.compress, bz2.decompress, id="bzip2"), +] + + +_STANDARD_COMPRESSION = [ + pytest.param(GzipCompressor, gzip.compress, id="gzip"), + pytest.param(DeflateCompressor, zlib.compress, id="deflate"), + pytest.param(Bzip2Compressor, bz2.compress, id="bzip2"), +] + + +def test_compressors_are_named_by_their_encoding() -> None: + assert extensions.names(Compressor) == ["bzip2", "deflate", "gzip"] + assert extensions.get(Compressor, "gzip") is GzipCompressor + assert extensions.get(Compressor, "deflate") is DeflateCompressor + assert extensions.get(Compressor, "bzip2") is Bzip2Compressor + + +@pytest.mark.parametrize(("compressor", "compress", "decompress"), _ROUND_TRIPS) +def test_compressors_round_trip_their_standard_format( + compressor: type[Compressor], compress: Callable[[bytes], bytes], decompress: Callable[[bytes], bytes] +) -> None: + instance = compressor(_URL) + + assert instance.decompress(compress(b"hello"), 100) == b"hello" + assert instance.decompress(instance.compress(b"hello"), 100) == b"hello" + assert decompress(instance.compress(b"hello")) == b"hello" + + +@pytest.mark.parametrize(("compressor", "compress"), _STANDARD_COMPRESSION) +def test_decompress_stops_at_max_length(compressor: type[Compressor], compress: Callable[[bytes], bytes]) -> None: + assert compressor(_URL).decompress(compress(b"\0" * 1000), 10) == b"\0" * 10 + + +@pytest.mark.parametrize(("compressor", "compress"), _STANDARD_COMPRESSION) +def test_decompress_rejects_malformed_and_cut_short_data( + compressor: type[Compressor], compress: Callable[[bytes], bytes] +) -> None: + instance = compressor(_URL) + + with pytest.raises(ValueError, match="malformed"): + instance.decompress(b"not compressed", 100) + with pytest.raises(ValueError, match="cut short"): + instance.decompress(compress(b"hello")[:-4], 100) + + +def test_gzip_decompresses_every_member_of_a_message() -> None: + data = gzip.compress(b"first") + gzip.compress(b"last") + + assert GzipCompressor(_URL).decompress(data, 100) == b"firstlast" + + +def test_gzip_members_share_the_max_length() -> None: + data = gzip.compress(b"x" * 6) + gzip.compress(b"y" * 6) + + assert GzipCompressor(_URL).decompress(data, 8) == b"x" * 6 + b"y" * 2 + + +def test_gzip_rejects_a_cut_short_last_member() -> None: + data = gzip.compress(b"first") + gzip.compress(b"last")[:-4] + + with pytest.raises(ValueError, match="cut short"): + GzipCompressor(_URL).decompress(data, 100) + + +def test_gzip_decompresses_members_of_any_length_after_the_first() -> None: + long = os.urandom(100_000) + data = gzip.compress(b"first") + gzip.compress(long) + gzip.compress(b"last") + + assert GzipCompressor(_URL).decompress(data, 200_000) == b"first" + long + b"last" + with pytest.raises(ValueError, match="malformed"): + GzipCompressor(_URL).decompress(data + b"not compressed", 200_000) + + +def test_gzip_decompresses_many_members_in_linear_time() -> None: + data = gzip.compress(b"", mtime=0) * 200_000 + started = time.perf_counter() + + assert GzipCompressor(_URL).decompress(data, 100) == b"" + # Quadratic decompression takes about nine seconds here, linear a tenth of one. + assert time.perf_counter() - started < 3 diff --git a/tests/unit/config/parsers/test_base.py b/tests/unit/config/parsers/test_base.py new file mode 100644 index 00000000..69090fe9 --- /dev/null +++ b/tests/unit/config/parsers/test_base.py @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from dubbo.config import ConfigParser +from dubbo.extension import Extensions + + +def test_installed_json_parser_reads_configuration(): + parser = Extensions().get(ConfigParser, "json")() + + assert parser.loads('{"references": {"orders": {"timeout": 1500}}}') == { + "references": {"orders": {"timeout": 1500}} + } diff --git a/tests/unit/config/parsers/test_json.py b/tests/unit/config/parsers/test_json.py new file mode 100644 index 00000000..8a191b6d --- /dev/null +++ b/tests/unit/config/parsers/test_json.py @@ -0,0 +1,60 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import sys + +import pytest + +from dubbo.config import ConfigParseError +from dubbo.config.parsers.json import JsonParser + + +@pytest.mark.parametrize("text", ["[]", "null", "true", "123"]) +def test_json_requires_mapping(text): + with pytest.raises(ConfigParseError, match="mapping"): + JsonParser().loads(text) + + +def test_json_error_keeps_original_cause(): + with pytest.raises(ConfigParseError, match="invalid JSON configuration") as caught: + JsonParser().loads("{broken") + assert isinstance(caught.value.__cause__, ValueError) + + +@pytest.fixture +def integer_limit(): + previous = sys.get_int_max_str_digits() + sys.set_int_max_str_digits(640) + yield + sys.set_int_max_str_digits(previous) + + +def test_json_integer_limit_is_reported_as_a_parse_error(integer_limit): + text = '{"value": ' + "1" * 641 + "}" + + with pytest.raises(ConfigParseError, match="invalid JSON configuration") as caught: + JsonParser().loads(text) + + assert isinstance(caught.value.__cause__, ValueError) + + +def test_json_decoder_depth_limit_is_reported_as_a_parse_error(): + # Deeper than Python 3.14 parses too, which bounds the stack rather than the calls. + text = '{"value": ' + "[" * 1_000_000 + "0" + "]" * 1_000_000 + "}" + with pytest.raises(ConfigParseError, match="invalid JSON configuration") as caught: + JsonParser().loads(text) + assert isinstance(caught.value.__cause__, RecursionError) diff --git a/tests/unit/config/parsers/test_properties.py b/tests/unit/config/parsers/test_properties.py new file mode 100644 index 00000000..4aaefccb --- /dev/null +++ b/tests/unit/config/parsers/test_properties.py @@ -0,0 +1,89 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.config import ConfigParseError, ConfigParser, DubboConfig +from dubbo.config.structure import structure_config +from dubbo.extension import Extensions + + +def test_properties_nests_dotted_keys_and_keeps_strings_and_java_escapes(): + pytest.importorskip("dotproperties") + parser = Extensions().get(ConfigParser, "properties")() + assert parser.loads( + "application.name=orders\nprotocols.tri.port=1\nprotocols.tri.port=50051\napplication.version=\\u4F60\\u597D\n" + ) == { + "application": {"name": "orders", "version": "你好"}, + "protocols": {"tri": {"port": "50051"}}, + } + + +def test_properties_reports_an_invalid_java_escape(): + pytest.importorskip("dotproperties") + parser = Extensions().get(ConfigParser, "properties")() + + with pytest.raises(ConfigParseError, match="invalid properties configuration") as caught: + parser.loads("bad=\\uXYZZ") + assert isinstance(caught.value.__cause__, ValueError) + + +@pytest.mark.parametrize("text", ["a=1\na.b=2", "a.b=2\na=1", "a..b=1", ".a=1", "a.=1"]) +def test_properties_rejects_conflicting_or_empty_key_segments(text): + pytest.importorskip("dotproperties") + with pytest.raises(ConfigParseError, match="invalid properties key"): + Extensions().get(ConfigParser, "properties")().loads(text) + + +def test_properties_keeps_the_dots_of_a_bracketed_segment_so_a_service_is_named_whole(): + pytest.importorskip("dotproperties") + parser = Extensions().get(ConfigParser, "properties")() + + data = parser.loads( + "provider.services[com.example.Greeter].timeout=3000\n" + "provider.services.[com.example.Greeter].methods.greet.retries=1\n" + ) + config = structure_config(data, DubboConfig) + + assert data == { + "provider": {"services": {"com.example.Greeter": {"timeout": "3000", "methods": {"greet": {"retries": "1"}}}}} + } + greeter = config.provider.services["com.example.Greeter"] + assert (greeter.timeout, greeter.methods["greet"].retries) == (3000, 1) + + +@pytest.mark.parametrize("key", ["a[b", "a[]", "a]b", "a[b]c", "a.[b"]) +def test_properties_rejects_an_unclosed_or_empty_bracket(key): + pytest.importorskip("dotproperties") + with pytest.raises(ConfigParseError, match="invalid properties key"): + Extensions().get(ConfigParser, "properties")().loads(f"{key}=1") + + +def test_properties_reads_json_where_the_configuration_expects_a_list(): + pytest.importorskip("dotproperties") + parser = Extensions().get(ConfigParser, "properties")() + + data = parser.loads( + 'consumer.references[com.example.Echo].urls=["tri://127.0.0.1:50051"]\napplication.name=["a"]\n' + ) + + assert data == { + "consumer": {"references": {"com.example.Echo": {"urls": ["tri://127.0.0.1:50051"]}}}, + "application": {"name": '["a"]'}, + } + with pytest.raises(ConfigParseError, match=r"'consumer\.references\.com\.example\.Echo\.urls' must be JSON"): + parser.loads("consumer.references[com.example.Echo].urls=tri://127.0.0.1:50051") diff --git a/tests/unit/config/parsers/test_yaml.py b/tests/unit/config/parsers/test_yaml.py new file mode 100644 index 00000000..5978e40d --- /dev/null +++ b/tests/unit/config/parsers/test_yaml.py @@ -0,0 +1,87 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.config import ConfigParseError, ConfigParser +from dubbo.extension import Extensions + + +def test_yaml_reads_a_mapping(): + pytest.importorskip("yaml") + parser = Extensions().get(ConfigParser, "yaml")() + + assert parser.loads("application:\n name: orders\n") == {"application": {"name": "orders"}} + + +@pytest.mark.parametrize( + ("text", "message"), + [ + ("!!python/object/apply:builtins.str [123]", "invalid YAML configuration"), + ("1: value", "configuration keys must be strings, in the mapping at line 1"), + ("consumer:\n 1: value", "configuration keys must be strings, in the mapping at line 2"), + ("- item", "configuration must have a mapping at its root"), + ], + ids=["python-object", "non-string-key", "nested-non-string-key", "non-mapping-root"], +) +def test_yaml_rejects_content_outside_the_configuration_format(text, message): + pytest.importorskip("yaml") + parser = Extensions().get(ConfigParser, "yaml")() + + with pytest.raises(ConfigParseError, match=message): + parser.loads(text) + + +@pytest.mark.parametrize( + "text", + ["root: &r {child: *r}", "&r {child: *r}", "root: &r [*r]", "a: &a {child: &b {child: *a}}"], +) +def test_yaml_rejects_recursive_aliases_at_the_parser(text): + yaml = pytest.importorskip("yaml") + parser = Extensions().get(ConfigParser, "yaml")() + with pytest.raises(ConfigParseError, match="invalid YAML configuration") as caught: + parser.loads(text) + assert isinstance(caught.value.__cause__, yaml.YAMLError) + + +def test_yaml_accepts_shared_aliases_and_merge_keys(): + pytest.importorskip("yaml") + parser = Extensions().get(ConfigParser, "yaml")() + data = parser.loads("base: &b {timeout: 10}\ncopy: *b\nmerged: {<<: *b, retries: 2}") + assert data == { + "base": {"timeout": 10}, + "copy": {"timeout": 10}, + "merged": {"timeout": 10, "retries": 2}, + } + + +def test_yaml_counts_only_what_aliases_add_against_the_node_budget(): + pytest.importorskip("yaml") + parser = Extensions().get(ConfigParser, "yaml")() + services = {f"s{i}": {"timeout": 1, "weight": 2} for i in range(2000)} + + assert parser.loads("\n".join(f"{name}: {{timeout: 1, weight: 2}}" for name in services)) == services + + +def test_yaml_rejects_aliases_that_expand_past_the_node_budget(): + pytest.importorskip("yaml") + parser = Extensions().get(ConfigParser, "yaml")() + lines = ["a0: &a0 {x: 1, y: 1}"] + lines += [f"a{i}: &a{i} {{x: *a{i - 1}, y: *a{i - 1}}}" for i in range(1, 17)] + + with pytest.raises(ConfigParseError, match="aliases add more than"): + parser.loads("\n".join(lines)) diff --git a/tests/unit/config/test_fields.py b/tests/unit/config/test_fields.py new file mode 100644 index 00000000..9188f5c5 --- /dev/null +++ b/tests/unit/config/test_fields.py @@ -0,0 +1,65 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import attrs + +from dubbo.config.fields import to_url_parameters, url_nested, url_parameter +from dubbo.utils.converters import to_milliseconds + + +@attrs.define(frozen=True, kw_only=True) +class Layer: + timeout: float | None = attrs.field(default=None, metadata=url_parameter("timeout", to_milliseconds)) + check: bool | None = attrs.field(default=None, metadata=url_parameter("check")) + retries: int | None = attrs.field(default=None, metadata=url_parameter("retries", default=2)) + note: str | None = None + + +def test_declared_fields_layer_from_low_to_high_and_skip_unset_values(): + low = Layer(timeout=1, check=True, note="not a parameter") + high = Layer(timeout=2.5) + + assert to_url_parameters(low) == {"timeout": "1000", "check": "true", "retries": "2"} + assert to_url_parameters(low, high) == {"timeout": "2500", "check": "true", "retries": "2"} + assert to_url_parameters(Layer()) == {"retries": "2"} + + +def test_default_applies_only_when_no_layer_sets_the_field(): + assert to_url_parameters(Layer(retries=0), Layer())["retries"] == "0" + assert to_url_parameters(Layer(), Layer(retries=5))["retries"] == "5" + + +@attrs.define(frozen=True, kw_only=True) +class Outer: + retries: int | None = attrs.field(default=None, metadata=url_parameter("retries")) + inner: Layer = attrs.field(factory=Layer, metadata=url_nested()) + methods: dict[str, Layer] = attrs.field(factory=dict, metadata=url_nested()) + parameters: dict[str, str] = attrs.field(factory=dict, metadata=url_nested()) + + +def test_nested_configurations_join_layer_by_layer_and_override_extra_parameters(): + low = Outer(inner=Layer(timeout=1), methods={"get": Layer(check=True)}, parameters={"check": "x", "custom": "a"}) + high = Outer(retries=7, inner=Layer(timeout=2), parameters={"custom": "b"}) + + assert to_url_parameters(low, high) == { + "retries": "7", + "timeout": "2000", + "check": "x", + "custom": "b", + "get.check": "true", + "get.retries": "2", + } diff --git a/tests/unit/config/test_loading.py b/tests/unit/config/test_loading.py new file mode 100644 index 00000000..6c8b9612 --- /dev/null +++ b/tests/unit/config/test_loading.py @@ -0,0 +1,438 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import sys + +import pytest + +from dubbo import Dubbo +from dubbo.config import ( + ApplicationConfig, + ConfigCenterConfig, + ConfigError, + ConfigParseError, + ConfigParser, + ConfigReadError, + ConsumerConfig, + ProviderConfig, + RegistryConfig, + ServiceConfig, + TripleConfig, +) +from dubbo.config.loading import load_config +from dubbo.config.structure import unstructure_config +from dubbo.extension import ApplicationScope, extensions + +APP = {"application": {"name": "orders"}} +pytestmark = pytest.mark.anyio + + +@pytest.fixture +async def layered(tmp_path, monkeypatch): + path = tmp_path / "dubbo.json" + path.write_text( + '{"application": {"name": "orders", "version": "1"},' + ' "registries": {"default": {"address": "zookeeper://zk:2181", "use_as_config_center": false}},' + ' "consumer": {"timeout": 3, "retries": 2, "registries": ["default"]}}', + encoding="utf-8", + ) + monkeypatch.setenv("LAYER_TEST__CONSUMER__TIMEOUT", "1.5") + monkeypatch.setenv("LAYER_TEST__CONSUMER__REGISTRIES", "[]") + + return await _configure( + path, + {"application": {"version": "2"}}, + env_prefix="LAYER_TEST__", + consumer=ConsumerConfig(retries=5), + ) + + +async def test_a_later_source_overrides_only_the_fields_it_sets(layered): + assert layered.application == ApplicationConfig(name="orders", version="2") + assert layered.registries == {"default": RegistryConfig(address="zookeeper://zk:2181", use_as_config_center=False)} + + +async def test_environment_variables_override_the_sources_with_converted_values(layered): + assert (layered.consumer.timeout, layered.consumer.registries) == (1.5, ()) + + +async def test_code_overrides_the_sources(layered): + assert layered.consumer.retries == 5 + + +async def test_keyword_objects_keep_lower_values_for_unset_fields(): + source = { + **APP, + "registries": {"default": {"address": "zookeeper://zk:2181", "use_as_config_center": False}}, + "provider": {"group": "blue", "services": {"org.example.Users": {"timeout": 2}}}, + } + config = await _configure( + source, + registries={"backup": RegistryConfig(address="nacos://n:8848", use_as_config_center=False)}, + provider=ProviderConfig(timeout=3), + ) + assert set(config.registries) == {"default", "backup"} + assert config.provider == ProviderConfig( + group="blue", timeout=3, services={"org.example.Users": ServiceConfig(timeout=2)} + ) + + +async def test_triple_settings_nest_in_files_and_environment_variables(monkeypatch): + monkeypatch.setenv("NEST_TEST__CONSUMER__TRIPLE__COMPRESSOR", "gzip") + config = await _configure( + APP, + {"protocols": {"tri": {"name": "tri", "triple": {"health_enabled": "true", "keep_alive_interval": 30}}}}, + env_prefix="NEST_TEST__", + ) + + assert config.protocols["tri"].triple == TripleConfig(health_enabled=True, keep_alive_interval=30.0) + assert config.consumer.triple == TripleConfig(compressor="gzip") + + +async def test_files_select_parsers_by_suffix(tmp_path): + pytest.importorskip("yaml") + pytest.importorskip("dotproperties") + yaml_path = tmp_path / "dubbo.yml" + yaml_path.write_text("application:\n name: orders\n", encoding="utf-8") + properties_path = tmp_path / "dubbo.properties" + properties_path.write_text("consumer.check=off\n", encoding="utf-8") + + config = await _configure(str(yaml_path), properties_path) + assert (config.application.name, config.consumer.check) == ("orders", False) + + +async def test_files_use_parsers_registered_on_the_shared_extensions(tmp_path, isolated_extensions): + class UpperParser: + def loads(self, text): + return {"application": {"name": text.strip().upper()}} + + extensions.register(ConfigParser, "upper", UpperParser) + path = tmp_path / "dubbo.upper" + path.write_text("orders", encoding="utf-8") + assert (await _configure(path)).application.name == "ORDERS" + + +async def test_a_file_whose_suffix_names_no_installed_parser_cannot_be_read(tmp_path): + unknown = tmp_path / "dubbo.ini" + unknown.write_text("", encoding="utf-8") + + with pytest.raises(ConfigReadError, match="parser 'ini'"): + await _configure(unknown) + + +async def test_a_file_without_a_suffix_cannot_be_read(tmp_path): + with pytest.raises(ConfigReadError, match="has no suffix"): + await _configure(tmp_path / "dubbo") + + +async def test_a_file_invalid_in_its_format_cannot_be_parsed(tmp_path): + broken = tmp_path / "broken.json" + broken.write_text("{", encoding="utf-8") + + with pytest.raises(ConfigParseError, match=r"invalid JSON configuration in '.*broken\.json'"): + await _configure(broken) + + +async def test_env_nests_paths_and_converts_scalar_fields(monkeypatch): + monkeypatch.setenv("ENV_TEST__APPLICATION__NAME", "orders") + monkeypatch.setenv("ENV_TEST__PROTOCOLS__TRI__PORT", "50051") + + config = await _configure(env_prefix="ENV_TEST__") + + assert config.protocols["tri"].port == 50051 + + +async def test_env_keeps_a_text_field_as_text_even_when_it_reads_as_json(monkeypatch): + monkeypatch.setenv("ENV_TEST__APPLICATION__NAME", '["kept as text"]') + + config = await _configure(env_prefix="ENV_TEST__") + + assert config.application.name == '["kept as text"]' + + +async def test_env_decodes_json_for_structured_fields(monkeypatch): + monkeypatch.setenv("JSON_TEST__APPLICATION__NAME", "orders") + monkeypatch.setenv("JSON_TEST__CONSUMER__REFERENCES", '{"org.example.UserService": {"timeout": 1.0}}') + monkeypatch.setenv("JSON_TEST__PROVIDER__REGISTRIES", '["default"]') + monkeypatch.setenv("JSON_TEST__REGISTRIES__DEFAULT", '{"address": "etcd://n:2379"}') + + config = await _configure(env_prefix="JSON_TEST__") + + assert config.consumer.references["org.example.UserService"].timeout == 1.0 + assert config.provider.registries == ("default",) + assert config.registries["default"].address == "etcd://n:2379" + + +async def test_env_leaves_unknown_keys_undecoded_for_validation_to_reject(monkeypatch): + monkeypatch.setenv("JSON_TEST__APPLICATION__NAME", "orders") + monkeypatch.setenv("JSON_TEST__UNKNOWN", "{not json}") + + with pytest.raises(ConfigError, match=r"extra fields found \(unknown\)"): + await _configure(env_prefix="JSON_TEST__") + + +async def test_env_rejects_invalid_json(monkeypatch): + monkeypatch.setenv("BAD_JSON__CONSUMER__REFERENCES", "users") + with pytest.raises(ConfigReadError, match=r"'consumer\.references' must be JSON"): + await _configure(APP, env_prefix="BAD_JSON__") + + +@pytest.mark.parametrize( + "variables", + [ + {"ROOT": "scalar", "ROOT__CHILD": "value"}, + {"ROOT__CHILD": "value", "ROOT": "scalar"}, + {"ROOT____CHILD": "value"}, + pytest.param( + {"ROOT": "upper", "root": "lower"}, + marks=pytest.mark.skipif(sys.platform == "win32", reason="Windows names variables regardless of case"), + ), + # A JSON value cannot be combined with variables inside it. + {"CONSUMER__REFERENCES": "{}", "CONSUMER__REFERENCES__USERS__TIMEOUT": "1"}, + ], +) +async def test_env_rejects_ambiguous_paths(monkeypatch, variables): + for key, value in variables.items(): + monkeypatch.setenv("PATH_TEST__" + key, value) + with pytest.raises(ConfigReadError, match="invalid configuration path in environment variable"): + await _configure(APP, env_prefix="PATH_TEST__") + + +async def test_the_address_to_register_comes_from_the_shared_environment_variables(monkeypatch): + monkeypatch.setenv("DUBBO_IP_TO_REGISTRY", "10.0.0.1") + monkeypatch.setenv("DUBBO_PORT_TO_REGISTRY", "20880") + + config = await _configure(APP, env_prefix="DUBBO_UNSET_TEST__") + + assert (config.application.advertised_host, config.application.advertised_port) == ("10.0.0.1", 20880) + + +async def test_the_advertised_port_of_a_protocol_comes_from_the_environment(monkeypatch): + monkeypatch.setenv("PORT_TEST__PROTOCOLS__TRI__ADVERTISED_PORT", "30051") + + config = await _configure({**APP, "protocols": {"tri": {"name": "tri"}}}, env_prefix="PORT_TEST__") + + assert config.protocols["tri"].advertised_port == 30051 + + +CENTER = {"application": {"name": "orders"}, "config_center": {"address": "memory://center"}} +ENTRY = ("dubbo", "dubbo.yaml") + + +async def test_remote_configuration_ranks_between_sources_and_environment(config_store, monkeypatch): + config_store.entries[ENTRY] = "consumer: {timeout: 2, group: remote, version: remote}" + monkeypatch.setenv("CENTER_TEST__CONSUMER__GROUP", "env") + + config = await _configure( + CENTER, + {"consumer": {"timeout": 1, "check": False}}, + env_prefix="CENTER_TEST__", + consumer=ConsumerConfig(version="code"), + ) + + consumer = config.consumer + assert (consumer.timeout, consumer.check) == (2, False) + assert (consumer.group, consumer.version) == ("env", "code") + assert config_store.reads == [ENTRY] + + +async def test_remote_configuration_completes_the_local_configuration(config_store): + config_store.entries[ENTRY] = "application: {name: orders}\nregistries: {zk: {address: 'zookeeper://zk:2181'}}" + + config = await _configure({"config_center": {"address": "memory://center"}, "provider": {"registries": ["zk"]}}) + + assert config.application.name == "orders" + assert config.registries == {"zk": RegistryConfig(address="zookeeper://zk:2181")} + + +async def test_config_center_merges_from_every_local_layer(config_store, monkeypatch): + monkeypatch.setenv("CENTER_TEST__CONFIG_CENTER__TIMEOUT", "5") + monkeypatch.setenv("CENTER_TEST__CONFIG_CENTER__NAMESPACE", "prod") + source = { + **CENTER, + "config_center": { + "address": "memory://file", + "group": "shared", + "namespace": "dev", + "parameters": {"cluster": "east"}, + }, + } + + config = await _configure( + source, env_prefix="CENTER_TEST__", config_center=ConfigCenterConfig(address="memory://code") + ) + + assert config.config_center == ConfigCenterConfig( + address="memory://code", namespace="prod", group="shared", timeout=5, parameters={"cluster": "east"} + ) + assert config_store.reads == [("shared", "dubbo.yaml")] + + +async def test_implementation_receives_the_url_with_the_application_scope(config_store): + center = { + "address": "memory://user:secret@center:2181,other:2181", + "namespace": "dev", + "timeout": 3, + "parameters": {"session-timeout": 3000, "sasl": True}, + } + + async with Dubbo(CENTER, {"config_center": center}, env_prefix=None): + (created,) = config_store.centers + assert isinstance(created.url.scope, ApplicationScope) + + url = created.url + assert (url.protocol, url.host, url.port, url.username, url.password) == ( + "memory", + "center", + 2181, + "user", + "secret", + ) + assert url.parameters == { + "backup": "other:2181", + "timeout": "3000", + "namespace": "dev", + "session-timeout": "3000", + "sasl": "true", + } + + +async def test_format_follows_the_key_suffix_unless_set(config_store): + config_store.entries[("dubbo", "dubbo.properties")] = "consumer.retries = 4" + config_store.entries[("dubbo", "settings")] = '{"consumer": {"retries": 5}}' + center = {"address": "memory://center"} + + by_suffix = await _configure(CENTER, {"config_center": {**center, "config_file": "dubbo.properties"}}) + by_format = await _configure(CENTER, {"config_center": {**center, "config_file": "settings", "format": "json"}}) + + assert (by_suffix.consumer.retries, by_format.consumer.retries) == (4, 5) + + +@pytest.mark.parametrize("text", [None, " \n"]) +async def test_missing_or_blank_entry_adds_nothing(config_store, text): + if text is not None: + config_store.entries[ENTRY] = text + + config = await _configure(CENTER, {"consumer": {"retries": 1}}) + + assert config.consumer.retries == 1 + + +async def test_an_entry_invalid_in_its_format_cannot_be_parsed(config_store): + config_store.entries[ENTRY] = "consumer: [" + + with pytest.raises(ConfigParseError, match=r"invalid YAML configuration in 'dubbo\.yaml' of group 'dubbo'"): + await _configure(CENTER) + + +async def test_connection_closes_when_startup_fails_after_connecting(config_store): + config_store.entries[ENTRY] = "consumer: {retries: -1}" + + with pytest.raises(ConfigError, match="'retries' must be >= 0"): + await _configure(CENTER) + + assert config_store.centers[0].closed + + +async def test_remote_configuration_cannot_set_the_configuration_center(config_store): + config_store.entries[ENTRY] = "config_center: {address: 'memory://other'}" + + with pytest.raises(ConfigError, match="must not set config_center"): + await _configure(CENTER) + + +@pytest.mark.parametrize( + ("center", "error", "message"), + [ + ({"address": "center:8848"}, ConfigError, "needs a scheme"), + ({"address": "memory://center", "adress": "typo"}, ConfigError, "adress"), + ({"address": "memory://center?timeout=1", "timeout": 2}, ConfigError, "timeout field and the 'timeout'"), + ({"address": "memory://center?zone=a", "parameters": {"zone": "b"}}, ConfigError, "'zone' differs"), + ({"address": "etcd://center:2379"}, ConfigReadError, "configuration center 'etcd'"), + ({"address": "etcd://center:2379", "check": False}, ConfigReadError, "configuration center 'etcd'"), + ], +) +async def test_invalid_configuration_center_fails_before_connecting(config_store, center, error, message): + # The invalid consumer shows that the configuration center is checked first. + with pytest.raises(error, match=message): + await _configure(CENTER, {"config_center": center}, {"consumer": {"retries": -1}}) + + assert config_store.centers == [] + + +@pytest.mark.parametrize( + ("center", "message"), + [ + ({"address": "memory://center", "config_file": "settings"}, "no suffix and no format is set"), + ({"address": "memory://center", "format": "ini"}, "parser 'ini'"), + ], +) +async def test_missing_parser_fails_before_connecting_even_when_unchecked(config_store, center, message): + with pytest.raises(ConfigReadError, match=message): + await _configure(CENTER, {"config_center": {**center, "check": False}}) + + assert config_store.centers == [] + + +async def test_unreadable_center_fails_startup_by_default(config_store): + config_store.error = ConnectionRefusedError("refused") + + with pytest.raises(ConfigReadError, match=r"memory://center\?timeout=30000") as caught: + await _configure(CENTER) + + assert isinstance(caught.value.__cause__, ConnectionRefusedError) + assert config_store.centers[0].closed + + +async def test_without_a_config_center_the_first_registry_of_a_kind_that_can_serve_as_one_does(config_store): + config_store.entries[ENTRY] = "consumer: {timeout: 2}" + registries = { + "etcd": {"address": "etcd://n:2379"}, + "off": {"address": "memory://off", "use_as_config_center": False}, + "memory": { + "address": "memory://u:p@a:1,b:2?timeout=1500&session=60000", + "group": "prod", + "parameters": {"x": "y"}, + }, + } + + config = await _configure({"application": {"name": "orders"}, "registries": registries}) + + assert config.config_center == ConfigCenterConfig( + address="memory://u:p@a:1", + namespace="prod", + timeout=1.5, + parameters={"backup": "b:2", "session": "60000", "x": "y"}, + ) + assert (config.consumer.timeout, config_store.reads) == (2, [ENTRY]) + assert config.registries["memory"].use_as_config_center is None + + +async def test_registries_serve_as_no_config_center_when_one_is_set_or_none_can(config_store): + config_store.entries[ENTRY] = "consumer: {timeout: 2}" + registries = {"memory": {"address": "memory://registry"}} + + config = await _configure({**CENTER, "registries": registries}) + assert config.config_center == ConfigCenterConfig(address="memory://center") + + config = await _configure({"application": {"name": "orders"}, "registries": {"etcd": {"address": "etcd://n:2379"}}}) + assert config.config_center is None + + +async def _configure(*sources, env_prefix=None, **options): + async with ApplicationScope() as scope: + return await load_config(sources, env_prefix=env_prefix, code=unstructure_config(options), scope=scope) diff --git a/tests/unit/config/test_models.py b/tests/unit/config/test_models.py new file mode 100644 index 00000000..f66d5021 --- /dev/null +++ b/tests/unit/config/test_models.py @@ -0,0 +1,191 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from pathlib import Path + +import attrs +import pytest + +from dubbo.config import ( + ApplicationConfig, + ConfigCenterConfig, + DubboConfig, + MetadataReportConfig, + ProtocolConfig, + ProviderConfig, + RegistryConfig, + ServiceConfig, + TLSConfig, + TripleConfig, +) +from dubbo.config.fields import to_url_parameters + + +def test_code_construction_validates_without_loading(): + config = DubboConfig( + application=ApplicationConfig(name="orders"), + # Port conflicts are left to the server that binds them. + protocols={"tri": ProtocolConfig(name="tri", port=50051), "dubbo": ProtocolConfig(name="dubbo", port=50051)}, + provider=ProviderConfig(protocols=("tri",)), + ) + assert config.provider.protocols == ("tri",) + with pytest.raises(ValueError, match="undefined registry"): + DubboConfig(application=ApplicationConfig(name="orders"), provider=ProviderConfig(registries=("default",))) + with pytest.raises(TypeError, match="'registries' must be "): + ProviderConfig(registries="default") + + +@pytest.mark.parametrize("model", [RegistryConfig, ConfigCenterConfig]) +@pytest.mark.parametrize( + ("address", "message"), + [ + ("localhost:2181", "needs a scheme"), + ("zookeeper:///root", "needs a host"), + ("zookeeper://zk1:2181,,zk2:2181", "empty host"), + ("zookeeper://", "needs a host"), + ("zookeeper://zk1:2181,", "empty host"), + ("zookeeper://zk1:2181,zk2:2181?backup=zk3:2181", "both after commas and in 'backup'"), + ], +) +def test_addresses_need_a_scheme_and_hosts(model, address, message): + with pytest.raises(ValueError, match=f"address .*{message}"): + model(address=address) + + +@pytest.mark.parametrize("model", [RegistryConfig, ConfigCenterConfig]) +def test_rejected_address_does_not_echo_its_password(model): + with pytest.raises(ValueError, match="fragments") as caught: + model(address="zookeeper://alice:hunter2@localhost:2181/#fragment") + + assert "hunter2" not in str(caught.value) + + +def test_registry_url_moves_further_hosts_to_backup_and_adds_parameters(): + url = RegistryConfig(address="zookeeper://zk1:2181,zk2:2181/dubbo", parameters={"session": "60000"}).to_url() + + assert (url.protocol, url.host, url.port, url.path) == ("zookeeper", "zk1", 2181, "dubbo") + assert url.parameters == {"backup": "zk2:2181", "session": "60000"} + + +def test_config_center_url_adds_fields_with_defaults_and_parameters(): + config = ConfigCenterConfig( + address="nacos://user:secret@n1:8848?cluster=east", namespace="dev", parameters={"region": "cn"} + ) + + url = config.to_url() + + assert (url.username, url.password, url.host) == ("user", "secret", "n1") + assert url.parameters == {"cluster": "east", "namespace": "dev", "timeout": "30000", "region": "cn"} + assert attrs.evolve(config, timeout=0.0001).to_url().parameters["timeout"] == "1" + + +@pytest.mark.parametrize("model", [RegistryConfig, ConfigCenterConfig]) +def test_parameters_are_strings_that_do_not_collide_with_the_address(model): + with pytest.raises(TypeError, match="must be "): + model(address="nacos://n:8848", parameters={"retries": 3}) + with pytest.raises(ValueError, match="'cluster' differs from the one in the address"): + model(address="nacos://n:8848?cluster=a", parameters={"cluster": "b"}) + with pytest.raises(ValueError, match="'backup' differs from the one in the address"): + model(address="nacos://n1:8848,n2:8848", parameters={"backup": "n3:8848"}) + + +def test_triple_parameters_are_strings_that_fields_do_not_set(): + with pytest.raises(TypeError, match="must be "): + TripleConfig(parameters={"stream-send-buffer-size": 1048576}) + with pytest.raises(ValueError, match="set the compressor field instead of the 'compressor' parameter"): + TripleConfig(parameters={"compressor": "gzip"}) + + +@pytest.mark.parametrize("field", ["namespace", "timeout"]) +@pytest.mark.parametrize("place", ["address", "parameters"]) +def test_a_config_center_option_comes_from_its_field_or_the_url_which_agree(field, place): + fields = ( + {"address": f"nacos://n:8848?{field}=1"} + if place == "address" + else {"address": "nacos://n:8848", "parameters": {field: "1"}} + ) + + # Above all, the address and parameters override the default timeout. + assert ConfigCenterConfig(**fields).to_url().parameters[field] == "1" + # The field agrees once it becomes a URL parameter: a timeout of 0.001 seconds is 1 millisecond. + same = {"namespace": "1", "timeout": 0.001}[field] + assert ConfigCenterConfig(**fields, **{field: same}).to_url().parameters[field] == "1" + with pytest.raises(ValueError, match=f"the {field} field and the '{field}' parameter differ"): + ConfigCenterConfig(**fields, **{field: 2}) + + +@pytest.mark.parametrize("model", [RegistryConfig, MetadataReportConfig]) +def test_a_namespace_comes_from_its_field_or_the_url_which_agree(model): + for fields in ( + {"address": "nacos://n:8848", "namespace": "dev"}, + {"address": "nacos://n:8848?namespace=dev"}, + {"address": "nacos://n:8848", "parameters": {"namespace": "dev"}}, + ): + assert model(**fields).to_url().parameters == {"namespace": "dev"} + # One value set twice is set once. + assert model(address="nacos://n:8848?namespace=dev", namespace="dev").to_url().parameters == {"namespace": "dev"} + with pytest.raises(ValueError, match="the namespace field and the 'namespace' parameter differ"): + model(address="nacos://n:8848?namespace=dev", namespace="prod") + + +@pytest.mark.parametrize( + ("registry", "expected"), + [ + ({"group": "orders", "namespace": "dev"}, "dev"), + ({"address": "nacos://n:8848?namespace=dev", "group": "orders"}, "dev"), + ({"parameters": {"namespace": "dev"}}, "dev"), + ({"group": "orders"}, "orders"), + ({"address": "nacos://n:8848?group=orders"}, "orders"), + ({"address": "nacos://n:8848?group=orders&namespace=dev", "group": "orders", "namespace": "dev"}, "dev"), + ], +) +def test_the_config_center_of_a_registry_is_in_its_namespace_else_its_group(registry, expected): + center = ConfigCenterConfig.from_registry(RegistryConfig(**{"address": "nacos://n:8848", **registry})) + + assert (center.namespace, center.parameters) == (expected, {}) + + +def test_a_registry_address_keeps_credentials_path_and_query_on_the_first_host(): + url = RegistryConfig(address=" zookeeper://user:secret@zk1:2181,[::1]:2181/root?session=5 ").to_url() + + assert (url.username, url.password, url.host, url.port, url.path) == ("user", "secret", "zk1", 2181, "root") + assert url.parameters == {"session": "5", "backup": "[::1]:2181"} + + +def test_a_registry_group_and_a_service_warmup_become_url_parameters(): + assert RegistryConfig(address="zookeeper://zk:2181", group="orders").to_url().parameters == {"group": "orders"} + assert RegistryConfig(address="zookeeper://zk:2181?group=orders").to_url().parameters == {"group": "orders"} + assert to_url_parameters(ServiceConfig(warmup=60)) == {"warmup": "60000"} + + +def test_the_advertised_port_of_the_application_goes_to_one_protocol_at_most(): + def config(**ports: int | None) -> DubboConfig: + protocols = {name: ProtocolConfig(name=name, advertised_port=port) for name, port in ports.items()} + return DubboConfig(application=ApplicationConfig(advertised_port=40000), protocols=protocols) + + config(tri=None) + config(tri=None, dubbo=30880) + with pytest.raises(ValueError, match="for the protocols 'tri', 'dubbo'; set advertised_port on each of them"): + config(tri=None, dubbo=None) + + +def test_tls_files_may_be_paths_and_are_kept_as_text(): + cert, key, ca = Path("certs/server.pem"), Path("certs/server.key"), Path("certs/ca.pem") + tls = TLSConfig(certfile=cert, keyfile=key, cafile=ca) + + assert (tls.certfile, tls.keyfile, tls.cafile) == (str(cert), str(key), str(ca)) + assert to_url_parameters(tls)["tls-cert-file"] == str(cert) diff --git a/tests/unit/config/test_structure.py b/tests/unit/config/test_structure.py new file mode 100644 index 00000000..b4cd9c2e --- /dev/null +++ b/tests/unit/config/test_structure.py @@ -0,0 +1,108 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.config import ( + ConfigError, + DubboConfig, + RegistryConfig, +) +from dubbo.config.structure import structure_config + +APP = {"application": {"name": "orders"}} + + +@pytest.mark.parametrize( + ("value", "message"), + [("127.0.0.1:50051", "needs a scheme"), ("tri:///path", "needs a host")], +) +def test_an_invalid_reference_url_fails_to_configure(value, message): + with pytest.raises(ConfigError, match=message): + structure_config( + {**APP, "consumer": {"references": {"com.example.UserService": {"urls": [value]}}}}, DubboConfig + ) + + +@pytest.mark.parametrize( + ("value", "expected"), + [(True, True), (False, False), ("true", True), (" Yes ", True), ("ON", True), ("1", True), ("off", False)], +) +def test_booleans_accept_real_booleans_and_standard_spellings(value, expected): + config = structure_config({**APP, "consumer": {"check": value}}, DubboConfig) + assert config.consumer.check is expected + + +@pytest.mark.parametrize("value", ["maybe", "", "enabled", 1, 0]) +def test_booleans_reject_other_values(value): + with pytest.raises(ConfigError, match=r"expected a boolean.* @ config\.consumer\.check"): + structure_config({**APP, "consumer": {"check": value}}, DubboConfig) + + +@pytest.mark.parametrize( + ("data", "message"), + [ + ( + {"registries": {"zk": {"address": "zookeeper://h:1", "use_as_config_center": False}}}, + r"application\.name is required once a registry is defined", + ), + ({"application": {"name": "orders", "nmae": "x"}}, r"extra fields found \(nmae\) @ config\.application"), + ( + {**APP, "protocols": {"tri": {"name": "tri", "port": True}}}, + r"integer, got True @ config\.protocols\['tri'\]", + ), + ({**APP, "protocols": {"tri": {"name": "tri", "port": "8O"}}}, r"integer, got '8O'"), + ({**APP, "protocols": {"tri": {"name": "tri", "port": 70000}}}, r"'port' must be <= 65535"), + ({"application": {"name": 1}}, r"string, got 1 @ config\.application\.name"), + ({**APP, "consumer": {"timeout": 0}}, r"'timeout' must be > 0"), + ({**APP, "provider": {"registries": "default"}}, r"list of names, got 'default'"), + ({**APP, "provider": {"protocols": ["dubbo"]}}, r"provider selects undefined protocol 'dubbo'"), + ( + {**APP, "consumer": {"references": {"org.example.Users": {"registries": ["nope"]}}}}, + r"reference 'org\.example\.Users' selects undefined registry 'nope'", + ), + ], +) +def test_invalid_configuration_names_the_problem_and_path(data, message): + with pytest.raises(ConfigError, match=message): + structure_config(data, DubboConfig) + + +def test_invalid_configuration_lists_each_problem_on_a_line_without_the_errors_of_cattrs(): + with pytest.raises(ConfigError) as caught: + structure_config({**APP, "protocols": {"tri": {"name": "tri", "port": "abc", "hots": 1}}}, DubboConfig) + + assert str(caught.value) == ( + "invalid configuration:\n" + " expected an integer, got 'abc' @ config.protocols['tri'].port\n" + " extra fields found (hots) @ config.protocols['tri']" + ) + assert caught.value.__cause__ is None + assert caught.value.__suppress_context__ + + +@pytest.mark.parametrize( + ("data", "message"), + [ + ({"zk": {"address": "zookeeper://h:1", "weight": "oops"}}, r"integer, got 'oops' @ config\.registries\['zk'\]"), + (["zookeeper://h:1"], r"expected a mapping, got list @ config\.registries"), + ], + ids=["invalid-entry", "not-a-mapping"], +) +def test_a_section_structured_alone_names_the_problem_and_path(data, message): + with pytest.raises(ConfigError, match=message): + structure_config(data, dict[str, RegistryConfig], path="config.registries") diff --git a/tests/unit/config/test_urls.py b/tests/unit/config/test_urls.py new file mode 100644 index 00000000..58ac6c23 --- /dev/null +++ b/tests/unit/config/test_urls.py @@ -0,0 +1,427 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import ssl + +import attrs +import pytest + +from dubbo.config import ( + ApplicationConfig, + ConfigError, + ConsumerConfig, + DubboConfig, + DubboProtocolConfig, + MetadataReportConfig, + MethodConfig, + ProtocolConfig, + ProviderConfig, + ReferenceConfig, + RegistryConfig, + ServiceConfig, + ShutdownConfig, + TLSConfig, + TripleConfig, +) +from dubbo.config.urls import ( + direct_urls, + internal_service_urls, + reference_registries, + reference_url, + service_registries, + service_urls, +) +from dubbo.extension import ApplicationScope +from dubbo.rpc.definition import Method, Service +from dubbo.url import ( + ADVERTISED_PORT, + APPLICATION_SCOPE, + METADATA_CONSUMER_URL, + METADATA_REPORT_URL, + PROVIDER_URL, + SSL_CONTEXT, + URL, +) + +SCOPE = ApplicationScope() +REGISTRIES = { + "zk": RegistryConfig(address="zookeeper://zk:2181"), + "nacos": RegistryConfig(address="nacos://n:8848", subscribe=False), +} + + +def _registry_with(config: DubboConfig) -> URL: + registries = {"zk": RegistryConfig(address="zookeeper://zk:2181")} + named = attrs.evolve(config, application=ApplicationConfig(name="users"), registries=registries) + [registry] = service_registries(named, "Users", SCOPE) + return registry + + +def _service(interface: str, *methods: str) -> Service: + return Service(interface=interface, methods=[Method(name=name, request=(), response=None) for name in methods]) + + +def test_a_service_takes_the_providers_settings_under_its_own(): + config = DubboConfig( + application=ApplicationConfig(name="users"), + registries=REGISTRIES, + protocols={"tri": ProtocolConfig(name="tri", port=50051, triple=TripleConfig(compressor="gzip"))}, + provider=ProviderConfig( + version="1.0", + timeout=3, + filters=("log",), + registries=("zk",), + services={"Users": ServiceConfig(group="beta", methods={"getUser": MethodConfig(timeout=10)})}, + ), + ) + + assert service_urls(config, _service("Users", "getUser", "rename"), SCOPE) == [ + URL( + protocol="tri", + host="0.0.0.0", + port=50051, + path="Users", + parameters={ + "triple.compressor": "gzip", + "application": "users", + "group": "beta", + "version": "1.0", + "timeout": "3000", + "service.filter": "log", + "getUser.timeout": "10000", + }, + ), + ] + registries = service_registries(config, "Users", SCOPE) + assert registries == [URL.parse("zookeeper://zk:2181")] + assert registries[0].attributes[APPLICATION_SCOPE] is SCOPE + + +def test_a_protocol_without_a_name_serves_the_protocol_its_key_names(): + config = DubboConfig( + protocols={"tri": ProtocolConfig(port=50051), "public": ProtocolConfig(name="tri", port=50052)}, + ) + + urls = [*service_urls(config, _service("Users"), SCOPE), *internal_service_urls(config, ["Users"], SCOPE).values()] + + assert [(url.protocol, url.port) for url in urls] == [("tri", 50051), ("tri", 50052), ("tri", 50051)] + + +def test_each_protocol_advertises_its_own_port_else_that_of_the_application(): + config = DubboConfig( + application=ApplicationConfig(name="users", advertised_port=40000), + protocols={ + "tri": ProtocolConfig(name="tri", advertised_port=30051), + "dubbo": ProtocolConfig(name="dubbo"), + "rest": ProtocolConfig(name="rest", advertised_port=8080), + }, + ) + + urls = [*service_urls(config, _service("Users"), SCOPE), *internal_service_urls(config, ["Users"], SCOPE).values()] + + assert [(url.protocol, url.attributes[ADVERTISED_PORT]) for url in urls] == [ + ("tri", 30051), + ("dubbo", 40000), + ("rest", 8080), + ] * 2 + unset = DubboConfig(application=ApplicationConfig(name="users")) + assert ADVERTISED_PORT not in service_urls(unset, _service("Users"), SCOPE)[0].attributes + + +def test_a_reference_takes_the_consumers_settings_and_its_subscribing_registries(): + config = DubboConfig( + application=ApplicationConfig(name="orders", advertised_host="10.0.0.1"), + registries=REGISTRIES, + consumer=ConsumerConfig( + retries=1, references={"Users": ReferenceConfig(check=False, methods={"rename": MethodConfig(retries=0)})} + ), + ) + + url = reference_url(config, _service("Users", "getUser", "rename"), SCOPE) + + assert url == URL( + protocol="consumer", + host="10.0.0.1", + path="Users", + parameters={"application": "orders", "retries": "1", "check": "false", "rename.retries": "0"}, + ) + assert url.attributes[APPLICATION_SCOPE] is SCOPE + assert direct_urls(config, url) == [] + assert reference_registries(config, "Users", SCOPE) == [URL.parse("zookeeper://zk:2181")] + + +def test_a_direct_reference_calls_its_urls_with_the_tags_they_are_written_with(): + reference = ReferenceConfig(urls=("tri://10.0.0.5:50051", "tri://10.0.0.6:50051?dubbo.tag=blue"), tag="gray") + config = DubboConfig(consumer=ConsumerConfig(references={"Users": reference})) + + url = reference_url(config, _service("Users"), SCOPE) + + assert url.parameters["dubbo.tag"] == "gray" + assert [direct.parameters.get("dubbo.tag") for direct in direct_urls(config, url)] == [None, "blue"] + + +def test_a_direct_reference_calls_its_urls_with_its_parameters_over_theirs(): + reference = ReferenceConfig(urls=("tri://10.0.0.5:50051?timeout=1&a=b",), timeout=2) + config = DubboConfig(consumer=ConsumerConfig(references={"Users": reference})) + + url = reference_url(config, _service("Users"), SCOPE) + + [direct] = direct_urls(config, url) + assert direct == URL.parse("tri://10.0.0.5:50051/Users?timeout=2000&a=b") + assert direct.attributes[PROVIDER_URL] == URL.parse("tri://10.0.0.5:50051/Users?timeout=1&a=b") + assert direct.scope is url.scope + + +def test_reference_triple_parameters_merge_key_by_key_over_the_consumers(): + reference = ReferenceConfig(urls=("tri://h:1",), triple=TripleConfig(parameters={"b": "reference", "c": "x"})) + config = DubboConfig( + consumer=ConsumerConfig( + triple=TripleConfig(compressor="gzip", connect_timeout=1.5, parameters={"a": "consumer", "b": "consumer"}), + references={"Users": reference}, + ), + ) + + parameters = reference_url(config, _service("Users"), SCOPE).parameters + + assert parameters == { + "triple.a": "consumer", + "triple.b": "reference", + "triple.c": "x", + "triple.compressor": "gzip", + "triple.connect-timeout": "1500", + } + + +def test_a_direct_reference_discovers_only_in_the_registries_it_selects_itself(): + registries = {"zk": RegistryConfig(address="zookeeper://zk:2181")} + reference = ReferenceConfig(urls=("tri://h:1",)) + config = DubboConfig( + application=ApplicationConfig(name="orders"), + registries=registries, + consumer=ConsumerConfig(registries=("zk",), references={"Users": reference}), + ) + assert direct_urls(config, reference_url(config, _service("Users"), SCOPE)) == [ + URL.parse("tri://h:1/Users?application=orders") + ] + assert reference_registries(config, "Users", SCOPE) == [] + + reference = ReferenceConfig(urls=("tri://h:1",), registries=("zk",)) + config = DubboConfig( + application=ApplicationConfig(name="orders"), + registries=registries, + consumer=ConsumerConfig(references={"Users": reference}), + ) + assert reference_registries(config, "Users", SCOPE) == [URL.parse("zookeeper://zk:2181")] + + +def test_internal_services_take_the_settings_of_the_protocols_of_the_services_but_not_of_the_provider(): + config = DubboConfig( + application=ApplicationConfig(name="users"), + protocols={ + "spare": ProtocolConfig(name="tri", port=50050), + "tri": ProtocolConfig(name="tri", port=50051, triple=TripleConfig(compressor="gzip")), + "other-tri": ProtocolConfig(name="tri", port=50052), + "dubbo": ProtocolConfig(name="dubbo", port=20880, dubbo=DubboProtocolConfig(payload=1024)), + }, + provider=ProviderConfig(timeout=3, filters=("log",), token=True, protocols=("tri", "other-tri", "dubbo")), + ) + + urls = internal_service_urls(config, ["Users"], SCOPE) + + assert urls == { + "tri": URL( + protocol="tri", + host="0.0.0.0", + port=50051, + parameters={"triple.compressor": "gzip", "application": "users"}, + ), + "dubbo": URL( + protocol="dubbo", host="0.0.0.0", port=20880, parameters={"payload": "1024", "application": "users"} + ), + } + assert urls["tri"].attributes == {APPLICATION_SCOPE: SCOPE} + + +def test_registries_name_the_metadata_report_set_apart_from_them(): + registries = {"zk": RegistryConfig(address="zookeeper://zk:2181")} + config = DubboConfig(application=ApplicationConfig(name="orders"), registries=registries) + assert METADATA_REPORT_URL not in service_registries(config, "Users", SCOPE)[0].attributes + + report = MetadataReportConfig(address="zookeeper://meta:2181", group="g", parameters={"timeout": "500"}) + config = DubboConfig(application=ApplicationConfig(name="orders"), registries=registries, metadata_report=report) + [registry] = reference_registries(config, "Users", SCOPE) + + named = registry.attributes[METADATA_REPORT_URL] + assert named == URL.parse("zookeeper://meta:2181?group=g&timeout=500") + assert named.attributes[APPLICATION_SCOPE] is SCOPE + + +def test_a_reference_needs_urls_or_a_registry_it_subscribes_to(): + with pytest.raises(ConfigError, match="needs urls"): + reference_registries(DubboConfig(), "Users", SCOPE) + + config = DubboConfig(application=ApplicationConfig(name="orders"), registries={"nacos": REGISTRIES["nacos"]}) + with pytest.raises(ConfigError, match="subscribes to none of its registries"): + reference_registries(config, "Users", SCOPE) + + +def test_settings_reject_methods_the_service_does_not_have(): + config = DubboConfig( + provider=ProviderConfig(services={"Users": ServiceConfig(methods={"get_user": MethodConfig(timeout=1)})}), + consumer=ConsumerConfig(references={"Users": ReferenceConfig(methods={"nope": MethodConfig(timeout=1)})}), + ) + + with pytest.raises(ConfigError, match="service 'Users' configures methods it does not have: get_user"): + service_urls(config, _service("Users", "getUser"), SCOPE) + with pytest.raises(ConfigError, match="reference 'Users' configures methods it does not have: nope"): + reference_url(config, _service("Users", "getUser"), SCOPE) + + +def test_triple_settings_stay_after_their_prefix_apart_from_the_service_identity(): + reference = ReferenceConfig(urls=("tri://h:1",), group="a", triple=TripleConfig(parameters={"group": "b"})) + config = DubboConfig(consumer=ConsumerConfig(references={"Users": reference})) + + parameters = reference_url(config, _service("Users"), SCOPE).parameters + + assert (parameters["group"], parameters["triple.group"]) == ("a", "b") + + +def test_dubbo_protocol_settings_reach_the_service_urls(): + settings = DubboProtocolConfig(payload=1024, heartbeat=30, heartbeat_timeout=90, max_concurrent_calls=50) + dubbo_protocol = ProtocolConfig(name="dubbo", dubbo=settings) + config = DubboConfig(protocols={"d": dubbo_protocol}) + + (served,) = service_urls(config, _service("Users"), SCOPE) + + assert {key: served.parameters[key] for key in ("payload", "heartbeat", "heartbeat.timeout")} == { + "payload": "1024", + "heartbeat": "30000", + "heartbeat.timeout": "90000", + } + assert served.parameters["max-concurrent-calls"] == "50" + + +def test_the_shutdown_grace_reaches_both_sides_as_shutwait(): + config = DubboConfig(shutdown=ShutdownConfig(grace=2.5)) + + (served,) = service_urls(config, _service("Users"), SCOPE) + referred = reference_url(config, _service("Users"), SCOPE) + + assert served.parameters["shutwait"] == referred.parameters["shutwait"] == "2500" + assert "shutwait" not in reference_url(DubboConfig(), _service("Users"), SCOPE).parameters + + +def test_tls_files_reach_both_sides_and_each_context_its_own(): + server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) + client_context = ssl.create_default_context() + tls = TLSConfig(certfile="c.pem", cafile="ca.pem", server_context=server_context, client_context=client_context) + reference = ReferenceConfig(urls=("tri://10.0.0.5:50051",)) + config = DubboConfig(tls=tls, consumer=ConsumerConfig(references={"Users": reference})) + files = {"ssl-enabled": "true", "tls-cert-file": "c.pem", "ca-cert-file": "ca.pem"} + + (served,) = service_urls(config, _service("Users"), SCOPE) + referred = reference_url(config, _service("Users"), SCOPE) + (direct,) = direct_urls(config, referred) + + assert files.items() <= served.parameters.items() + assert served.attributes[SSL_CONTEXT] is server_context + assert files.items() <= referred.parameters.items() + assert referred.attributes[SSL_CONTEXT] is client_context + assert direct.attributes[SSL_CONTEXT] is client_context + internal = internal_service_urls(config, ["Users"], SCOPE)["tri"] + assert files.items() <= internal.parameters.items() + assert internal.attributes[SSL_CONTEXT] is server_context + # The MetadataService of instances is called as the references call. + metadata_consumer = _registry_with(config).attributes[METADATA_CONSUMER_URL] + assert files.items() <= metadata_consumer.parameters.items() + assert metadata_consumer.attributes[SSL_CONTEXT] is client_context + assert "ssl-enabled" not in reference_url(DubboConfig(), _service("Users"), SCOPE).parameters + + +def test_a_token_of_true_is_one_random_token_for_all_protocols_and_one_of_false_none(): + protocols = {"a": ProtocolConfig(name="tri", port=1), "b": ProtocolConfig(name="tri", port=2)} + services = {"Orders": ServiceConfig(token=False), "Items": ServiceConfig(token="s3")} + config = DubboConfig(protocols=protocols, provider=ProviderConfig(token=True, services=services)) + + first, second = (url.parameters["token"] for url in service_urls(config, _service("Users"), SCOPE)) + assert first == second + assert len(first) == 32 + assert service_urls(config, _service("Users"), SCOPE)[0].parameters["token"] != first + assert all("token" not in url.parameters for url in service_urls(config, _service("Orders"), SCOPE)) + assert service_urls(config, _service("Items"), SCOPE)[0].parameters["token"] == "s3" + + +def test_governance_settings_and_parameters_reach_the_urls_below_the_fields(): + method = MethodConfig(tps=2, deprecated=False, actives=1) + service = ServiceConfig( + executes=4, deprecated=True, serialization="json", parameters={"b": "service"}, methods={"getUser": method} + ) + provider = ProviderConfig(accesslog=True, tps=10, tps_interval=1.5, parameters={"a": "provider", "b": "provider"}) + reference = ReferenceConfig(urls=("tri://h:1",), parameters={"d": "reference"}, methods={"getUser": method}) + config = DubboConfig( + provider=attrs.evolve(provider, services={"Users": service}), + consumer=ConsumerConfig( + actives=3, serialization="json", parameters={"c": "consumer"}, references={"Users": reference} + ), + ) + + (served,) = service_urls(config, _service("Users", "getUser"), SCOPE) + referred = reference_url(config, _service("Users", "getUser"), SCOPE) + + assert { + "accesslog": "true", + "tps": "10", + "tps.interval": "1500", + "executes": "4", + "deprecated": "true", + "getUser.tps": "2", + "getUser.deprecated": "false", + "serialization": "json", + "a": "provider", + "b": "service", + }.items() <= served.parameters.items() + assert { + "actives": "3", + "getUser.actives": "1", + "serialization": "json", + "c": "consumer", + "d": "reference", + }.items() <= referred.parameters.items() + with pytest.raises(ValueError, match="set the timeout field instead of the 'timeout' parameter"): + ServiceConfig(parameters={"timeout": "1"}) + + +def test_a_reference_leaves_out_the_settings_of_methods_that_only_providers_read(): + method = MethodConfig(retries=1, loadbalance="first", weight=5, deprecated=True, tps=1) + reference = ReferenceConfig(urls=("tri://h:1",), methods={"getUser": method}) + service = ServiceConfig(methods={"getUser": method}) + config = DubboConfig( + provider=ProviderConfig(services={"Users": service}), consumer=ConsumerConfig(references={"Users": reference}) + ) + + (served,) = service_urls(config, _service("Users", "getUser"), SCOPE) + referred = reference_url(config, _service("Users", "getUser"), SCOPE) + + assert { + "getUser.weight": "5", + "getUser.deprecated": "true", + "getUser.tps": "1", + }.items() <= served.parameters.items() + assert {key for key in referred.parameters if key.startswith("getUser.")} == { + "getUser.retries", + "getUser.loadbalance", + } diff --git a/tests/unit/config_center/test_base.py b/tests/unit/config_center/test_base.py new file mode 100644 index 00000000..8c96200d --- /dev/null +++ b/tests/unit/config_center/test_base.py @@ -0,0 +1,55 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.config_center import ConfigCenter, get_config_center +from dubbo.extension import ApplicationScope, extensions +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = pytest.mark.anyio + + +async def test_an_application_shares_one_configuration_center_per_url(isolated_extensions): + created = [] + + class Center(ConfigCenter): + def __init__(self, url): + super().__init__(url) + self.connected, self.closed = False, False + created.append(self) + + async def __aenter__(self): + self.connected = True + return self + + async def aclose(self): + self.closed = True + + extensions.register(ConfigCenter, "memory", Center) + + async with ApplicationScope() as scope: + url = URL(protocol="memory", host="center", attributes={APPLICATION_SCOPE: scope}) + first = await get_config_center(url) + assert await get_config_center(url) is first + assert created == [first] + assert (first.connected, first.closed) == (True, False) + + assert first.closed + with pytest.raises(RuntimeError, match="belongs to no application"): + await get_config_center(URL(protocol="memory", host="center")) + assert created == [first] diff --git a/tests/unit/config_center/test_zookeeper.py b/tests/unit/config_center/test_zookeeper.py new file mode 100644 index 00000000..5426427f --- /dev/null +++ b/tests/unit/config_center/test_zookeeper.py @@ -0,0 +1,66 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import pytest + +from dubbo import Dubbo +from dubbo.config_center.zookeeper import ZookeeperConfigCenter +from dubbo.extension import ApplicationScope +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = pytest.mark.anyio + + +async def test_entry_is_the_node_under_namespace_config_group_key(memory_zookeeper): + memory_zookeeper.put("/dubbo/config/dubbo/dubbo.yaml", b"application: {name: default}") + memory_zookeeper.put("/prod/config/orders/app.yaml", "application: {name: 订单}".encode()) + center = {"address": "zookeeper://zk:2181?client=memory"} + + async with Dubbo({"config_center": center}, env_prefix=None) as default: + assert default.config.application.name == "default" + custom = {**center, "group": "orders", "config_file": "app.yaml", "namespace": "prod"} + async with Dubbo({"config_center": custom}, env_prefix=None) as prod: + assert prod.config.application.name == "订单" + + +async def test_centers_of_one_ensemble_share_a_connection_within_an_application(memory_zookeeper): + first = URL.parse("zookeeper://zk:2181?client=memory&namespace=a&timeout=5000") + second = URL.parse("zookeeper://zk:2181?client=memory&namespace=b&timeout=5000") + + async with ( + ApplicationScope() as scope, + ZookeeperConfigCenter(first.replace(attributes={APPLICATION_SCOPE: scope})) as a, + ZookeeperConfigCenter(second.replace(attributes={APPLICATION_SCOPE: scope})) as b, + ): + assert await a.get("a", group="orders") is None + assert await b.get("b", group="billing") is None + + assert len(memory_zookeeper.urls) == 1 + + +async def test_watch_decodes_the_text(memory_zookeeper): + memory_zookeeper.put("/dubbo/config/dubbo/rules", b"rule") + url = URL.parse("zookeeper://zk?client=memory") + + async with ( + ApplicationScope() as scope, + ZookeeperConfigCenter(url.replace(attributes={APPLICATION_SCOPE: scope})) as center, + center.watch("rules", group="dubbo") as values, + ): + with anyio.fail_after(5): + assert await anext(values) == "rule" diff --git a/tests/unit/extension/test_loader.py b/tests/unit/extension/test_loader.py new file mode 100644 index 00000000..3d44b2c9 --- /dev/null +++ b/tests/unit/extension/test_loader.py @@ -0,0 +1,350 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import subprocess +import sys +import typing +from importlib.metadata import EntryPoint, EntryPoints +from pathlib import Path + +import pytest + +from dubbo import DubboError +from dubbo.extension import ExtensionError, Extensions, extension_point, loader + +_GROUP = "apache_dubbo.test_renderer" + + +class Renderer(typing.Protocol): + def __init__(self, *, prefix: str) -> None: ... + + def render(self, text: str) -> str: ... + + +class OtherRenderer(typing.Protocol): + def __init__(self, *, prefix: str) -> None: ... + + def render(self, text: str) -> str: ... + + +class PrefixRenderer: + def __init__(self, *, prefix: str) -> None: + self.prefix = prefix + + def render(self, text: str) -> str: + return self.prefix + text + + +@pytest.fixture +def catalogue(monkeypatch): + entries = [] + monkeypatch.setattr(loader, "_POINTS", {Renderer: _GROUP, OtherRenderer: _GROUP + "_other"}) + monkeypatch.setattr(loader.metadata, "entry_points", lambda: EntryPoints(entries)) + return entries + + +def test_register_returns_class_function_and_bound_method_without_calling(catalogue) -> None: + calls = [] + + def factory(*, prefix: str) -> Renderer: + calls.append(prefix) + return PrefixRenderer(prefix=prefix) + + class Container: + def resolve(self, *, prefix: str) -> Renderer: + return factory(prefix=prefix) + + extensions = Extensions() + extensions.register(Renderer, "class", PrefixRenderer) + extensions.register(Renderer, "function", factory) + extensions.register(Renderer, "container", Container().resolve) + + cls = extensions.get(Renderer, "class") + function = extensions.get(Renderer, "function") + method = extensions.get(Renderer, "container") + assert cls is PrefixRenderer + assert function is factory + assert calls == [] + assert function(prefix="a").render("b") == "ab" + assert method(prefix="c").render("d") == "cd" + assert calls == ["a", "c"] + assert cls(prefix="x") is not cls(prefix="x") + + +def test_registrations_are_isolated_by_instance_and_extension_point(catalogue) -> None: + first, second = Extensions(), Extensions() + first.register(Renderer, "same", PrefixRenderer) + first.register(OtherRenderer, "same", PrefixRenderer) + assert first.get(Renderer, "same") is PrefixRenderer + assert first.get(OtherRenderer, "same") is PrefixRenderer + with pytest.raises(ExtensionError, match="unknown extension 'same'"): + second.get(Renderer, "same") + + +def test_duplicate_registration_never_replaces_existing_factory(catalogue) -> None: + extensions = Extensions() + extensions.register(Renderer, "builtin", PrefixRenderer) + with pytest.raises(ExtensionError, match="duplicate extension 'builtin'"): + extensions.register(Renderer, "builtin", lambda **kwargs: None) + assert extensions.get(Renderer, "builtin") is PrefixRenderer + + +def test_names_list_installed_and_registered_implementations_without_loading(catalogue) -> None: + catalogue.append(EntryPoint("installed", "_dubbo_test_missing_module:Renderer", _GROUP)) + extensions = Extensions() + extensions.register(Renderer, "registered", PrefixRenderer) + + assert extensions.names(Renderer) == ["installed", "registered"] + assert extensions.names(OtherRenderer) == [] + with pytest.raises(ExtensionError, match="unknown extension point"): + extensions.names(str) + + +def test_unknown_point_cannot_be_registered(catalogue) -> None: + extensions = Extensions() + with pytest.raises(ExtensionError, match="unknown extension point"): + extensions.register(str, "custom", str) + with pytest.raises(ExtensionError, match="unknown extension point"): + extensions.get(str, "custom") + + +def test_non_callable_registration_is_an_argument_error(catalogue) -> None: + extensions = Extensions() + with pytest.raises(TypeError, match="must be callable"): + extensions.register(Renderer, "bad", object()) + with pytest.raises(ExtensionError, match="unknown extension 'bad'"): + extensions.get(Renderer, "bad") + + +def test_factory_exceptions_belong_to_the_caller(catalogue) -> None: + failure = ValueError("factory failed") + + def factory(*, prefix: str) -> Renderer: + raise failure + + extensions = Extensions() + extensions.register(Renderer, "failing", factory) + loaded = extensions.get(Renderer, "failing") + with pytest.raises(ValueError, match="factory failed") as caught: + loaded(prefix="x") + assert caught.value is failure + + +def test_entry_points_are_imported_on_get_and_only_factories_are_cached(catalogue, tmp_path, monkeypatch) -> None: + module_name = "_dubbo_test_lazy_extension" + (tmp_path / f"{module_name}.py").write_text( + "created = 0\n" + "class Renderer:\n" + " def __init__(self, *, prefix):\n" + " global created\n" + " created += 1\n" + " self.prefix = prefix\n" + " def render(self, text):\n" + " return self.prefix + text\n" + ) + monkeypatch.syspath_prepend(str(tmp_path)) + catalogue.append(EntryPoint(name="plugin", value=f"{module_name}:Renderer", group=_GROUP)) + try: + extensions = Extensions() + assert module_name not in sys.modules + factory = extensions.get(Renderer, "plugin") + module = sys.modules[module_name] + assert module.created == 0 + module.Renderer = None + assert extensions.get(Renderer, "plugin") is factory + assert factory(prefix="a").render("b") == "ab" + factory(prefix="c") + assert module.created == 2 + finally: + sys.modules.pop(module_name, None) + + +def test_direct_registration_cannot_replace_unloaded_entry_point(catalogue) -> None: + catalogue.append(EntryPoint(name="plugin", value="_missing_dubbo_plugin:Factory", group=_GROUP)) + extensions = Extensions() + with pytest.raises(ExtensionError, match="duplicate extension 'plugin'"): + extensions.register(Renderer, "plugin", PrefixRenderer) + + +def test_duplicate_discovery_fails_before_import(catalogue) -> None: + catalogue.extend( + [ + EntryPoint(name="same", value="_first_missing_plugin:Factory", group=_GROUP), + EntryPoint(name="same", value="_second_missing_plugin:Factory", group=_GROUP), + ] + ) + extensions = Extensions() + with pytest.raises(ExtensionError, match="duplicate extension 'same'"): + extensions.get(Renderer, "other") + + +def test_declared_point_is_returned_unchanged_and_resolves_its_group(catalogue, monkeypatch) -> None: + monkeypatch.setattr(loader, "_POINTS", {}) + + class Point(typing.Protocol): + def __init__(self, *, prefix: str) -> None: ... + + def render(self, text: str) -> str: ... + + assert extension_point(_GROUP)(Point) is Point + catalogue.append(EntryPoint(name="plugin", value="builtins:None", group=_GROUP)) + with pytest.raises(ExtensionError, match=f"group '{_GROUP}' must be callable"): + Extensions().get(Point, "plugin") + + +def test_no_name_selects_the_default_the_point_declares(catalogue, monkeypatch) -> None: + monkeypatch.setattr(loader, "_POINTS", {}) + monkeypatch.setattr(loader, "_DEFAULTS", {}) + + class Point(typing.Protocol): + def __init__(self, *, prefix: str) -> None: ... + + class Bare(typing.Protocol): + def __init__(self, *, prefix: str) -> None: ... + + extension_point(_GROUP, default="prefix")(Point) + extension_point(_GROUP + "_bare")(Bare) + instance = Extensions() + instance.register(Point, "prefix", PrefixRenderer) + + assert instance.get(Point, None) is PrefixRenderer + with pytest.raises(ExtensionError, match="no default"): + instance.get(Bare, None) + + +def test_discovery_waits_for_first_use(catalogue, monkeypatch) -> None: + calls = [] + monkeypatch.setattr(loader.metadata, "entry_points", lambda: calls.append(1) or EntryPoints(catalogue)) + extensions = Extensions() + assert calls == [] + extensions.register(Renderer, "class", PrefixRenderer) + assert calls == [1] + + +def test_discovery_happens_once_and_ignores_unrelated_groups(catalogue, monkeypatch) -> None: + calls = [] + + def discover(): + calls.append(1) + return EntryPoints(catalogue) + + monkeypatch.setattr(loader.metadata, "entry_points", discover) + catalogue.extend( + [ + EntryPoint(name="same", value="_missing_plugin:Factory", group="unrelated"), + EntryPoint(name="same", value="_missing_plugin:Other", group="unrelated"), + ] + ) + extensions = Extensions() + extensions.register(Renderer, "class", PrefixRenderer) + assert extensions.get(Renderer, "class") is PrefixRenderer + assert calls == [1] + catalogue.append(EntryPoint(name="later", value="_missing_plugin:Factory", group=_GROUP)) + with pytest.raises(ExtensionError, match="unknown extension 'later'"): + extensions.get(Renderer, "later") + + +@pytest.mark.parametrize( + ("target", "cause"), + [("_missing_dubbo_plugin:Factory", ModuleNotFoundError), ("builtins:_missing_dubbo_attribute", AttributeError)], +) +def test_import_failure_preserves_cause_and_context(catalogue, target: str, cause: type[Exception]) -> None: + catalogue.append(EntryPoint(name="broken", value=target, group=_GROUP)) + extensions = Extensions() + with pytest.raises(ExtensionError, match="cannot load extension 'broken'") as caught: + extensions.get(Renderer, "broken") + assert isinstance(caught.value, DubboError) + assert isinstance(caught.value.__cause__, cause) + assert _GROUP in str(caught.value) + assert target in str(caught.value) + + +def test_non_callable_entry_point_is_an_extension_error(catalogue) -> None: + catalogue.append(EntryPoint(name="bad", value="builtins:None", group=_GROUP)) + extensions = Extensions() + with pytest.raises(ExtensionError, match="must be callable"): + extensions.get(Renderer, "bad") + + +def test_ty_preserves_factory_parameters_and_result_interface(tmp_path: Path) -> None: + source = """import typing +from dubbo.extension import Extensions + +class Point(typing.Protocol): + def __init__(self, *, prefix: str) -> None: ... + def render(self, text: str) -> str: ... + +class Implementation: + def __init__(self, *, prefix: str) -> None: pass + def render(self, text: str) -> str: return text + +def factory(*, prefix: str) -> Point: + return Implementation(prefix=prefix) + +extensions = Extensions() +extensions.register(Point, "class", Implementation) +extensions.register(Point, "function", factory) +provider = extensions.get(Point, "class") +instance = provider(prefix="x") +instance.render("text") + +def parse(text: str, /) -> dict[str, object]: + raise NotImplementedError + +def parse_upper(text: str, /) -> dict[str, object]: + return {"text": text.upper()} + +extensions.register(parse, "upper", parse_upper) +parsed: dict[str, object] = extensions.get(parse, "upper")("text") +""" + valid = tmp_path / "valid.py" + valid.write_text(source) + result = subprocess.run( + ["ty", "check", "--python-version", "3.10", "--output-format", "concise", str(valid)], + capture_output=True, + text=True, + ) + assert result.returncode == 0, result.stdout + result.stderr + + invalid = tmp_path / "invalid.py" + invalid.write_text( + source + + """ +class BadConstructor: + def __init__(self, count: int) -> None: pass + def render(self, text: str) -> str: return text + +extensions.register(Point, "bad", BadConstructor) +provider(count=1) + +def parse_number(text: int, /) -> dict[str, object]: + return {} + +extensions.register(parse, "number", parse_number) +extensions.get(parse, "upper")(1) +instance.not_a_method() +""" + ) + result = subprocess.run( + ["ty", "check", "--python-version", "3.10", "--output-format", "concise", str(invalid)], + capture_output=True, + text=True, + ) + assert result.returncode != 0 + assert "invalid-argument-type" in result.stdout + assert "unknown-argument" in result.stdout + assert "missing-attribute" in result.stdout diff --git a/tests/unit/extension/test_scope.py b/tests/unit/extension/test_scope.py new file mode 100644 index 00000000..ac61b254 --- /dev/null +++ b/tests/unit/extension/test_scope.py @@ -0,0 +1,272 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import AsyncIterator +from contextlib import AsyncExitStack, asynccontextmanager + +import anyio +import pytest + +from dubbo.extension import ApplicationScope, Resource + + +class Connections: + """Open fake connections and record when each opens and closes.""" + + def __init__(self) -> None: + self.events: list[str] = [] + self.fail = False + + def connect(self, address: str) -> "Connection": + return Connection(self, address) + + +class Connection(Resource): + def __init__(self, connections: Connections, address: str) -> None: + self.connections = connections + self.address = address + + async def __aenter__(self) -> "Connection": + self.connections.events.append(f"open {self.address}") + await anyio.sleep(0.01) + if self.connections.fail: + raise ConnectionRefusedError(self.address) + return self + + async def aclose(self) -> None: + self.connections.events.append(f"close {self.address}") + await anyio.sleep(0.01) + + +@pytest.mark.anyio +async def test_scope_opens_each_key_once_and_closes_in_reverse_order() -> None: + connections = Connections() + + async with ApplicationScope() as scope: + first = await scope.share("a", lambda: connections.connect("a")) + again = await scope.share("a", lambda: connections.connect("a")) + other = await scope.share("b", lambda: connections.connect("b")) + assert first is again + assert other is not first + assert connections.events == ["open a", "open b"] + + assert connections.events[2:] == ["close b", "close a"] + + +@pytest.mark.anyio +async def test_failed_opening_is_retried_by_the_next_request() -> None: + connections = Connections() + connections.fail = True + + async with ApplicationScope() as scope: + with pytest.raises(ConnectionRefusedError): + await scope.share("a", lambda: connections.connect("a")) + + connections.fail = False + assert (await scope.share("a", lambda: connections.connect("a"))).address == "a" + + assert connections.events == ["open a", "open a", "close a"] + + +@pytest.mark.anyio +async def test_any_task_shares_while_the_scope_is_open() -> None: + connections = Connections() + shared = [] + + async with ApplicationScope() as scope: + + async def share() -> None: + shared.append(await scope.share("a", lambda: connections.connect("a"))) + + async with anyio.create_task_group() as tasks: + tasks.start_soon(share) + tasks.start_soon(share) + + assert shared[0] is shared[1] + + assert connections.events == ["open a", "close a"] + + with pytest.raises(RuntimeError, match="not open"): + await scope.share("a", lambda: connections.connect("a")) + + +@pytest.mark.anyio +async def test_a_user_that_shares_while_it_opens_closes_before_the_shared_resource() -> None: + connections = Connections() + + class User(Resource): + def __init__(self, scope: ApplicationScope) -> None: + self.scope = scope + + async def __aenter__(self) -> "User": + await self.scope.share("a", lambda: connections.connect("a")) + return self + + async def aclose(self) -> None: + connections.events.append("close user") + + async with AsyncExitStack() as stack: + scope = await stack.enter_async_context(ApplicationScope()) + await stack.enter_async_context(User(scope)) + + assert connections.events == ["open a", "close user", "close a"] + + +@pytest.mark.anyio +async def test_a_cancelled_scope_closes_what_it_shares_at_once() -> None: + connections = Connections() + + with anyio.CancelScope() as cancelled: + async with ApplicationScope() as scope: + await scope.share("a", lambda: connections.connect("a")) + cancelled.cancel() + await anyio.sleep_forever() + + assert connections.events == ["open a", "close a"] + + +@pytest.mark.anyio +async def test_a_shared_resource_may_share_another_while_it_opens() -> None: + connections = Connections() + + @asynccontextmanager + async def user(scope: ApplicationScope) -> AsyncIterator[str]: + await scope.share("a", lambda: connections.connect("a")) + yield "user" + connections.events.append("close user") + + async with ApplicationScope() as scope: + assert await scope.share("user", lambda: user(scope)) == "user" + + assert connections.events == ["open a", "close user", "close a"] + + +@pytest.mark.anyio +async def test_a_shared_resource_may_hold_a_task_group() -> None: + stopped = [] + + @asynccontextmanager + async def worker() -> AsyncIterator[None]: + async with anyio.create_task_group() as tasks: + tasks.start_soon(anyio.sleep_forever) + yield + tasks.cancel_scope.cancel() + stopped.append(True) + + async with ApplicationScope() as scope: + await scope.share("worker", worker) + + assert stopped == [True] + + +@pytest.mark.anyio +async def test_a_failing_task_of_a_shared_resource_exits_it_and_fails_the_scope_with_its_error() -> None: + failing, exited = anyio.Event(), [] + + @asynccontextmanager + async def worker() -> AsyncIterator[None]: + async def fail() -> None: + await failing.wait() + raise ValueError("the worker failed") + + try: + async with anyio.create_task_group() as tasks: + tasks.start_soon(fail) + yield + finally: + exited.append(True) + + async def run() -> None: + async with ApplicationScope() as scope: + await scope.share("worker", worker) + failing.set() + await anyio.sleep_forever() + + with pytest.raises(ExceptionGroup) as raised: + await run() + + assert raised.group_contains(ValueError, match="the worker failed", depth=None) + assert exited == [True] + + +@pytest.mark.anyio +async def test_closing_waits_for_a_resource_still_opening_and_closes_it() -> None: + opening, leaving, events = anyio.Event(), anyio.Event(), [] + + @asynccontextmanager + async def slow() -> AsyncIterator[str]: + opening.set() + await leaving.wait() + events.append("open") + yield "slow" + events.append("close") + + async with anyio.create_task_group() as tasks, ApplicationScope() as scope: + tasks.start_soon(scope.share, "slow", slow) + await opening.wait() + # Closing begins before the resource goes on opening. + leaving.set() + + assert events == ["open", "close"] + + +@pytest.mark.anyio +async def test_cancelling_a_request_cancels_the_opening() -> None: + connections = Connections() + + @asynccontextmanager + async def slow() -> AsyncIterator[str]: + await anyio.sleep_forever() + yield "never" + + async with ApplicationScope() as scope: + with anyio.fail_after(5), anyio.move_on_after(0.05): + await scope.share("slow", slow) + + assert (await scope.share("a", lambda: connections.connect("a"))).address == "a" + + assert connections.events == ["open a", "close a"] + + +@pytest.mark.anyio +async def test_cancelling_a_request_as_the_resource_opens_exits_the_resource() -> None: + events = [] + + async with ApplicationScope() as scope: + with anyio.CancelScope() as request: + + @asynccontextmanager + async def cancelling() -> AsyncIterator[str]: + request.cancel() + try: + yield "opened" + finally: + events.append("close") + + await scope.share("a", cancelling) + + assert events == ["close"] + + +@pytest.mark.anyio +async def test_the_state_of_an_application_lasts_until_its_scope_closes() -> None: + async with ApplicationScope() as scope: + kept = scope.state.setdefault(Connections, Connections()) + again = scope.state.setdefault(Connections, Connections()) + + assert again is kept + assert scope.state == {} diff --git a/tests/unit/filter/conftest.py b/tests/unit/filter/conftest.py new file mode 100644 index 00000000..0fddb833 --- /dev/null +++ b/tests/unit/filter/conftest.py @@ -0,0 +1,87 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import attrs +import pytest + +from dubbo import Invocation, Invoker, Method, Result +from dubbo.extension import ApplicationScope +from dubbo.url import APPLICATION_SCOPE, URL + + +@attrs.define(kw_only=True) +class _Ending(Invoker): + result: Result + url: URL + calls: list[Invocation] = attrs.field(factory=list) + closed: bool = False + + async def invoke(self, invocation: Invocation) -> Result: + self.calls.append(invocation) + + return self.result + + async def aclose(self) -> None: + self.closed = True + + +@attrs.define(kw_only=True) +class _Gate(Invoker): + url: URL + opened: anyio.Event = attrs.field(factory=anyio.Event) + entered: list[str] = attrs.field(factory=list) + + async def invoke(self, invocation: Invocation) -> Result: + self.entered.append(invocation.method) + if invocation.method.startswith("wait"): + await self.opened.wait() + + return Result(value=invocation.method) + + async def aclose(self) -> None: + pass + + +@pytest.fixture +def url() -> URL: + return URL.parse("tri://127.0.0.1:50051/com.example.UserService").replace( + attributes={APPLICATION_SCOPE: ApplicationScope()} + ) + + +@pytest.fixture +def ending(url): + return lambda result: _Ending(result=result, url=url) + + +@pytest.fixture +def gate(url): + return _Gate(url=url) + + +@pytest.fixture +def call(): + def create(method: str = "getUser", **attachments: str | bytes) -> Invocation: + return Invocation( + interface="com.example.UserService", + method=method, + definition=Method(name=method, request=(), response=None), + attachments=attachments, + ) + + return create diff --git a/tests/unit/filter/test_accesslog.py b/tests/unit/filter/test_accesslog.py new file mode 100644 index 00000000..6c544540 --- /dev/null +++ b/tests/unit/filter/test_accesslog.py @@ -0,0 +1,105 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +from types import SimpleNamespace + +import anyio +import pytest + +from dubbo import Invocation, Result, RpcError, Status +from dubbo.filter import accesslog +from dubbo.filter.accesslog import AccessLogFilter + +pytestmark = pytest.mark.anyio + + +@pytest.mark.parametrize( + ("error", "parameters", "line"), + [ + (None, {}, "com.example.UserService getUser OK 1.2ms"), + (RpcError(Status.NOT_FOUND), {}, "com.example.UserService getUser NOT_FOUND 1.2ms"), + (KeyError("u"), {}, "com.example.UserService getUser UNKNOWN 1.2ms"), + (None, {"group": "g", "version": "1.0"}, "g/com.example.UserService:1.0 getUser OK 1.2ms"), + ], + ids=["success", "rpc-status", "handler-exception", "service-key"], +) +async def test_access_log_records_the_service_method_status_and_elapsed_time( + error, parameters, line, monkeypatch, ending, call, url, caplog +): + monkeypatch.setattr(accesslog, "time", SimpleNamespace(perf_counter=iter([1.0, 1.0012]).__next__)) + expected = Result(value="u", error=error) + + with caplog.at_level(logging.INFO, logger="dubbo.accesslog"): + result = await AccessLogFilter(url.update_parameters(parameters)).invoke(ending(expected).invoke, call()) + + assert result is expected + assert [(record.name, record.levelno, record.getMessage()) for record in caplog.records] == [ + ("dubbo.accesslog", logging.INFO, line) + ] + + +async def test_access_log_records_a_cancelled_call(monkeypatch, call, url, caplog): + monkeypatch.setattr(accesslog, "time", SimpleNamespace(perf_counter=iter([1.0, 1.0012]).__next__)) + + async def call_next(invocation: Invocation) -> Result: + scope.cancel() + await anyio.sleep_forever() + + with caplog.at_level(logging.INFO, logger="dubbo.accesslog"), anyio.CancelScope() as scope: + await AccessLogFilter(url).invoke(call_next, call()) + + assert [record.getMessage() for record in caplog.records] == ["com.example.UserService getUser CANCELLED 1.2ms"] + + +async def test_access_log_records_a_call_that_raises_and_lets_the_exception_through(monkeypatch, call, url, caplog): + monkeypatch.setattr(accesslog, "time", SimpleNamespace(perf_counter=iter([1.0, 1.0012]).__next__)) + + async def call_next(invocation: Invocation) -> Result: + raise OSError("lost") + + with caplog.at_level(logging.INFO, logger="dubbo.accesslog"), pytest.raises(OSError, match="lost"): + await AccessLogFilter(url).invoke(call_next, call()) + + assert [record.getMessage() for record in caplog.records] == ["com.example.UserService getUser UNKNOWN 1.2ms"] + + +@pytest.mark.parametrize( + ("parameters", "group", "version"), + [({}, None, None), ({"group": "g", "version": "1.0"}, "g", "1.0")], + ids=["plain", "group-and-version"], +) +async def test_access_log_gives_each_value_as_a_field_of_its_record( + parameters, group, version, monkeypatch, ending, call, url, caplog +): + monkeypatch.setattr(accesslog, "time", SimpleNamespace(perf_counter=iter([1.0, 1.0015]).__next__)) + + with caplog.at_level(logging.INFO, logger="dubbo.accesslog"): + await AccessLogFilter(url.update_parameters(parameters)).invoke( + ending(Result(error=RpcError(Status.NOT_FOUND))).invoke, call() + ) + + [record] = caplog.records + fields = {name: getattr(record, name) for name in ("service", "group", "version", "method", "status")} + assert fields == { + "service": "com.example.UserService", + "group": group, + "version": version, + "method": "getUser", + "status": "NOT_FOUND", + } + assert record.duration_ms == pytest.approx(1.5) diff --git a/tests/unit/filter/test_activecount.py b/tests/unit/filter/test_activecount.py new file mode 100644 index 00000000..3ad1c342 --- /dev/null +++ b/tests/unit/filter/test_activecount.py @@ -0,0 +1,52 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import pytest + +from dubbo import Invocation, Result +from dubbo.filter.activecount import ActiveCountFilter, active_counts + +pytestmark = pytest.mark.anyio + + +async def test_active_count_tracks_calls_per_method_until_they_finish(gate, call, url): + filter_ = ActiveCountFilter(url) + counts = active_counts(url) + + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + tasks.start_soon(filter_.invoke, gate.invoke, call("wait")) + tasks.start_soon(filter_.invoke, gate.invoke, call("wait")) + await anyio.wait_all_tasks_blocked() + assert (counts.get(url, "wait"), counts.get(url, "other")) == (2, 0) + gate.opened.set() + + assert counts.get(url, "wait") == 0 + + +async def test_active_count_releases_the_count_when_the_next_invoker_raises(call, url): + counts = active_counts(url) + + async def fail(invocation: Invocation) -> Result: + assert counts.get(url, "fail") == 1 + raise RuntimeError("down") + + with pytest.raises(RuntimeError, match="down"): + await ActiveCountFilter(url).invoke(fail, call("fail")) + + assert counts.get(url, "fail") == 0 diff --git a/tests/unit/filter/test_actives.py b/tests/unit/filter/test_actives.py new file mode 100644 index 00000000..0a09f249 --- /dev/null +++ b/tests/unit/filter/test_actives.py @@ -0,0 +1,85 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import pytest + +from dubbo import Result, RpcError, Status +from dubbo.filter import chain_filters +from dubbo.filter.activecount import active_counts +from dubbo.filter.actives import ActivesFilter + +pytestmark = pytest.mark.anyio + + +async def test_actives_queues_calls_per_method_until_a_slot_is_released(gate, call, url): + invoker = chain_filters(gate, [ActivesFilter(url.update_parameters({"actives": "1", "timeout": "60000"}))]) + results: list[Result] = [] + + async def invoke() -> None: + results.append(await invoker.invoke(call("wait"))) + + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + tasks.start_soon(invoke) + tasks.start_soon(invoke) + await anyio.wait_all_tasks_blocked() + assert (results, gate.entered) == ([], ["wait"]) + assert (await invoker.invoke(call("other"))).value == "other" + gate.opened.set() + + assert [result.value for result in results] == ["wait", "wait"] + assert gate.entered == ["wait", "other", "wait"] + + +async def test_actives_returns_unavailable_when_the_method_queue_timeout_expires(gate, call, url): + invoker = chain_filters( + gate, [ActivesFilter(url.update_parameters({"actives": "1", "timeout": "60000", "wait_briefly.timeout": "50"}))] + ) + + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + tasks.start_soon(invoker.invoke, call("wait_briefly")) + await anyio.wait_all_tasks_blocked() + refused = await invoker.invoke(call("wait_briefly")) + gate.opened.set() + + assert isinstance(refused.error, RpcError) + assert (refused.error.status, refused.error.message, gate.entered) == ( + Status.UNAVAILABLE, + "com.example.UserService.wait_briefly makes 1 calls at once to 127.0.0.1:50051, and none ended within 0.05 seconds", + ["wait_briefly"], + ) + + +async def test_actives_made_again_holds_calls_beyond_those_under_way_through_the_one_before(gate, call, url): + limited = url.update_parameters({"actives": "1", "timeout": "50"}) + before = chain_filters(gate, [ActivesFilter(limited)]) + again = chain_filters(gate, [ActivesFilter(limited)]) + counts = active_counts(url) + + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + tasks.start_soon(before.invoke, call("wait")) + await anyio.wait_all_tasks_blocked() + under_way = counts.get(url, "wait") + held = await again.invoke(call("wait")) + gate.opened.set() + + assert under_way == 1 + assert isinstance(held.error, RpcError) + assert (held.error.status, gate.entered, counts.get(url, "wait")) == (Status.UNAVAILABLE, ["wait"], 0) diff --git a/tests/unit/filter/test_base.py b/tests/unit/filter/test_base.py new file mode 100644 index 00000000..e696bfc3 --- /dev/null +++ b/tests/unit/filter/test_base.py @@ -0,0 +1,159 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import pytest + +from dubbo import Invocation, Invoke, Result +from dubbo.extension import extensions +from dubbo.filter import Filter, chain_filters, get_attempt_filters, get_service_filters +from dubbo.filter.accesslog import AccessLogFilter +from dubbo.filter.activecount import ActiveCountFilter +from dubbo.filter.actives import ActivesFilter +from dubbo.filter.deprecated import DeprecatedFilter +from dubbo.filter.executes import ExecutesFilter +from dubbo.filter.token import TokenFilter +from dubbo.filter.tps import TpsFilter +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +@pytest.mark.parametrize( + ("side", "parameters", "expected"), + [ + ( + "service", + {"accesslog": "true", "token": "s", "getUser.tps": "2", "executes": "0", "service.filter": "named"}, + [AccessLogFilter, TokenFilter, TpsFilter, "named"], + ), + ( + "attempt", + {"getUser.deprecated": "true", "actives": "2", "tps": "1", "reference.attempt-filter": "named"}, + [DeprecatedFilter, ActivesFilter, "named"], + ), + ("attempt", {"loadbalance": "leastactive"}, [ActiveCountFilter]), + ("attempt", {"getUser.loadbalance": "leastactive"}, [ActiveCountFilter]), + ("attempt", {"actives": "2", "loadbalance": "leastactive"}, [ActivesFilter]), + ("service", {"accesslog": "false", "executes": "0", "deprecated": "false", "actives": "0"}, []), + ("attempt", {"accesslog": "false", "executes": "0", "deprecated": "false", "actives": "0"}, []), + ("attempt", {"loadbalance": "roundrobin"}, []), + ("attempt", {"deprecated": "maybe"}, []), + ], + ids=[ + "service-before-named", + "attempt-before-named", + "least-active", + "method-least-active", + "actives-counting-for-least-active", + "disabled-service", + "disabled-attempt", + "uncounted-round-robin", + "unreadable-deprecated", + ], +) +def test_settings_add_their_filters_before_named_filters(side, parameters, expected, isolated_extensions, url): + class Named: + def __init__(self, url: URL) -> None: + pass + + async def invoke(self, call_next: Invoke, invocation: Invocation) -> Result: + return await call_next(invocation) + + extensions.register(Filter, "named", Named) + configured = url.update_parameters(parameters) + + filters = get_service_filters(configured) if side == "service" else get_attempt_filters(configured) + + assert [type(filter_) for filter_ in filters] == [Named if item == "named" else item for item in expected] + + +@pytest.mark.parametrize("create", [ActiveCountFilter, ActivesFilter, DeprecatedFilter, ExecutesFilter, TpsFilter]) +def test_a_filter_that_keeps_state_requires_the_application_that_keeps_it(create, url): + with pytest.raises(RuntimeError, match="belongs to no application"): + create(url.replace(attributes={})) + + +@pytest.mark.parametrize( + ("create", "key"), + [(ActivesFilter, "actives"), (ExecutesFilter, "executes"), (TpsFilter, "tps")], + ids=["actives", "executes", "tps"], +) +async def test_a_negative_limit_limits_no_call(create, key, ending, call, url): + limited = create(url.update_parameters({key: "-1"})) + end = ending(Result()) + + with anyio.fail_after(5): + results = [await limited.invoke(end.invoke, call()) for _ in range(2)] + + assert results == [Result(), Result()] + + +async def test_a_chain_keeps_the_invoker_url_and_closes_the_invoker(ending, url): + end = ending(Result()) + invoker = chain_filters(end, [AccessLogFilter(url), AccessLogFilter(url)]) + + assert invoker.url is end.url + await invoker.aclose() + + assert end.closed is True + + +def test_a_chain_without_filters_is_the_original_invoker(ending): + end = ending(Result()) + + assert chain_filters(end, []) is end + + +async def test_a_filter_chain_runs_first_outermost_and_can_change_the_response(ending, call): + events = [] + + class Record: + def __init__(self, name: str) -> None: + self.name = name + + async def invoke(self, call_next: Invoke, invocation: Invocation) -> Result: + events.append(f"{self.name}>") + result = await call_next(invocation) + events.append(f"<{self.name}") + result.attachments[self.name] = "seen" + + return result + + end = ending(Result(value="ok", attachments={"audit-id": "1"})) + invoker = chain_filters(end, [Record("outer"), Record("inner")]) + + result = await invoker.invoke(call()) + + assert (result.value, result.error, dict(result.attachments), events) == ( + "ok", + None, + {"audit-id": "1", "inner": "seen", "outer": "seen"}, + ["outer>", "inner>", " Result: + return Result(value="cached") + + end = ending(Result(value="uncached")) + + result = await chain_filters(end, [Answer()]).invoke(call()) + + assert (result, end.calls) == (Result(value="cached"), []) diff --git a/tests/unit/filter/test_deprecated.py b/tests/unit/filter/test_deprecated.py new file mode 100644 index 00000000..4da96d98 --- /dev/null +++ b/tests/unit/filter/test_deprecated.py @@ -0,0 +1,48 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging + +import pytest + +from dubbo import Result +from dubbo.extension import ApplicationScope +from dubbo.filter.deprecated import DeprecatedFilter +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = pytest.mark.anyio + + +async def test_deprecated_warns_once_per_method_and_application_across_provider_addresses(ending, call, caplog): + url = URL.parse("tri://10.0.0.5:50051/test.Deprecating?deprecated=true&kept.deprecated=false") + first, second = (url.replace(attributes={APPLICATION_SCOPE: ApplicationScope()}) for _ in range(2)) + filters = [DeprecatedFilter(first), DeprecatedFilter(first.replace(host="10.0.0.6")), DeprecatedFilter(second)] + end = ending(Result()) + + with caplog.at_level(logging.WARNING, logger="dubbo.filter.deprecated"): + for filter_ in (filters[0], *filters): + await filter_.invoke(end.invoke, call("old")) + await filter_.invoke(end.invoke, call("kept")) + + assert [(record.name, record.levelno, record.getMessage()) for record in caplog.records] == [ + ( + "dubbo.filter.deprecated", + logging.WARNING, + "Calling test.Deprecating.old, which its provider at 10.0.0.5:50051 deprecates", + ) + ] * 2 + assert [invocation.method for invocation in end.calls] == ["old", "kept"] * 4 diff --git a/tests/unit/filter/test_executes.py b/tests/unit/filter/test_executes.py new file mode 100644 index 00000000..1419b6e2 --- /dev/null +++ b/tests/unit/filter/test_executes.py @@ -0,0 +1,88 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import pytest + +from dubbo import Result, RpcError, Status +from dubbo.filter import chain_filters +from dubbo.filter.activecount import active_counts +from dubbo.filter.executes import ExecutesFilter + +pytestmark = pytest.mark.anyio + + +async def test_executes_rejects_calls_above_the_method_limit_until_a_running_call_finishes(gate, call, url): + invoker = chain_filters(gate, [ExecutesFilter(url.update_parameters({"executes": "5", "wait.executes": "1"}))]) + completed: list[Result] = [] + + async def invoke() -> None: + completed.append(await invoker.invoke(call("wait"))) + + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + tasks.start_soon(invoke) + await anyio.wait_all_tasks_blocked() + refused = await invoker.invoke(call("wait")) + other = await invoker.invoke(call("other")) + gate.opened.set() + after = await invoker.invoke(call("wait")) + + assert isinstance(refused.error, RpcError) + assert (refused.error.status, refused.error.message) == ( + Status.UNAVAILABLE, + "com.example.UserService.wait serves 1 calls at once", + ) + assert (completed, other.value, after.value, gate.entered) == ( + [Result(value="wait")], + "other", + "wait", + ["wait", "other", "wait"], + ) + + +async def test_executes_made_again_counts_the_calls_running_through_the_one_before(gate, call, url): + before = chain_filters(gate, [ExecutesFilter(url.update_parameters({"executes": "2"}))]) + lowered = chain_filters(gate, [ExecutesFilter(url.update_parameters({"executes": "1"}))]) + + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + tasks.start_soon(before.invoke, call("wait")) + await anyio.wait_all_tasks_blocked() + refused = await lowered.invoke(call("wait")) + gate.opened.set() + after = await lowered.invoke(call("wait")) + + assert isinstance(refused.error, RpcError) + assert (refused.error.status, after.value, gate.entered) == (Status.UNAVAILABLE, "wait", ["wait", "wait"]) + + +async def test_executes_counts_the_calls_served_apart_from_those_the_application_makes(gate, call, url): + served = chain_filters(gate, [ExecutesFilter(url.update_parameters({"executes": "1"}))]) + + with active_counts(url).counting(url, "wait"): + result = await served.invoke(call("other")) + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + tasks.start_soon(served.invoke, call("wait")) + await anyio.wait_all_tasks_blocked() + refused = await served.invoke(call("wait")) + gate.opened.set() + + assert result.value == "other" + assert isinstance(refused.error, RpcError) + assert gate.entered == ["other", "wait"] diff --git a/tests/unit/filter/test_token.py b/tests/unit/filter/test_token.py new file mode 100644 index 00000000..827d2d46 --- /dev/null +++ b/tests/unit/filter/test_token.py @@ -0,0 +1,46 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo import Result, RpcError, Status +from dubbo.filter.token import TokenFilter + +pytestmark = pytest.mark.anyio + + +async def test_token_filter_calls_the_handler_when_the_token_matches(ending, call, url): + end = ending(Result(value="ok")) + + result = await TokenFilter(url.update_parameters({"token": "s3"})).invoke(end.invoke, call(token="s3")) + + assert result == Result(value="ok") + assert len(end.calls) == 1 + + +@pytest.mark.parametrize("attachments", [{}, {"token": "s4"}], ids=["missing", "wrong"]) +async def test_token_filter_denies_a_call_without_the_matching_token(attachments, ending, call, url): + end = ending(Result(value="ok")) + + result = await TokenFilter(url.update_parameters({"token": "s3"})).invoke(end.invoke, call(**attachments)) + + assert isinstance(result.error, RpcError) + assert (result.error.status, result.error.message, end.calls) == ( + Status.PERMISSION_DENIED, + "com.example.UserService.getUser needs its token", + [], + ) diff --git a/tests/unit/filter/test_tps.py b/tests/unit/filter/test_tps.py new file mode 100644 index 00000000..d75fe10c --- /dev/null +++ b/tests/unit/filter/test_tps.py @@ -0,0 +1,68 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from types import SimpleNamespace + +import pytest + +from dubbo import Result, RpcError, Status +from dubbo.filter import tps +from dubbo.filter.tps import TpsFilter + +pytestmark = pytest.mark.anyio + + +async def test_tps_counts_methods_together_except_those_with_their_own_windows(monkeypatch, ending, call, url): + now = [0.0] + monkeypatch.setattr(tps, "time", SimpleNamespace(monotonic=lambda: now[0])) + filter_ = TpsFilter( + url.update_parameters({"tps": "2", "tps.interval": "60000", "own.tps": "1", "own.tps.interval": "50"}) + ) + end = ending(Result()) + + shared = [await filter_.invoke(end.invoke, call(method)) for method in "aba"] + own = [await filter_.invoke(end.invoke, call("own")) for _ in range(2)] + now[0] = 0.05 + renewed = await filter_.invoke(end.invoke, call("own")) + shared_after = await filter_.invoke(end.invoke, call("a")) + + assert shared[:2] == [Result(), Result()] + assert own[0] == renewed == Result() + errors = [shared[2].error, own[1].error, shared_after.error] + assert all(isinstance(error, RpcError) for error in errors) + assert [(error.status, error.message) for error in errors] == [ + (Status.UNAVAILABLE, "com.example.UserService.a serves 2 calls in 60.0 seconds"), + (Status.UNAVAILABLE, "com.example.UserService.own serves 1 calls in 0.05 seconds"), + (Status.UNAVAILABLE, "com.example.UserService.a serves 2 calls in 60.0 seconds"), + ] + assert [invocation.method for invocation in end.calls] == ["a", "b", "own", "own"] + + +async def test_tps_made_again_keeps_the_calls_its_window_counted_under_the_new_rate(ending, call, url): + end = ending(Result()) + before = TpsFilter(url.update_parameters({"tps": "2"})) + + counted = [await before.invoke(end.invoke, call()) for _ in range(2)] + same = await TpsFilter(url.update_parameters({"tps": "2"})).invoke(end.invoke, call()) + raised = TpsFilter(url.update_parameters({"tps": "3"})) + after = [await raised.invoke(end.invoke, call()) for _ in range(2)] + + assert counted == [Result(), Result()] + assert isinstance(same.error, RpcError) + assert after[0] == Result() + assert isinstance(after[1].error, RpcError) + assert len(end.calls) == 3 diff --git a/tests/unit/metadata/service/data/Capture.java.txt b/tests/unit/metadata/service/data/Capture.java.txt new file mode 100644 index 00000000..37af30f5 --- /dev/null +++ b/tests/unit/metadata/service/data/Capture.java.txt @@ -0,0 +1,48 @@ +import com.alibaba.com.caucho.hessian.io.Hessian2Input; +import com.alibaba.com.caucho.hessian.io.Hessian2Output; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; +import org.apache.dubbo.metadata.MetadataInfo; +import org.apache.dubbo.metadata.MetadataInfo.ServiceInfo; + +public class Capture { + public static void main(String[] args) throws Exception { + Map params = new TreeMap<>(); + params.put("application", "demo-provider"); + params.put("methods", "sayHello,sayHelloAsync"); + params.put("side", "provider"); + ServiceInfo service = new ServiceInfo( + "org.apache.dubbo.demo.DemoService", "g1", "1.0.0", "dubbo", 20880, + "org.apache.dubbo.demo.DemoService", params); + ServiceInfo bare = new ServiceInfo( + "org.apache.dubbo.demo.GreeterService", null, null, "tri", -1, + "org.apache.dubbo.demo.GreeterService", new TreeMap<>()); + Map services = new HashMap<>(); + services.put(service.getMatchKey(), service); + services.put(bare.getMatchKey(), bare); + MetadataInfo info = new MetadataInfo("demo-provider", "b7b1f9e4c0d8a3d6e5f2a1b0c9d8e7f6", services); + + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + Hessian2Output out = new Hessian2Output(bytes); + out.writeObject(info); + out.flush(); + Files.write(Path.of(args[0]), bytes.toByteArray()); + + try (FileInputStream file = new FileInputStream(args[1])) { + MetadataInfo read = (MetadataInfo) new Hessian2Input(file).readObject(); + System.out.println("app=" + read.getApp() + " revision=" + read.getRevision()); + for (Map.Entry entry : new TreeMap<>(read.getServices()).entrySet()) { + ServiceInfo s = entry.getValue(); + System.out.println(entry.getKey() + " -> name=" + s.getName() + " group=" + s.getGroup() + + " version=" + s.getVersion() + " protocol=" + s.getProtocol() + " port=" + s.getPort() + + " path=" + s.getPath() + " params=" + new TreeMap<>(s.getParams()) + + " matchKey=" + s.getMatchKey()); + } + } + } +} diff --git a/tests/unit/metadata/service/data/metadata_info.md b/tests/unit/metadata/service/data/metadata_info.md new file mode 100644 index 00000000..b96aa633 --- /dev/null +++ b/tests/unit/metadata/service/data/metadata_info.md @@ -0,0 +1,24 @@ +# MetadataService 1.0.0 values + +`org.apache.dubbo.metadata.MetadataInfo` values in Hessian 2.0, as the +MetadataService 1.0.0 returns them from `getMetadataInfo(String)`. + +Peer: Apache Dubbo 3.3.6 (`org.apache.dubbo:dubbo:3.3.6`) with +`org.apache.dubbo:hessian-lite:4.0.4`, on Eclipse Temurin 21. +Captured on 2026-11-14 with the Java program in `Capture.java.txt`: + + CP=/root/.m2/repository/org/apache/dubbo/dubbo/3.3.6/dubbo-3.3.6.jar:/root/.m2/repository/org/apache/dubbo/hessian-lite/4.0.4/hessian-lite-4.0.4.jar + docker run --rm --network none -v ~/.m2:/root/.m2:ro -v "$PWD":/w -w /w maven:3.9-eclipse-temurin-21 \ + sh -c "cp Capture.java.txt Capture.java && javac -cp $CP Capture.java && java -cp $CP:. Capture metadata_info_java.hessian metadata_info_python.hessian" + +- `metadata_info_java.hessian`: what Java writes for the metadata of + `demo-provider` at revision `b7b1f9e4c0d8a3d6e5f2a1b0c9d8e7f6`, with + `g1/org.apache.dubbo.demo.DemoService:1.0.0:dubbo` on port 20880 and + `org.apache.dubbo.demo.GreeterService:tri` without group, version or port. +- `metadata_info_python.hessian`: what `MetadataServiceV1Server` writes for + the metadata of `orders-app` serving `g1/com.example.OrderService:2.0.0:dubbo` + and `com.example.Health:dubbo` on port 20881. Java read it back as: + + app=orders-app revision=265ea22115086ffa295b1c5ffa5dfaba + com.example.Health:dubbo -> name=com.example.Health group=null version=null protocol=dubbo port=20881 path=com.example.Health params={} matchKey=com.example.Health:dubbo + g1/com.example.OrderService:2.0.0:dubbo -> name=com.example.OrderService group=g1 version=2.0.0 protocol=dubbo port=20881 path=com.example.OrderService params={application=orders-app, methods=find,list, side=provider} matchKey=g1/com.example.OrderService:2.0.0:dubbo diff --git a/tests/unit/metadata/service/data/metadata_info_java.hessian b/tests/unit/metadata/service/data/metadata_info_java.hessian new file mode 100644 index 00000000..f96b8bc3 --- /dev/null +++ b/tests/unit/metadata/service/data/metadata_info_java.hessian @@ -0,0 +1 @@ +C0&org.apache.dubbo.metadata.MetadataInfo“servicesrevisionapp`H00g1/org.apache.dubbo.demo.DemoService:1.0.0:dubboC02org.apache.dubbo.metadata.MetadataInfo$ServiceInfo—paramspathportprotocolversiongroupnameaMjava.util.TreeMap application demo-providermethodssayHello,sayHelloAsyncsideproviderZ0!org.apache.dubbo.demo.DemoServiceÔQ�dubbo1.0.0g10!org.apache.dubbo.demo.DemoService0(org.apache.dubbo.demo.GreeterService:triaM�Z0$org.apache.dubbo.demo.GreeterService�triNN0$org.apache.dubbo.demo.GreeterServiceZ0 b7b1f9e4c0d8a3d6e5f2a1b0c9d8e7f6 demo-provider \ No newline at end of file diff --git a/tests/unit/metadata/service/data/metadata_info_python.hessian b/tests/unit/metadata/service/data/metadata_info_python.hessian new file mode 100644 index 00000000..0dfcca4c --- /dev/null +++ b/tests/unit/metadata/service/data/metadata_info_python.hessian @@ -0,0 +1,3 @@ +C0&org.apache.dubbo.metadata.MetadataInfo“apprevisionservices` +orders-app0 265ea22115086ffa295b1c5ffa5dfabaH0'g1/com.example.OrderService:2.0.0:dubboC02org.apache.dubbo.metadata.MetadataInfo$ServiceInfo—namegroupversionprotocolportpathparamsacom.example.OrderServiceg12.0.0dubboÔQ‘com.example.OrderServiceH application +orders-appmethods find,listsideproviderZcom.example.Health:dubboacom.example.HealthNNdubboÔQ‘com.example.HealthHZZ \ No newline at end of file diff --git a/tests/unit/metadata/service/test_client.py b/tests/unit/metadata/service/test_client.py new file mode 100644 index 00000000..66b62d47 --- /dev/null +++ b/tests/unit/metadata/service/test_client.py @@ -0,0 +1,59 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +import dubbo.metadata.service.client as client +from dubbo.exceptions import RpcError, Status +from dubbo.extension import ApplicationScope +from dubbo.rpc import Result +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = pytest.mark.anyio + + +@pytest.mark.parametrize( + "path", ["org.apache.dubbo.metadata.MetadataServiceV2", "org.apache.dubbo.metadata.MetadataService"] +) +async def test_a_call_to_the_metadata_service_may_take_five_seconds(monkeypatch, path): + referred = [] + + class Invoker: + async def invoke(self, invocation): + return Result(error=RpcError(Status.UNAVAILABLE, "unreachable")) + + async def aclose(self): + pass + + class Protocol: + async def refer(self, url, definition): + referred.append(url) + return Invoker() + + async def get_protocol(name, scope): + return Protocol() + + monkeypatch.setattr(client, "get_protocol", get_protocol) + + url = URL.parse(f"tri://10.0.0.5:50051/{path}?timeout=1000").replace( + attributes={APPLICATION_SCOPE: ApplicationScope()} + ) + with pytest.raises(RpcError): + await client.call_metadata_service(url, "r1") + + # The time of a call is its URL's, which a consumer's own settings must not shorten. + assert [url.parameters["timeout"] for url in referred] == ["5000"] diff --git a/tests/unit/metadata/service/test_v1.py b/tests/unit/metadata/service/test_v1.py new file mode 100644 index 00000000..c37a0159 --- /dev/null +++ b/tests/unit/metadata/service/test_v1.py @@ -0,0 +1,131 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from pathlib import Path +from typing import Any + +import pytest + +from dubbo.metadata import MetadataInfo, ServiceInfo +from dubbo.metadata.service.server import MetadataStore +from dubbo.metadata.service.v1 import ( + JavaMetadataInfo, + JavaServiceInfo, + MetadataServiceV1, + MetadataServiceV1Server, + read_metadata_info, +) +from dubbo.rpc.definition import get_definition +from dubbo.rpc.invocation import Invocation, Invoke, Result +from dubbo.serialization.hessian2 import Hessian2Serialization +from dubbo.url import URL + +pytestmark = pytest.mark.anyio +_DATA = Path(__file__).parent / "data" +_ORDERS = MetadataInfo.from_services( + "orders-app", + [ + ServiceInfo( + name="com.example.OrderService", + group="g1", + version="2.0.0", + protocol="dubbo", + port=20881, + path="com.example.OrderService", + params={"application": "orders-app", "methods": "find,list", "side": "provider"}, + ), + ServiceInfo(name="com.example.Health", protocol="dubbo", port=20881, path="com.example.Health"), + ], +) + + +def _response_codec(): + (method,) = (method for method in get_definition(MetadataServiceV1).methods if method.name == "getMetadataInfo") + return Hessian2Serialization(URL.parse("dubbo://127.0.0.1")).codec([method.response]) + + +def _returning(value: Any) -> Invoke: + async def invoke(invocation: Invocation) -> Result: + return Result(value=value) + + return invoke + + +async def test_the_metadata_java_serves_reads_as_its_services() -> None: + (value,) = _response_codec().decode((_DATA / "metadata_info_java.hessian").read_bytes()) + + info = await read_metadata_info(_returning(value), "b7b1f9e4c0d8a3d6e5f2a1b0c9d8e7f6") + + demo = ServiceInfo( + name="org.apache.dubbo.demo.DemoService", + group="g1", + version="1.0.0", + protocol="dubbo", + port=20880, + path="org.apache.dubbo.demo.DemoService", + params={"application": "demo-provider", "methods": "sayHello,sayHelloAsync", "side": "provider"}, + ) + greeter = ServiceInfo( + name="org.apache.dubbo.demo.GreeterService", + protocol="tri", + port=-1, + path="org.apache.dubbo.demo.GreeterService", + ) + assert info == MetadataInfo.from_services("demo-provider", [demo, greeter]) + + +async def test_served_metadata_travels_as_java_reads_it() -> None: + metadata = MetadataStore() + metadata.add(_ORDERS) + + value = await MetadataServiceV1Server(metadata, "orders-app").get_metadata_info(_ORDERS.revision) + + assert _response_codec().encode((value,)) == (_DATA / "metadata_info_python.hessian").read_bytes() + + +async def test_a_revision_not_served_is_answered_with_none() -> None: + metadata = MetadataStore() + metadata.add(_ORDERS) + + assert await MetadataServiceV1Server(metadata, "orders-app").get_metadata_info("other") is None + assert await read_metadata_info(_returning(None), "other") is None + + +async def test_the_server_answers_the_other_methods_java_calls() -> None: + metadata = MetadataStore() + metadata.add(_ORDERS) + server = MetadataServiceV1Server(metadata, "orders-app") + + assert await server.service_name() == "orders-app" + assert await server.version() == "1.0.0" + assert await server.get_service_definition("g1/com.example.OrderService:2.0.0") == "" + assert await server.get_metadata_infos() == [await server.get_metadata_info(_ORDERS.revision)] + + +@pytest.mark.parametrize( + "value", + [ + pytest.param(JavaMetadataInfo(revision="r", services={}), id="no-application"), + pytest.param( + JavaMetadataInfo(app="a", revision="r", services={"k": JavaServiceInfo(name="x.Y", port=1)}), + id="service-without-protocol", + ), + ], +) +async def test_metadata_that_misses_what_names_a_service_cannot_be_read(value: JavaMetadataInfo) -> None: + with pytest.raises(ValueError, match="the metadata"): + await read_metadata_info(_returning(value), "r") diff --git a/tests/unit/metadata/service/test_v2.py b/tests/unit/metadata/service/test_v2.py new file mode 100644 index 00000000..23134529 --- /dev/null +++ b/tests/unit/metadata/service/test_v2.py @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo import RpcError, Status +from dubbo.metadata.service.server import MetadataStore + +pytestmark = pytest.mark.anyio + + +async def test_the_metadata_service_serves_no_openapi_document(): + from dubbo.metadata.service.v2 import MetadataServiceV2Server, OpenAPIRequest + + with pytest.raises(RpcError, match="OpenAPI documents are not served") as raised: + await MetadataServiceV2Server(MetadataStore()).get_open_api_info(OpenAPIRequest()) + + assert raised.value.status is Status.UNIMPLEMENTED diff --git a/tests/unit/metadata/test_info.py b/tests/unit/metadata/test_info.py new file mode 100644 index 00000000..f9501c34 --- /dev/null +++ b/tests/unit/metadata/test_info.py @@ -0,0 +1,66 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import hashlib +import json + +from dubbo.metadata import MetadataInfo, ServiceInfo + + +def test_the_revision_hashes_the_services_as_dubbo_for_java_describes_them(): + service = ServiceInfo( + name="com.example.Greeter", + group="g", + version="1.0", + protocol="tri", + port=50051, + path="com.example.Greeter", + params={"side": "provider", "methods": "greet"}, + ) + info = MetadataInfo.from_services("demo", [service]) + + # MetadataInfo#calRevision: the application, then per service its match + # key, port, path and parameters as java.util.TreeMap#toString renders them. + described = "g/com.example.Greeter:1.0:tri50051com.example.Greeter{methods=greet, side=provider}" + + assert service.describe() == described + assert info.revision == hashlib.md5(("demo" + described).encode()).hexdigest() + assert MetadataInfo.from_services("demo", []).revision == "0" + + +def test_remote_metadata_reads_back_from_its_json(): + service = ServiceInfo( + name="com.example.Greeter", protocol="tri", port=50051, path="com.example.Greeter", params={"a": "1"} + ) + info = MetadataInfo.from_services("demo", [service]) + + data = json.loads(info.to_json()) + + assert data == { + "app": "demo", + "revision": info.revision, + "services": { + "com.example.Greeter:tri": { + "name": "com.example.Greeter", + "protocol": "tri", + "port": 50051, + "path": "com.example.Greeter", + "params": {"a": "1"}, + } + }, + } + assert MetadataInfo.from_json(info.to_json()) == info diff --git a/tests/unit/metadata/test_instance.py b/tests/unit/metadata/test_instance.py new file mode 100644 index 00000000..546903a6 --- /dev/null +++ b/tests/unit/metadata/test_instance.py @@ -0,0 +1,104 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import json + +import pytest + +from dubbo.metadata.instance import InstanceMetadata +from dubbo.url import URL + +_V1 = "org.apache.dubbo.metadata.MetadataService" +_V2 = "org.apache.dubbo.metadata.MetadataServiceV2" + + +def _metadata(params: object, **values: str) -> dict[str, str]: + return {"dubbo.metadata.revision": "r1", "dubbo.metadata-service.url-params": json.dumps(params), **values} + + +@pytest.mark.parametrize( + ("metadata", "expected"), + [ + pytest.param( + _metadata({"protocol": "tri", "port": "50052", "version": "2.0.0"}, **{"meta-v": "2.0.0"}), + URL(protocol="tri", host="10.0.0.1", port=50052, path=_V2, parameters={"version": "2.0.0"}), + id="v2-over-tri", + ), + pytest.param( + _metadata({"protocol": "dubbo", "port": "20880", "version": "1.0.0"}, **{"meta-v": "1.0.0"}), + URL( + protocol="dubbo", + host="10.0.0.1", + port=20880, + path=_V1, + parameters={"version": "1.0.0", "serialization": "hessian2"}, + ), + id="v1-over-dubbo", + ), + pytest.param( + _metadata({"protocol": "tri", "port": "50052"}), + URL( + protocol="tri", + host="10.0.0.1", + port=50052, + path=_V1, + parameters={"version": "1.0.0", "serialization": "hessian2"}, + ), + id="v1-over-tri-without-meta-v", + ), + pytest.param( + _metadata({"protocol": "dubbo"}, **{"meta-v": "2.0.0"}), + URL( + protocol="dubbo", + host="10.0.0.1", + port=50051, + path=_V1, + parameters={"version": "1.0.0", "serialization": "hessian2"}, + ), + id="v1-at-the-instance-port-over-a-protocol-other-than-tri", + ), + ], +) +def test_local_metadata_locates_the_metadata_service_it_says(metadata: dict[str, str], expected: URL) -> None: + instance = InstanceMetadata.from_metadata("10.0.0.1", 50051, metadata) + + assert instance is not None + assert instance.metadata_service == expected + + +def test_an_instance_without_metadata_service_parameters_serves_none() -> None: + instance = InstanceMetadata.from_metadata("10.0.0.1", 50051, {"dubbo.metadata.revision": "r1"}) + + assert instance is not None + assert instance.metadata_service is None + + +def test_remote_metadata_is_not_read_from_the_instance() -> None: + metadata = _metadata({"protocol": "tri"}, **{"dubbo.metadata.storage-type": "remote"}) + + instance = InstanceMetadata.from_metadata("10.0.0.1", 50051, metadata) + + assert instance is not None + assert instance.metadata_service is None + + +@pytest.mark.parametrize( + "params", [pytest.param([], id="not-an-object"), pytest.param({"port": "1"}, id="no-protocol")] +) +def test_metadata_service_parameters_that_cannot_be_read_fail(params: object) -> None: + with pytest.raises(ValueError, match="cannot be read"): + InstanceMetadata.from_metadata("10.0.0.1", 50051, _metadata(params)) diff --git a/tests/unit/protoc/data/README.md b/tests/unit/protoc/data/README.md new file mode 100644 index 00000000..aa4ae4fd --- /dev/null +++ b/tests/unit/protoc/data/README.md @@ -0,0 +1,7 @@ +# Generated contract fixture + +`greeter_v1_dubbo.py.txt` is the expected generated source for the request and +`METHODS` in `test_plugin.py`: a nested local response message, an imported +protobuf wrapper, all four RPC shapes, acronym and keyword method names, +escaped comments, and an empty service. It is an output contract fixture, not +evidence captured from a Java or Go peer. diff --git a/tests/unit/protoc/data/greeter_v1_dubbo.py.txt b/tests/unit/protoc/data/greeter_v1_dubbo.py.txt new file mode 100644 index 00000000..bd3f1be5 --- /dev/null +++ b/tests/unit/protoc/data/greeter_v1_dubbo.py.txt @@ -0,0 +1,83 @@ +# Generated by protoc-gen-python-dubbo. DO NOT EDIT! +# source: demo/greeter-v1.proto +"""Dubbo service contracts of demo/greeter-v1.proto.""" + +import abc +import typing + +import dubbo + +from demo import greeter_v1_pb2 +from google.protobuf import wrappers_pb2 + +__all__ = ["Greeter", "GreeterServicer", "Empty", "EmptyServicer"] + + +@dubbo.service("demo.Greeter") +class Greeter(typing.Protocol): + """Greets people.""" + + @dubbo.method("SayHello") + async def say_hello(self, request: wrappers_pb2.StringValue) -> greeter_v1_pb2.Outer.Inner: + """Says hello. + + Says it "twice": \\ \"\"\" . + """ + + @dubbo.method("LotsOfReplies") + def lots_of_replies(self, request: wrappers_pb2.StringValue) -> dubbo.ServerStream[wrappers_pb2.StringValue]: ... + + @dubbo.method("LotsOfGreetings") + def lots_of_greetings(self) -> dubbo.ClientStream[wrappers_pb2.StringValue, wrappers_pb2.StringValue]: ... + + @dubbo.method("BidiHello") + def bidi_hello(self) -> dubbo.BidiStream[wrappers_pb2.StringValue, wrappers_pb2.StringValue]: ... + + @dubbo.method("GetHTTPStatus") + async def get_http_status(self, request: wrappers_pb2.StringValue) -> wrappers_pb2.StringValue: ... + + @dubbo.method("Import") + async def import_(self, request: wrappers_pb2.StringValue) -> wrappers_pb2.StringValue: ... + + +@dubbo.service("demo.Greeter") +class GreeterServicer(abc.ABC): + """Greets people.""" + + @dubbo.method("SayHello") + @abc.abstractmethod + async def say_hello(self, request: wrappers_pb2.StringValue) -> greeter_v1_pb2.Outer.Inner: + """Says hello. + + Says it "twice": \\ \"\"\" . + """ + + @dubbo.method("LotsOfReplies") + @abc.abstractmethod + async def lots_of_replies(self, request: wrappers_pb2.StringValue, stream: dubbo.SendStream[wrappers_pb2.StringValue]) -> None: ... + + @dubbo.method("LotsOfGreetings") + @abc.abstractmethod + async def lots_of_greetings(self, stream: dubbo.ReceiveStream[wrappers_pb2.StringValue]) -> wrappers_pb2.StringValue: ... + + @dubbo.method("BidiHello") + @abc.abstractmethod + async def bidi_hello(self, stream: dubbo.Stream[wrappers_pb2.StringValue, wrappers_pb2.StringValue]) -> None: ... + + @dubbo.method("GetHTTPStatus") + @abc.abstractmethod + async def get_http_status(self, request: wrappers_pb2.StringValue) -> wrappers_pb2.StringValue: ... + + @dubbo.method("Import") + @abc.abstractmethod + async def import_(self, request: wrappers_pb2.StringValue) -> wrappers_pb2.StringValue: ... + + +@dubbo.service("demo.Empty") +class Empty(typing.Protocol): + ... + + +@dubbo.service("demo.Empty") +class EmptyServicer(abc.ABC): + ... diff --git a/tests/unit/protoc/test_plugin.py b/tests/unit/protoc/test_plugin.py new file mode 100644 index 00000000..35e35f70 --- /dev/null +++ b/tests/unit/protoc/test_plugin.py @@ -0,0 +1,165 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import sys +import types +from pathlib import Path + +import pytest +from google.protobuf import descriptor_pb2, wrappers_pb2 +from google.protobuf.compiler.plugin_pb2 import CodeGeneratorRequest + +from dubbo.protoc import generate +from dubbo.rpc.definition import RpcType, get_contract_methods, get_definition + +STRING = ".google.protobuf.StringValue" + + +GOLDEN = Path(__file__).with_name("data").joinpath("greeter_v1_dubbo.py.txt").read_text() + + +def _request(*methods: dict[str, object]) -> CodeGeneratorRequest: + wrappers = descriptor_pb2.FileDescriptorProto() + wrappers_pb2.DESCRIPTOR.CopyToProto(wrappers) + greeter = descriptor_pb2.FileDescriptorProto( + name="demo/greeter-v1.proto", package="demo", dependency=["google/protobuf/wrappers.proto"] + ) + greeter.message_type.add(name="Outer").nested_type.add(name="Inner") + service = greeter.service.add(name="Greeter") + for method in methods: + service.method.add(**method) + greeter.service.add(name="Empty") + greeter.source_code_info.location.add(path=[6, 0], leading_comments=" Greets people.\n") + greeter.source_code_info.location.add( + path=[6, 0, 2, 0], leading_comments=' Says hello.\n\n Says it "twice": \\ """ .\n' + ) + return CodeGeneratorRequest(file_to_generate=[greeter.name], proto_file=[wrappers, greeter]) + + +METHODS = ( + {"name": "SayHello", "input_type": STRING, "output_type": ".demo.Outer.Inner"}, + {"name": "LotsOfReplies", "input_type": STRING, "output_type": STRING, "server_streaming": True}, + {"name": "LotsOfGreetings", "input_type": STRING, "output_type": STRING, "client_streaming": True}, + { + "name": "BidiHello", + "input_type": STRING, + "output_type": STRING, + "client_streaming": True, + "server_streaming": True, + }, + {"name": "GetHTTPStatus", "input_type": STRING, "output_type": STRING}, + {"name": "Import", "input_type": STRING, "output_type": STRING}, +) + + +def test_a_service_becomes_a_contract_with_python_names_and_the_pb2_messages(): + response = generate(_request(*METHODS)) + + assert not response.error + assert [(file.name, file.content) for file in response.file] == [("demo/greeter_v1_dubbo.py", GOLDEN)] + + +def test_the_generated_contract_defines_the_service(monkeypatch): + module = types.ModuleType("demo.greeter_v1_pb2") + module.Outer = type("Outer", (), {"Inner": wrappers_pb2.StringValue}) + package = types.ModuleType("demo") + package.greeter_v1_pb2 = module + monkeypatch.setitem(sys.modules, "demo", package) + monkeypatch.setitem(sys.modules, "demo.greeter_v1_pb2", module) + namespace: dict[str, object] = {} + + exec(generate(_request(*METHODS)).file[0].content, namespace) + + definition = get_definition(namespace["Greeter"]) + assert definition.interface == "demo.Greeter" + assert [(method.name, method.rpc_type) for method in definition.methods] == [ + ("SayHello", RpcType.UNARY), + ("LotsOfReplies", RpcType.SERVER_STREAM), + ("LotsOfGreetings", RpcType.CLIENT_STREAM), + ("BidiHello", RpcType.BIDI_STREAM), + ("GetHTTPStatus", RpcType.UNARY), + ("Import", RpcType.UNARY), + ] + assert list(get_contract_methods(namespace["Greeter"]))[-1] == "import_" + assert get_definition(namespace["GreeterServicer"]) == definition + assert definition.method("SayHello").response is wrappers_pb2.StringValue + + +def test_a_message_named_with_a_keyword_and_a_comment_ending_in_a_quote_generate_valid_python(): + request = _request({"name": "Echo", "input_type": ".demo.Outer.class", "output_type": ".demo.class"}) + greeter = request.proto_file[1] + greeter.message_type[0].nested_type.add(name="class") + greeter.message_type.add(name="class") + greeter.source_code_info.location.add(path=[6, 0, 2, 0], leading_comments=' Returns "ready"\n') + + content = generate(request).file[0].content + + compile(content, "demo/greeter_v1_dubbo.py", "exec") + assert 'getattr(getattr(greeter_v1_pb2, "Outer"), "class")' not in content + assert 'getattr(greeter_v1_pb2.Outer, "class")' in content + assert 'getattr(greeter_v1_pb2, "class")' in content + assert '"""Returns "ready\\""""' in content + + +def test_pb2_modules_with_the_same_basename_keep_their_message_types_distinct(monkeypatch): + generated = _request({"name": "Copy", "input_type": STRING, "output_type": ".other.Value"}) + other = descriptor_pb2.FileDescriptorProto(name="other/wrappers.proto", package="other") + other.message_type.add(name="Value") + generated.proto_file.insert(0, other) + module = types.ModuleType("other.wrappers_pb2") + module.Value = wrappers_pb2.Int64Value + package = types.ModuleType("other") + package.wrappers_pb2 = module + monkeypatch.setitem(sys.modules, "other", package) + monkeypatch.setitem(sys.modules, "other.wrappers_pb2", module) + namespace = {} + + exec(generate(generated).file[0].content, namespace) + method = get_definition(namespace["Greeter"]).method("Copy") + + assert method.request[0].type is wrappers_pb2.StringValue + assert method.response is wrappers_pb2.Int64Value + + +@pytest.mark.parametrize( + ("names", "error"), + [ + (["GetUser", "get_user"], "methods of Greeter share the Python name 'get_user'"), + (["_Hidden"], "method Greeter._Hidden would be private in Python"), + (["Dubbo"], "method Greeter.Dubbo would hide the imported name 'dubbo'"), + (["Wrappers_pb2"], "method Greeter.Wrappers_pb2 would hide the imported name 'wrappers_pb2'"), + ], +) +def test_a_service_that_cannot_be_a_contract_sets_the_error(names, error): + response = generate(_request(*({"name": name, "input_type": STRING, "output_type": STRING} for name in names))) + + assert response.error == f"demo/greeter-v1.proto: {error}" + assert not response.file + + +def test_a_service_named_as_an_import_sets_the_error(): + request = _request({"name": "SayHello", "input_type": STRING, "output_type": STRING}) + request.proto_file[1].service[0].name = "typing" + + assert generate(request).error == "demo/greeter-v1.proto: a contract would hide the imported name 'typing'" + + +def test_a_file_named_with_dots_generates_beside_its_pb2_module(): + request = _request({"name": "SayHello", "input_type": STRING, "output_type": STRING}) + request.proto_file[1].name = request.file_to_generate[0] = "demo/greeter.v1.proto" + + assert [file.name for file in generate(request).file] == ["demo/greeter/v1_dubbo.py"] diff --git a/tests/unit/protocol/dubbo/test_body.py b/tests/unit/protocol/dubbo/test_body.py new file mode 100644 index 00000000..4a83818d --- /dev/null +++ b/tests/unit/protocol/dubbo/test_body.py @@ -0,0 +1,262 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import dataclasses +from typing import Any + +import hessian2 +import pytest + +from dubbo import Method, Parameter +from dubbo.exceptions import RemoteError, Status +from dubbo.protocol.dubbo.body import ( + MethodCodec, + ResponseCodec, + ResponseStatus, + read_request_head, + service_version, + status_error, + supports_response_attachments, + to_attachments, +) +from dubbo.serialization.hessian2 import Hessian2Serialization +from dubbo.url import URL + + +@hessian2.java_class("com.example.User") +@dataclasses.dataclass +class User: + name: str + age: int + + +FIND = Method( + name="find", request=(Parameter(name="name", type=str), Parameter(name="id", type=hessian2.Long)), response=User +) +FORGET = Method(name="forget", request=(Parameter(name="name", type=str),), response=None) +TAGS = Method(name="tags", request=(Parameter(name="tags", type=tuple[str, ...]),), response=set[str]) + +SERIALIZATION = Hessian2Serialization(URL(protocol="dubbo")) +RESPONSES = ResponseCodec(SERIALIZATION) + + +def _codec(method: Method = FIND, version: str = "1.0") -> MethodCodec: + return MethodCodec(RESPONSES, "com.example.UserService", version, method) + + +def _encode(*values: Any) -> bytes: + return SERIALIZATION.codec((Any,) * len(values)).encode(values) + + +def test_a_request_carries_the_call_and_its_attachments() -> None: + codec = _codec() + data = codec.encode_request(("bob", 7), {"group": "a"}) + assert hessian2.loads_many(data) == [ + "2.0.2", + "com.example.UserService", + "1.0", + "find", + "Ljava/lang/String;J", + "bob", + 7, + {"group": "a"}, + ] + reader = SERIALIZATION.reader(data) + + head = read_request_head(reader) + + assert (head.dubbo_version, head.path, head.version) == ("2.0.2", "com.example.UserService", "1.0") + assert (head.method, head.descriptor) == ("find", "Ljava/lang/String;J") + assert codec.read_arguments(reader) == (("bob", 7), {"group": "a"}) + + +def test_arguments_decode_as_the_parameter_types() -> None: + codec = _codec(TAGS) + reader = SERIALIZATION.reader(codec.encode_request((("a", "b"),), {})) + read_request_head(reader) + + assert codec.read_arguments(reader) == ((("a", "b"),), {}) + + +def test_an_argument_of_another_type_is_rejected() -> None: + reader = SERIALIZATION.reader( + _encode("2.0.2", "com.example.UserService", "1.0", "find", "Ljava/lang/String;J", 1, 7, {}) + ) + read_request_head(reader) + + with pytest.raises(ValueError, match="expected str"): + _codec().read_arguments(reader) + + +@pytest.mark.parametrize( + ("values", "message"), + [ + ((), "message ends before this value"), + (("2.0.2", "a", "1.0", "m"), "message ends before this value"), + ((1, "a", "", "m", ""), "expected str, got int"), + (("2.0.2", "a", "1.0", "m", ["not text"]), "expected str, got a list"), + ], + ids=["empty", "missing-descriptor", "non-text-version", "non-text-descriptor"], +) +def test_request_heads_reject_missing_or_non_text_fields(values, message): + with pytest.raises(ValueError, match=message): + read_request_head(SERIALIZATION.reader(_encode(*values))) + + +def test_attachments_that_are_no_map_of_text_are_rejected() -> None: + reader = SERIALIZATION.reader( + _encode("2.0.2", "a.B", "", "find", "Ljava/lang/String;J", "bob", 7, "not attachments") + ) + read_request_head(reader) + + with pytest.raises(ValueError, match="expected dict"): + _codec().read_arguments(reader) + + +@pytest.mark.parametrize("attachments", [None, {"dubbo": "2.0.2"}]) +def test_a_response_carries_the_value(attachments: dict[str, str] | None) -> None: + codec = _codec() + + response = codec.decode_response(codec.encode_value(User("bob", 3), attachments)) + + assert (response.value, response.exception, response.attachments) == (User("bob", 3), None, attachments or {}) + + +def test_a_value_decodes_as_the_return_type() -> None: + codec = _codec(TAGS) + + assert codec.decode_response(codec.encode_value({"a"}, None)).value == {"a"} + + +FIND_OR_NONE = Method(name="find", request=FIND.request, response=User | None) + + +@pytest.mark.parametrize("method", [FIND_OR_NONE, FORGET]) +def test_nothing_returned_travels_as_a_null_response(method: Method) -> None: + codec = _codec(method) + + for attachments in (None, {"k": "v"}): + response = codec.decode_response(codec.encode_value(None, attachments)) + assert (response.value, response.exception, response.attachments) == (None, None, attachments or {}) + + +@pytest.mark.parametrize("attachments", [None, {"k": "v"}]) +def test_a_null_response_fails_a_method_whose_return_type_allows_no_none(attachments: dict[str, str] | None) -> None: + codec = _codec() + + with pytest.raises(ValueError, match=r"declare User \| None"): + codec.decode_response(RESPONSES.encode_null(attachments)) + + +@pytest.mark.parametrize("attachments", [None, {"k": "v"}]) +def test_a_response_carries_the_exception(attachments: dict[str, str] | None) -> None: + error = RemoteError("java.lang.IllegalStateException", "bad") + + response = RESPONSES.decode_response(RESPONSES.encode_exception(error, attachments)) + + assert isinstance(response.exception, RemoteError) + assert str(response.exception) == "java.lang.IllegalStateException: bad" + assert response.attachments == (attachments or {}) + + +def test_values_after_a_response_are_left_unread() -> None: + codec = _codec() + data = codec.encode_value(User("bob", 3), None) + SERIALIZATION.codec((None,)).encode((None,)) + + assert codec.decode_response(data).value == User("bob", 3) + assert RESPONSES.decode_message(RESPONSES.encode_message("why") + b"N") == "why" + + +@pytest.mark.parametrize( + ("values", "message"), + [ + ((), "message ends before this value"), + (("x",), "expected int, got str"), + ((9, "v"), "kind is 0 to 5"), + ((1,), "message ends before this value"), + ((1, 2), "expected str, got int"), + ((4, "v"), "message ends before this value"), + ((4, "v", "not attachments"), "expected dict, got str"), + ], + ids=[ + "empty", + "non-integer-kind", + "unknown-kind", + "missing-value", + "wrong-value-type", + "missing-attachments", + "non-map-attachments", + ], +) +def test_response_bodies_reject_missing_fields_unknown_kinds_and_wrong_types(values, message): + with pytest.raises(ValueError, match=message): + RESPONSES.decode_response(_encode(*values), str) + + +@pytest.mark.parametrize( + ("version", "supported"), + [ + ("2.0.2", True), + ("2.0.99", True), + ("2.0.10", True), + ("2.0.1", False), + ("2.1.0", False), + ("3.0.0", False), + ("", False), + ("x", False), + ], +) +def test_response_attachments_reach_consumers_of_2_0_2_to_2_0_99(version: str, supported: bool) -> None: + assert supports_response_attachments(version) is supported + + +@pytest.mark.parametrize( + ("status", "rpc_status"), + [ + (ResponseStatus.SERVER_TIMEOUT, Status.DEADLINE_EXCEEDED), + (ResponseStatus.SERVICE_NOT_FOUND, Status.UNAVAILABLE), + (ResponseStatus.BAD_REQUEST, Status.INVALID_ARGUMENT), + (ResponseStatus.SERVICE_ERROR, Status.INTERNAL), + (ResponseStatus.SERVER_ERROR, Status.UNKNOWN), + (ResponseStatus.CHANNEL_INACTIVE, Status.UNAVAILABLE), + (99, Status.UNKNOWN), + ], +) +def test_a_status_reaches_the_consumer_as_an_error(status: int, rpc_status: Status) -> None: + error = status_error(status, "why") + + assert error.status is rpc_status + assert error.message.endswith(": why") + + +def test_received_attachments_become_text() -> None: + attachments = to_attachments({"a": "x", "b": b"y", "c": 3, "d": True, "e": object()}) + + assert dict(attachments) == {"a": "x", "b": b"y", "c": "3", "d": "true"} + + +@pytest.mark.parametrize("version", ["", "0.0.0", "*", None]) +def test_no_version_reads_as_empty(version: str | None) -> None: + head = read_request_head(SERIALIZATION.reader(_encode("2.0.2", "a.B", version, "m", ""))) + + assert head.version == service_version(version) == "" + + +def test_a_service_without_a_version_is_called_as_0_0_0() -> None: + reader = SERIALIZATION.reader(_codec(version="").encode_request(("bob", 7), {})) + + assert [reader.load(str) for _ in range(3)][2] == "0.0.0" diff --git a/tests/unit/protocol/dubbo/test_client.py b/tests/unit/protocol/dubbo/test_client.py new file mode 100644 index 00000000..2b059cdd --- /dev/null +++ b/tests/unit/protocol/dubbo/test_client.py @@ -0,0 +1,183 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +from typing import Any + +import anyio +import pytest + +import dubbo.utils.dialer as dialer_module +from dubbo.exceptions import RpcError, Status +from dubbo.protocol.dubbo.client import DubboClient +from dubbo.protocol.dubbo.connection import DubboConnection +from dubbo.serialization.hessian2 import Hessian2Serialization +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +class _Transport(asyncio.Transport): + def get_extra_info(self, name: str, default: Any = None) -> Any: + return default + + def is_closing(self) -> bool: + return False + + def write(self, data: Any) -> None: + pass + + def close(self) -> None: + pass + + +def _client(**parameters: str) -> DubboClient: + url = URL(protocol="dubbo", host="127.0.0.1", port=1, parameters=parameters) + return DubboClient(url, Hessian2Serialization(url), 2) + + +def _connected(protocol_factory: Any) -> tuple[_Transport, DubboConnection]: + transport = _Transport() + connection = protocol_factory() + connection.connection_made(transport) + return transport, connection + + +async def test_call_that_stops_waiting_leaves_the_attempt_to_the_others(monkeypatch: pytest.MonkeyPatch) -> None: + started = anyio.Event() + release = anyio.Event() + attempts = 0 + + async def slow_create_connection(protocol_factory, host, port, **kwargs): + nonlocal attempts + attempts += 1 + started.set() + await release.wait() + return _connected(protocol_factory) + + monkeypatch.setattr(asyncio.get_running_loop(), "create_connection", slow_create_connection) + client = _client() + + with anyio.move_on_after(0.01): + await client._connect() + await started.wait() + # The attempt runs on. + assert client._dialer._attempt is not None + + release.set() + connection = await client._connect() + + assert attempts == 1 + assert client.available + connection.connection_lost(None) + await client.aclose() + + +async def test_an_unanswered_attempt_fails_at_the_connect_timeout_and_leaves_the_client_unavailable( + monkeypatch: pytest.MonkeyPatch, +) -> None: + attempts = 0 + + async def unanswered_create_connection(*args, **kwargs): + nonlocal attempts + attempts += 1 + await anyio.sleep_forever() + + monkeypatch.setattr(asyncio.get_running_loop(), "create_connection", unanswered_create_connection) + # No retry within the test, so that the state after the failure stays. + monkeypatch.setattr(dialer_module, "backoff", lambda: iter([60.0] * 3)) + async with _client(**{"connect-timeout": "50"}) as client: + # Only the connect timeout ends the attempt; the bound only keeps a broken timeout from hanging. + with anyio.fail_after(5): + while client._dialer._attempt is not None: + await anyio.sleep(0.01) + + assert (attempts, client.available) == (1, False) + + +async def test_failed_attempt_fails_each_waiting_call_as_unavailable(monkeypatch: pytest.MonkeyPatch) -> None: + async def refused_create_connection(*args, **kwargs): + raise ConnectionRefusedError + + monkeypatch.setattr(asyncio.get_running_loop(), "create_connection", refused_create_connection) + client = _client() + + with pytest.raises(RpcError, match="cannot connect") as caught: + await client._connect() + + assert caught.value.status is Status.UNAVAILABLE + assert not client.available + await client.aclose() + + +async def test_entered_client_connects_and_reconnects_in_the_background(monkeypatch: pytest.MonkeyPatch) -> None: + connected = anyio.Event() + connections: list[DubboConnection] = [] + + async def create_connection(protocol_factory, host, port, **kwargs): + transport, connection = _connected(protocol_factory) + connections.append(connection) + connected.set() + return transport, connection + + monkeypatch.setattr(asyncio.get_running_loop(), "create_connection", create_connection) + monkeypatch.setattr(dialer_module, "backoff", lambda: iter([0.01] * 3)) + async with _client() as client: + with anyio.fail_after(5): + await connected.wait() + await anyio.wait_all_tasks_blocked() + assert client.available + + connected = anyio.Event() + connections[0].connection_lost(None) + assert not client.available + with anyio.fail_after(5): + await connected.wait() + await anyio.wait_all_tasks_blocked() + + assert len(connections) == 2 + assert client.available + connections[1].connection_lost(None) + + +async def test_each_call_pending_on_a_lost_connection_raises_its_own_error(monkeypatch: pytest.MonkeyPatch) -> None: + connections: list[DubboConnection] = [] + + async def create_connection(protocol_factory, host, port, **kwargs): + transport, connection = _connected(protocol_factory) + connections.append(connection) + return transport, connection + + monkeypatch.setattr(asyncio.get_running_loop(), "create_connection", create_connection) + monkeypatch.setattr(dialer_module, "backoff", lambda: iter([60.0] * 3)) + raised: list[RpcError] = [] + + async def call(client: DubboClient) -> None: + try: + await client.call(b"body") + except RpcError as error: + raised.append(error) + + async with _client() as client, anyio.create_task_group() as calls: + calls.start_soon(call, client) + calls.start_soon(call, client) + await anyio.wait_all_tasks_blocked() + connections[0].connection_lost(None) + + first, second = raised + assert first is not second + assert first.status is second.status is Status.UNAVAILABLE diff --git a/tests/unit/protocol/dubbo/test_connection.py b/tests/unit/protocol/dubbo/test_connection.py new file mode 100644 index 00000000..42b06f4a --- /dev/null +++ b/tests/unit/protocol/dubbo/test_connection.py @@ -0,0 +1,112 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import struct +from typing import Any + +import pytest + +from dubbo.protocol.dubbo.connection import DubboConnection, EventBodies +from dubbo.serialization.hessian2 import Hessian2Serialization +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +class _Transport(asyncio.Transport): + def __init__(self) -> None: + super().__init__() + self.reading = True + + def get_extra_info(self, name: str, default: Any = None) -> Any: + return default + + def is_closing(self) -> bool: + return False + + def pause_reading(self) -> None: + self.reading = False + + def resume_reading(self) -> None: + self.reading = True + + def write(self, data: Any) -> None: + pass + + def close(self) -> None: + pass + + +def _connection(transport: asyncio.Transport, frames: list[bytes], *, pause_reading: bool = False) -> DubboConnection: + connection = DubboConnection( + on_frame=lambda _connection, _flags, _status, _request_id, body: frames.append(body), + on_closed=lambda _connection: None, + serialization_id=2, + events=EventBodies.from_serialization(Hessian2Serialization(URL(protocol="dubbo"))), + heartbeat=None, + idle_timeout=60.0, + max_body=8 * 1024 * 1024, + pause_reading=pause_reading, + ) + connection.connection_made(transport) + return connection + + +def _receive(connection: DubboConnection, data: bytes) -> None: + buffer = connection.get_buffer(-1) + buffer[: len(data)] = data + connection.buffer_updated(len(data)) + + +async def test_a_frame_takes_memory_as_its_bytes_arrive() -> None: + frames: list[bytes] = [] + connection = _connection(_Transport(), frames) + size = 8 * 1024 * 1024 + + _receive(connection, struct.pack(">HBBqI", 0xDABB, 0xC2, 0, 1, size)) + + assert len(connection.get_buffer(-1)) < 256 * 1024 + for _ in range(size // 65536): + _receive(connection, b"x" * 65536) + assert frames == [b"x" * size] + connection.connection_lost(None) + + +async def test_the_buffer_returns_to_its_base_size_once_a_large_frame_is_handled() -> None: + frames: list[bytes] = [] + connection = _connection(_Transport(), frames) + size = 3 * 1024 * 1024 + + _receive(connection, struct.pack(">HBBqI", 0xDABB, 0xC2, 0, 1, size)) + for _ in range(size // 65536): + _receive(connection, b"x" * 65536) + + assert len(frames[0]) == size + assert len(connection.get_buffer(-1)) < 256 * 1024 + connection.connection_lost(None) + + +async def test_a_server_connection_stops_reading_while_it_cannot_write() -> None: + transport = _Transport() + connection = _connection(transport, [], pause_reading=True) + + connection.pause_writing() + assert not transport.reading + connection.resume_writing() + assert transport.reading + connection.connection_lost(None) diff --git a/tests/unit/protocol/test_generic.py b/tests/unit/protocol/test_generic.py new file mode 100644 index 00000000..894edd5e --- /dev/null +++ b/tests/unit/protocol/test_generic.py @@ -0,0 +1,141 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import datetime +import enum +import typing +from collections.abc import Mapping, Sequence +from typing import Annotated, Any + +import attrs +import hessian2 +import pytest + +from dubbo import Method, Parameter +from dubbo.exceptions import Status +from dubbo.protocol.generic import GENERIC_INVOKE, GenericInvoker +from dubbo.rpc.definition import Service +from dubbo.rpc.invocation import Invocation, Result +from dubbo.serialization.hessian2 import Hessian2Serialization +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +@hessian2.java_class("com.example.Color") +class Color(enum.Enum): + RED = "r" + + +@hessian2.java_class("com.example.Paint") +@attrs.define(kw_only=True) +class Paint: + main_color: Color | None + shades: tuple[Color, ...] + by_name: dict[str, Color] + + +_PAINT = Method( + name="paint", + request=(Parameter(name="color", type=Color), Parameter(name="paint", type=Paint)), + response=str, +) + + +@hessian2.java_class("com.example.Shade") +@attrs.define(kw_only=True) +class Shade: + _main_color: Color + + +@hessian2.java_class("com.example.Pair") +@attrs.define(kw_only=True) +class Pair: + values: tuple[int, int] + + +async def _call(*arguments: Any, method: Method = _PAINT) -> tuple[Result, list[Invocation]]: + called: list[Invocation] = [] + + async def invoke(invocation: Invocation) -> Result: + called.append(invocation) + return Result(value="ok") + + serialization = Hessian2Serialization(URL.parse("tri://127.0.0.1/x?serialization=hessian2")) + invoker = GenericInvoker(invoke, Service(interface="x", methods=(method,)), serialization) + invocation = Invocation( + interface="x", method="$invoke", definition=GENERIC_INVOKE, arguments=(method.name, None, arguments) + ) + + return await invoker.invoke(invocation), called + + +async def test_enum_names_realize_as_the_enums_the_parameters_declare() -> None: + paint = {"class": "com.example.Paint", "mainColor": "RED", "shades": ["RED"], "byName": {"a": "RED"}} + + result, called = await _call("RED", paint) + + assert result.error is None + assert called[0].arguments == ( + Color.RED, + Paint(main_color=Color.RED, shades=(Color.RED,), by_name={"a": Color.RED}), + ) + + +async def test_a_name_of_no_member_stands_for_none_of_the_parameters() -> None: + result, called = await _call("BLUE", None) + + assert (result.error.status, called) == (Status.INVALID_ARGUMENT, []) + + +_TYPE_ALIAS = getattr(typing, "TypeAliasType", None) + + +def _method(annotation: Any) -> Method: + return Method(name="take", request=(Parameter(name="value", type=annotation),), response=str) + + +@pytest.mark.parametrize( + ("annotation", "argument", "expected"), + [ + (Annotated[Color, "documented"], "RED", Color.RED), + (Mapping[str, Color], {"a": "RED"}, {"a": Color.RED}), + (Sequence[Color], ["RED"], [Color.RED]), + pytest.param( + _TYPE_ALIAS and _TYPE_ALIAS("Colour", Color), + "RED", + Color.RED, + marks=pytest.mark.skipif(_TYPE_ALIAS is None, reason="type statements need Python 3.12"), + ), + (Shade, {"class": "com.example.Shade", "_mainColor": "RED"}, Shade(main_color=Color.RED)), + (datetime.date, "2026-11-15", datetime.date(2026, 11, 15)), + (datetime.time, "12:34", datetime.time(12, 34)), + (hessian2.LocalDateTime, "2026-11-15T12:34:56", datetime.datetime(2026, 11, 15, 12, 34, 56)), + ], + ids=["annotated", "mapping", "sequence", "type-alias", "leading-underscore", "date", "time", "date-time"], +) +async def test_values_realize_as_the_parameters_declare_them(annotation: Any, argument: Any, expected: Any) -> None: + result, called = await _call(argument, method=_method(annotation)) + + assert result.error is None + assert called[0].arguments == (expected,) + + +async def test_a_tuple_of_another_length_stands_for_none_of_the_parameters() -> None: + result, called = await _call({"class": "com.example.Pair", "values": [1, 2, 3]}, method=_method(Pair)) + + assert (result.error.status, called) == (Status.INVALID_ARGUMENT, []) diff --git a/tests/unit/protocol/test_java.py b/tests/unit/protocol/test_java.py new file mode 100644 index 00000000..b667085a --- /dev/null +++ b/tests/unit/protocol/test_java.py @@ -0,0 +1,249 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import dataclasses +import datetime +import decimal +import typing +from collections.abc import Mapping, Sequence +from typing import Annotated, Any + +import hessian2 +import pytest + +from dubbo import Method, Parameter +from dubbo.exceptions import RemoteError, RpcError, Status +from dubbo.protocol.java import caller_error, java_exception, java_type_name, method_descriptor +from dubbo.rpc.definition import JavaType +from dubbo.serialization import Codec, Reader +from dubbo.serialization.hessian2 import Hessian2Serialization +from dubbo.url import URL + + +@hessian2.java_class("com.example.User") +@dataclasses.dataclass +class User: + name: str + + +@dataclasses.dataclass +class Undeclared: + name: str + + +@hessian2.java_class("com.example.Cat") +@dataclasses.dataclass +class Cat: + name: str + + +class _Unnamed: + """A format of Java objects that declares no types of its own.""" + + content_subtype = "unnamed" + + def __init__(self) -> None: + self.url = URL(protocol="dubbo") + + def codec(self, types: Any) -> Codec[tuple[Any, ...]]: + raise NotImplementedError + + def reader(self, data: bytes) -> Reader: + raise NotImplementedError + + def java_type(self, annotation: Any) -> str | None: + return None + + +HESSIAN2 = Hessian2Serialization(URL(protocol="dubbo")) + + +def _method(*types: Any) -> Method: + return Method( + name="find", request=tuple(Parameter(name=f"p{i}", type=t) for i, t in enumerate(types)), response=str + ) + + +@hessian2.java_class("java.lang.IllegalStateException") +@dataclasses.dataclass +class IllegalState(Exception): + detail_message: str = "" + + +@pytest.mark.parametrize( + ("annotation", "descriptor"), + [ + (bool, "Z"), + (int, "I"), + (float, "D"), + (hessian2.Long, "J"), + (bool | None, "Ljava/lang/Boolean;"), + (int | None, "Ljava/lang/Integer;"), + (float | None, "Ljava/lang/Double;"), + (hessian2.Long | None, "Ljava/lang/Long;"), + (Annotated[int, "other metadata"], "I"), + (Annotated[hessian2.Long, "the id"], "J"), + (str, "Ljava/lang/String;"), + (str | None, "Ljava/lang/String;"), + (bytes, "[B"), + (decimal.Decimal, "Ljava/math/BigDecimal;"), + (datetime.date, "Ljava/time/LocalDate;"), + (hessian2.BigInteger, "Ljava/math/BigInteger;"), + (hessian2.Instant, "Ljava/time/Instant;"), + (hessian2.Date, "Ljava/util/Date;"), + (hessian2.LocalDateTime, "Ljava/time/LocalDateTime;"), + (User, "Lcom/example/User;"), + (User | None, "Lcom/example/User;"), + (list[User], "Ljava/util/List;"), + (Sequence[str], "Ljava/util/List;"), + (list, "Ljava/util/List;"), + (set[int], "Ljava/util/Set;"), + (dict[str, User], "Ljava/util/Map;"), + (Mapping[str, int], "Ljava/util/Map;"), + (tuple[str, ...], "[Ljava/lang/String;"), + (tuple[int, ...], "[I"), + (tuple[int | None, ...], "[Ljava/lang/Integer;"), + (tuple[User, ...], "[Lcom/example/User;"), + (tuple[tuple[int, ...], ...], "[[I"), + (Any, "Ljava/lang/Object;"), + ], + ids=repr, +) +def test_a_parameter_type_has_the_java_descriptor(annotation: Any, descriptor: str) -> None: + assert method_descriptor(HESSIAN2, _method(annotation)) == descriptor + + +def test_a_method_descriptor_joins_its_parameters() -> None: + assert method_descriptor(HESSIAN2, _method(str, hessian2.Long, User)) == "Ljava/lang/String;JLcom/example/User;" + assert method_descriptor(HESSIAN2, _method()) == "" + + +@pytest.mark.parametrize( + ("annotation", "name"), + [(hessian2.Long, "long"), (int | None, "java.lang.Integer"), (tuple[str, ...], "[Ljava.lang.String;")], + ids=repr, +) +def test_a_java_type_is_named_as_class_get_name_names_it(annotation: Any, name: str) -> None: + assert java_type_name(HESSIAN2, annotation) == name + + +@pytest.mark.parametrize( + ("annotation", "name"), + [(Annotated[Any, JavaType("long")], "long"), (Annotated[hessian2.Long, JavaType("int")], "int")], + ids=["any", "long"], +) +def test_a_java_type_in_the_metadata_names_the_type(annotation: Any, name: str) -> None: + assert java_type_name(HESSIAN2, annotation) == name + + +def test_a_java_type_in_the_metadata_gives_the_parameter_descriptor() -> None: + assert method_descriptor( + HESSIAN2, _method(Annotated[Any, JavaType("[Ljava.lang.String;")], Annotated[Any, JavaType("com.example.User")]) + ) == ("[Ljava/lang/String;Lcom/example/User;") + + +def test_python_types_have_java_types_whatever_the_serialization() -> None: + serialization: Any = _Unnamed() + + assert ( + method_descriptor(serialization, _method(int, str, list[str], bytes)) == "ILjava/lang/String;Ljava/util/List;[B" + ) + with pytest.raises(TypeError, match="has no Java type"): + method_descriptor(serialization, _method(User)) + + +@pytest.mark.parametrize( + ("annotation", "message"), + [ + (Undeclared, "Undeclared"), + (User | Cat, "several Java types"), + (datetime.datetime, "datetime"), + (tuple[str, int], "tuple\\[X, ...\\]"), + ], +) +def test_a_type_without_one_java_type_has_no_descriptor(annotation: Any, message: str) -> None: + with pytest.raises(TypeError, match=f"find has a parameter with no Java type: .*{message}"): + method_descriptor(HESSIAN2, _method(annotation)) + + +@pytest.mark.skipif(not hasattr(typing, "TypeAliasType"), reason="type aliases arrive in Python 3.12") +def test_an_alias_stands_for_its_type() -> None: + alias = typing.TypeAliasType("UserId", hessian2.Long) # type: ignore[attr-defined] + + assert method_descriptor(HESSIAN2, _method(alias, list[alias])) == "JLjava/util/List;" + + +@pytest.mark.parametrize( + ("status", "code"), + [ + (Status.DEADLINE_EXCEEDED, 2), + (Status.PERMISSION_DENIED, 4), + (Status.UNAVAILABLE, 1), + (Status.UNIMPLEMENTED, 11), + (Status.NOT_FOUND, 0), + ], +) +def test_an_rpc_error_travels_as_an_rpc_exception_with_the_code_java_gives_its_status( + status: Status, code: int +) -> None: + sent = java_exception(HESSIAN2, RpcError(status, "why")) + + assert isinstance(sent, RemoteError) + assert (sent.class_name, sent.message, dict(sent.fields)) == ( + "org.apache.dubbo.rpc.RpcException", + "why", + {"code": code}, + ) + + +@pytest.mark.parametrize( + "error", [RemoteError("com.example.UserNotFound", "bob"), IllegalState("no")], ids=["remote-error", "declared"] +) +def test_an_exception_of_a_java_class_travels_as_itself(error: Exception) -> None: + assert java_exception(HESSIAN2, error) is error + + +def test_an_undeclared_python_exception_travels_as_a_runtime_exception() -> None: + sent = java_exception(HESSIAN2, ValueError("broken")) + + assert isinstance(sent, RemoteError) + assert (sent.class_name, sent.message) == ("java.lang.RuntimeException", "ValueError: broken") + + +@pytest.mark.parametrize( + ("code", "status"), + [ + (2, Status.DEADLINE_EXCEEDED), + (8, Status.DEADLINE_EXCEEDED), + (13, Status.UNAUTHENTICATED), + (7, Status.UNAVAILABLE), + (3, Status.UNKNOWN), + ("x", Status.UNKNOWN), + ], + ids=repr, +) +def test_a_received_rpc_exception_takes_the_status_of_its_code(code: object, status: Status) -> None: + received = caller_error(RemoteError("org.apache.dubbo.rpc.RpcException", "why", fields={"code": code})) + + assert (received.status, received.message) == (status, "why") + + +def test_a_received_exception_that_is_not_an_rpc_exception_keeps_its_status(): + error = RemoteError("java.lang.IllegalStateException", "x") + + assert caller_error(error) is error + assert error.status is Status.UNKNOWN diff --git a/tests/unit/protocol/test_served.py b/tests/unit/protocol/test_served.py new file mode 100644 index 00000000..a31b459e --- /dev/null +++ b/tests/unit/protocol/test_served.py @@ -0,0 +1,124 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import pytest + +from dubbo.protocol.served import ClientPool + +pytestmark = pytest.mark.anyio + + +class _Client: + def __init__(self) -> None: + self.closed = False + + async def __aenter__(self) -> "_Client": + return self + + async def aclose(self) -> None: + self.closed = True + + +async def test_the_last_share_given_back_closes_a_pooled_client() -> None: + pool: ClientPool[_Client] = ClientPool() + first = await pool.acquire("a", _Client) + second = await pool.acquire("a", _Client) + + await pool.release(first) + assert second is first + assert not first.closed + + await pool.release(second) + assert first.closed + await pool.aclose() + + +async def test_a_share_given_back_after_its_client_closed_changes_nothing() -> None: + pool: ClientPool[_Client] = ClientPool() + first = await pool.acquire("a", _Client) + await pool.release(first) + + await pool.release(first) + replacement = await pool.acquire("a", _Client) + + assert replacement is not first + assert not replacement.closed + await pool.aclose() + + +async def test_a_share_taken_while_a_duplicate_client_closes_keeps_the_shared_one_open() -> None: + connected = anyio.Event() + first_share_given_back = anyio.Event() + shares: list[_Client] = [] + + class SlowClient(_Client): + async def __aenter__(self) -> "SlowClient": + await connected.wait() + return self + + async def aclose(self) -> None: + if self not in shares: + await first_share_given_back.wait() + await super().aclose() + + pool: ClientPool[_Client] = ClientPool() + + async def acquire() -> None: + shares.append(await pool.acquire("a", SlowClient)) + + async with anyio.create_task_group() as task_group: + task_group.start_soon(acquire) + task_group.start_soon(acquire) + await anyio.wait_all_tasks_blocked() + connected.set() + while not shares: + await anyio.wait_all_tasks_blocked() + + await pool.release(shares[0]) + first_share_given_back.set() + + assert shares[1] is shares[0] + assert not shares[0].closed + await pool.aclose() + + +async def test_a_closed_pool_closes_its_clients_and_lends_no_more() -> None: + pool: ClientPool[_Client] = ClientPool() + client = await pool.acquire("a", _Client) + + await pool.aclose() + + assert client.closed + with pytest.raises(RuntimeError, match="closed"): + await pool.acquire("a", _Client) + + +async def test_closing_the_pool_closes_every_client_even_when_one_fails_to_close() -> None: + class _Failing(_Client): + async def aclose(self) -> None: + await super().aclose() + raise OSError("cannot close") + + pool: ClientPool[_Client] = ClientPool() + failing = await pool.acquire("a", _Failing) + other = await pool.acquire("b", _Client) + + with pytest.raises(OSError, match="cannot close"): + await pool.aclose() + + assert (failing.closed, other.closed) == (True, True) diff --git a/tests/unit/protocol/triple/conftest.py b/tests/unit/protocol/triple/conftest.py new file mode 100644 index 00000000..ba81d245 --- /dev/null +++ b/tests/unit/protocol/triple/conftest.py @@ -0,0 +1,57 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.extension import extensions +from dubbo.serialization.hessian2 import Hessian2Serialization +from dubbo.transport.h2 import H2Client +from dubbo.url import URL + + +@pytest.fixture +def clients(isolated_extensions): + clients = [] + + class Client: + def __init__(self, url): + self.url = url + self.closed = False + clients.append(self) + + @property + def available(self): + return not self.closed + + async def __aenter__(self): + return self + + async def aclose(self): + self.closed = True + + extensions.register(H2Client, "memory", Client) + return clients + + +@pytest.fixture +def hessian2() -> Hessian2Serialization: + return Hessian2Serialization(URL(protocol="tri")) + + +@pytest.fixture +def client_url(): + return URL(protocol="tri", host="127.0.0.1", port=1, parameters={"triple.client": "memory"}) diff --git a/tests/unit/protocol/triple/grpc/test_compression.py b/tests/unit/protocol/triple/grpc/test_compression.py new file mode 100644 index 00000000..a0e70250 --- /dev/null +++ b/tests/unit/protocol/triple/grpc/test_compression.py @@ -0,0 +1,34 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.protocol.triple.grpc.compression import Compressors +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +def test_compressors_accept_identity_and_every_installed_compressor() -> None: + compressors = Compressors(URL(protocol="tri")) + + assert compressors.accept_encoding == b"identity,bzip2,deflate,gzip" + assert compressors.get(None) is None + assert compressors.get(b"identity") is None + assert compressors.get(b"gzip") is compressors.get(b"gzip") + with pytest.raises(LookupError, match="not supported"): + compressors.get(b"snappy") diff --git a/tests/unit/protocol/triple/grpc/test_framing.py b/tests/unit/protocol/triple/grpc/test_framing.py new file mode 100644 index 00000000..0f45a1ef --- /dev/null +++ b/tests/unit/protocol/triple/grpc/test_framing.py @@ -0,0 +1,106 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import gzip +from collections.abc import Awaitable, Callable + +import pytest + +from dubbo import RpcError, Status +from dubbo.constants import DEFAULT_MAX_RECEIVE_MESSAGE_SIZE +from dubbo.protocol.triple.grpc.compression import Compressors +from dubbo.protocol.triple.grpc.framing import frame, read_message +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +class _Sent: + """The receiving side of a stream on which the peer sent ``data`` and ended.""" + + def __init__(self, data: bytes) -> None: + self._data = data + + async def receive_data_exactly(self, nbytes: int) -> bytes: + chunk, self._data = self._data[:nbytes], self._data[nbytes:] + return chunk + + +def _reader(data: bytes, encoding: bytes | None = None) -> Callable[[], Awaitable[bytes | None]]: + """Return a function that reads the next message of a stream on which the peer sent ``data``.""" + sent = _Sent(data) + compressor = Compressors(URL(protocol="tri")).get(encoding) + return lambda: read_message(sent, DEFAULT_MAX_RECEIVE_MESSAGE_SIZE, compressor) # ty: ignore[invalid-argument-type] + + +def _compressed(message: bytes) -> bytes: + data = gzip.compress(message) + return b"\x01" + len(data).to_bytes(4, "big") + data + + +def test_frame_prefixes_the_flag_and_big_endian_length() -> None: + assert frame(b"abc") == b"\x00\x00\x00\x00\x03abc" + assert frame(b"") == b"\x00\x00\x00\x00\x00" + + +async def test_frame_compresses_with_a_compressor() -> None: + compressor = Compressors(URL(protocol="tri")).get(b"gzip") + + framed = frame(b"abc", compressor) + + assert framed[0] == 1 + assert int.from_bytes(framed[1:5], "big") == len(framed) - 5 + assert await _reader(framed, b"gzip")() == b"abc" + + +async def test_a_stream_receives_messages_until_the_peer_ends() -> None: + read = _reader(frame(b"a") + frame(b"") + _compressed(b"b"), b"gzip") + + assert [await read() for _ in range(3)] == [b"a", b"", b"b"] + assert await read() is None + + +@pytest.mark.parametrize( + ("data", "encoding", "status", "message"), + [ + (b"\x00\x00", None, Status.INTERNAL, "inside a message prefix"), + (frame(b"abc")[:-1], None, Status.INTERNAL, "inside a message"), + ( + b"\x00" + (DEFAULT_MAX_RECEIVE_MESSAGE_SIZE + 1).to_bytes(4, "big"), + None, + Status.RESOURCE_EXHAUSTED, + "larger than", + ), + (b"\x02\x00\x00\x00\x00", None, Status.INTERNAL, "invalid compressed flag 2"), + # PROTOCOL-HTTP2.md:98; compression.md:105 + (_compressed(b"a"), None, Status.INTERNAL, "without grpc-encoding"), + (b"\x01\x00\x00\x00\x01x", b"gzip", Status.INTERNAL, "cannot decompress"), + ( + _compressed(b"\0" * (DEFAULT_MAX_RECEIVE_MESSAGE_SIZE + 1)), + b"gzip", + Status.RESOURCE_EXHAUSTED, + "decompressed message", + ), + ], +) +async def test_a_stream_rejects_broken_messages( + data: bytes, encoding: bytes | None, status: Status, message: str +) -> None: + with pytest.raises(RpcError, match=message) as caught: + await _reader(data, encoding)() + + assert caught.value.status is status diff --git a/tests/unit/protocol/triple/grpc/test_headers.py b/tests/unit/protocol/triple/grpc/test_headers.py new file mode 100644 index 00000000..9c0af3a9 --- /dev/null +++ b/tests/unit/protocol/triple/grpc/test_headers.py @@ -0,0 +1,65 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.protocol.triple.grpc.headers import content_subtype, decode_timeout, encode_timeout + + +@pytest.mark.parametrize( + ("seconds", "encoded"), + [ + (0.05, b"50000000n"), + (0.5, b"500000u"), + (1.5, b"1500000u"), + (1000.0, b"1000000m"), + (1e6, b"1000000S"), + (1e9, b"16666667M"), + ], +) +def test_encode_timeout_uses_the_finest_unit_that_fits_eight_digits(seconds: float, encoded: bytes) -> None: + assert encode_timeout(seconds) == encoded + + +@pytest.mark.parametrize( + ("value", "seconds"), [(b"1H", 3600), (b"2M", 120), (b"3S", 3), (b"4m", 4e-3), (b"5u", 5e-6), (b"6n", 6e-9)] +) +def test_decode_timeout_reads_every_unit(value: bytes, seconds: float) -> None: + assert decode_timeout(value) == pytest.approx(seconds) + + +@pytest.mark.parametrize("value", [b"", b"1", b"S", b"123456789S", b"-1S", b"1s", b"1.5S"]) +def test_decode_timeout_rejects_malformed_values(value: bytes) -> None: + with pytest.raises(ValueError, match="malformed grpc-timeout"): + decode_timeout(value) + + +@pytest.mark.parametrize( + ("value", "expected"), + [ + (b"application/grpc", b""), + (b"application/grpc+proto", b"proto"), + (b"application/grpc+json; charset=utf-8", b"json"), + (b"application/grpc;x=y", b""), + (b"application/grpcx", None), + (b"application/json", None), + (None, None), + ], + ids=["grpc", "protobuf", "json-with-parameters", "grpc-with-parameters", "wrong-suffix", "http-json", "absent"], +) +def test_content_subtype_recognises_only_grpc_media_types(value, expected): + assert content_subtype(value) == expected diff --git a/tests/unit/protocol/triple/grpc/test_status.py b/tests/unit/protocol/triple/grpc/test_status.py new file mode 100644 index 00000000..1e493cfe --- /dev/null +++ b/tests/unit/protocol/triple/grpc/test_status.py @@ -0,0 +1,162 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest +from google.protobuf import descriptor_pool +from google.protobuf.wrappers_pb2 import Int32Value, StringValue + +from dubbo import Status +from dubbo._proto.google.rpc import status_pb2 +from dubbo._proto.pool import pool +from dubbo.protocol.triple import ErrorDetail, TripleError +from dubbo.protocol.triple.grpc.status import response_error, status_headers, trailer_error, transport_error +from dubbo.transport.h2 import H2ConnectionError, H2ErrorCode, H2StreamError, H2StreamResetError + + +@pytest.mark.parametrize( + ("http_status", "status"), + [ + (b"400", Status.INTERNAL), + (b"401", Status.UNAUTHENTICATED), + (b"403", Status.PERMISSION_DENIED), + (b"404", Status.UNIMPLEMENTED), + (b"429", Status.UNAVAILABLE), + (b"502", Status.UNAVAILABLE), + (b"503", Status.UNAVAILABLE), + (b"504", Status.UNAVAILABLE), + (b"500", Status.UNKNOWN), + ], +) +def test_response_error_maps_http_statuses(http_status: bytes, status: Status) -> None: + error = response_error({b":status": http_status, b"content-type": b"application/grpc"}) + + assert error is not None + assert error.status is status + + +def test_response_error_requires_a_grpc_content_type() -> None: + assert response_error({b":status": b"200", b"content-type": b"application/grpc+proto"}) is None + + error = response_error({b":status": b"200", b"content-type": b"text/html"}) + assert error is not None + assert error.status is Status.UNKNOWN + + +def test_trailer_error_reads_grpc_status_and_message() -> None: + assert trailer_error({b"grpc-status": b"0"}) is None + + error = trailer_error({b"grpc-status": b"7", b"grpc-message": b"no%20way"}) + assert error is not None + assert (error.status, error.message) == (Status.PERMISSION_DENIED, "no way") + + +@pytest.mark.parametrize( + ("fields", "status"), + [ + ({}, Status.UNKNOWN), + ({b"grpc-status": b"x"}, Status.INTERNAL), + ({b"grpc-status": b"9" * 5000}, Status.INTERNAL), + ({b"grpc-status": b"99"}, Status.UNKNOWN), + ], + ids=["missing", "malformed", "too-long", "unknown"], +) +def test_trailer_error_handles_missing_and_unknown_statuses(fields: dict[bytes, bytes], status: Status) -> None: + error = trailer_error(fields) + + assert error is not None + assert error.status is status + + +def test_an_error_detail_holds_a_protobuf_message() -> None: + detail = ErrorDetail.from_message(StringValue(value="name")) + + assert detail.type_url == "type.googleapis.com/google.protobuf.StringValue" + assert detail.unpack(StringValue) == StringValue(value="name") + assert detail.unpack(Int32Value) is None + + +@pytest.mark.parametrize("padded", [False, True]) +def test_error_details_travel_in_the_trailers(padded: bool) -> None: + detail = ErrorDetail.from_message(StringValue(value="name")) + fields = dict(status_headers(TripleError(Status.INVALID_ARGUMENT, "bad", details=[detail]))) + if padded: + value = fields[b"grpc-status-details-bin"] + fields[b"grpc-status-details-bin"] = value + b"=" * (-len(value) % 4) + + error = trailer_error(fields) + + assert isinstance(error, TripleError) + assert (error.status, error.message, error.details) == (Status.INVALID_ARGUMENT, "bad", (detail,)) + + +@pytest.mark.parametrize("value", [b"!!", b"AQID"]) +def test_malformed_error_details_leave_the_status(value: bytes) -> None: + error = trailer_error({b"grpc-status": b"5", b"grpc-status-details-bin": value}) + + assert error is not None + assert error.status is Status.NOT_FOUND + assert not isinstance(error, TripleError) + + +def test_the_framework_protos_stay_out_of_the_default_pool() -> None: + assert status_pb2.DESCRIPTOR.pool is pool + assert pool is not descriptor_pool.Default() + + +@pytest.mark.parametrize( + ("error", "status"), + [ + (H2StreamResetError(1, H2ErrorCode.NO_ERROR), Status.INTERNAL), + (H2StreamResetError(1, H2ErrorCode.PROTOCOL_ERROR), Status.INTERNAL), + (H2StreamResetError(1, H2ErrorCode.REFUSED_STREAM), Status.UNAVAILABLE), + (H2StreamResetError(1, H2ErrorCode.CANCEL), Status.CANCELLED), + (H2StreamResetError(1, H2ErrorCode.ENHANCE_YOUR_CALM), Status.RESOURCE_EXHAUSTED), + (H2StreamResetError(1, H2ErrorCode.INADEQUATE_SECURITY), Status.PERMISSION_DENIED), + (H2StreamResetError(1, 0xFF), Status.INTERNAL), + (H2ConnectionError("lost"), Status.UNAVAILABLE), + (H2StreamError("broken", stream_id=1), Status.INTERNAL), + ], + ids=[ + "no-error-reset", + "protocol-reset", + "refused-reset", + "cancelled-reset", + "overload-reset", + "security-reset", + "unknown-reset", + "connection-loss", + "stream-failure", + ], +) +def test_transport_failures_map_to_rpc_statuses_and_keep_their_messages(error, status): + mapped = transport_error(error) + + assert (mapped.status, mapped.message) == (status, str(error)) + + +def test_error_details_that_contradict_the_status_fail_the_call() -> None: + detail = ErrorDetail.from_message(StringValue(value="name")) + fields = dict(status_headers(TripleError(Status.INVALID_ARGUMENT, "bad", details=[detail]))) + fields[b"grpc-status"] = b"%d" % Status.PERMISSION_DENIED + + error = trailer_error(fields) + + # PROTOCOL-HTTP2.md:142-145 + assert error is not None + assert error.status is Status.INTERNAL + assert not isinstance(error, TripleError) + assert "grpc-status-details-bin has code 3 but grpc-status is 7" in error.message diff --git a/tests/unit/protocol/triple/test_attachments.py b/tests/unit/protocol/triple/test_attachments.py new file mode 100644 index 00000000..66b53a78 --- /dev/null +++ b/tests/unit/protocol/triple/test_attachments.py @@ -0,0 +1,128 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import json + +import pytest +from multidict import MultiDict + +from dubbo.protocol.triple.attachments import attachment_headers, split_headers +from dubbo.protocol.triple.headers import percent_decode, percent_encode + + +@pytest.mark.parametrize( + ("attachments", "message"), + [ + ({"a b": "x"}, "cannot be a gRPC metadata name"), + ({"grpc-status": "0"}, "cannot be a gRPC metadata name"), + ({"tri-service-group": "g"}, "cannot be a gRPC metadata name"), + ({"a": "失"}, "printable ASCII"), + ({"a": "x\n"}, "printable ASCII"), + ({"a": b"x"}, "printable ASCII"), + ({"a-bin": "x"}, "must be bytes"), + ({"A": "1", "a": "2"}, "differ only in case"), + ], +) +def test_attachment_headers_reject_what_metadata_cannot_carry( + attachments: dict[str, str | bytes], message: str +) -> None: + with pytest.raises(ValueError, match=message): + attachment_headers(attachments) + + +def test_split_headers_keeps_reserved_fields_out_of_attachments() -> None: + fields, attachments = split_headers( + ( + (b":path", b"/s/m"), + (b"content-type", b"application/grpc"), + (b"te", b"trailers"), + (b"grpc-timeout", b"1S"), + (b"tri-service-version", b"1.0"), + (b"tri-header-convert", b"not json"), + (b"user-id", b"\xe5\xa4\xb1"), + (b"blob-bin", b"AAEC"), + (b"broken-bin", b"!!!!"), + ) + ) + + assert set(fields) == { + b":path", + b"content-type", + b"te", + b"grpc-timeout", + b"tri-service-version", + b"tri-header-convert", + } + assert attachments == {"user-id": "失", "blob-bin": b"\x00\x01\x02"} + + +@pytest.mark.parametrize( + ("value", "data"), + [ + (b"AAEC", [b"\x00\x01\x02"]), + (b"AAE=", [b"\x00\x01"]), + (b"AAE", [b"\x00\x01"]), + (b"AAE, !, AAEC", [b"\x00\x01", b"\x00\x01\x02"]), + ], +) +def test_binary_attachments_accept_padded_unpadded_and_joined_values(value: bytes, data: list[bytes]) -> None: + assert split_headers(((b"blob-bin", value),))[1].getall("blob-bin") == data + + +def test_repeated_attachments_keep_every_value_and_travel_one_field_each() -> None: + attachments = MultiDict([("Tag", "a"), ("Tag", "b"), ("blob-bin", b"\x01"), ("blob-bin", b"\x02")]) + + headers = attachment_headers(attachments) + + assert headers[:4] == [(b"tag", b"a"), (b"tag", b"b"), (b"blob-bin", b"AQ"), (b"blob-bin", b"Ag")] + received = split_headers(tuple(headers))[1] + assert received.getall("Tag") == ["a", "b"] + assert received.getall("blob-bin") == [b"\x01", b"\x02"] + + +def test_binary_attachments_travel_as_unpadded_base64_under_their_own_key() -> None: + headers = attachment_headers({"Blob-bin": b"\x00\x01"}) + + assert headers[0] == (b"blob-bin", b"AAE") + assert split_headers(tuple(headers))[1] == {"Blob-bin": b"\x00\x01"} + + +def test_attachments_travel_as_lowercase_headers_with_their_case_recorded() -> None: + headers = attachment_headers({"tenant": "a", "Trace-Id": "b"}) + + assert headers[:2] == [(b"tenant", b"a"), (b"trace-id", b"b")] + assert headers[2][0] == b"tri-header-convert" + assert json.loads(percent_decode(headers[2][1])) == {"trace-id": "Trace-Id"} + assert split_headers((*headers, (b"grpc-status", b"0"), (b":status", b"200")))[1] == { + "tenant": "a", + "Trace-Id": "b", + } + + +def test_the_conversion_table_names_each_header_as_sent_with_its_suffix() -> None: + headers = attachment_headers({"Trace": "a", "trace-bin": b"\x00"}) + + assert json.loads(percent_decode(headers[2][1])) == {"trace": "Trace"} + assert split_headers(tuple(headers))[1] == {"Trace": "a", "trace-bin": b"\x00"} + + +def test_a_table_entry_without_the_suffix_leaves_a_binary_attachment_as_sent() -> None: + table = percent_encode('{"trace":"Trace"}') + + _, attachments = split_headers(((b"trace-bin", b"AAH/"), (b"tri-header-convert", table))) + + assert attachments == {"trace-bin": b"\x00\x01\xff"} diff --git a/tests/unit/protocol/triple/test_headers.py b/tests/unit/protocol/triple/test_headers.py new file mode 100644 index 00000000..90f46606 --- /dev/null +++ b/tests/unit/protocol/triple/test_headers.py @@ -0,0 +1,28 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from dubbo.protocol.triple.headers import percent_decode, percent_encode + + +def test_grpc_message_percent_encodes_all_but_printable_ascii() -> None: + assert percent_encode("a b%c\n失") == b"a b%25c%0A%E5%A4%B1" + assert percent_decode(b"a b%25c%0A%E5%A4%B1") == "a b%c\n失" + + +def test_grpc_message_keeps_malformed_escapes() -> None: + assert percent_decode(b"100%zz") == "100%zz" + assert percent_decode(b"%E5") == "�" diff --git a/tests/unit/protocol/triple/test_messages.py b/tests/unit/protocol/triple/test_messages.py new file mode 100644 index 00000000..414d298d --- /dev/null +++ b/tests/unit/protocol/triple/test_messages.py @@ -0,0 +1,72 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest +from google.protobuf.wrappers_pb2 import StringValue + +from dubbo import Method, Parameter, RpcType +from dubbo.protocol.triple.messages import method_messages +from dubbo.serialization.hessian2 import Hessian2Serialization +from dubbo.serialization.protobuf import ProtobufSerialization +from dubbo.url import URL + + +def _method(*parameters: object, response: object = StringValue, rpc_type: RpcType = RpcType.UNARY) -> Method: + return Method( + name="Say", + rpc_type=rpc_type, + request=tuple(Parameter(name=f"p{i}", type=t) for i, t in enumerate(parameters)), + response=response, + ) + + +@pytest.mark.parametrize( + ("method", "message"), + [ + (_method(), "the request of Say: protobuf carries one message"), + (_method(StringValue, StringValue), "the request of Say: protobuf carries one message"), + (_method(str), "the request of Say: protobuf carries messages"), + (_method(StringValue, response=None), "the response of Say: protobuf carries messages, not None"), + ], +) +def test_triple_carries_one_message_each_way(method: Method, message: str) -> None: + with pytest.raises(TypeError, match=message): + method_messages(ProtobufSerialization(URL(protocol="tri")), method) + + +def test_only_a_format_of_java_objects_travels_wrapped_with_its_exceptions(hessian2: Hessian2Serialization) -> None: + method = Method( + name="greet", request=(Parameter(name="name", type=str), Parameter(name="times", type=int)), response=str + ) + + say = Method(name="Say", request=(Parameter(name="request", type=StringValue),), response=StringValue) + plain = method_messages(ProtobufSerialization(URL(protocol="tri")), say) + wrapped = method_messages(hessian2, method) + + assert (plain.content_subtype, plain.exception) == ("proto", None) + assert wrapped.content_subtype == "proto" + assert wrapped.exception is not None + assert wrapped.request.decode(wrapped.request.encode(("bob", 2))) == ("bob", 2) + + +def test_protobuf_messages_travel_as_themselves_in_a_format_of_java_objects(hessian2: Hessian2Serialization) -> None: + say = Method(name="Say", request=(Parameter(name="request", type=StringValue),), response=StringValue) + + messages = method_messages(hessian2, say) + + assert (messages.content_subtype, messages.exception) == ("proto", None) + assert messages.request.encode((StringValue(value="bob"),)) == StringValue(value="bob").SerializeToString() diff --git a/tests/unit/protocol/triple/test_protocol.py b/tests/unit/protocol/triple/test_protocol.py new file mode 100644 index 00000000..729026c6 --- /dev/null +++ b/tests/unit/protocol/triple/test_protocol.py @@ -0,0 +1,130 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import ssl +import typing +from importlib import metadata + +import pytest +from google.protobuf.wrappers_pb2 import StringValue + +import dubbo +from dubbo.constants import DEFAULT_JAVA_SERIALIZATION +from dubbo.extension import extensions +from dubbo.protocol.triple import TripleProtocol +from dubbo.rpc.invocation import Invocation +from dubbo.serialization import Serialization +from dubbo.serialization.protobuf import ProtobufSerialization +from dubbo.url import SSL_CONTEXT + +pytestmark = pytest.mark.anyio + + +@dubbo.service("test.Echo") +class _Echo(typing.Protocol): + async def say(self, request: StringValue) -> StringValue: ... + + +async def test_a_reference_passes_transport_parameters_to_its_client(clients, client_url): + url = client_url.update_parameters({"triple.stream-send-buffer-size": "1048576", "timeout": "1000"}) + + async with TripleProtocol() as protocol: + await protocol.refer(url, dubbo.get_definition(_Echo)) + + assert [client.url.parameters for client in clients] == [ + {"client": "memory", "stream-send-buffer-size": "1048576"} + ] + + assert all(client.closed for client in clients) + + +@pytest.mark.parametrize(("shared", "made"), [(False, ["a", "b"]), (True, ["a"])]) +async def test_references_share_a_serialization_only_if_it_says_so(clients, client_url, shared, made) -> None: + urls = [] + + class Recording(ProtobufSerialization): + def __init__(self, url): + urls.append(url.parameters["setting"]) + + Recording.shared = shared + extensions.register(Serialization, "recording", Recording) + url = client_url.update_parameters({"serialization": "recording"}) + + async with TripleProtocol() as protocol: + for setting in ("a", "b"): + await protocol.refer(url.update_parameters({"setting": setting}), dubbo.get_definition(_Echo)) + + assert urls == made + + +async def test_references_that_differ_only_in_call_settings_share_a_client(clients, client_url) -> None: + call = { + "interface": "demo.Greeter", + "group": "g", + "timeout": "100", + "say.timeout": "50", + "triple.compressor": "gzip", + } + + async with TripleProtocol() as protocol: + await protocol.refer(client_url, dubbo.get_definition(_Echo)) + await protocol.refer(client_url.update_parameters(call), dubbo.get_definition(_Echo)) + + assert len(clients) == 1 + + +@pytest.mark.parametrize( + "parameters", + [{"triple.max-concurrent-streams": "8"}, {"triple.stream-send-buffer-size": "1048576"}], + ids=["max-concurrent-streams", "stream-send-buffer-size"], +) +async def test_references_of_other_connection_settings_get_another_client( + clients, client_url, parameters: dict[str, str] +) -> None: + async with TripleProtocol() as protocol: + await protocol.refer(client_url, dubbo.get_definition(_Echo)) + await protocol.refer(client_url.update_parameters(parameters), dubbo.get_definition(_Echo)) + + assert len(clients) == 2 + + +async def test_references_of_different_tls_contexts_get_different_clients(clients, client_url) -> None: + lax, strict = ssl.create_default_context(), ssl.create_default_context() + + async with TripleProtocol() as protocol: + for context in (lax, lax, strict): + await protocol.refer(client_url.replace(attributes={SSL_CONTEXT: context}), dubbo.get_definition(_Echo)) + + assert len(clients) == 2 + + +async def test_a_generic_call_without_its_plugin_tells_why_it_cannot_load(clients, client_url, monkeypatch): + plugin = metadata.EntryPoint( + name=DEFAULT_JAVA_SERIALIZATION, value="dubbo_absent:Plugin", group="apache_dubbo.serialization" + ) + monkeypatch.setitem(extensions._entries(Serialization), DEFAULT_JAVA_SERIALIZATION, plugin) + definition = dubbo.get_definition(_Echo) + + async with TripleProtocol() as protocol: + invoker = await protocol.refer(client_url, definition) + invocation = Invocation( + interface="test.Echo", method="say", definition=definition.methods[0], arguments=("hi",), generic="true" + ) + result = await invoker.invoke(invocation) + + assert result.error is not None + assert "No module named 'dubbo_absent'" in str(result.error) diff --git a/tests/unit/protocol/triple/test_settings.py b/tests/unit/protocol/triple/test_settings.py new file mode 100644 index 00000000..69972c6d --- /dev/null +++ b/tests/unit/protocol/triple/test_settings.py @@ -0,0 +1,31 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.protocol.triple.settings import TripleSettings +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +def test_the_message_size_limit_comes_from_the_url() -> None: + assert TripleSettings.from_url(URL(protocol="tri")).max_message_size == 4 * 1024 * 1024 + url = URL(protocol="tri", parameters={"max-receive-message-size": "10"}) + assert TripleSettings.from_url(url).max_message_size == 10 + with pytest.raises(ValueError, match="must be positive"): + TripleSettings.from_url(URL(protocol="tri", parameters={"max-receive-message-size": "0"})) diff --git a/tests/unit/protocol/triple/test_wrapper.py b/tests/unit/protocol/triple/test_wrapper.py new file mode 100644 index 00000000..faef1283 --- /dev/null +++ b/tests/unit/protocol/triple/test_wrapper.py @@ -0,0 +1,70 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from typing import Any + +import pytest + +from dubbo._proto.org.apache.dubbo.triple.triple_wrapper_pb2 import TripleRequestWrapper, TripleResponseWrapper +from dubbo.protocol.triple.wrapper import wrapped_codec +from dubbo.serialization.hessian2 import Hessian2Serialization + +pytestmark = pytest.mark.anyio + + +def test_each_value_travels_alone_beside_its_java_type(hessian2: Hessian2Serialization) -> None: + codec = wrapped_codec(hessian2, (str, int | None, tuple[str, ...])) + + data = codec.encode(("bob", 7, ("a",))) + + wrapper = TripleRequestWrapper.FromString(data) + assert wrapper.serializeType == "hessian2" + assert list(wrapper.argTypes) == ["java.lang.String", "java.lang.Integer", "[Ljava.lang.String;"] + assert [hessian2.codec((Any,)).decode(argument)[0] for argument in wrapper.args] == ["bob", 7, ["a"]] + assert codec.decode(data) == ("bob", 7, ("a",)) + + +def test_one_value_is_a_response_wrapper(hessian2: Hessian2Serialization) -> None: + codec = wrapped_codec(hessian2, (str,)) + value = hessian2.codec((str,)).encode(("bob",)) + + assert ( + codec.encode(("bob",)) + == TripleResponseWrapper(serializeType="hessian2", data=value, type="java.lang.String").SerializeToString() + ) + + +def test_a_wrapper_that_names_hessian4_is_read_as_hessian2(hessian2: Hessian2Serialization) -> None: + codec = wrapped_codec(hessian2, (str,)) + value = hessian2.codec((str,)).encode(("bob",)) + + assert codec.decode(TripleResponseWrapper(serializeType="hessian4", data=value).SerializeToString()) == ("bob",) + + +@pytest.mark.parametrize( + ("data", "message"), + [ + (b"\xff", "not a wrapped message"), + (TripleRequestWrapper(serializeType="fastjson2", args=[b"N"]).SerializeToString(), "in 'fastjson2'"), + (TripleRequestWrapper(serializeType="hessian2", args=[b"N", b"N"]).SerializeToString(), "expected 1 values"), + ], +) +def test_a_wrapper_must_hold_one_value_of_each_type_in_the_format( + hessian2: Hessian2Serialization, data: bytes, message: str +) -> None: + with pytest.raises(ValueError, match=message): + wrapped_codec(hessian2, (Any,)).decode(data) diff --git a/tests/unit/registry/nacos/test_interface.py b/tests/unit/registry/nacos/test_interface.py new file mode 100644 index 00000000..eb0a5949 --- /dev/null +++ b/tests/unit/registry/nacos/test_interface.py @@ -0,0 +1,65 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +from contextlib import asynccontextmanager + +import anyio +import pytest + +from dubbo.extension import ApplicationScope, Resource, extensions +from dubbo.registry.nacos import NacosInterfaceRegistry +from dubbo.transport.nacos import NacosInstance, NacosNamingClient +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = pytest.mark.anyio + + +async def test_an_instance_that_holds_no_valid_url_is_left_out_of_the_others(isolated_extensions, caplog): + caplog.set_level(logging.WARNING) + bad = NacosInstance(host="10.0.0.1", port=1, metadata={"protocol": "bad protocol", "path": "test.Greeter"}) + good = NacosInstance(host="10.0.0.2", port=2, metadata={"protocol": "tri", "path": "test.Greeter"}) + + class Snapshot(Resource): + def __init__(self, url: URL) -> None: + pass + + async def aclose(self) -> None: + pass + + @asynccontextmanager + async def watch(self, service: str, group: str): + async def snapshots(): + yield [bad, good] + await anyio.sleep_forever() + + yield snapshots() + + extensions.register(NacosNamingClient, "snapshot", Snapshot) + + async with ( + ApplicationScope() as scope, + NacosInterfaceRegistry( + URL.parse("nacos://127.0.0.1:8848?client=snapshot").replace(attributes={APPLICATION_SCOPE: scope}) + ) as registry, + registry.subscribe("test.Greeter", group=None, version=None) as updates, + ): + with anyio.fail_after(5): + urls = await anext(updates) + + assert [url.host for url in urls] == ["10.0.0.2"] + assert "Ignoring the instance 10.0.0.1:1" in caplog.text diff --git a/tests/unit/registry/test_consumer.py b/tests/unit/registry/test_consumer.py new file mode 100644 index 00000000..8d37f07e --- /dev/null +++ b/tests/unit/registry/test_consumer.py @@ -0,0 +1,213 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from contextlib import asynccontextmanager +from importlib.metadata import version + +import anyio +import attrs +import pytest + +from dubbo.extension import ApplicationScope, extensions +from dubbo.registry import InterfaceRegistry +from dubbo.registry.consumer import Consumer, register_consumer +from dubbo.rpc.definition import Method, Service +from dubbo.url import APPLICATION_SCOPE, PROVIDER_URL, URL +from dubbo.utils import Latest + +CONSUMER = Consumer(interface="test.Greeter", group="a", version="1", parameters={"application": "c"}) + + +@pytest.mark.parametrize( + ("query", "accepted"), + [ + ("group=a&version=1", True), + ("group=b&version=1", False), + ("group=a&version=2", False), + ("group=a&version=1&category=consumers", False), + ("group=a&version=1&interface=test.Other", False), + ], +) +def test_a_consumer_accepts_providers_of_its_service_only(query, accepted): + url = URL.parse(f"tri://10.0.0.5:50051/test.Greeter?{query}") + + assert (CONSUMER.prepare(url) is not None) is accepted + + +def test_a_consumer_ignores_providers_of_protocols_not_installed(): + assert CONSUMER.prepare(URL.parse("rest://10.0.0.5:8080/test.Greeter?group=a&version=1")) is None + + +@pytest.mark.parametrize( + ("wanted", "group", "accepted"), + [("*", "x", True), ("a,b", "b", True), ("a,b", "c", False), (None, None, True), (None, "a", False)], +) +def test_a_consumer_group_may_accept_several(wanted, group, accepted): + consumer = Consumer(interface="test.Greeter", group=wanted, version=None, parameters={}) + query = f"?group={group}" if group else "" + + assert (consumer.prepare(URL.parse(f"tri://h:1/test.Greeter{query}")) is not None) is accepted + + +def test_the_consumer_timeouts_come_before_those_of_a_provider(): + consumer = Consumer( + interface="test.Greeter", group=None, version=None, parameters={"timeout": "100", "Greet.timeout": "100"} + ) + + url = consumer.prepare( + URL.parse("tri://10.0.0.5:1/test.Greeter?methods=Greet,Say&timeout=2000&Greet.timeout=50&Say.timeout=30") + ) + + assert url is not None + assert url.parameters == {"methods": "Greet,Say", "timeout": "100", "Greet.timeout": "100", "Say.timeout": "30"} + + +def test_a_provider_url_takes_only_what_providers_publish_for_their_consumers(): + provider = URL.parse( + "tri://10.0.0.5:50051/test.Greeter?application=p&group=a&version=1&timeout=2000&weight=50&dubbo.tag=gray" + "×tamp=7&methods=Greet&Greet.weight=5&Greet.retries=9&zone=x&serialization=hessian2&shutwait=30000" + "&triple.compressor=gzip" + ) + + url = CONSUMER.prepare(provider) + + assert url == URL.parse( + "tri://10.0.0.5:50051/test.Greeter?application=c&remote.application=p&group=a&version=1&timeout=2000" + "&weight=50&dubbo.tag=gray×tamp=7&methods=Greet&Greet.weight=5&serialization=hessian2" + ) + + +def test_a_provider_url_takes_the_serialization_of_the_reference_over_that_of_the_provider(): + consumer = attrs.evolve(CONSUMER, parameters={"application": "c", "serialization": "protobuf"}) + + url = consumer.prepare(URL.parse("tri://10.0.0.5:1/test.Greeter?group=a&version=1&serialization=hessian2")) + + assert url is not None + assert url.parameters["serialization"] == "protobuf" + + +def test_a_provider_url_takes_the_attributes_of_the_reference_and_keeps_what_the_provider_published(): + consumer = attrs.evolve(CONSUMER, attributes={"key": "value"}) + published = URL.parse("tri://10.0.0.5:50051/test.Greeter?group=a&version=1") + + url = consumer.prepare(published) + + assert url is not None + assert url.attributes == {"key": "value", PROVIDER_URL: published} + + +def test_a_provider_url_takes_the_tag_of_the_provider_alone(): + consumer = attrs.evolve(CONSUMER, parameters={"application": "c", "dubbo.tag": "gray"}) + + untagged = consumer.prepare(URL.parse("tri://10.0.0.5:1/test.Greeter?group=a&version=1")) + tagged = consumer.prepare(URL.parse("tri://10.0.0.5:1/test.Greeter?group=a&version=1&dubbo.tag=blue")) + + assert untagged is not None + assert "dubbo.tag" not in untagged.parameters + assert tagged is not None + assert tagged.parameters["dubbo.tag"] == "blue" + + +def test_a_provider_url_that_lists_no_methods_keeps_what_it_publishes_for_each_method(): + url = CONSUMER.prepare( + URL.parse("tri://10.0.0.5:1/test.Greeter?group=a&version=1&Greet.timeout=50&Greet.retries=9&.weight=1") + ) + + assert url is not None + assert url.parameters == {"application": "c", "group": "a", "version": "1", "Greet.timeout": "50"} + + +@pytest.mark.anyio +async def test_a_watch_keeps_the_url_of_a_provider_that_does_not_change(): + unchanged = URL.parse("tri://10.0.0.5:1/test.Greeter?group=a&version=1") + snapshots = Latest() + + @asynccontextmanager + async def subscription(): + yield aiter(snapshots) + + snapshots.publish([unchanged]) + with anyio.fail_after(5): + async with CONSUMER.watch(subscription(), URL.parse("tri://10.0.0.1/test.Greeter")) as urls: + [first] = await anext(urls) + snapshots.publish([unchanged, URL.parse("tri://10.0.0.6:1/test.Greeter?group=a&version=1")]) + kept, _ = await anext(urls) + + assert kept is first + + +class _Registry(InterfaceRegistry): + def __init__(self, url, registered, removed): + super().__init__(url) + self.registered, self.removed = registered, removed + + @asynccontextmanager + async def register(self, url): + self.registered.append(url) + try: + yield + finally: + self.removed.append(url) + + async def aclose(self): + pass + + async def __aenter__(self): + return self + + +@pytest.mark.parametrize( + ("generic", "extra"), + [(None, {"methods": "Greet"}), ("protobuf-json", {"generic": "protobuf-json"})], + ids=["contract", "generic"], +) +@pytest.mark.anyio +async def test_consumer_registration_publishes_its_generic_mode_in_place_of_methods( + isolated_extensions, monkeypatch, generic, extra +): + registered, removed = [], [] + + monkeypatch.setattr("time.time_ns", lambda: 1700000000000000000) + extensions.register(InterfaceRegistry, "memory", lambda url: _Registry(url, registered, removed)) + service = Service(interface="test.Greeter", methods=[Method(name="Greet", request=(), response=None)]) + reference = URL.parse("consumer://10.0.0.9/test.Greeter?application=c&group=a&timeout=1000") + + async with ApplicationScope() as scope: + registry = URL.parse("memory://registry?register-mode=interface").replace(attributes={APPLICATION_SCOPE: scope}) + async with register_consumer(reference, service, [registry], generic=generic): + assert registered == [ + URL( + protocol="consumer", + host="10.0.0.9", + path="test.Greeter", + parameters={ + "application": "c", + "group": "a", + "side": "consumer", + "category": "consumers", + "check": "false", + "interface": "test.Greeter", + "dubbo": "2.0.2", + "release": version("apache-dubbo"), + "timestamp": "1700000000000", + **extra, + }, + ) + ] + assert removed == [] + + assert removed == registered diff --git a/tests/unit/registry/test_discovery.py b/tests/unit/registry/test_discovery.py new file mode 100644 index 00000000..8ba3c932 --- /dev/null +++ b/tests/unit/registry/test_discovery.py @@ -0,0 +1,238 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from contextlib import asynccontextmanager + +import anyio +import pytest + +import dubbo.registry.discovery as discovery +from dubbo.extension import ApplicationScope, Resource, extensions +from dubbo.metadata import MetadataInfo, MetadataReport, ServiceInfo +from dubbo.registry import InstanceRegistry, ServiceInstance +from dubbo.registry.discovery import subscribe_by_instance +from dubbo.url import APPLICATION_SCOPE, URL +from dubbo.utils import Latest + +pytestmark = pytest.mark.anyio + + +async def test_an_unreadable_revision_is_read_again_without_watching_the_registry_again( + isolated_extensions, monkeypatch +): + monkeypatch.setattr(discovery, "backoff", lambda: iter([0.01] * 1000)) + info = MetadataInfo.from_services( + "demo", [ServiceInfo(name="test.Greeter", protocol="tri", port=50051, path="test.Greeter")] + ) + snapshots = Latest() + subscriptions = 0 + failures = 0 + + def instance(revision, host="10.0.0.5"): + return ServiceInstance( + app="demo", + host=host, + port=50051, + metadata={"dubbo.metadata.revision": revision, "dubbo.metadata.storage-type": "remote"}, + ) + + class Instances(Resource): + @asynccontextmanager + async def subscribe(self, app): + nonlocal subscriptions + subscriptions += 1 + yield aiter(snapshots) + + async def aclose(self): + pass + + class Report(Resource): + async def get_app_metadata(self, app, revision): + nonlocal failures + if revision != info.revision: + failures += 1 + raise OSError("unreachable") + return info + + async def aclose(self): + pass + + extensions.register(InstanceRegistry, "memory", lambda url: Instances()) + extensions.register(MetadataReport, "memory", lambda url: Report()) + snapshots.publish([instance(info.revision), instance("new", host="10.0.0.6")]) + seen = [] + + with anyio.fail_after(5): + async with ApplicationScope() as scope: + url = URL.parse("memory://registry").replace(attributes={APPLICATION_SCOPE: scope}) + async with subscribe_by_instance(url, "test.Greeter", ["demo"]) as urls, anyio.create_task_group() as tasks: + + async def collect(): + async for each in urls: + seen.append(each) # noqa: PERF401 - the iteration never ends, so each value is kept as it comes + + tasks.start_soon(collect) + while failures < 5: + await anyio.sleep(0.01) + tasks.cancel_scope.cancel() + + # Each retry reads the unreadable revision again; the instance with the readable one keeps its URLs throughout. + assert subscriptions == 1 + assert seen + assert all(each == [URL.parse("tri://10.0.0.5:50051/test.Greeter")] for each in seen) + + +async def test_an_unreadable_new_revision_keeps_the_last_urls_until_the_instance_leaves(isolated_extensions): + info = MetadataInfo.from_services( + "demo", [ServiceInfo(name="test.Greeter", protocol="tri", port=50051, path="test.Greeter")] + ) + failed = anyio.Event() + snapshots = Latest() + + def instance(revision): + return ServiceInstance( + app="demo", + host="10.0.0.5", + port=50051, + metadata={"dubbo.metadata.revision": revision, "dubbo.metadata.storage-type": "remote"}, + ) + + class Instances(Resource): + @asynccontextmanager + async def subscribe(self, app): + yield aiter(snapshots) + + async def aclose(self): + pass + + class Report(Resource): + async def get_app_metadata(self, app, revision): + if revision != info.revision: + failed.set() + raise OSError("unreachable") + return info + + async def aclose(self): + pass + + extensions.register(InstanceRegistry, "memory", lambda url: Instances()) + extensions.register(MetadataReport, "memory", lambda url: Report()) + snapshots.publish([instance(info.revision)]) + + with anyio.fail_after(5): + async with ApplicationScope() as scope: + url = URL.parse("memory://registry").replace(attributes={APPLICATION_SCOPE: scope}) + async with subscribe_by_instance(url, "test.Greeter", ["demo"]) as urls: + assert await anext(urls) == [URL.parse("tri://10.0.0.5:50051/test.Greeter")] + + snapshots.publish([instance("new")]) + await failed.wait() + assert await anext(urls) == [URL.parse("tri://10.0.0.5:50051/test.Greeter")] + + snapshots.publish([]) + assert await anext(urls) == [] + + +async def test_an_instance_that_does_not_change_keeps_the_same_urls_when_another_is_replaced(isolated_extensions): + info = MetadataInfo.from_services( + "demo", [ServiceInfo(name="test.Greeter", protocol="tri", port=50051, path="test.Greeter")] + ) + snapshots = Latest() + + def instance(host): + return ServiceInstance( + app="demo", + host=host, + port=50051, + metadata={"dubbo.metadata.revision": info.revision, "dubbo.metadata.storage-type": "remote"}, + ) + + class Instances(Resource): + @asynccontextmanager + async def subscribe(self, app): + yield aiter(snapshots) + + async def aclose(self): + pass + + class Report(Resource): + async def get_app_metadata(self, app, revision): + return info + + async def aclose(self): + pass + + extensions.register(InstanceRegistry, "memory", lambda url: Instances()) + extensions.register(MetadataReport, "memory", lambda url: Report()) + snapshots.publish([instance("10.0.0.5"), instance("10.0.0.6")]) + + with anyio.fail_after(5): + async with ApplicationScope() as scope: + url = URL.parse("memory://registry").replace(attributes={APPLICATION_SCOPE: scope}) + async with subscribe_by_instance(url, "test.Greeter", ["demo"]) as urls: + kept, _ = await anext(urls) + snapshots.publish([instance("10.0.0.5"), instance("10.0.0.7")]) + after = await anext(urls) + + assert after == [kept, URL.parse("tri://10.0.0.7:50051/test.Greeter")] + assert after[0] is kept + + +async def test_an_instance_whose_metadata_holds_no_valid_url_leaves_the_others_of_its_application( + isolated_extensions, +): + good = MetadataInfo.from_services( + "demo", [ServiceInfo(name="test.Greeter", protocol="tri", port=50051, path="test.Greeter")] + ) + bad = MetadataInfo.from_services( + "demo", [ServiceInfo(name="test.Other", protocol="tri", port=65536, path="test.Other")] + ) + infos = {good.revision: good, bad.revision: bad} + + def instance(host, revision): + return ServiceInstance( + app="demo", + host=host, + port=50051, + metadata={"dubbo.metadata.revision": revision, "dubbo.metadata.storage-type": "remote"}, + ) + + class Instances(Resource): + @asynccontextmanager + async def subscribe(self, app): + snapshots = Latest() + snapshots.publish([instance("10.0.0.5", good.revision), instance("10.0.0.6", bad.revision)]) + yield aiter(snapshots) + + async def aclose(self): + pass + + class Report(Resource): + async def get_app_metadata(self, app, revision): + return infos[revision] + + async def aclose(self): + pass + + extensions.register(InstanceRegistry, "memory", lambda url: Instances()) + extensions.register(MetadataReport, "memory", lambda url: Report()) + + with anyio.fail_after(5): + async with ApplicationScope() as scope: + url = URL.parse("memory://registry").replace(attributes={APPLICATION_SCOPE: scope}) + async with subscribe_by_instance(url, "test.Greeter", ["demo"]) as urls: + assert await anext(urls) == [URL.parse("tri://10.0.0.5:50051/test.Greeter")] diff --git a/tests/unit/registry/test_provider.py b/tests/unit/registry/test_provider.py new file mode 100644 index 00000000..bd4c4130 --- /dev/null +++ b/tests/unit/registry/test_provider.py @@ -0,0 +1,259 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import math +from contextlib import asynccontextmanager +from importlib.metadata import version + +import anyio +import pytest +from anyio.lowlevel import checkpoint + +from dubbo.config import ApplicationConfig, DubboConfig, ShutdownConfig +from dubbo.extension import ApplicationScope, extensions +from dubbo.protocol.exported import ExportedService +from dubbo.registry import InterfaceRegistry +from dubbo.registry.provider import ( + _InterfaceRegistration, + _Kept, + _register_on_change, + register_services, +) +from dubbo.rpc.definition import Method, Service +from dubbo.url import ADVERTISED_PORT, APPLICATION_SCOPE, CONFIG_CENTER_URL, URL +from dubbo.utils import Latest + +pytestmark = pytest.mark.anyio + + +class _Registry(InterfaceRegistry): + def __init__(self, url, registered, removed): + super().__init__(url) + self.registered, self.removed = registered, removed + + @asynccontextmanager + async def register(self, url): + self.registered.append(url) + try: + yield + finally: + self.removed.append(url) + + async def aclose(self): + pass + + async def __aenter__(self): + return self + + +async def test_a_change_of_the_rules_applies_while_registering_an_earlier_one_still_fails() -> None: + changes: Latest[None] = Latest() + rules, applied, attempted = ["first"], [], [] + send, receive = anyio.create_memory_object_stream[None](math.inf) + + async def register() -> None: + attempted.append(rules[0]) + send.send_nowait(None) + await checkpoint() + raise ConnectionError("the registry is down") + + with anyio.fail_after(5): + async with send, receive, anyio.create_task_group() as task_group: + task_group.start_soon(_register_on_change, changes, lambda: applied.append(rules[0]), register) + changes.publish(None) + await receive.receive() + rules[0] = "second" + changes.publish(None) + await receive.receive() + task_group.cancel_scope.cancel() + + assert applied == ["first", "second"] + assert attempted == ["first", "second"] + + +async def test_simplification_keeps_an_overridden_interface_extra_keys_and_declared_method_prefixes(config_store): + registered, removed = [], [] + + extensions.register(InterfaceRegistry, "recording", lambda url: _Registry(url, registered, removed)) + config_store.put( + "demo.configurators", + """scope: application +key: demo +configs: + - side: provider + parameters: + interface: test.Greeter + Greet.timeout: 500 + Greeting.timeout: 700 + custom: x +""", + ) + config = DubboConfig(application=ApplicationConfig(name="demo"), shutdown=ShutdownConfig(unregister_wait=0)) + definition = Service( + interface="greeter", methods=[Method(name=name, request=(), response=None) for name in ("Greet", "Farewell")] + ) + + with anyio.fail_after(5): + async with ApplicationScope() as scope: + attributes = {APPLICATION_SCOPE: scope} + center = URL.parse("memory://rules").replace(attributes=attributes) + served = URL.parse("tri://10.0.0.5:50051/greeter?application=demo").replace( + attributes=attributes | {CONFIG_CENTER_URL: center} + ) + registry = URL.parse( + "recording://registry?register-mode=interface&simplified=true&extra-keys=custom" + ).replace(attributes=attributes) + exported = ExportedService( + interface="greeter", + definition=definition, + url=served, + reconfigure=lambda changes: None, + registries=[registry], + ) + + async with register_services(config, [exported], scope): + assert registered == [ + URL( + protocol="tri", + host="10.0.0.5", + port=50051, + path="greeter", + parameters={ + "application": "demo", + "dubbo": "2.0.2", + "release": version("apache-dubbo"), + "side": "provider", + "interface": "test.Greeter", + "Greet.timeout": "500", + "custom": "x", + }, + ) + ] + + assert removed == registered + + +@pytest.mark.parametrize("simplified", ["false", "true"]) +async def test_a_registry_publishes_the_parameters_of_a_service_its_extra_keys_name(isolated_extensions, simplified): + registered, removed = [], [] + + extensions.register(InterfaceRegistry, "recording", lambda url: _Registry(url, registered, removed)) + config = DubboConfig(application=ApplicationConfig(name="demo"), shutdown=ShutdownConfig(unregister_wait=0)) + definition = Service(interface="greeter", methods=[Method(name="Greet", request=(), response=None)]) + + with anyio.fail_after(5): + async with ApplicationScope() as scope: + attributes = {APPLICATION_SCOPE: scope} + served = URL.parse("tri://10.0.0.5:50051/greeter?application=demo&env=gray&threads=9").replace( + attributes=attributes + ) + registry = URL.parse( + f"recording://registry?register-mode=interface&simplified={simplified}&extra-keys=env" + ).replace(attributes=attributes) + exported = ExportedService( + interface="greeter", + definition=definition, + url=served, + reconfigure=lambda changes: None, + registries=[registry], + ) + + async with register_services(config, [exported], scope): + [url] = registered + assert url.parameters["env"] == "gray" + assert "threads" not in url.parameters + + +@pytest.mark.parametrize(("advertised", "expected"), [({ADVERTISED_PORT: 30051}, 30051), ({}, 50051)]) +async def test_a_service_is_registered_with_the_advertised_port_of_its_protocol( + isolated_extensions, advertised, expected +): + registered, removed = [], [] + + extensions.register(InterfaceRegistry, "recording", lambda url: _Registry(url, registered, removed)) + config = DubboConfig(application=ApplicationConfig(name="demo"), shutdown=ShutdownConfig(unregister_wait=0)) + definition = Service(interface="greeter", methods=[Method(name="Greet", request=(), response=None)]) + + with anyio.fail_after(5): + async with ApplicationScope() as scope: + attributes = {APPLICATION_SCOPE: scope} + served = URL.parse("tri://10.0.0.5:50051/greeter?application=demo").replace( + attributes=attributes | advertised + ) + registry = URL.parse("recording://registry?register-mode=interface").replace(attributes=attributes) + exported = ExportedService( + interface="greeter", + definition=definition, + url=served, + reconfigure=lambda changes: None, + registries=[registry], + ) + + async with register_services(config, [exported], scope): + [url] = registered + assert (url.host, url.port) == ("10.0.0.5", expected) + + +async def test_a_url_whose_registration_failed_is_registered_again_next_time(): + registered, removed = [], [] + failures = [ConnectionError("the registry is down")] + + class Flaky(_Registry): + @asynccontextmanager + async def register(self, url): + if failures: + raise failures.pop() + async with super().register(url): + yield + + first, second = URL.parse("tri://10.0.0.5:1/greeter?weight=1"), URL.parse("tri://10.0.0.5:1/greeter?weight=2") + async with anyio.create_task_group() as task_group: + registration = _InterfaceRegistration( + registry=URL.parse("memory://registry"), client=Flaky(None, registered, removed), kept=_Kept(task_group) + ) + + with pytest.raises(ConnectionError): + await registration.register([first]) + await registration.register([first]) + await registration.register([second]) + await registration.unregister() + + assert (registered, removed) == ([first, second], [first, second]) + + +async def test_a_registration_is_entered_and_exited_in_one_task_whichever_task_registers_and_releases(): + tasks: list[tuple[str, int]] = [] + + class Recording(_Registry): + @asynccontextmanager + async def register(self, url): + tasks.append(("enter", anyio.get_current_task().id)) + yield + tasks.append(("exit", anyio.get_current_task().id)) + + url = URL.parse("tri://10.0.0.5:1/greeter") + async with anyio.create_task_group() as task_group: + registration = _InterfaceRegistration( + registry=URL.parse("memory://registry"), client=Recording(None, [], []), kept=_Kept(task_group) + ) + async with anyio.create_task_group() as registering: + registering.start_soon(registration.register, [url]) + await registration.unregister() + + [(_, entered), (_, exited)] = tasks + assert entered == exited + assert entered != anyio.get_current_task().id diff --git a/tests/unit/registry/test_registration.py b/tests/unit/registry/test_registration.py new file mode 100644 index 00000000..a040896e --- /dev/null +++ b/tests/unit/registry/test_registration.py @@ -0,0 +1,47 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.config import ApplicationConfig +from dubbo.config.fields import to_url_parameters +from dubbo.registry.registration import published_parameters, registers, simplified +from dubbo.url import URL + + +@pytest.mark.parametrize("check", [registers, simplified]) +def test_a_registry_setting_that_is_not_a_boolean_is_rejected(check): + with pytest.raises(ValueError, match="maybe"): + check(URL.parse("zookeeper://zk?register=maybe&simplified=maybe")) + + +def test_the_description_of_the_application_is_published_with_its_services(): + application = ApplicationConfig( + name="orders", owner="alice,bob", organization="shop", architecture="trade", environment="test" + ) + + assert published_parameters(to_url_parameters(application)) == { + "application": "orders", + "owner": "alice,bob", + "organization": "shop", + "architecture": "trade", + "environment": "test", + } + + +def test_the_serialization_of_a_service_is_published_for_its_consumers(): + assert published_parameters({"serialization": "hessian2", "threads": "200"}) == {"serialization": "hessian2"} diff --git a/tests/unit/registry/zookeeper/test_instance.py b/tests/unit/registry/zookeeper/test_instance.py new file mode 100644 index 00000000..bf6eea93 --- /dev/null +++ b/tests/unit/registry/zookeeper/test_instance.py @@ -0,0 +1,71 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import itertools +import typing +from contextlib import AsyncExitStack + +import anyio +import pytest + +from dubbo.extension import ApplicationScope, extensions +from dubbo.registry import ServiceInstance +from dubbo.registry.zookeeper import ZookeeperInstanceRegistry +from dubbo.transport.zookeeper import ZookeeperClient, ZookeeperError +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = pytest.mark.anyio + + +async def test_an_instance_watch_that_fails_after_the_first_instances_is_watched_again(memory_zookeeper, monkeypatch): + client = extensions.get(ZookeeperClient, "memory") + failures = 1 + + class Flaky(client): + def watch(self, path: str) -> typing.Any: + nonlocal failures + if path.endswith("10.0.0.6:50051") and failures: + failures -= 1 + raise ZookeeperError("unreachable") + return super().watch(path) + + monkeypatch.setattr("dubbo.utils.async_.backoff", lambda: itertools.repeat(0)) + extensions.register(ZookeeperClient, "flaky", Flaky) + first = ServiceInstance(app="demo", host="10.0.0.5", port=50051) + second = ServiceInstance(app="demo", host="10.0.0.6", port=50051) + + async with ( + ApplicationScope() as scope, + AsyncExitStack() as stack, + ZookeeperInstanceRegistry( + URL.parse("zookeeper://127.0.0.1?client=flaky").replace(attributes={APPLICATION_SCOPE: scope}) + ) as discovery, + ): + await stack.enter_async_context(discovery.register(first)) + async with discovery.subscribe("demo") as updates: + with anyio.fail_after(5): + assert await anext(updates) == [first] + + await stack.enter_async_context(discovery.register(second)) + with anyio.fail_after(5): + async for instances in updates: + if len(instances) == 2: + break + + assert sorted(instances, key=lambda instance: instance.id) == [first, second] + + assert failures == 0 diff --git a/tests/unit/registry/zookeeper/test_interface.py b/tests/unit/registry/zookeeper/test_interface.py new file mode 100644 index 00000000..49b356b0 --- /dev/null +++ b/tests/unit/registry/zookeeper/test_interface.py @@ -0,0 +1,48 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging + +import anyio +import pytest + +from dubbo.extension import ApplicationScope +from dubbo.registry.zookeeper import ZookeeperInterfaceRegistry +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = pytest.mark.anyio + + +async def test_a_node_that_holds_no_url_is_ignored_without_logging_its_name(memory_zookeeper, caplog): + caplog.set_level(logging.WARNING) + parent = "/dubbo/test.Greeter/providers" + memory_zookeeper.put(f"{parent}/no-scheme%3Ftoken%3Dsecret", b"") + memory_zookeeper.put(f"{parent}/tri%3A%2F%2F10.0.0.1%3A50051%2Ftest.Greeter", b"") + + async with ( + ApplicationScope() as scope, + ZookeeperInterfaceRegistry( + URL.parse("zookeeper://127.0.0.1?client=memory").replace(attributes={APPLICATION_SCOPE: scope}) + ) as registry, + registry.subscribe("test.Greeter", group=None, version=None) as updates, + ): + with anyio.fail_after(5): + urls = await anext(updates) + + assert [url.host for url in urls] == ["10.0.0.1"] + assert f"Ignoring a node in {parent}" in caplog.text + assert "secret" not in caplog.text diff --git a/tests/unit/rpc/conftest.py b/tests/unit/rpc/conftest.py new file mode 100644 index 00000000..c4cf8c91 --- /dev/null +++ b/tests/unit/rpc/conftest.py @@ -0,0 +1,84 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import abc +import typing + +import attrs +import pytest + +import dubbo +from dubbo import Invocation, Result + + +@dubbo.service("com.example.UserService") +class UserService(typing.Protocol): + async def rename(self, id: int, name: str) -> str: ... + @dubbo.method("findByName") + async def find(self, name: str, limit: int = 10) -> list[str]: ... + async def fail(self, error: str) -> None: ... + async def sleep(self) -> None: ... + + def watch(self, query: str) -> dubbo.ServerStream[int]: ... + def upload(self) -> dubbo.ClientStream[bytes, int]: ... + def chat(self) -> dubbo.BidiStream[str, str]: ... + + +@dubbo.service("com.example.UserService") +class UserServiceServicer(abc.ABC): + @abc.abstractmethod + async def rename(self, id: int, name: str) -> str: ... + @dubbo.method("findByName") + @abc.abstractmethod + async def find(self, name: str, limit: int = 10) -> list[str]: ... + @abc.abstractmethod + async def fail(self, error: str) -> None: ... + @abc.abstractmethod + async def sleep(self) -> None: ... + + @abc.abstractmethod + async def watch(self, query: str, events: dubbo.SendStream[int]) -> None: ... + @abc.abstractmethod + async def upload(self, chunks: dubbo.ReceiveStream[bytes]) -> int: ... + @abc.abstractmethod + async def chat(self, stream: dubbo.Stream[str, str]) -> None: ... + + +@attrs.define(kw_only=True) +class _Recording: + result: Result = attrs.field(factory=lambda: Result(value="answer")) + calls: list[Invocation] = attrs.field(factory=list) + + async def invoke(self, invocation: Invocation) -> Result: + self.calls.append(invocation) + + return self.result + + +@pytest.fixture +def contract(): + return UserService + + +@pytest.fixture +def servicer(): + return UserServiceServicer + + +@pytest.fixture +def recording(): + return _Recording() diff --git a/tests/unit/rpc/test_client.py b/tests/unit/rpc/test_client.py new file mode 100644 index 00000000..02c9563d --- /dev/null +++ b/tests/unit/rpc/test_client.py @@ -0,0 +1,243 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import inspect +import typing +from typing import Annotated, Any + +import attrs +import pytest + +import dubbo +from dubbo import Invocation, Method, Parameter, Result, RpcError, Status, get_definition +from dubbo.rpc.client import GenericService, proxy +from dubbo.rpc.definition import JavaType + +pytestmark = pytest.mark.anyio + + +@pytest.mark.parametrize( + ("args", "kwargs", "arguments"), + [(("a",), {"limit": 2}, ("a", 2)), ((), {"name": "b"}, ("b", 10)), (("c", 3), {}, ("c", 3))], + ids=["mixed", "keyword-and-default", "positional"], +) +async def test_proxy_binds_arguments_in_parameter_order(args, kwargs, arguments, contract, recording): + users = proxy(contract, recording.invoke) + + result = await users.find(*args, **kwargs) + + assert result == "answer" + assert recording.calls == [ + Invocation( + interface="com.example.UserService", + method="findByName", + definition=get_definition(contract).method("findByName"), + arguments=arguments, + ) + ] + + +@pytest.mark.parametrize( + ("args", "message"), + [((), "missing a required argument"), (("c", 3, 4), "too many positional arguments")], + ids=["missing", "too-many"], +) +async def test_proxy_reports_bad_arguments_before_making_the_call(args, message, contract, recording): + users = proxy(contract, recording.invoke) + + with pytest.raises(TypeError, match=rf"find\(\): {message}"): + await users.find(*args) + + assert recording.calls == [] + + +@attrs.frozen +class Stock: + sku: str + on_hand: int + + +@dubbo.service("com.example.Inventory") +class Inventory(typing.Protocol): + @dubbo.method("GetStock") + async def get_stock(self, sku: "str", warehouse: str = "SH") -> "Stock": + """Return the stock of a SKU in a warehouse. + + Args: + sku: Stock keeping unit. + warehouse: Code of the warehouse. + """ + ... + + def watch(self, sku: str) -> dubbo.ServerStream["Stock"]: + """Stream each change of the stock of a SKU.""" + + +def test_proxy_methods_have_the_name_signature_annotations_and_docstring_of_the_contract(recording): + inventory = proxy(Inventory, recording.invoke) + + for name in ("get_stock", "watch"): + method = getattr(inventory, name) + declared = getattr(Inventory, name) + assert method.__name__ == name + assert method.__doc__ == declared.__doc__ + assert list(inspect.signature(method).parameters) == list(inspect.signature(declared).parameters)[1:] + assert typing.get_type_hints(method) == typing.get_type_hints(declared) + + assert typing.get_type_hints(inventory.get_stock) == {"sku": str, "warehouse": str, "return": Stock} + assert inspect.iscoroutinefunction(inventory.get_stock) + assert not inspect.iscoroutinefunction(inventory.watch) + + +def test_proxy_requires_the_caller_view_of_a_streaming_contract(servicer, recording): + with pytest.raises(TypeError, match="declares how its streaming methods are served"): + proxy(servicer, recording.invoke) + + +@pytest.mark.parametrize( + ("types", "annotations"), + [ + (None, [Any, Any]), + (["java.lang.String", "int"], [Annotated[Any, JavaType("java.lang.String")], Annotated[Any, JavaType("int")]]), + ], + ids=["inferred-any", "java-types"], +) +async def test_generic_calls_describe_a_unary_method_without_the_service_contract(types, annotations, recording): + users = GenericService("com.example.UserService", recording.invoke) + + result = await users.call("findByName", "g", 2, types=types) + + assert result == "answer" + assert recording.calls == [ + Invocation( + interface="com.example.UserService", + method="findByName", + generic="true", + arguments=("g", 2), + definition=Method( + name="findByName", + request=tuple( + Parameter(name=f"arg{index}", type=annotation) for index, annotation in enumerate(annotations) + ), + response=Any, + ), + ) + ] + + +@pytest.mark.parametrize( + "types", [["int"], "java.lang.String", ["java.lang.String", ""]], ids=["wrong-count", "bare-string", "empty-type"] +) +async def test_generic_calls_require_one_nonempty_java_type_per_argument(types, recording): + with pytest.raises(TypeError, match="one Java type for each of the 2 arguments"): + await GenericService("com.example.UserService", recording.invoke).call("findByName", "g", 2, types=types) + + assert recording.calls == [] + + +def test_generic_services_refuse_unknown_modes(recording): + with pytest.raises(ValueError, match=r"generic must be one of .*not 'nativejava'"): + GenericService("com.example.UserService", recording.invoke, generic="nativejava") + + +@pytest.mark.parametrize("generic", [False, True], ids=["contract", "generic"]) +async def test_unary_calls_raise_the_returned_error_and_record_response_attachments(generic, contract, recording): + error = RpcError(Status.PERMISSION_DENIED, "operator required") + recording.result = Result(error=error, attachments={"audit-id": "7"}) + + request = ( + GenericService("com.example.UserService", recording.invoke).call("fail", "rpc") + if generic + else proxy(contract, recording.invoke).fail("rpc") + ) + + with dubbo.outgoing() as call, pytest.raises(RpcError, match="PERMISSION_DENIED: operator required") as raised: + await request + + assert raised.value is error + assert raised.value.__cause__ is None + assert dict(call.response_attachments) == {"audit-id": "7"} + + +@attrs.define(kw_only=True) +class _Stream: + response_attachments: dict[str, str] = attrs.field(factory=lambda: {"query": "3"}) + closed: bool = False + + async def __aenter__(self): + return self + + async def __aexit__(self, *_: object) -> None: + self.closed = True + + +async def test_a_stream_sends_the_attachments_present_when_its_block_opens(contract, recording): + stream = _Stream() + recording.result = Result(value=stream) + opening = proxy(contract, recording.invoke).watch("1") + assert recording.calls == [] + + with dubbo.outgoing({"operator": "alice"}): + async with opening as opened: + assert opened is stream + + assert recording.calls == [ + Invocation( + interface="com.example.UserService", + method="watch", + definition=get_definition(contract).method("watch"), + arguments=("1",), + attachments={"operator": "alice"}, + ) + ] + assert stream.closed is True + + +async def test_a_stream_records_its_response_attachments_on_exit(contract, recording): + stream = _Stream() + recording.result = Result(value=stream) + + with dubbo.outgoing() as call: + async with proxy(contract, recording.invoke).watch("3"): + pass + + assert stream.closed is True + assert dict(call.response_attachments) == {"query": "3"} + + +async def test_a_stream_leaves_the_callers_exception_unwrapped(contract, recording): + stream = _Stream() + recording.result = Result(value=stream) + + with dubbo.outgoing() as call, pytest.raises(KeyError, match="mine"): + async with proxy(contract, recording.invoke).watch("3"): + raise KeyError("mine") + + assert stream.closed is True + assert dict(call.response_attachments) == {"query": "3"} + + +async def test_a_failed_stream_opening_raises_the_error_and_records_its_attachments(contract, recording): + error = RpcError(Status.ABORTED, "watch failed") + recording.result = Result(error=error, attachments={"query": "fail"}) + + with dubbo.outgoing() as call, pytest.raises(RpcError, match="ABORTED: watch failed") as raised: + async with proxy(contract, recording.invoke).watch("fail"): + pytest.fail("the stream must not open") + + assert raised.value is error + assert dict(call.response_attachments) == {"query": "fail"} diff --git a/tests/unit/rpc/test_context.py b/tests/unit/rpc/test_context.py new file mode 100644 index 00000000..9f4c2177 --- /dev/null +++ b/tests/unit/rpc/test_context.py @@ -0,0 +1,98 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest +from multidict import MultiDict + +import dubbo +from dubbo.rpc.context import attachments_to_send, record_response, serving + + +def test_incoming_outside_a_handler() -> None: + with pytest.raises(LookupError, match="only while a service handler runs"): + dubbo.incoming() + + +def test_outgoing_blocks_nest() -> None: + with dubbo.outgoing({"a": "1", "b": "1"}): + with dubbo.outgoing({"b": "2"}) as inner: + assert dict(inner.attachments) == {"a": "1", "b": "2"} + with dubbo.outgoing({"c": "3"}, inherit=False) as fresh: + assert dict(fresh.attachments) == {"c": "3"} + + +def test_outgoing_keeps_repeated_values_and_replaces_them_by_key() -> None: + with dubbo.outgoing(MultiDict([("tag", "a"), ("tag", "b"), ("user", "u")])): + with dubbo.outgoing() as inherited: + assert inherited.attachments.getall("tag") == ["a", "b"] + with dubbo.outgoing({"tag": "c"}) as inner: + assert list(inner.attachments.items()) == [("tag", "c"), ("user", "u")] + + +def test_serving_preserves_received_attachments_but_does_not_forward_credentials_or_routing(): + received = { + "tenant": "t1", + "token": "secret", + "timeout": "3000", + "_TO": "3000", + "dubbo.tag": "gray", + "Authorization": "Bearer x", + "cookie": "c", + } + + with serving(received, peer=None): + assert dict(dubbo.incoming().attachments) == received + assert dict(attachments_to_send()) == {"tenant": "t1"} + with dubbo.outgoing({"token": "own"}): + assert dict(attachments_to_send()) == {"tenant": "t1", "token": "own"} + + +@pytest.mark.parametrize( + ("additions", "inherit", "expected"), + [ + ({}, True, {"tenant": "t1", "operator": "alice"}), + ({"hop": "middle", "tenant": "t2"}, True, {"tenant": "t2", "operator": "alice", "hop": "middle"}), + ({"key": "x"}, False, {"key": "x"}), + ], + ids=["forward", "override", "cut-inheritance"], +) +def test_calls_inherit_the_served_attachments_unless_their_block_starts_fresh(additions, inherit, expected): + with serving({"tenant": "t1", "operator": "alice"}, peer=None), dubbo.outgoing(additions, inherit=inherit): + assert dict(attachments_to_send()) == expected + + +def test_serving_uses_the_received_attachments_and_restores_the_callers_block(): + with dubbo.outgoing({"tenant": "caller"}): + with serving({"tenant": "served", "filtered": "yes"}, peer=None): + assert dict(attachments_to_send()) == {"tenant": "served", "filtered": "yes"} + + assert dict(attachments_to_send()) == {"tenant": "caller"} + + +def test_response_attachments_belong_to_the_innermost_calling_block(): + with dubbo.outgoing() as caller: + with serving({}, peer=None): + with dubbo.outgoing({"key": "x"}, inherit=False) as downstream: + record_response({"from": "downstream"}) + record_response({"must-not": "leak-to-caller"}) + assert dict(caller.response_attachments) == {} + record_response({"from": "middle"}) + + assert (dict(caller.response_attachments), dict(downstream.response_attachments)) == ( + {"from": "middle"}, + {"from": "downstream"}, + ) diff --git a/tests/unit/rpc/test_definition.py b/tests/unit/rpc/test_definition.py new file mode 100644 index 00000000..894fe917 --- /dev/null +++ b/tests/unit/rpc/test_definition.py @@ -0,0 +1,283 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import typing +from collections.abc import Awaitable + +import pytest + +import dubbo +from dubbo import Method, Parameter, RpcType, Service, get_definition + + +@pytest.mark.parametrize( + ("source", "message"), + [ + ("async def m(self, a) -> None: ...", "annotate the type of parameter 'a'"), + ("async def m(self, a: int): ...", "annotate its return type"), + ("async def m(self, a: int, /) -> None: ...", "positional-only parameter 'a'"), + ("async def m(self, *, a: int) -> None: ...", "keyword-only parameter 'a'"), + ("async def m(self, *a: int) -> None: ...", "variadic positional parameter 'a'"), + ("async def m(self, **a: int) -> None: ...", "variadic keyword parameter 'a'"), + ("async def m() -> None: ...", "must take self"), + ("def m(self) -> None: ...", "must be an async def, or a def returning dubbo.ServerStream"), + ("async def m(self) -> dubbo.ServerStream[int]: ...", "must be a def, not an async def"), + ("def m(self) -> dubbo.ServerStream[int]: ...", "exactly one request parameter"), + ("def m(self, a: int) -> dubbo.BidiStream[int, int]: ...", "requests are sent on the stream"), + ("m: int", "must be a method"), + ("async def m(self, s: dubbo.SendStream[int]) -> None: ...", "exactly one request parameter before"), + ("async def m(self, s: dubbo.SendStream[int], a: int) -> None: ...", "one stream, as its last parameter"), + ("async def m(self, a: int, s: dubbo.SendStream[int]) -> int: ...", "must return None"), + ("async def m(self, a: int, s: dubbo.ReceiveStream[int]) -> int: ...", "must take only its stream"), + ("async def m(self, s: dubbo.Stream) -> None: ...", "message types of its stream 's'"), + ("def m(self, a: int) -> dubbo.ServerStream: ...", "message types of the stream it returns"), + ], + ids=[ + "unannotated", + "no-return", + "positional-only", + "keyword-only", + "args", + "kwargs", + "no-self", + "sync", + "async-stream", + "stream-without-request", + "bidi-with-parameter", + "attribute", + "served-stream-without-request", + "stream-not-last", + "served-stream-returns", + "client-stream-with-request", + "bare-stream", + "bare-called-stream", + ], +) +def test_service_rejects_invalid_members(source: str, message: str) -> None: + namespace: dict[str, object] = {} + exec(f"class Contract(typing.Protocol):\n {source}", {"dubbo": dubbo, "typing": typing}, namespace) + + contract = dubbo.service("Contract")(namespace["Contract"]) # type: ignore[arg-type] + + with pytest.raises(TypeError, match=message): + dubbo.get_definition(contract) + + +def test_a_contract_declares_streams_for_one_side() -> None: + @dubbo.service("Contract") + class Contract(typing.Protocol): + def watch(self, query: str) -> dubbo.ServerStream[int]: ... + async def upload(self, chunks: dubbo.ReceiveStream[bytes]) -> int: ... + + with pytest.raises(TypeError, match="declare each side in its own class"): + get_definition(Contract) + + +def test_service_definition_preserves_wire_names_parameter_defaults_and_stream_shapes(contract): + assert get_definition(contract) == Service( + interface="com.example.UserService", + methods=( + Method( + name="rename", request=(Parameter(name="id", type=int), Parameter(name="name", type=str)), response=str + ), + Method( + name="findByName", + request=(Parameter(name="name", type=str), Parameter(name="limit", type=int, default=10)), + response=list[str], + ), + Method(name="fail", request=(Parameter(name="error", type=str),), response=None), + Method(name="sleep", request=(), response=None), + Method( + name="watch", rpc_type=RpcType.SERVER_STREAM, request=(Parameter(name="query", type=str),), response=int + ), + Method( + name="upload", + rpc_type=RpcType.CLIENT_STREAM, + request=(Parameter(name="message", type=bytes),), + response=int, + ), + Method( + name="chat", rpc_type=RpcType.BIDI_STREAM, request=(Parameter(name="message", type=str),), response=str + ), + ), + ) + + +def test_caller_and_servicer_contracts_describe_the_same_service(contract, servicer): + assert get_definition(servicer) == get_definition(contract) + + +def test_streaming_methods_need_one_request_parameter(): + with pytest.raises(ValueError, match="server_stream method 'm' must have exactly one request parameter, not 0"): + Method(name="m", rpc_type=RpcType.SERVER_STREAM, request=(), response=int) + + +def test_service_definitions_reject_duplicate_method_names(): + method = Method(name="m", request=(), response=None) + + with pytest.raises(ValueError, match="S defines methods more than once: m"): + Service(interface="S", methods=(method, method)) + + +def test_contract_annotations_resolve_names_defined_later_and_reuse_the_built_definition(): + namespace = {"dubbo": dubbo, "typing": typing} + exec( + """ +from __future__ import annotations + +@dubbo.service("Contract") +class Contract(typing.Protocol): + async def clone(self) -> Contract: ... + async def find(self, query: Query) -> Query: ... + +class Query: ... +""", + namespace, + ) + + definition = get_definition(namespace["Contract"]) + + assert definition == Service( + interface="Contract", + methods=( + Method(name="clone", request=(), response=namespace["Contract"]), + Method( + name="find", request=(Parameter(name="query", type=namespace["Query"]),), response=namespace["Query"] + ), + ), + ) + assert get_definition(namespace["Contract"]) is definition + + +def test_contract_annotations_resolve_names_inside_annotations_and_keep_defaults(): + namespace = {"dubbo": dubbo, "typing": typing} + exec( + """ +@dubbo.service("Contract") +class Contract(typing.Protocol): + def watch(self, query: "Query" = None) -> dubbo.ServerStream["Query"]: ... + +class Query: ... +""", + namespace, + ) + + assert get_definition(namespace["Contract"]).method("watch") == Method( + name="watch", + rpc_type=RpcType.SERVER_STREAM, + request=(Parameter(name="query", type=namespace["Query"], default=None),), + response=namespace["Query"], + ) + + +def test_a_contract_has_the_methods_of_the_classes_it_extends(): + @dubbo.service("Parent") + class Parent(typing.Protocol): + async def inherited(self) -> int: ... + + @dubbo.service("Child") + class Child(Parent, typing.Protocol): + async def own(self) -> int: ... + + class Incomplete(Child): + async def own(self) -> int: + return 0 + + assert [method.name for method in get_definition(Child).methods] == ["inherited", "own"] + with pytest.raises(TypeError, match=r"Incomplete\.inherited is not implemented"): + Service.from_implementation(Incomplete()) + + +def test_unresolvable_annotations_name_the_method(): + namespace = {"dubbo": dubbo, "typing": typing} + exec( + """ +from __future__ import annotations + +@dubbo.service("Contract") +class Contract(typing.Protocol): + async def broken(self) -> Missing: ... +""", + namespace, + ) + + with pytest.raises(TypeError, match=r"Contract\.broken has an annotation that cannot be resolved"): + get_definition(namespace["Contract"]) + + namespace["Missing"] = str + + assert get_definition(namespace["Contract"]).method("broken").response is str + + +def test_contracts_reject_duplicate_wire_names(): + @dubbo.service("Contract") + class Contract(typing.Protocol): + @dubbo.method("getUser") + async def get_user(self) -> None: ... + @dubbo.method("getUser") + def watch_user(self, id: int) -> dubbo.ServerStream[int]: ... + + with pytest.raises(ValueError, match="more than once: getUser"): + get_definition(Contract) + + +def test_wire_method_names_cannot_be_empty(): + with pytest.raises(ValueError, match="method name must not be empty"): + dubbo.method("") + + +@pytest.mark.parametrize( + ("declaration", "implementation", "message"), + [ + ("async def find(self) -> None: ...", "pass", r"Implementation\.find is not implemented"), + ( + "def watch(self, query: str) -> dubbo.ServerStream[int]: ...", + "pass", + "declares how callers hold its streaming methods", + ), + ( + "async def watch(self, query: str, events: dubbo.SendStream[int]) -> None: ...", + "async def watch(self, chunks: dubbo.ReceiveStream[str]) -> int: return 0", + "does not take the arguments of a server_stream method", + ), + ( + "async def upload(self, chunks: dubbo.ReceiveStream[bytes]) -> int: ...", + "def upload(self, chunks: dubbo.ReceiveStream[bytes]) -> Awaitable[int]: ...", + r"Implementation\.upload must be an async def", + ), + ( + "async def find(self, name: str, limit: int = 10) -> list[str]: ...", + "async def find(self, name: str) -> list[str]: return []", + "does not take the arguments of a unary method", + ), + ], + ids=["missing-handler", "caller-view", "wrong-stream-shape", "synchronous-handler", "wrong-unary-arity"], +) +def test_implementations_supply_async_handlers_with_the_contract_arguments(declaration, implementation, message): + namespace = {"dubbo": dubbo, "typing": typing, "Awaitable": Awaitable} + exec( + f"@dubbo.service('Contract')\nclass Contract(typing.Protocol):\n {declaration}\n\nclass Implementation(Contract):\n {implementation}", + namespace, + ) + + with pytest.raises(TypeError, match=message): + Service.from_implementation(namespace["Implementation"]()) + + +def test_implementations_need_a_service_contract(): + with pytest.raises(TypeError, match="object does not implement a service contract"): + Service.from_implementation(object()) diff --git a/tests/unit/rpc/test_server.py b/tests/unit/rpc/test_server.py new file mode 100644 index 00000000..ebbf173c --- /dev/null +++ b/tests/unit/rpc/test_server.py @@ -0,0 +1,176 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import pytest + +import dubbo +from dubbo import Invocation, Method, Parameter, Result, RpcError, RpcType, Service, Status +from dubbo.filter import chain_filters +from dubbo.rpc.context import serving +from dubbo.rpc.server import ServiceInvoker +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +async def test_service_invoker_returns_the_handler_value_and_response_attachments(): + async def rename(id: int, name: str) -> str: + call = dubbo.incoming() + call.response_attachments["audit-id"] = str(id) + return f"{name}@{call.attachments['operator']}" + + method = Method( + name="rename", + request=(Parameter(name="id", type=int), Parameter(name="name", type=str)), + response=str, + handler=rename, + ) + invoker = ServiceInvoker(url=URL(protocol="local"), service=Service(interface="Users", methods=(method,))) + invocation = Invocation( + interface="Users", method="rename", definition=method, arguments=(7, "b"), attachments={"operator": "alice"} + ) + + with serving(invocation.attachments, peer=None): + result = await invoker.invoke(invocation) + + assert result == Result(value="b@alice", attachments={"audit-id": "7"}) + + +@pytest.mark.parametrize( + ("name", "arguments", "status", "message"), + [ + ("find", ("g", 1), Status.UNIMPLEMENTED, "Users has no method 'find'"), + ("findByName", ("g",), Status.INVALID_ARGUMENT, "findByName() takes 2 arguments, not 1"), + ], + ids=["python-name-is-not-wire-name", "missing-argument"], +) +async def test_service_invoker_rejects_calls_that_do_not_match_its_served_method(name, arguments, status, message): + async def find(name: str, limit: int) -> list[str]: + pytest.fail("a rejected call must not reach the handler") + + method = Method( + name="findByName", + request=(Parameter(name="name", type=str), Parameter(name="limit", type=int)), + response=list[str], + handler=find, + ) + invoker = ServiceInvoker(url=URL(protocol="local"), service=Service(interface="Users", methods=(method,))) + + result = await invoker.invoke(Invocation(interface="Users", method=name, definition=method, arguments=arguments)) + + assert isinstance(result.error, RpcError) + assert (result.error.status, result.error.message) == (status, message) + + +@pytest.mark.parametrize( + "error", + [RpcError(Status.PERMISSION_DENIED, "operator required"), ValueError("broken")], + ids=["rpc-error", "handler-exception"], +) +async def test_service_invoker_returns_the_handler_error_with_its_response_attachments(error): + async def fail() -> None: + dubbo.incoming().response_attachments["audit-id"] = "7" + raise error + + method = Method(name="fail", request=(), response=None, handler=fail) + invoker = ServiceInvoker(url=URL(protocol="local"), service=Service(interface="Users", methods=(method,))) + + with serving({}, peer=None): + result = await invoker.invoke(Invocation(interface="Users", method="fail", definition=method)) + + assert result == Result(error=error, attachments={"audit-id": "7"}) + + +async def test_service_invoker_propagates_cancellation_to_the_handler(): + cancelled = anyio.Event() + + async def wait() -> None: + try: + await anyio.sleep_forever() + finally: + cancelled.set() + + method = Method(name="wait", request=(), response=None, handler=wait) + invoker = ServiceInvoker(url=URL(protocol="local"), service=Service(interface="Users", methods=(method,))) + + with pytest.raises(TimeoutError), anyio.fail_after(0), serving({}, peer=None): + await invoker.invoke(Invocation(interface="Users", method="wait", definition=method)) + + assert cancelled.is_set() + + +async def test_serving_filters_complete_only_after_the_stream_handler_returns(): + entered, release, finished = anyio.Event(), anyio.Event(), [] + + class Record: + async def invoke(self, call_next, invocation): + result = await call_next(invocation) + finished.append(invocation.method) + return result + + async def watch(query: str, stream: dubbo.SendStream[int]) -> None: + entered.set() + await release.wait() + + method = Method( + name="watch", + rpc_type=RpcType.SERVER_STREAM, + request=(Parameter(name="query", type=str),), + response=int, + handler=watch, + ) + invoker = chain_filters( + ServiceInvoker(url=URL(protocol="local"), service=Service(interface="Users", methods=(method,))), [Record()] + ) + + class Sink(dubbo.SendStream[int]): + async def send(self, message: int) -> None: + pass + + with anyio.fail_after(5), serving({}, peer=None): + async with anyio.create_task_group() as tasks: + tasks.start_soon( + invoker.invoke, + Invocation(interface="Users", method="watch", definition=method, arguments=("2", Sink())), + ) + await entered.wait() + assert finished == [] + release.set() + + assert finished == ["watch"] + + +@pytest.mark.parametrize( + ("raised", "logged"), + [(AttributeError("a bug in the handler"), True), (RpcError(Status.NOT_FOUND, "no such user"), False)], + ids=["unexpected", "chosen-status"], +) +async def test_a_handler_failure_reaches_the_caller_and_only_an_unexpected_one_is_logged(raised, logged, caplog): + async def rename(id: int) -> str: + raise raised + + method = Method(name="rename", request=(Parameter(name="id", type=int),), response=str, handler=rename) + invoker = ServiceInvoker(url=URL(protocol="local"), service=Service(interface="Users", methods=(method,))) + invocation = Invocation(interface="Users", method="rename", definition=method, arguments=(7,)) + + with serving(invocation.attachments, peer=None): + result = await invoker.invoke(invocation) + + assert result.error is raised + records = [record for record in caplog.records if record.name == "dubbo.rpc.server"] + assert [(record.levelname, record.exc_info[1]) for record in records] == ([("ERROR", raised)] if logged else []) diff --git a/tests/unit/serialization/test_base.py b/tests/unit/serialization/test_base.py new file mode 100644 index 00000000..6817d940 --- /dev/null +++ b/tests/unit/serialization/test_base.py @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.extension import ExtensionError +from dubbo.serialization import JavaSerialization, get_java_serialization, get_serialization +from dubbo.serialization.protobuf import ProtobufSerialization +from dubbo.url import URL + + +def test_get_serialization_reads_the_serialization_parameter() -> None: + assert isinstance(get_serialization(URL(protocol="tri")), ProtobufSerialization) + assert isinstance( + get_serialization(URL(protocol="tri", parameters={"serialization": "protobuf"})), ProtobufSerialization + ) + with pytest.raises(ExtensionError, match="fastjson2"): + get_serialization(URL(protocol="tri", parameters={"serialization": "fastjson2"})) + + +def test_protobuf_carries_no_java_objects() -> None: + url = URL(protocol="dubbo", parameters={"serialization": "protobuf"}) + + assert not isinstance(ProtobufSerialization(url), JavaSerialization) + with pytest.raises(ValueError, match="'protobuf' does not carry Java objects"): + get_java_serialization(url) diff --git a/tests/unit/serialization/test_hessian2.py b/tests/unit/serialization/test_hessian2.py new file mode 100644 index 00000000..db2e51ab --- /dev/null +++ b/tests/unit/serialization/test_hessian2.py @@ -0,0 +1,318 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import dataclasses +import datetime +import decimal +import enum +from typing import Annotated, Any + +import attrs +import hessian2 +import pytest + +from dubbo.exceptions import RemoteError, Status +from dubbo.extension import extensions +from dubbo.serialization import JavaSerialization, Serialization, get_java_serialization +from dubbo.serialization.hessian2 import Hessian2Serialization +from dubbo.url import URL + + +@hessian2.java_class("com.example.Address") +@dataclasses.dataclass +class Address: + city: str + postal_code: str + + +@hessian2.java_class("com.example.User") +@dataclasses.dataclass +class User: + user_id: hessian2.Long + tags: list[hessian2.Long] + address: Address + + +@hessian2.java_class("java.lang.IllegalStateException") +@dataclasses.dataclass +class IllegalState(Exception): + detail_message: str = "" + + +@dataclasses.dataclass +class Undeclared: + name: str + + +def _serialization() -> Hessian2Serialization: + return Hessian2Serialization(URL(protocol="dubbo")) + + +def _user() -> User: + return User(user_id=7, tags=[1, 2], address=Address(city="Hangzhou", postal_code="310000")) + + +def test_hessian2_is_named_hessian2_and_carries_java_objects() -> None: + assert extensions.get(Serialization, "hessian2") is Hessian2Serialization + assert isinstance(_serialization(), JavaSerialization) + assert isinstance(get_java_serialization(URL(protocol="dubbo")), Hessian2Serialization) + + +def test_a_codec_decodes_the_classes_its_types_name() -> None: + codec = _serialization().codec((str, User, dict[str, Any])) + values = ("find", _user(), {"path": "com.example.UserService"}) + + assert codec.decode(codec.encode(values)) == values + + +def test_a_codec_builds_the_containers_its_types_name() -> None: + codec = _serialization().codec((tuple[str, ...], set[int])) + + assert codec.decode(codec.encode((("a", "b"), {1}))) == (("a", "b"), {1}) + + +def test_a_codec_rejects_types_hessian2_cannot_decode() -> None: + with pytest.raises(TypeError, match="several members"): + _serialization().codec((list[int] | set[int],)) + + +def test_a_codec_rejects_a_value_of_another_type() -> None: + data = _serialization().codec((int,)).encode((1,)) + + with pytest.raises(ValueError, match="expected str"): + _serialization().codec((str,)).decode(data) + + +def test_a_codec_rejects_another_number_of_values() -> None: + data = _serialization().codec((str,)).encode(("one",)) + + with pytest.raises(ValueError): # noqa: PT011 - the count is hessian2's to word + _serialization().codec((str, str)).decode(data) + + +def test_a_codec_writes_tagged_types() -> None: + serialization = _serialization() + tagged = serialization.codec((hessian2.Long,)) + plain = serialization.codec((int,)) + + assert tagged.encode((1,)) != plain.encode((1,)) + assert tagged.decode(tagged.encode((1,))) == (1,) + + +def test_an_object_where_any_value_fits_decodes_as_a_hessian_object() -> None: + data = _serialization().codec((User,)).encode((_user(),)) + + (value,) = _serialization().codec((Any,)).decode(data) + + assert isinstance(value, hessian2.HessianObject) + assert value.class_name == "com.example.User" + + +def test_a_value_without_a_java_name_cannot_be_encoded() -> None: + with pytest.raises(TypeError, match="Undeclared"): + _serialization().codec((Undeclared,)).encode((Undeclared(name="a"),)) + + +def test_a_reader_reads_values_one_at_a_time() -> None: + serialization = _serialization() + data = serialization.codec((str, User, None)).encode(("user", _user(), None)) + + reader = serialization.reader(data) + + assert reader.load(str) == "user" + assert reader.load(User) == _user() + with pytest.raises(ValueError, match="expected int"): + serialization.reader(data).load(int) + + +def test_a_reader_fails_after_the_last_value() -> None: + reader = _serialization().reader(_serialization().codec((str,)).encode(("only",))) + + reader.load(str) + with pytest.raises(ValueError, match="ends before this value"): + reader.load(str) + + +@pytest.mark.parametrize( + ("annotation", "name"), + [ + (hessian2.Long, "long"), + (Annotated[hessian2.Long, "the id"], "long"), + (User, "com.example.User"), + (str, "java.lang.String"), + (decimal.Decimal, "java.math.BigDecimal"), + (hessian2.Instant, "java.time.Instant"), + (IllegalState, "java.lang.IllegalStateException"), + (int, None), + (list[str], None), + (Undeclared, None), + ], + ids=repr, +) +def test_java_type_names_what_hessian2_declares(annotation: Any, name: str | None) -> None: + assert _serialization().java_type(annotation) == name + + +def test_a_remote_error_travels_as_an_object_of_its_class() -> None: + codec = _serialization().codec((Exception,)) + error = RemoteError("java.lang.IllegalStateException", "no user", fields={"code": 7}) + + data = codec.encode((error,)) + (received,) = codec.decode(data) + (sent,) = _serialization().codec((Any,)).decode(data) + + assert sent.class_name == "java.lang.IllegalStateException" + assert sent.fields["detailMessage"] == "no user" + assert isinstance(received, RemoteError) + assert (received.status, received.class_name, received.message) == ( + Status.UNKNOWN, + "java.lang.IllegalStateException", + "no user", + ) + assert received.fields["code"] == 7 + assert str(received) == "java.lang.IllegalStateException: no user" + + +def test_a_forwarded_remote_error_keeps_its_cause() -> None: + serialization = _serialization() + cause = hessian2.HessianObject("java.io.IOException", {"detailMessage": "disk"}) + data = serialization.codec((Any,)).encode( + (hessian2.HessianObject("java.lang.IllegalStateException", {"detailMessage": "no", "cause": cause}),) + ) + + received = serialization.reader(data).load(Exception) + (forwarded,) = serialization.codec((Any,)).decode(serialization.codec((Exception,)).encode((received,))) + + assert forwarded.fields["cause"] == cause + + +def test_a_declared_exception_travels_as_its_class() -> None: + serialization = _serialization() + + data = serialization.codec((Exception,)).encode((IllegalState("broken"),)) + + assert str(serialization.reader(data).load(Exception)) == "java.lang.IllegalStateException: broken" + + +def test_a_throwable_sent_as_text_reads_as_an_exception() -> None: + data = _serialization().codec((str,)).encode(("java.lang.NullPointerException",)) + + error = _serialization().reader(data).load(Exception) + + assert (error.class_name, error.message) == ("java.lang.Exception", "java.lang.NullPointerException") + + +@hessian2.java_class("com.example.Color") +class _Color(enum.Enum): + RED = "r" + + +@hessian2.java_class("com.example.Address") +@attrs.define(kw_only=True) +class _Address: + city: str + + +@hessian2.java_class("com.example.User") +@attrs.define(kw_only=True) +class _Member: + name: str + user_id: hessian2.Long + address: _Address | None + color: _Color | None + tags: tuple[str, ...] + + +def test_generalizing_keeps_the_java_types_of_the_fields() -> None: + serialization = _serialization() + user = _Member(name="bob", user_id=7, address=None, color=_Color.RED, tags=("a",)) + + generalized = serialization.generalize((user,), tuple[_Member, ...]) + + codec = hessian2.Codec() + # A long stays a long and a String[] stays one, as encoding the user writes them; the array of users is + # an array of objects, now maps. + assert hessian2.Typed(7, hessian2.Long) in generalized.value[0].values() + data = codec.dumps(generalized) + assert b"\xe7" in data + assert b"[string" in data + assert b"[object" in data + assert codec.loads(data) == [ + {"class": "com.example.User", "name": "bob", "userId": 7, "address": None, "color": "RED", "tags": ["a"]} + ] + + +def test_generalizing_leaves_a_null_alone() -> None: + serialization = _serialization() + + assert serialization.generalize(None, _Member | None) is None + + +def test_generalizing_refuses_what_holds_itself_or_has_no_java_class() -> None: + serialization = _serialization() + looped: list[Any] = [] + looped.append(looped) + + with pytest.raises(ValueError, match="holds itself"): + serialization.generalize(looped, Any) + with pytest.raises(TypeError): + serialization.generalize(object(), Any) + + +@hessian2.java_class("com.example.Tint") +@attrs.define(frozen=True, kw_only=True) +class _Tint: + color: _Color + + +def test_generalizing_reaches_an_object_that_several_hold_once() -> None: + shared: list[Any] = [_Color.RED] + for _ in range(16): + shared = [shared, shared] + + generalized = _serialization().generalize(shared, Any) + + # Each level doubles the paths to the innermost list, but not the work: the halves stay one list. + assert generalized[0] is generalized[1] + + +@pytest.mark.parametrize( + ("value", "annotation", "expected"), + [ + ({_Color.RED}, set[_Color], {"RED"}), + (frozenset({_Color.RED}), frozenset[_Color], frozenset({"RED"})), + ({_Tint(color=_Color.RED)}, set[_Tint], [{"class": "com.example.Tint", "color": "RED"}]), + ], + ids=["set", "frozenset", "set-of-objects"], +) +def test_generalizing_reaches_into_sets(value: Any, annotation: Any, expected: Any) -> None: + assert _serialization().generalize(value, annotation) == expected + + +@pytest.mark.parametrize( + ("value", "annotation", "expected"), + [ + (datetime.date(2026, 11, 15), datetime.date, "2026-11-15"), + (datetime.time(12, 34), datetime.time, "12:34"), + (datetime.time(12, 34, 56, 789000), datetime.time, "12:34:56.789"), + (datetime.datetime(2026, 11, 15, 12, 34, 56), hessian2.LocalDateTime, "2026-11-15T12:34:56"), + (datetime.datetime(2026, 11, 15, 12, 34, 0, 1), hessian2.LocalDateTime, "2026-11-15T12:34:00.000001"), + ], + ids=["local-date", "local-time-minutes", "local-time-millis", "local-date-time", "local-date-time-micros"], +) +def test_generalizing_gives_java_time_values_as_java_prints_them(value: Any, annotation: Any, expected: str) -> None: + assert _serialization().generalize(value, annotation) == expected diff --git a/tests/unit/serialization/test_protobuf.py b/tests/unit/serialization/test_protobuf.py new file mode 100644 index 00000000..55fcd6c3 --- /dev/null +++ b/tests/unit/serialization/test_protobuf.py @@ -0,0 +1,67 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest +from google.protobuf.wrappers_pb2 import Int64Value, StringValue + +from dubbo.extension import extensions +from dubbo.serialization import Serialization +from dubbo.serialization.protobuf import ProtobufSerialization +from dubbo.url import URL + + +def test_protobuf_is_named_protobuf_and_travels_as_proto() -> None: + assert extensions.get(Serialization, "protobuf") is ProtobufSerialization + assert ProtobufSerialization.content_subtype == "proto" + + +def test_protobuf_codec_preserves_the_message_wire_bytes(): + codec = ProtobufSerialization(URL(protocol="tri")).codec((StringValue,)) + message = StringValue(value="hi") + + assert codec.encode((message,)) == b"\x0a\x02hi" + assert codec.decode(b"\x0a\x02hi") == (message,) + + +@pytest.mark.parametrize( + ("types", "message"), + [ + ((), "one message of a known type"), + ((StringValue, StringValue), "one message of a known type"), + ((str,), "carries messages, not "), + ((None,), "carries messages, not None"), + ], +) +def test_protobuf_rejects_what_is_not_one_message_and_names_the_format_for_python_types( + types: tuple[object, ...], message: str +) -> None: + with pytest.raises(TypeError, match=message) as caught: + ProtobufSerialization(URL(protocol="tri")).codec(types) + + assert str(caught.value).endswith( + "; set the serialization to hessian2, or use the dubbo protocol, to carry Python types and several parameters" + ) + + +def test_protobuf_checks_the_message_type() -> None: + codec = ProtobufSerialization(URL(protocol="tri")).codec((StringValue,)) + + # SerializeToString itself would encode the wrong message without complaint. + with pytest.raises(TypeError, match="expected StringValue, not Int64Value"): + codec.encode((Int64Value(value=1),)) + with pytest.raises(ValueError, match="not a StringValue"): + codec.decode(b"\xff\xff") diff --git a/tests/unit/test_application.py b/tests/unit/test_application.py new file mode 100644 index 00000000..30720285 --- /dev/null +++ b/tests/unit/test_application.py @@ -0,0 +1,541 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import logging +import typing +from collections.abc import AsyncIterator +from contextlib import asynccontextmanager + +import anyio +import pytest +from google.protobuf.wrappers_pb2 import StringValue + +import dubbo +from dubbo import Dubbo +from dubbo.config import ( + ApplicationConfig, + ConfigError, + ConfigReadError, + ConsumerConfig, + MethodConfig, + ProtocolConfig, + ProviderConfig, + ReferenceConfig, + ServiceConfig, +) +from dubbo.extension import ExtensionError, extensions +from dubbo.protocol import Exporter, Protocol +from dubbo.rpc.context import serving +from dubbo.rpc.invocation import Invoker + +pytestmark = pytest.mark.anyio +APP = {"application": {"name": "orders"}} + + +async def test_default_env_prefix_reads_dubbo_variables(monkeypatch): + monkeypatch.setenv("DUBBO__APPLICATION__NAME", "from-env") + async with Dubbo() as app: + assert app.config.application.name == "from-env" + + +async def test_configuration_exists_only_after_start(): + app = Dubbo(APP, env_prefix=None) + with pytest.raises(RuntimeError, match="once the application has started"): + _ = app.config + async with app: + assert app.config.application.name == "orders" + with pytest.raises(RuntimeError, match="already"): + await app.__aenter__() + + +async def test_sources_are_read_at_start_and_left_unmodified(tmp_path): + source = {"application": {"name": "orders"}} + path = tmp_path / "later.json" + app = Dubbo(source, path, env_prefix=None) + path.write_text('{"application": {"version": "1"}}', encoding="utf-8") + + async with app: + assert app.config.application == ApplicationConfig(name="orders", version="1") + + assert source == {"application": {"name": "orders"}} + + +async def test_an_unreadable_source_reports_the_path_and_original_error(tmp_path): + app = Dubbo(tmp_path / "missing.json", env_prefix=None) + + with pytest.raises(ConfigReadError, match=r"missing\.json") as caught: + await app.__aenter__() + + assert isinstance(caught.value.__cause__, FileNotFoundError) + + +@dubbo.service("com.example.UserService") +class UserService(typing.Protocol): + @dubbo.method("getUser") + async def get_user(self, id: StringValue) -> StringValue: ... + + +class UserServiceImpl(UserService): + async def get_user(self, id: StringValue) -> StringValue: + return StringValue(value="user " + id.value) + + +def test_a_service_is_exported_once(): + app = Dubbo(APP, env_prefix=None) + app.export(UserServiceImpl()) + + with pytest.raises(ValueError, match="already exported"): + app.export(UserServiceImpl()) + + +def test_only_an_implementation_of_a_service_contract_is_exported(): + app = Dubbo(APP, env_prefix=None) + + with pytest.raises(TypeError, match="does not implement a service contract"): + app.export(object()) + + +async def test_services_are_exported_and_referenced_only_before_start(memory_protocol): + app = Dubbo(APP, env_prefix=None, protocols={"memory": ProtocolConfig(name="memory")}) + app.export(UserServiceImpl()) + app.refer(UserService, url="memory://local:1") + + async with app: + with pytest.raises(RuntimeError, match="cannot export once the application has started"): + app.export(UserServiceImpl()) + with pytest.raises(RuntimeError, match="cannot refer once the application has started"): + app.refer(UserService) + + +async def test_a_reference_calls_only_while_its_application_runs(memory_protocol): + app = Dubbo(APP, env_prefix=None, protocols={"memory": ProtocolConfig(name="memory")}) + app.export(UserServiceImpl()) + users = app.refer(UserService, url="memory://local:1") + + async with app: + assert await users.get_user(StringValue(value="7")) == StringValue(value="user 7") + + with pytest.raises(RuntimeError, match=r"com\.example\.UserService is called only while the application runs"): + await users.get_user(StringValue(value="1")) + + +@pytest.mark.parametrize( + "options", + [{"provider": ProviderConfig(filters=("nope",))}, {"consumer": ConsumerConfig(filters=("nope",))}], + ids=["service", "reference"], +) +async def test_a_filter_that_is_not_installed_fails_startup(options, memory_protocol): + app = Dubbo(APP, env_prefix=None, protocols={"memory": ProtocolConfig(name="memory")}, **options) + app.export(UserServiceImpl()) + app.refer(UserService, url="memory://local:1") + + with pytest.raises(ExtensionError, match=r"unknown extension 'nope' in group 'apache_dubbo\.filter'"): + await app.__aenter__() + + +async def test_a_reference_needs_a_url(): + app = Dubbo(APP, env_prefix=None) + app.refer(UserService) + + with pytest.raises(ConfigError, match=r"reference 'com\.example\.UserService' needs urls"): + await app.__aenter__() + + +@pytest.mark.parametrize( + ("options", "message"), + [ + ( + {"consumer": ConsumerConfig(references={"com.example.UserService": ReferenceConfig(urls=("trii://h:1",))})}, + r"unknown extension 'trii' in group 'apache_dubbo\.protocol'; installed: .*tri", + ), + ( + {"protocols": {"main": ProtocolConfig(name="grpc", port=0)}}, + r"unknown extension 'grpc' in group 'apache_dubbo\.protocol'", + ), + ], + ids=["reference", "protocol"], +) +async def test_an_unknown_protocol_fails_to_start(options, message): + app = Dubbo(APP, env_prefix=None, **options) + if "consumer" in options: + app.refer(UserService) + else: + app.export(UserServiceImpl()) + + with pytest.raises(ExtensionError, match=message): + await app.__aenter__() + + +@pytest.mark.parametrize("setting", ["cluster", "loadbalance"]) +async def test_a_reference_does_not_start_with_an_extension_not_installed(setting, memory_protocol): + app = Dubbo( + APP, + env_prefix=None, + consumer=ConsumerConfig( + references={"com.example.UserService": ReferenceConfig(urls=("memory://local:1",), **{setting: "nope"})} + ), + ) + app.refer(UserService) + + with pytest.raises(ExtensionError, match=f"unknown extension 'nope' in group 'apache_dubbo.{setting}'"): + async with app: + pass + + +@asynccontextmanager +async def _stuck_stopping(app: Dubbo) -> AsyncIterator[None]: + try: + yield + finally: + await anyio.sleep_forever() + + +async def test_leaving_stops_within_the_grace_in_all(): + app = Dubbo({**APP, "shutdown": {"grace": 0.1}}, lifespan=_stuck_stopping, env_prefix=None) + + with anyio.fail_after(2): + async with app: + pass + + +async def test_stopping_past_the_grace_after_an_error_raises_the_error(): + app = Dubbo({**APP, "shutdown": {"grace": 0.1}}, lifespan=_stuck_stopping, env_prefix=None) + + async def run() -> None: + async with app: + raise ValueError("the body failed") + + with anyio.fail_after(2), pytest.raises(ValueError, match="the body failed"): + await run() + + +async def test_a_failed_start_closes_within_the_configured_grace(isolated_extensions): + class Stuck(Invoker): + def __init__(self, url): + self._url = url + + @property + def url(self): + return self._url + + async def invoke(self, invocation): + raise NotImplementedError + + async def aclose(self): + await anyio.sleep_forever() + + class SecondFails(Protocol): + def __init__(self): + self.referred = 0 + + async def refer(self, url, definition): + self.referred += 1 + if self.referred == 2: + raise RuntimeError("the second reference failed") + return Stuck(url) + + async def aclose(self): + pass + + extensions.register(Protocol, "stuck", SecondFails) + app = Dubbo({**APP, "shutdown": {"grace": 0.1}, "consumer": {"routers": []}}, env_prefix=None) + app.refer_generic("com.example.First", url="stuck://127.0.0.1:1") + app.refer_generic("com.example.Second", url="stuck://127.0.0.1:1") + + with anyio.fail_after(2), pytest.raises(RuntimeError, match="the second reference failed"): + async with app: + pass + + +async def test_another_contract_cannot_refer_to_the_same_service(): + @dubbo.service("com.example.UserService") + class OtherUserService(typing.Protocol): + async def get_user(self, id: int) -> str: ... + + app = Dubbo(APP, env_prefix=None) + app.refer(UserService) + + with pytest.raises(ValueError, match=r"another contract already refers to com\.example\.UserService"): + app.refer(OtherUserService) + + +@pytest.mark.parametrize( + ("options", "message"), + [ + ( + { + "provider": ProviderConfig( + services={"com.example.UserService": ServiceConfig(methods={"get_user": MethodConfig(timeout=1)})} + ) + }, + "service 'com.example.UserService' configures methods it does not have: get_user", + ), + ( + { + "consumer": ConsumerConfig( + references={"com.example.UserService": ReferenceConfig(methods={"nope": MethodConfig()})} + ) + }, + "reference 'com.example.UserService' configures methods it does not have: nope", + ), + ], + ids=["service", "reference"], +) +async def test_start_checks_method_settings_against_the_contract(options, message): + # Methods are configured by the names they have on the wire. + app = Dubbo(APP, env_prefix=None, **options) + app.export(UserServiceImpl()) + app.refer(UserService) + + with pytest.raises(ConfigError, match=message): + await app.__aenter__() + + +def test_invalid_source_type_fails_at_construction(): + with pytest.raises(TypeError, match="path or a mapping"): + Dubbo([("application", {})]) + + +async def test_the_lifespan_runs_while_the_application_runs(): + events: list[str] = [] + + @asynccontextmanager + async def lifespan(app: Dubbo) -> AsyncIterator[None]: + events.append(f"start {app.config.application.name}") + yield + events.append("stop") + + async with Dubbo({"application": {"name": "orders"}}, lifespan=lifespan, env_prefix=None): + assert events == ["start orders"] + + assert events == ["start orders", "stop"] + + +async def test_a_lifespan_that_fails_to_start_fails_startup(): + @asynccontextmanager + async def lifespan(app: Dubbo) -> AsyncIterator[None]: + raise RuntimeError("no database") + yield + + app = Dubbo({"application": {"name": "orders"}}, lifespan=lifespan, env_prefix=None) + + with pytest.raises(RuntimeError, match="no database"): + await app.__aenter__() + with pytest.raises(RuntimeError, match="once the application has started"): + _ = app.config + + +async def test_serve_forever_needs_a_started_application(): + with pytest.raises(RuntimeError, match="once it has started"): + await Dubbo(APP, env_prefix=None).serve_forever() + + +def test_a_reference_takes_one_url_in_code_and_does_not_show_the_other(): + app = Dubbo(env_prefix=None) + app.refer(UserService, url="tri://alice:secret@127.0.0.1:1") + + with pytest.raises(ValueError, match="already referred to at another url") as caught: + app.refer(UserService, url="tri://127.0.0.1:2") + assert "secret" not in str(caught.value) + + +async def test_a_starting_application_refuses_to_start_again_or_to_refer(): + starting, proceed = anyio.Event(), anyio.Event() + + @asynccontextmanager + async def lifespan(app: Dubbo) -> AsyncIterator[None]: + starting.set() + await proceed.wait() + yield + + app = Dubbo(APP, lifespan=lifespan, env_prefix=None) + + async def run() -> None: + async with app: + pass + + with anyio.fail_after(5): + async with anyio.create_task_group() as task_group: + task_group.start_soon(run) + await starting.wait() + + with pytest.raises(RuntimeError, match="already started"): + await app.__aenter__() + with pytest.raises(RuntimeError, match="once the application has started"): + app.refer(UserService) + proceed.set() + + +class _Reference(Invoker): + def __init__(self, protocol, url): + self.protocol, self._url = protocol, url + + @property + def url(self): + return self._url + + async def invoke(self, invocation): + with serving(invocation.attachments, peer=None): + return await self.protocol.services[self.url.path].invoke(invocation) + + async def aclose(self): + pass + + +class _Exporter(Exporter): + def __init__(self, url, services): + self._url, self.services = url, services + + @property + def url(self): + return self._url + + async def aclose(self): + self.services.pop(self.url.path) + + +class _Protocol(Protocol): + def __init__(self): + self.services = {} + + async def export(self, url, definition, invoker): + self.services[definition.interface] = invoker + return _Exporter(url, self.services) + + async def refer(self, url, definition): + return _Reference(self, url) + + async def aclose(self): + pass + + +@pytest.fixture +def memory_protocol(isolated_extensions): + extensions.register(Protocol, "memory", _Protocol) + + +@pytest.mark.parametrize( + ("interface", "options", "message"), + [ + ("com.example.UserService", {"url": "tri://other:2"}, "already referred to at another url"), + ("com.example.UserService", {"generic": "gson"}, "already referred to with generic=true"), + ("", {}, "interface must not be empty"), + ], + ids=["conflicting-url", "conflicting-form", "empty-interface"], +) +def test_generic_references_reject_conflicting_or_empty_identity(interface, options, message): + app = Dubbo(env_prefix=None) + app.refer_generic("com.example.UserService", url="tri://local:1") + + with pytest.raises(ValueError, match=message): + app.refer_generic(interface, **options) + + +CENTER = {"application": {"name": "orders"}, "config_center": {"address": "memory://center"}} + + +async def test_connection_stays_open_until_the_application_stops(config_store): + app = Dubbo(CENTER, env_prefix=None) + + async with app: + (center,) = config_store.centers + assert (center.connected, center.closed) == (True, False) + + assert center.closed + + +async def test_unchecked_center_failure_starts_with_local_configuration(config_store, caplog): + config_store.error = ConnectionRefusedError("refused") + center = {"address": "memory://user:secret@center", "check": False} + app = Dubbo(CENTER, {"consumer": {"retries": 1}, "config_center": center}, env_prefix=None) + + with caplog.at_level(logging.WARNING, logger="dubbo"): + async with app: + assert app.config.consumer.retries == 1 + # The connection itself works, so it stays open for later readers. + assert (config_store.centers[0].connected, config_store.centers[0].closed) == (True, False) + + assert config_store.centers[0].closed + + # The URL in the warning hides the password. + assert "Starting without configuration center memory://user:***@center" in caplog.text + assert "secret" not in caplog.text + + +USERS = "com.example.UserService" + + +async def test_export_and_refer_take_settings_above_those_of_the_sources(memory_protocol): + source = { + **APP, + "provider": {"services": {USERS: {"weight": 10, "timeout": 2}}}, + "consumer": {"references": {USERS: {"retries": 7, "timeout": 2}}}, + } + app = Dubbo(source, env_prefix=None, protocols={"memory": ProtocolConfig(name="memory")}) + app.export(UserServiceImpl(), config=ServiceConfig(weight=50)) + users = app.refer(UserService, url="memory://local:1", config=ReferenceConfig(retries=5)) + + async with app: + service, reference = app.config.provider.services[USERS], app.config.consumer.references[USERS] + assert (service.weight, service.timeout) == (50, 2) + assert (reference.retries, reference.timeout, reference.urls) == (5, 2, ("memory://local:1",)) + assert await users.get_user(StringValue(value="7")) == StringValue(value="user 7") + + +def test_a_service_given_settings_by_the_provider_argument_takes_no_others_from_export(): + app = Dubbo(env_prefix=None, provider=ProviderConfig(services={USERS: ServiceConfig(weight=10)})) + + with pytest.raises(ValueError, match=r"com\.example\.UserService is already configured in provider\.services"): + app.export(UserServiceImpl(), config=ServiceConfig(weight=50)) + + +@pytest.mark.parametrize( + ("first", "second", "message"), + [ + ({"config": ReferenceConfig(retries=5)}, {"config": ReferenceConfig(retries=6)}, "with other settings"), + ({}, {"url": "tri://a:1", "config": ReferenceConfig(urls=("tri://b:1",))}, "name different providers"), + ({"url": "tri://a:1"}, {"config": ReferenceConfig(urls=("tri://b:1",))}, "name different providers"), + ( + {"config": ReferenceConfig(urls=("tri://a:1", "tri://b:1"))}, + {"url": "tri://a:1"}, + "name different providers", + ), + ], + ids=["other-settings", "url-and-urls", "url-then-urls", "urls-then-url"], +) +def test_a_reference_takes_one_set_of_settings_whose_urls_agree_with_its_url(first, second, message): + app = Dubbo(env_prefix=None) + app.refer(UserService, **first) + + with pytest.raises(ValueError, match=message): + app.refer_generic(USERS, **second) + + +def test_a_reference_given_settings_by_the_consumer_argument_takes_no_others_from_refer(): + app = Dubbo(env_prefix=None, consumer=ConsumerConfig(references={USERS: ReferenceConfig(retries=1)})) + + with pytest.raises(ValueError, match=r"com\.example\.UserService is already configured in consumer\.references"): + app.refer(UserService, config=ReferenceConfig(retries=5)) + + +def test_a_reference_may_repeat_its_settings_and_the_url_they_name(): + config = ReferenceConfig(urls=("tri://a:1",), retries=5) + app = Dubbo(env_prefix=None) + app.refer(UserService, url="tri://a:1", config=config) + + app.refer(UserService, config=config) + app.refer_generic(USERS, url="tri://a:1", config=ReferenceConfig(urls=("tri://a:1",), retries=5)) diff --git a/tests/unit/test_url.py b/tests/unit/test_url.py new file mode 100644 index 00000000..ee765d1e --- /dev/null +++ b/tests/unit/test_url.py @@ -0,0 +1,219 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import attrs +import pytest + +from dubbo import URL +from dubbo.extension import ApplicationScope +from dubbo.url import APPLICATION_SCOPE +from dubbo.utils.converters import comma_separated, milliseconds + + +def test_components_are_decoded_and_round_trip() -> None: + url = URL.parse( + "TRI://us%40er:p%3Aa%2Bss@LOCALHOST:50051/example.Greeter" + "?tag=a&timeout=3000&tag=b&empty=&bare&token=a%2Bb+c%26d%3D%25" + ) + + assert (url.protocol, url.host, url.port, url.path) == ("tri", "localhost", 50051, "example.Greeter") + assert (url.username, url.password) == ("us@er", "p:a+ss") + # A repeated key keeps its last value, in the position of its first. + assert list(url.parameters.items()) == [ + ("tag", "b"), + ("timeout", "3000"), + ("empty", ""), + ("bare", ""), + ("token", "a+b c&d=%"), + ] + assert URL.parse(url.render_as_string(hide_secrets=False)) == url + + +def test_password_is_hidden_unless_rendered_on_request() -> None: + url = URL.parse("nacos://user:p%3Ass@host:8848") + + assert "p:ss" not in repr(url) + assert str(url) == url.render_as_string() == "nacos://user:***@host:8848" + assert url.render_as_string(hide_secrets=False) == "nacos://user:p%3Ass@host:8848" + + +def test_secret_parameters_are_hidden_unless_rendered_on_request() -> None: + url = URL.parse("nacos://host:8848?token=t0k&accessKey=ak&secretKey=sk&group=a") + + assert str(url) == "nacos://host:8848?token=%2A%2A%2A&accessKey=%2A%2A%2A&secretKey=%2A%2A%2A&group=a" + assert not {"t0k", "ak", "sk"} & set(repr(url).replace("'", " ").split()) + assert url.parameters["token"] == "t0k" + assert "token=t0k" in url.render_as_string(hide_secrets=False) + + +@pytest.mark.parametrize( + ("text", "message"), + [ + pytest.param("zookeeper://alice:hunter2@host/#fragment", "fragments", id="fragment"), + pytest.param("nacos://alice:hunter2@bad\uff03host:8848", "invalid host", id="host-under-nfkc"), + ], +) +def test_rejected_text_is_not_echoed(text: str, message: str) -> None: + with pytest.raises(ValueError, match=message) as caught: + URL.parse(text) + + assert "hunter2" not in str(caught.value) + assert caught.value.__cause__ is None + + +def test_render_escapes_what_the_components_hold() -> None: + url = URL(protocol="tri", host="2001:DB8::1", port=50051, path="中文 空格/x?y#z", parameters={"中文": "a+b &c"}) + + assert url.host == "2001:db8::1" + assert str(url) == ( + "tri://[2001:db8::1]:50051/%E4%B8%AD%E6%96%87%20%E7%A9%BA%E6%A0%BC/x%3Fy%23z?%E4%B8%AD%E6%96%87=a%2Bb+%26c" + ) + assert URL.parse(str(url)) == url + + +@pytest.mark.parametrize( + "text", + [ + "tri://192.168.1.6:50051/com.foo.HelloService?timeout=3000&group=a", + "consumer://192.168.1.2/com.foo.HelloService?check=false", + "empty://0.0.0.0/com.foo.HelloService?category=providers", + "zookeeper://10.20.153.10:2181?backup=10.20.153.11:2181,10.20.153.12:2181", + "nacos://user:secret@[::1]:8848/path", + "file:///home/user1/router.js?type=script", + "memory:center", + ], + ids=["provider", "consumer", "empty", "ensemble", "ipv6", "file", "opaque"], +) +def test_dubbo_url_forms_round_trip(text: str) -> None: + url = URL.parse(text) + + assert URL.parse(url.render_as_string(hide_secrets=False)) == url + + +def test_parameters_are_a_read_only_copy_and_fields_are_frozen() -> None: + source = {"tag": "a"} + url = URL(protocol="tri", parameters=source) + source["tag"] = "changed" + + assert url.parameters == {"tag": "a"} + with pytest.raises(TypeError): + url.parameters["tag"] = "changed" + with pytest.raises(attrs.exceptions.FrozenInstanceError): + url.path = "changed" + + +def test_update_parameters_adds_and_replaces_keys() -> None: + url = URL.parse("tri://host/service?timeout=1000&group=a") + + updated = url.update_parameters({"timeout": "3000", "version": "1"}) + + assert updated.parameters == {"timeout": "3000", "group": "a", "version": "1"} + assert url.parameters == {"timeout": "1000", "group": "a"} + + +def test_urls_are_hashable_values_regardless_of_parameter_order() -> None: + first = URL(protocol="tri", host="host", parameters={"a": "1", "b": "2"}) + second = URL(protocol="tri", host="host", parameters={"b": "2", "a": "1"}) + + assert first == second + assert {first: "value"}[second] == "value" + assert first != first.update_parameters({"a": "changed"}) + + +def test_nested_url_decodes_exactly_one_layer() -> None: + inner = "tri://host/service?token=a%2Bb&timeout=1000" + outer = URL(protocol="example", host="host", parameters={"target": inner}) + + recovered = URL.parse(str(outer)).parameters["target"] + + assert recovered == inner + assert URL.parse(recovered).parameters["token"] == "a+b" + + +def test_empty_host_is_no_host_and_whitespace_is_ignored() -> None: + assert URL(protocol="file", host="", path="a").host is None + assert URL.parse(" \ttri://host/service\r\n") == URL.parse("tri://host/service") + + +@pytest.mark.parametrize( + ("text", "message"), + [ + ("", "needs a scheme"), + ("host/path", "needs a scheme"), + ("1tri://host", "scheme"), + ("tri://host/path#fragment", "fragments"), + ("tri://host:65536/", "[Pp]ort"), + ("tri://host:no/", "[Pp]ort"), + ("tri://%FF@host/", "utf-8"), + ("tri://host/?x=%FF", "utf-8"), + ("tri://:50051/", "require host"), + ], +) +def test_invalid_text_is_rejected(text: str, message: str) -> None: + with pytest.raises(ValueError, match=message): + URL.parse(text) + + +@pytest.mark.parametrize( + ("fields", "message"), + [ + ({"protocol": ""}, "URL scheme"), + ({"protocol": "bad scheme"}, "URL scheme"), + ({"host": "host", "port": 65536}, "port must"), + ({"port": 50051}, "require host"), + ({"username": "user"}, "require host"), + ({"host": "host", "password": "secret"}, "requires username"), + ], +) +def test_invalid_fields_are_rejected(fields: dict, message: str) -> None: + with pytest.raises(ValueError, match=message): + URL(**{"protocol": "tri", **fields}) + + +def test_get_parameter_converts_a_present_parameter_and_defaults_an_absent_one() -> None: + url = URL.parse("tri://host/?timeout=3000&retries=2&backup=a:1,%20b:2,") + + assert url.get_parameter("timeout", milliseconds, 1.0) == 3.0 + assert url.get_parameter("retries", int, 0) == 2 + assert url.get_parameter("backup", comma_separated, ()) == ("a:1", "b:2") + assert url.get_parameter("weight", float, None) is None + + +def test_get_parameter_names_the_key_of_a_rejected_value() -> None: + url = URL.parse("tri://host/?timeout=fast") + + with pytest.raises(ValueError, match="'timeout': must be whole milliseconds, not 'fast'"): + url.get_parameter("timeout", milliseconds, 1.0) + + +def test_the_scope_travels_with_derived_urls_outside_text_equality_and_repr() -> None: + scope = ApplicationScope() + url = URL.parse("zookeeper://zk:2181?group=a").replace(attributes={APPLICATION_SCOPE: scope}) + + assert url.update_parameters({"group": "b"}).scope is scope + assert url == URL.parse("zookeeper://zk:2181?group=a") + assert hash(url) == hash(URL.parse("zookeeper://zk:2181?group=a")) + assert str(url) == "zookeeper://zk:2181?group=a" + assert "scope" not in repr(url) + + +def test_address_and_userinfo_join_their_components() -> None: + assert URL.parse("zookeeper://user:p%40ss@[::1]:2181").address == "[::1]:2181" + assert URL.parse("zookeeper://user:p%40ss@[::1]:2181").userinfo == "user:p@ss" + assert URL.parse("zookeeper://user@zk").address == "zk" + assert URL.parse("zookeeper://user@zk").userinfo == "user" + assert URL.parse("zookeeper://zk:2181").userinfo is None diff --git a/tests/unit/transport/h2/aio/conftest.py b/tests/unit/transport/h2/aio/conftest.py new file mode 100644 index 00000000..44fa9253 --- /dev/null +++ b/tests/unit/transport/h2/aio/conftest.py @@ -0,0 +1,203 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio + +import anyio +import pytest + +from dubbo.transport.h2.aio.connection import AioH2Connection +from dubbo.url import URL + + +class _RecordingTransport(asyncio.Transport): + def __init__(self) -> None: + super().__init__() + self.writes: list[bytes] = [] + self.close_calls = 0 + + def write(self, data: bytes) -> None: + self.writes.append(data) + + def close(self) -> None: + self.close_calls += 1 + + def is_closing(self) -> bool: + return self.close_calls > 0 + + def get_write_buffer_size(self) -> int: + return 0 + + +class _RecordingTLSObject: + def __init__(self, selected_alpn: str | None, version: str, compression: str | None) -> None: + self._selected_alpn = selected_alpn + self._version = version + self._compression = compression + + def selected_alpn_protocol(self) -> str | None: + return self._selected_alpn + + def version(self) -> str: + return self._version + + def compression(self) -> str | None: + return self._compression + + +class _RecordingTLSTransport(_RecordingTransport): + def __init__(self, selected_alpn: str | None, version: str = "TLSv1.3", compression: str | None = None) -> None: + super().__init__() + self._ssl_object = _RecordingTLSObject(selected_alpn, version, compression) + self.abort_calls = 0 + + def get_extra_info(self, name: str, default=None): + if name == "ssl_object": + return self._ssl_object + return default + + def abort(self) -> None: + self.abort_calls += 1 + + +def _connection_url( + *, + max_concurrent_streams: int | None = None, + keep_alive_interval: float | None = None, + keep_alive_timeout: float | None = None, +) -> URL: + """Return a URL that sets the given HTTP/2 options of a connection, with times in seconds.""" + parameters = { + "max-concurrent-streams": None if max_concurrent_streams is None else str(max_concurrent_streams), + "keep-alive-interval": None if keep_alive_interval is None else str(round(keep_alive_interval * 1000)), + "keep-alive-timeout": None if keep_alive_timeout is None else str(round(keep_alive_timeout * 1000)), + } + return URL( + protocol="tri", + host="127.0.0.1", + port=1, + parameters={key: value for key, value in parameters.items() if value is not None}, + ) + + +@pytest.fixture +def connection_url(): + return _connection_url + + +@pytest.fixture +def transport_type(): + return _RecordingTransport + + +@pytest.fixture +def tls_transport_type(): + return _RecordingTLSTransport + + +class _Timer: + def __init__(self, deadline, callback): + self.deadline = deadline + self.callback = callback + self.cancelled = False + + def cancel(self): + self.cancelled = True + + +class _Clock: + def __init__(self): + self.now = 100.0 + self.timers = [] + + def time(self): + return self.now + + def monotonic(self): + return self.now + + def call_at(self, deadline, callback): + timer = _Timer(deadline, callback) + self.timers.append(timer) + return timer + + def call_later(self, delay, callback): + return self.call_at(self.now + delay, callback) + + def advance(self, seconds): + target = self.now + seconds + while active := [timer for timer in self.timers if not timer.cancelled and timer.deadline <= target]: + timer = min(active, key=lambda timer: timer.deadline) + self.timers.remove(timer) + self.now = timer.deadline + timer.callback() + self.now = target + + +@pytest.fixture +def clock(): + return _Clock() + + +@pytest.fixture +def keep_alive_clock(monkeypatch, clock): + from dubbo.transport.h2.aio.keep_alive import KeepAlive + + monkeypatch.setattr( + "dubbo.transport.h2.aio.connection.KeepAlive", lambda loop, **options: KeepAlive(clock, **options) + ) + return clock + + +@pytest.fixture +async def h2_pair(credits): + import ngh2 + + class CreditingConnection(AioH2Connection): + def consume(self, stream_id, amount): + if amount: + credits.append((stream_id, amount)) + super().consume(stream_id, amount) + + client = CreditingConnection(ngh2.Role.CLIENT, url=_connection_url()) + streams = [] + server = AioH2Connection(ngh2.Role.SERVER, url=_connection_url(), on_stream=streams.append) + client_wire, server_wire = _RecordingTransport(), _RecordingTransport() + client.connection_made(client_wire) + server.connection_made(server_wire) + + async def exchange(): + await anyio.wait_all_tasks_blocked() + while client_wire.writes or server_wire.writes: + for wire, receiver in [(client_wire, server), (server_wire, client)]: + data = b"".join(wire.writes) + wire.writes.clear() + for start in range(0, len(data), 65536): + chunk = data[start : start + 65536] + receiver.get_buffer(len(chunk))[: len(chunk)] = chunk + receiver.buffer_updated(len(chunk)) + await anyio.wait_all_tasks_blocked() + + yield client, server, streams, exchange + + client.connection_lost(None) + server.connection_lost(None) + + +@pytest.fixture +def credits(): + return [] diff --git a/tests/unit/transport/h2/aio/test_bdp.py b/tests/unit/transport/h2/aio/test_bdp.py new file mode 100644 index 00000000..06a93302 --- /dev/null +++ b/tests/unit/transport/h2/aio/test_bdp.py @@ -0,0 +1,128 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.transport.h2.aio.bdp import MAX_WINDOW, BdpEstimator + +pytestmark = pytest.mark.anyio + +_WINDOW = 65536 + +_RTT = 0.01 + + +def _probe(estimator: BdpEstimator, returned: int, *, at: float = 0.0, rtt: float = _RTT) -> int | None: + """Return ``returned`` credit after DATA, writing the PING it queues at ``at`` and acknowledging it ``rtt`` later.""" + estimator.data_received = True + assert estimator.credit_returned(returned) + estimator.probe_written(at) + return estimator.probe_acknowledged(at + rtt) + + +def test_a_window_that_limits_the_flow_grows_to_twice_the_sample_in_pairs_of_frames() -> None: + estimator = BdpEstimator(_WINDOW) + + # Twice 60000 rounds up to four pairs of 16 KiB frames. + assert _probe(estimator, 60000) == 131072 + assert estimator.window == 131072 + + +def test_credit_returned_slowly_grows_nothing() -> None: + assert _probe(BdpEstimator(_WINDOW), 10000) is None + + +def test_the_sample_is_the_credit_between_acknowledgements_wherever_the_probe_starts() -> None: + estimator = BdpEstimator(_WINDOW) + assert _probe(estimator, 60000) == 131072 + + # Half the next burst returns before DATA allows a probe; it still belongs to the sample. + assert not estimator.credit_returned(50000) + estimator.data_received = True + assert estimator.credit_returned(50000) + estimator.probe_written(_RTT + 0.005) + + # 100000 bytes over the 10 ms since the last acknowledgement, times the smoothed 9.375 ms round trip. + assert estimator.probe_acknowledged(2 * _RTT) == 196608 + + +def test_the_round_trip_starts_when_the_ping_is_written() -> None: + estimator = BdpEstimator(_WINDOW) + estimator.data_received = True + assert estimator.credit_returned(60000) + + # The PING waits a second behind paused writes; that wait is not part of the round trip. + estimator.probe_written(1.0) + assert estimator.probe_acknowledged(1.0 + _RTT) == 131072 + + +def test_an_acknowledgement_no_written_probe_waits_for_changes_nothing() -> None: + estimator = BdpEstimator(_WINDOW) + assert estimator.probe_acknowledged(100.0) is None + + estimator.data_received = True + assert estimator.credit_returned(60000) + assert estimator.probe_acknowledged(100.0) is None + + estimator.probe_written(200.0) + assert estimator.probe_acknowledged(200.0 + _RTT) == 131072 + + +def test_a_slower_rate_does_not_grow_the_window() -> None: + estimator = BdpEstimator(_WINDOW) + assert _probe(estimator, 60000) == 131072 + + # More bytes over a much longer span: the window is not what limits the flow. + assert _probe(estimator, 100000, at=1.0) is None + + +def test_a_fast_probe_that_grows_nothing_leaves_slower_growth_possible() -> None: + estimator = BdpEstimator(_WINDOW) + # 40000 bytes in 10 ms is fast, but fills less than two thirds of the window. + assert _probe(estimator, 40000) is None + + # The round trip lengthens and a slower flow now fills the window. + assert _probe(estimator, 300000, at=_RTT, rtt=0.1) == 131072 + + +def test_no_probe_starts_before_data_arrives_after_the_last_acknowledgement() -> None: + estimator = BdpEstimator(_WINDOW) + assert not estimator.credit_returned(100) + + _probe(estimator, 60000) + assert not estimator.credit_returned(10 * MAX_WINDOW) + + estimator.data_received = True + assert estimator.credit_returned(1) + + +def test_probes_that_grow_nothing_wait_for_more_credit() -> None: + estimator = BdpEstimator(_WINDOW) + assert _probe(estimator, 10000) is None + assert _probe(estimator, 40000, at=1.0) is None + + # Two probes grew nothing: the next waits for credit of one window since the acknowledgement. + estimator.data_received = True + assert not estimator.credit_returned(_WINDOW // 2) + assert estimator.credit_returned(_WINDOW // 2) + + +def test_the_window_stops_at_the_cap_and_tuning_finishes() -> None: + estimator = BdpEstimator(MAX_WINDOW // 2) + + assert _probe(estimator, MAX_WINDOW) == MAX_WINDOW + assert estimator.finished diff --git a/tests/unit/transport/h2/aio/test_client.py b/tests/unit/transport/h2/aio/test_client.py new file mode 100644 index 00000000..ccf7da2c --- /dev/null +++ b/tests/unit/transport/h2/aio/test_client.py @@ -0,0 +1,552 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import ssl +from typing import cast + +import anyio +import ngh2 +import pytest + +import dubbo.utils.dialer as dialer_module +from dubbo.extension import extensions +from dubbo.transport.h2 import ( + H2Client, + H2ConnectionError, + H2Server, +) +from dubbo.transport.h2.aio import AioH2Client, AioH2Server, AioH2Stream +from dubbo.transport.h2.aio.connection import AioH2Connection +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + +# An empty SETTINGS frame, with which a server starts its connection preface. +_SERVER_SETTINGS = b"\x00\x00\x00\x04\x00\x00\x00\x00\x00" + + +def _answer(connection: AioH2Connection) -> None: + """Deliver the preface of a server that answers, which the client waits for before using the connection.""" + connection.get_buffer(len(_SERVER_SETTINGS))[: len(_SERVER_SETTINGS)] = _SERVER_SETTINGS + connection.buffer_updated(len(_SERVER_SETTINGS)) + + +# Only the addresses of a host name are raced; an IP address is one. +@pytest.mark.parametrize( + ("host", "server_name", "checked", "race"), + [ + ("provider.example", "service.example", "service.example", {"happy_eyeballs_delay": 0.25}), + ("192.0.2.1", "", "192.0.2.1", {}), + ], + ids=["named", "empty-checks-host"], +) +async def test_client_passes_tls_identity_and_happy_eyeballs_to_asyncio( + monkeypatch: pytest.MonkeyPatch, request_headers, h2_url, tls_transport_type, host, server_name, checked, race +) -> None: + captured: dict[str, object] = {} + + async def create_connection(protocol_factory, host, port, **kwargs): + captured.update(host=host, port=port, **kwargs) + connection = protocol_factory() + transport = tls_transport_type("h2") + connection.connection_made(transport) + _answer(connection) + return transport, connection + + loop = asyncio.get_running_loop() + monkeypatch.setattr(loop, "create_connection", create_connection) + client = AioH2Client(h2_url(host, 443, ssl_enabled="true", tls_server_name=server_name)) + stream = await client.open_stream(request_headers, end_stream=True) + context = captured["ssl"] + assert context.minimum_version >= ssl.TLSVersion.TLSv1_2 + assert context.options & ssl.OP_NO_COMPRESSION + assert context.options & ssl.OP_NO_RENEGOTIATION + + assert stream.stream_id == 1 + assert captured == { + "host": host, + "port": 443, + "ssl": context, + "server_hostname": checked, + **race, + } + connection = client._active_connection + assert connection is not None + connection.connection_lost(None) + await client.aclose() + + +def test_aio_is_the_default_client_and_server() -> None: + assert extensions.get(H2Client, None) is AioH2Client + assert extensions.get(H2Server, None) is AioH2Server + + +def test_client_requires_a_host_and_port() -> None: + with pytest.raises(ValueError, match="host and a port"): + AioH2Client(URL(protocol="tri", host="127.0.0.1")) + + +async def test_client_reports_alpn_failure_without_reconnecting( + monkeypatch: pytest.MonkeyPatch, request_headers, h2_url, tls_transport_type +) -> None: + attempts = 0 + + async def create_connection(protocol_factory, host, port, **kwargs): + nonlocal attempts + attempts += 1 + connection = protocol_factory() + + class RejectingTransport(tls_transport_type): + def abort(self) -> None: + self.abort_calls += 1 + connection.connection_lost(None) + + transport = RejectingTransport(None) + connection.connection_made(transport) + return transport, connection + + loop = asyncio.get_running_loop() + monkeypatch.setattr(loop, "create_connection", create_connection) + client = AioH2Client(h2_url("service.example", 443, ssl_enabled="true")) + + with pytest.raises(H2ConnectionError, match="ALPN"): + await client.open_stream(request_headers, end_stream=True) + + assert attempts == 1 + # Nothing public shows that the client let go of its connection. + assert client._active_connection is None + await client.aclose() + + +async def test_caller_that_stops_waiting_leaves_the_attempt_to_the_others( + monkeypatch: pytest.MonkeyPatch, request_headers, h2_url, transport_type +) -> None: + started = anyio.Event() + release = anyio.Event() + attempts = 0 + + async def slow_create_connection(protocol_factory, host, port, **kwargs): + nonlocal attempts + attempts += 1 + started.set() + await release.wait() + connection = protocol_factory() + transport = transport_type() + connection.connection_made(transport) + _answer(connection) + return transport, connection + + loop = asyncio.get_running_loop() + monkeypatch.setattr(loop, "create_connection", slow_create_connection) + client = AioH2Client(h2_url("127.0.0.1", 1)) + + with anyio.move_on_after(0.01): + await client.open_stream(request_headers, end_stream=True) + await started.wait() + # The attempt runs on. + assert client._dialer._attempt is not None + + release.set() + stream = await client.open_stream(request_headers, end_stream=True) + + assert attempts == 1 + assert stream.stream_id == 1 + assert client.available + connection = client._active_connection + assert connection is not None + connection.connection_lost(None) + await client.aclose() + + +async def test_an_unanswered_attempt_fails_at_the_connect_timeout_and_leaves_the_client_unavailable( + monkeypatch: pytest.MonkeyPatch, h2_url +) -> None: + attempts = 0 + + async def unanswered_create_connection(*args, **kwargs): + nonlocal attempts + attempts += 1 + await anyio.sleep_forever() + + monkeypatch.setattr(asyncio.get_running_loop(), "create_connection", unanswered_create_connection) + # No retry within the test, so that the state after the failure stays. + monkeypatch.setattr(dialer_module, "backoff", lambda: iter([60.0] * 3)) + async with AioH2Client(h2_url("127.0.0.1", 1, connect_timeout="50")) as client: + # Only the connect timeout ends the attempt; the bound only keeps a broken timeout from hanging. + with anyio.fail_after(5): + while client._dialer._attempt is not None: + await anyio.sleep(0.01) + + assert (attempts, client.available) == (1, False) + + +async def test_entered_client_connects_and_reconnects_in_the_background( + monkeypatch: pytest.MonkeyPatch, h2_url, transport_type +) -> None: + connections: list[AioH2Connection] = [] + + async def create_connection(protocol_factory, host, port, **kwargs): + connection = protocol_factory() + transport = transport_type() + connection.connection_made(transport) + _answer(connection) + connections.append(connection) + return transport, connection + + async def until(condition) -> None: + with anyio.fail_after(5): + while not condition(): + await anyio.sleep(0.001) + + loop = asyncio.get_running_loop() + monkeypatch.setattr(loop, "create_connection", create_connection) + monkeypatch.setattr(dialer_module, "backoff", lambda: iter([0.01] * 3)) + async with AioH2Client(h2_url("127.0.0.1", 1)) as client: + await until(lambda: connections) + assert client.available + + connections[0].connection_lost(None) + assert not client.available + await until(lambda: len(connections) == 2 and client.available) + + connections[1].connection_lost(None) + + +async def test_concurrent_streams_wait_for_connection_establishment( + monkeypatch: pytest.MonkeyPatch, request_headers, h2_url, transport_type +) -> None: + dial_started = anyio.Event() + release_dial = anyio.Event() + second_opened = anyio.Event() + streams: list[AioH2Stream] = [] + attempts = 0 + loop = asyncio.get_running_loop() + + async def delayed_create_connection(protocol_factory, host, port, **kwargs): + nonlocal attempts + attempts += 1 + dial_started.set() + await release_dial.wait() + connection = protocol_factory() + transport = transport_type() + connection.connection_made(transport) + _answer(connection) + return transport, connection + + monkeypatch.setattr(loop, "create_connection", delayed_create_connection) + client = AioH2Client(h2_url("127.0.0.1", 1)) + + async def open_stream(signal: anyio.Event | None = None) -> None: + streams.append(await client.open_stream(request_headers, end_stream=True)) + if signal is not None: + signal.set() + + async with anyio.create_task_group() as task_group: + task_group.start_soon(open_stream) + await dial_started.wait() + task_group.start_soon(open_stream, second_opened) + await anyio.wait_all_tasks_blocked() + + assert not second_opened.is_set() + assert not streams + + release_dial.set() + + assert attempts == 1 + assert {stream.stream_id for stream in streams} == {1, 3} + connection = client._active_connection + assert connection is not None + connection.connection_lost(None) + await client.aclose() + + +@pytest.mark.parametrize("value", ["0", "-1"]) +def test_client_rejects_a_connect_timeout_that_is_not_positive(value: str, h2_url) -> None: + with pytest.raises(ValueError, match="connect-timeout"): + AioH2Client(h2_url("127.0.0.1", 1, connect_timeout=value)) + + +async def test_client_is_available_only_while_it_is_connected( + monkeypatch: pytest.MonkeyPatch, request_headers, h2_url, transport_type +) -> None: + refuse = True + attempts = 0 + loop = asyncio.get_running_loop() + + async def create_connection(protocol_factory, host, port, **kwargs): + nonlocal attempts + attempts += 1 + if refuse: + raise ConnectionRefusedError + connection = protocol_factory() + transport = transport_type() + connection.connection_made(transport) + _answer(connection) + return transport, connection + + async def until(condition) -> None: + with anyio.fail_after(5): + while not condition(): + await anyio.sleep(0.001) + + monkeypatch.setattr(loop, "create_connection", create_connection) + # Each failure in a row waits the next delay; a success starts them again. + monkeypatch.setattr(dialer_module, "backoff", lambda: iter([0.01, 60.0])) + client = AioH2Client(h2_url("127.0.0.1", 1)) + # Nothing is connected before the first attempt succeeds. + assert not client.available + + with pytest.raises(H2ConnectionError, match="failed to connect"): + await client.open_stream(request_headers, end_stream=True) + assert not client.available + # The attempt after the first delay fails too, and the next waits the second. + await until(lambda: attempts == 2) + assert not client.available + + # Opening a stream still connects while the client is unavailable. + refuse = False + await client.open_stream(request_headers, end_stream=True) + assert client.available + + # A lost connection waits the first delay again before the client connects in the background. + connection = client._active_connection + assert connection is not None + connection.connection_lost(None) + assert not client.available + await until(lambda: client.available) + assert attempts == 4 + + connection = client._active_connection + assert connection is not None + connection.connection_lost(None) + await client.aclose() + assert not client.available + + +async def test_client_aclose_abandons_an_inflight_connection_attempt( + monkeypatch: pytest.MonkeyPatch, request_headers, h2_url +) -> None: + create_started = anyio.Event() + loop = asyncio.get_running_loop() + + async def stalled_create_connection(protocol_factory, host, port, **kwargs): + # As a dial to an unreachable address, which only the operating system would end. + create_started.set() + await anyio.sleep_forever() + + client = AioH2Client(h2_url("127.0.0.1", 1)) + monkeypatch.setattr(loop, "create_connection", stalled_create_connection) + + async def open_stream() -> None: + with pytest.raises(RuntimeError, match="closed"): + await client.open_stream(request_headers, end_stream=True) + + async with anyio.create_task_group() as task_group: + task_group.start_soon(open_stream) + await create_started.wait() + with anyio.fail_after(5): + await client.aclose() + + # Nothing public shows that the client let go of its connections. + assert client._active_connection is None + assert not client._draining_connections + + +async def test_concurrent_client_close_waits_for_connection_cleanup(h2_url) -> None: + started = anyio.Event() + release = anyio.Event() + + class DelayedConnection: + def start_close(self) -> None: + pass + + async def aclose(self) -> None: + started.set() + await release.wait() + + client = AioH2Client(h2_url("127.0.0.1", 1)) + client._active_connection = cast(AioH2Connection, DelayedConnection()) + first_done = anyio.Event() + second_done = anyio.Event() + + async def close(done: anyio.Event) -> None: + await client.aclose() + done.set() + + async with anyio.create_task_group() as task_group: + task_group.start_soon(close, first_done) + await started.wait() + task_group.start_soon(close, second_done) + await anyio.wait_all_tasks_blocked() + assert not second_done.is_set() + release.set() + await first_done.wait() + await second_done.wait() + + +async def test_client_aclose_inside_a_cancelled_scope_aborts_its_connection( + h2_url, connection_url, transport_type +) -> None: + client = AioH2Client(h2_url("127.0.0.1", 1)) + connection = AioH2Connection(ngh2.Role.CLIENT, url=connection_url(), on_closed=client._connection_closed) + loop = asyncio.get_running_loop() + + class AbortingTransport(transport_type): + def abort(self) -> None: + loop.call_soon(connection.connection_lost, None) + + connection.connection_made(AbortingTransport()) + client._active_connection = connection + + with anyio.CancelScope() as scope: + scope.cancel() + await client.aclose() + + assert connection.closed + # Nothing public shows that the client let go of its connection. + assert client._active_connection is None + + +async def test_client_reselects_when_goaway_arrives_during_capacity_wait( + monkeypatch: pytest.MonkeyPatch, request_headers, h2_url, connection_url, transport_type +) -> None: + config = connection_url(max_concurrent_streams=1) + client = AioH2Client(h2_url("127.0.0.1", 1, max_concurrent_streams="1")) + old_connection = AioH2Connection( + ngh2.Role.CLIENT, + url=config, + on_closed=client._connection_closed, + ) + old_connection.connection_made(transport_type()) + old_connection._streams_by_id[1] = AioH2Stream(old_connection, 1, headers_sent=True) + client._active_connection = old_connection + assert old_connection.accepting_streams + + loop = asyncio.get_running_loop() + + async def create_connection(protocol_factory, host, port, **kwargs): + connection = protocol_factory() + transport = transport_type() + connection.connection_made(transport) + _answer(connection) + return transport, connection + + monkeypatch.setattr(loop, "create_connection", create_connection) + opened: list[AioH2Stream] = [] + + async def open_stream() -> None: + opened.append(await client.open_stream(request_headers, end_stream=True)) + + async with anyio.create_task_group() as task_group: + task_group.start_soon(open_stream) + await anyio.wait_all_tasks_blocked() + assert not opened + + old_connection._draining = True + old_connection._notify_capacity() + + new_connection = client._active_connection + assert new_connection is not None + assert new_connection is not old_connection + assert opened[0].stream_id == 1 + + old_connection.connection_lost(None) + new_connection.connection_lost(None) + await client.aclose() + + +async def test_client_reselects_when_connection_fails_during_capacity_wait( + monkeypatch: pytest.MonkeyPatch, request_headers, h2_url, connection_url, transport_type +) -> None: + config = connection_url(max_concurrent_streams=1) + client = AioH2Client(h2_url("127.0.0.1", 1, max_concurrent_streams="1")) + old_connection = AioH2Connection( + ngh2.Role.CLIENT, + url=config, + on_closed=client._connection_closed, + ) + + class AbortTransport(transport_type): + def abort(self) -> None: + old_connection.connection_lost(None) + + old_connection.connection_made(AbortTransport()) + old_connection._streams_by_id[1] = AioH2Stream(old_connection, 1, headers_sent=True) + client._active_connection = old_connection + + loop = asyncio.get_running_loop() + + async def create_connection(protocol_factory, host, port, **kwargs): + connection = protocol_factory() + transport = transport_type() + connection.connection_made(transport) + _answer(connection) + return transport, connection + + monkeypatch.setattr(loop, "create_connection", create_connection) + opened: list[AioH2Stream] = [] + + async def open_stream() -> None: + opened.append(await client.open_stream(request_headers, end_stream=True)) + + async with anyio.create_task_group() as task_group: + task_group.start_soon(open_stream) + await anyio.wait_all_tasks_blocked() + assert not opened + + old_connection._fail_connection(H2ConnectionError("connection lost")) + old_connection.abort() + + new_connection = client._active_connection + assert new_connection is not None + assert new_connection is not old_connection + assert opened[0].stream_id == 1 + + new_connection.connection_lost(None) + await client.aclose() + + +async def test_client_limits_reselection_before_stream_allocation( + monkeypatch: pytest.MonkeyPatch, request_headers, h2_url, transport_type +) -> None: + attempts: list[AioH2Connection] = [] + loop = asyncio.get_running_loop() + + async def create_connection(protocol_factory, host, port, **kwargs): + connection = protocol_factory() + + class ClosingTransport(transport_type): + def close(self) -> None: + super().close() + connection.connection_lost(None) + + transport = ClosingTransport() + connection.connection_made(transport) + _answer(connection) + connection._draining = True + attempts.append(connection) + return transport, connection + + monkeypatch.setattr(loop, "create_connection", create_connection) + client = AioH2Client(h2_url("127.0.0.1", 1)) + + with pytest.raises(H2ConnectionError, match="unavailable before opening"): + await client.open_stream(request_headers, end_stream=True) + + assert len(attempts) == 2 + await client.aclose() diff --git a/tests/unit/transport/h2/aio/test_connection.py b/tests/unit/transport/h2/aio/test_connection.py new file mode 100644 index 00000000..1594eaa3 --- /dev/null +++ b/tests/unit/transport/h2/aio/test_connection.py @@ -0,0 +1,278 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +from functools import partial + +import anyio +import ngh2 +import pytest + +import dubbo.utils.async_ as async_module +from dubbo.transport.h2 import ( + H2ConnectionError, + H2StreamError, +) +from dubbo.transport.h2.aio.connection import AioH2Connection + +pytestmark = pytest.mark.anyio + + +@pytest.mark.parametrize( + ("peername", "peer"), + [(("127.0.0.1", 5000), "127.0.0.1:5000"), (("::1", 5000, 0, 0), "[::1]:5000"), ("/tmp/socket", None), (None, None)], + ids=["ipv4", "ipv6", "unix", "absent"], +) +async def test_stream_peer_formats_the_transport_address( + peername, peer, connection_url, transport_type, request_headers +): + class PeerTransport(transport_type): + def get_extra_info(self, name, default=None): + return peername if name == "peername" else default + + connection = AioH2Connection(ngh2.Role.CLIENT, url=connection_url()) + connection.connection_made(PeerTransport()) + stream = await connection.open_stream(request_headers, end_stream=True) + + assert stream.peer == peer + connection.connection_lost(None) + + +@pytest.mark.parametrize("value", ["0", "-1"]) +def test_a_connection_rejects_a_send_buffer_that_is_not_positive(value: str, h2_url) -> None: + with pytest.raises(ValueError, match="stream-send-buffer-size"): + AioH2Connection(ngh2.Role.CLIENT, url=h2_url("127.0.0.1", 1, stream_send_buffer_size=value)) + + +@pytest.mark.parametrize( + ("transport", "message"), + [ + ((None, "TLSv1.3", None), "ALPN"), + (("h2", "TLSv1.1", None), "TLSv1.1"), + (("h2", "TLSv1.3", "zlib"), "compression"), + ], +) +async def test_tls_connection_requires_what_http2_needs_before_sending_preface( + transport: tuple[str | None, str, str | None], message: str, connection_url, tls_transport_type +) -> None: + connection = AioH2Connection( + ngh2.Role.CLIENT, + url=connection_url(), + require_h2_alpn=True, + ) + + transport = tls_transport_type(*transport) + connection.connection_made(transport) + + assert transport.abort_calls == 1 + assert not transport.writes + connection.start_close() + assert not transport.writes + with pytest.raises(H2ConnectionError, match=message): + connection.raise_if_failed() + connection.connection_lost(None) + + +async def test_keep_alive_deadline_survives_backpressure_and_ignores_an_unmatched_ack( + connection_url, transport_type, keep_alive_clock +): + connection = AioH2Connection(ngh2.Role.CLIENT, url=connection_url(keep_alive_interval=10, keep_alive_timeout=20)) + transport = transport_type() + connection.connection_made(transport) + server = ngh2.Connection(ngh2.Role.SERVER) + server.initiate_connection() + + def receive(data): + connection.get_buffer(len(data))[: len(data)] = data + connection.buffer_updated(len(data)) + + receive(server.data_to_send()) + connection.pause_writing() + keep_alive_clock.advance(10) + connection.resume_writing() + assert b"".join(transport.writes).endswith(b"\x00\x00\x08\x06\x00\x00\x00\x00\x00" + (1).to_bytes(8, "big")) + receive(b"\x00\x00\x08\x06\x01\x00\x00\x00\x00" + b"87654321") + keep_alive_clock.advance(19) + connection.raise_if_failed() + + receive(b"\x00\x00\x08\x06\x01\x00\x00\x00\x00" + (1).to_bytes(8, "big")) + keep_alive_clock.advance(1) + connection.raise_if_failed() + connection.connection_lost(None) + keep_alive_clock.advance(100) + + +async def test_inbound_bytes_postpone_keep_alive_without_engine_events( + connection_url, transport_type, keep_alive_clock +): + connection = AioH2Connection(ngh2.Role.CLIENT, url=connection_url(keep_alive_interval=10)) + transport = transport_type() + connection.connection_made(transport) + preface = b"".join(transport.writes) + keep_alive_clock.advance(5) + + connection.get_buffer(1)[0] = 0 + connection.buffer_updated(1) + keep_alive_clock.advance(5) + await anyio.wait_all_tasks_blocked() + assert b"".join(transport.writes) == preface + + keep_alive_clock.advance(5) + await anyio.wait_all_tasks_blocked() + assert b"".join(transport.writes) == preface + b"\x00\x00\x08\x06\x00\x00\x00\x00\x00" + (1).to_bytes(8, "big") + connection.connection_lost(None) + + +async def test_keep_alive_timeout_fails_streams_and_aborts_connection( + connection_url, transport_type, keep_alive_clock, request_headers +): + connection = AioH2Connection(ngh2.Role.CLIENT, url=connection_url(keep_alive_interval=10, keep_alive_timeout=20)) + + class AbortTransport(transport_type): + aborts = 0 + + def abort(self): + self.aborts += 1 + connection.connection_lost(None) + + transport = AbortTransport() + connection.connection_made(transport) + stream = await connection.open_stream(request_headers, end_stream=True) + connection.pause_writing() + + keep_alive_clock.advance(30) + + assert transport.aborts == 1 + assert connection.closed + with pytest.raises(H2ConnectionError, match="PING acknowledgement timed out"): + await stream.receive_headers() + + +async def test_pre_attachment_close_finishes_once_after_transport_loss(connection_url, transport_type) -> None: + closed: list[AioH2Connection] = [] + connection = AioH2Connection( + ngh2.Role.CLIENT, + url=connection_url(), + on_closed=closed.append, + ) + + connection.start_close() + assert not connection.closed + assert not closed + + transport = transport_type() + connection.connection_made(transport) + assert transport.close_calls == 1 + assert not connection.closed + + connection.connection_lost(None) + await connection.wait_closed() + assert connection.closed + assert closed == [connection] + + connection.connection_lost(None) + assert closed == [connection] + + +async def test_connection_aclose_waits_for_connection_lost_after_abort( + monkeypatch: pytest.MonkeyPatch, connection_url, transport_type +) -> None: + connection = AioH2Connection(ngh2.Role.CLIENT, url=connection_url()) + loop = asyncio.get_running_loop() + + class AbortTransport(transport_type): + def __init__(self) -> None: + super().__init__() + self.abort_calls = 0 + + def abort(self) -> None: + self.abort_calls += 1 + loop.call_soon(connection.connection_lost, None) + + transport = AbortTransport() + connection.connection_made(transport) + monkeypatch.setattr(async_module, "_CLOSE_GRACE", 0.0) + + await connection.aclose() + + assert transport.abort_calls == 1 + assert connection.closed + + +async def test_stream_reports_a_failure_found_while_writing_its_headers( + request_headers, connection_url, transport_type +) -> None: + class _BusyTransport(transport_type): + def get_write_buffer_size(self) -> int: + return 1 + + connection = AioH2Connection(ngh2.Role.CLIENT, url=connection_url()) + connection.connection_made(_BusyTransport()) + headers = (*request_headers, (b"x-large", b"x" * 70_000)) + + # The engine finds the oversized field only when it writes the frame, at the end of the iteration. + stream = await connection.open_stream(headers, end_stream=True) + + with pytest.raises(H2StreamError): + await stream.receive_headers() + + +async def test_an_idle_client_reports_invalid_headers_when_opening_beside_another_call( + request_headers, connection_url, transport_type +) -> None: + connection = AioH2Connection(ngh2.Role.CLIENT, url=connection_url()) + connection.connection_made(transport_type()) + await connection.open_stream(request_headers, end_stream=False) + + with pytest.raises(H2StreamError): + await connection.open_stream((*request_headers, (b"x-large", b"x" * 70_000)), end_stream=True) + + +async def test_cancelled_open_withdraws_the_stream_before_its_headers_leave( + request_headers, connection_url, transport_type +) -> None: + connection = AioH2Connection(ngh2.Role.CLIENT, url=connection_url()) + transport = transport_type() + connection.connection_made(transport) + preface = b"".join(transport.writes) + connection.pause_writing() + + async with anyio.create_task_group() as task_group: + task_group.start_soon(partial(connection.open_stream, request_headers, end_stream=True)) + # The stream exists and its open waits for asyncio to resume writing. + await anyio.wait_all_tasks_blocked() + task_group.cancel_scope.cancel() + + connection.resume_writing() + + # The reset stream's HEADERS never leave, so nothing follows the preface. + assert b"".join(transport.writes) == preface + # Nothing public shows that the connection let go of the stream. + assert not connection._streams_by_id + + +async def test_a_lost_connection_forgets_its_streams(request_headers, connection_url, transport_type) -> None: + connection = AioH2Connection(ngh2.Role.CLIENT, url=connection_url()) + connection.connection_made(transport_type()) + stream = await connection.open_stream(request_headers, end_stream=True) + + connection.connection_lost(None) + + # A stream the caller still holds keeps no sibling, and reports the loss. + assert not connection._streams_by_id + with pytest.raises(H2ConnectionError): + await stream.receive_headers() diff --git a/tests/unit/transport/h2/aio/test_server.py b/tests/unit/transport/h2/aio/test_server.py new file mode 100644 index 00000000..95b8cfac --- /dev/null +++ b/tests/unit/transport/h2/aio/test_server.py @@ -0,0 +1,230 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +from typing import cast + +import anyio +import pytest + +from dubbo.transport.h2.aio import AioH2Server +from dubbo.transport.h2.aio.connection import AioH2Connection + +pytestmark = pytest.mark.anyio + + +class _RecordingSocket: + def __init__(self, host: str = "127.0.0.1", port: int = 20_880) -> None: + self._address = host, port + + def getsockname(self) -> tuple[str, int]: + return self._address + + +class _RecordingServer: + def __init__(self) -> None: + self.sockets = [_RecordingSocket()] + self.closed = False + self._closed = anyio.Event() + + def close(self) -> None: + self.closed = True + self._closed.set() + + async def wait_closed(self) -> None: + await self._closed.wait() + + async def start_serving(self) -> None: + pass + + +class _FakeServerConnection: + """Stands in for a server connection; tests override how it closes.""" + + def announce_shutdown(self) -> None: + pass + + def start_close(self) -> None: + pass + + async def aclose(self) -> None: + pass + + +@pytest.mark.parametrize( + ("parameters", "message"), + [ + ({"ssl_handshake_timeout": "0"}, "must be positive"), + ({"shutwait": "-1"}, "whole milliseconds"), + ({"initial_window_size": str(2**31)}, "HTTP/2"), + ], + ids=["handshake-timeout", "shutwait", "http2-setting"], +) +def test_server_rejects_invalid_settings(parameters: dict[str, str], message: str, h2_url) -> None: + async def handler(stream) -> None: + raise AssertionError("no stream is opened") + + with pytest.raises(ValueError, match=message): + AioH2Server(h2_url("127.0.0.1", 443, **parameters), handler) + + +async def test_server_maps_listener_failure(monkeypatch: pytest.MonkeyPatch, h2_url) -> None: + async def fail_create_server(*args, **kwargs): + raise OSError("address unavailable") + + async def handler(stream) -> None: + raise AssertionError("the listener cannot create streams") + + server = AioH2Server(h2_url("127.0.0.1", 0), handler) + monkeypatch.setattr(asyncio.get_running_loop(), "create_server", fail_create_server) + + with pytest.raises(OSError, match="address unavailable"): + async with server: + pass + + +async def test_server_rejects_multiple_ephemeral_listener_ports(monkeypatch: pytest.MonkeyPatch, h2_url) -> None: + listener = _RecordingServer() + listener.sockets = [ + _RecordingSocket(), + _RecordingSocket("::1", 20_881), + ] + + async def create_server(*args, **kwargs): + return cast(asyncio.Server, listener) + + async def handler(stream) -> None: + raise AssertionError("the fake listener cannot create streams") + + server = AioH2Server(h2_url("localhost", 0), handler) + monkeypatch.setattr(asyncio.get_running_loop(), "create_server", create_server) + + with pytest.raises(ValueError, match="port 0 binds to different ports"): + async with server: + pass + + assert listener.closed + + +async def test_server_aclose_waits_for_each_connection_to_close(monkeypatch: pytest.MonkeyPatch, h2_url) -> None: + listener = _RecordingServer() + loop = asyncio.get_running_loop() + + async def create_server(*args, **kwargs): + return cast(asyncio.Server, listener) + + async def handler(stream) -> None: + raise AssertionError("the fake listener cannot create streams") + + server = AioH2Server(h2_url("127.0.0.1", 0), handler) + monkeypatch.setattr(loop, "create_server", create_server) + + class SlowConnection(_FakeServerConnection): + def __init__(self) -> None: + self.closed = anyio.Event() + + async def aclose(self) -> None: + loop.call_soon(self._finish_close) + await self.closed.wait() + + def _finish_close(self) -> None: + server._connections.discard(cast(AioH2Connection, self)) + self.closed.set() + + connection = SlowConnection() + async with server: + server._connections.add(cast(AioH2Connection, connection)) + await server.aclose() + + assert connection.closed.is_set() + assert not server._connections + assert listener.closed + + +async def test_server_aborts_a_connection_established_during_shutdown(h2_url, transport_type) -> None: + async def handler(stream) -> None: + raise AssertionError("no stream is opened") + + server = AioH2Server(h2_url("127.0.0.1", 0), handler) + first_waiting = anyio.Event() + release_first = anyio.Event() + close_finished = anyio.Event() + + class GateConnection(_FakeServerConnection): + async def aclose(self) -> None: + first_waiting.set() + await release_first.wait() + server._connections.discard(cast(AioH2Connection, self)) + + server._connections.add(cast(AioH2Connection, GateConnection())) + + async def close_server() -> None: + await server.aclose() + close_finished.set() + + async with anyio.create_task_group() as task_group: + task_group.start_soon(close_server) + await first_waiting.wait() + + class AbortedTransport(transport_type): + abort_calls = 0 + + def abort(self) -> None: + self.abort_calls += 1 + + late = server._create_connection() + transport = AbortedTransport() + late.connection_made(transport) + # Nothing else would close it, as the server owns only the connections it had. + assert transport.abort_calls == 1 + assert late not in server._connections + + release_first.set() + await close_finished.wait() + late.connection_lost(None) + + assert not server._connections + + +async def test_closing_a_starting_server_retires_its_listener(monkeypatch: pytest.MonkeyPatch, h2_url) -> None: + listener = _RecordingServer() + created = anyio.Event() + release = anyio.Event() + + async def create_server(*args, **kwargs): + # The listener accepts nothing until the server owns it. + assert kwargs["start_serving"] is False + created.set() + await release.wait() + return cast(asyncio.Server, listener) + + async def handler(stream) -> None: + raise AssertionError("the fake listener cannot create streams") + + monkeypatch.setattr(asyncio.get_running_loop(), "create_server", create_server) + server = AioH2Server(h2_url("127.0.0.1", 0), handler) + starting = asyncio.get_running_loop().create_task(server.__aenter__()) + await created.wait() + + await server.aclose() + release.set() + with pytest.raises(RuntimeError, match="closed while it started"): + await starting + + assert listener.closed + with pytest.raises(RuntimeError): + await server.__aenter__() diff --git a/tests/unit/transport/h2/aio/test_stream.py b/tests/unit/transport/h2/aio/test_stream.py new file mode 100644 index 00000000..e603cde4 --- /dev/null +++ b/tests/unit/transport/h2/aio/test_stream.py @@ -0,0 +1,232 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from functools import partial + +import anyio +import ngh2 +import pytest + +from dubbo.transport.h2 import ( + H2ErrorCode, + H2StreamError, + H2StreamResetError, +) +from dubbo.transport.h2.aio import AioH2Stream +from dubbo.transport.h2.aio.connection import AioH2Connection + +pytestmark = pytest.mark.anyio + + +@pytest.mark.parametrize( + ("parameters", "size", "returns"), + [({}, 256 * 1024, True), ({}, 512 * 1024, False), ({"stream_send_buffer_size": "1048576"}, 512 * 1024, True)], + ids=["default-fits", "default-full", "configured-fits"], +) +async def test_send_blocks_only_when_queued_body_exceeds_the_send_buffer( + parameters, size, returns, h2_url, transport_type, request_headers +): + connection = AioH2Connection(ngh2.Role.CLIENT, url=h2_url("127.0.0.1", 1, **parameters)) + connection.connection_made(transport_type()) + stream = await connection.open_stream(request_headers, end_stream=False) + returned = anyio.Event() + + async def send(): + await stream.send_data(b"x" * size) + returned.set() + + async with anyio.create_task_group() as tasks: + tasks.start_soon(send) + await anyio.wait_all_tasks_blocked() + assert returned.is_set() is returns + tasks.cancel_scope.cancel() + + connection.connection_lost(None) + + +async def test_send_rejects_overlap_and_waits_for_asyncio_backpressure( + request_headers, connection_url, transport_type +) -> None: + connection = AioH2Connection(ngh2.Role.CLIENT, url=connection_url()) + transport = transport_type() + connection.connection_made(transport) + stream = await connection.open_stream(request_headers, end_stream=False) + assert stream is not None + + connection.pause_writing() + writes_before_send = len(transport.writes) + completed = anyio.Event() + + async def send() -> None: + await stream.send_data(b"payload", end_stream=True) + completed.set() + + async with anyio.create_task_group() as task_group: + task_group.start_soon(send) + await anyio.wait_all_tasks_blocked() + assert not completed.is_set() + assert len(transport.writes) == writes_before_send + with pytest.raises(H2StreamError, match="already sending"): + await stream.send_data(b"overlap") + connection.resume_writing() + await completed.wait() + + +async def test_end_remains_idempotent_after_the_send_direction_has_ended( + request_headers, connection_url, transport_type +) -> None: + connection = AioH2Connection(ngh2.Role.CLIENT, url=connection_url()) + connection.connection_made(transport_type()) + stream = await connection.open_stream(request_headers, end_stream=True) + assert stream is not None + + connection.connection_lost(None) + + await stream.end() + + +@pytest.mark.parametrize("operation", ["headers", "data", "trailers", "end"]) +async def test_cancelling_a_queued_send_resets_the_stream_for_both_peers( + operation, h2_pair, request_headers, response_headers +): + client, server, streams, exchange = h2_pair + peer = await client.open_stream(request_headers, end_stream=False) + await exchange() + stream = streams[0] + if operation != "headers": + await stream.send_headers(response_headers) + await exchange() + server.pause_writing() + scopes = [] + + async def send(): + with anyio.CancelScope() as scope: + scopes.append(scope) + if operation == "headers": + await stream.send_headers(response_headers, end_stream=True) + elif operation == "data": + await stream.send_data(b"payload", end_stream=True) + elif operation == "trailers": + await stream.send_trailers(((b"grpc-status", b"0"),)) + else: + await stream.end() + + async with anyio.create_task_group() as tasks: + tasks.start_soon(send) + await anyio.wait_all_tasks_blocked() + scopes[0].cancel() + + with pytest.raises(H2StreamError, match="reset locally"): + await stream.receive_data() + server.resume_writing() + await exchange() + with pytest.raises(H2StreamResetError, match="reset") as raised: + await peer.receive_data() + assert raised.value.error_code == H2ErrorCode.CANCEL + + +async def test_cancelled_send_wakes_receiver_when_reset_fails(request_headers, connection_url, transport_type) -> None: + class FailingResetConnection(AioH2Connection): + def reset_stream(self, stream_id, error_code): + raise H2StreamError("reset failed", stream_id=stream_id) + + connection = FailingResetConnection(ngh2.Role.CLIENT, url=connection_url()) + connection.connection_made(transport_type()) + stream = await connection.open_stream(request_headers, end_stream=False) + assert stream is not None + connection.pause_writing() + + async def receive() -> None: + with pytest.raises(H2StreamError, match="operation was cancelled"): + await stream.receive_headers() + + async with anyio.create_task_group() as task_group: + task_group.start_soon(receive) + async with anyio.create_task_group() as sending: + sending.start_soon(partial(stream.send_data, b"payload", end_stream=True)) + await anyio.wait_all_tasks_blocked() + sending.cancel_scope.cancel() + + +async def test_receive_rejects_overlap_and_reset_wakes_a_waiter( + request_headers, connection_url, transport_type +) -> None: + connection = AioH2Connection(ngh2.Role.CLIENT, url=connection_url()) + connection.connection_made(transport_type()) + stream = await connection.open_stream(request_headers, end_stream=True) + assert stream is not None + completed = anyio.Event() + + async def receive() -> None: + with pytest.raises(H2StreamError, match="reset locally"): + await stream.receive_headers() + completed.set() + + async with anyio.create_task_group() as task_group: + task_group.start_soon(receive) + await anyio.wait_all_tasks_blocked() + connection.pause_writing() + with pytest.raises(H2StreamError, match="already receiving"): + await stream.receive_data_exactly(0) + await stream.reset() + with anyio.fail_after(5): + await completed.wait() + + connection.resume_writing() + + +async def test_cancelling_exact_receive_preserves_partial_bytes_for_the_next_receive( + h2_pair, request_headers, response_headers, credits +): + client, _server, streams, exchange = h2_pair + stream = await client.open_stream(request_headers, end_stream=True) + await exchange() + peer = streams[0] + await peer.send_headers(response_headers) + await peer.send_data(b"abc") + await exchange() + scopes = [] + + async def receive(): + with anyio.CancelScope() as scope: + scopes.append(scope) + await stream.receive_data_exactly(5) + + async with anyio.create_task_group() as tasks: + tasks.start_soon(receive) + await anyio.wait_all_tasks_blocked() + scopes[0].cancel() + + assert credits == [(stream.stream_id, 3)] + + await peer.send_data(b"defg", end_stream=True) + await exchange() + + assert await stream.receive_data_exactly(5) == b"abcde" + assert await stream.receive_data_exactly(2) == b"fg" + assert credits == [(stream.stream_id, 3), (stream.stream_id, 2), (stream.stream_id, 2)] + assert await stream.receive_data() == b"" + + +@pytest.mark.parametrize("error_code", [-1, 0x1_0000_0000]) +async def test_reset_validates_error_code_after_stream_finished(error_code: int, connection_url) -> None: + connection = AioH2Connection(ngh2.Role.CLIENT, url=connection_url()) + stream = AioH2Stream(connection, 1, headers_sent=True) + stream._on_closed() + + with pytest.raises(ValueError, match="unsigned 32-bit"): + await stream.reset(error_code) diff --git a/tests/unit/transport/h2/test_exceptions.py b/tests/unit/transport/h2/test_exceptions.py new file mode 100644 index 00000000..05c685d5 --- /dev/null +++ b/tests/unit/transport/h2/test_exceptions.py @@ -0,0 +1,41 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from dubbo import DubboError +from dubbo.transport.h2 import ( + H2ConnectionError, + H2Error, + H2StreamError, + H2StreamResetError, +) + + +def test_h2_connection_error_preserves_goaway_context() -> None: + error = H2ConnectionError("peer rejected the connection", error_code=1, last_stream_id=7) + + assert isinstance(error, H2Error) + assert isinstance(error, DubboError) + assert error.error_code == 1 + assert error.last_stream_id == 7 + + +def test_h2_stream_reset_preserves_unknown_error_code() -> None: + error = H2StreamResetError(stream_id=3, error_code=0xFF) + + assert isinstance(error, H2StreamError) + assert error.stream_id == 3 + assert error.error_code == 0xFF diff --git a/tests/unit/transport/nacos/sdk/test_config.py b/tests/unit/transport/nacos/sdk/test_config.py new file mode 100644 index 00000000..e7ddcf10 --- /dev/null +++ b/tests/unit/transport/nacos/sdk/test_config.py @@ -0,0 +1,133 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import hashlib + +import anyio +import attrs +import pytest +from v2.nacos import ConfigParam, NacosException + +from dubbo.transport.nacos import NacosError +from dubbo.transport.nacos.sdk import SdkNacosConfigClient +from dubbo.transport.nacos.sdk import config as sdk_config +from dubbo.url import URL + +pytestmark = pytest.mark.anyio + + +@attrs.define(kw_only=False) +class _Configs: + """A configuration service of the SDK that another writer changes once while it is read.""" + + content: str | tuple[str, str] + interference: str | None = None + published: list[tuple[str, str, str, str]] = attrs.field(factory=list) + + @property + def grpc_client_proxy(self): + return self + + async def start(self): + pass + + async def shutdown(self): + pass + + async def get_config(self, param: ConfigParam) -> str | tuple[str, str]: + return self.content + + async def publish_config(self, param: ConfigParam) -> bool: + self.published.append((param.data_id, param.group, param.content, param.cas_md5)) + if self.interference is not None: + self.content, self.interference = self.interference, None + raise NacosException(400, "md5 does not match") + self.content = param.content + return True + + +@pytest.mark.parametrize(("current", "md5"), [("", "0"), ("a", hashlib.md5(b"a").hexdigest())]) +async def test_sdk_writes_a_configuration_if_it_is_still_what_was_read(monkeypatch, current, md5): + configs = _Configs(content=current) + monkeypatch.setattr(sdk_config, "NacosConfigService", lambda settings: configs) + + async with SdkNacosConfigClient(URL.parse("nacos://n")) as client: + await client.update("d", "g", lambda content: (content or "") + "b") + + assert configs.published == [("d", "g", current + "b", md5)] + + +async def test_sdk_reads_the_local_cache_it_falls_back_to_as_the_configuration(monkeypatch): + configs = _Configs(content=("a", "")) + monkeypatch.setattr(sdk_config, "NacosConfigService", lambda settings: configs) + + async with SdkNacosConfigClient(URL.parse("nacos://n")) as client: + assert await client.get("d", "g") == "a" + + +async def test_sdk_fails_a_read_whose_fallback_finds_no_local_cache(monkeypatch): + configs = _Configs(content=("", "")) + monkeypatch.setattr(sdk_config, "NacosConfigService", lambda settings: configs) + + async with SdkNacosConfigClient(URL.parse("nacos://n")) as client: + with pytest.raises(NacosError, match="cannot read d"): + await client.get("d", "g") + + +async def test_sdk_reads_a_configuration_again_that_changed_before_it_was_written(monkeypatch): + configs = _Configs(content="a", interference="a,c") + monkeypatch.setattr(sdk_config, "NacosConfigService", lambda settings: configs) + monkeypatch.setattr(sdk_config, "_CAS_WAIT", 0) + + async with SdkNacosConfigClient(URL.parse("nacos://n")) as client: + await client.update("d", "g", lambda content: f"{content},b") + + assert configs.content == "a,c,b" + assert configs.published == [ + ("d", "g", "a,b", hashlib.md5(b"a").hexdigest()), + ("d", "g", "a,c,b", hashlib.md5(b"a,c").hexdigest()), + ] + + +async def test_sdk_watch_cancelled_while_adding_its_listener_leaves_none(monkeypatch): + class Configs: + def __init__(self): + self.grpc_client_proxy = self + self.listeners = [] + + async def start(self): + pass + + async def shutdown(self): + pass + + async def add_listener(self, data_id, group, listener): + self.listeners.append(listener) + await anyio.sleep_forever() + + async def remove_listener(self, data_id, group, listener): + self.listeners.remove(listener) + + configs = Configs() + monkeypatch.setattr(sdk_config, "NacosConfigService", lambda settings: configs) + + async with SdkNacosConfigClient(URL.parse("nacos://n")) as client: + with anyio.move_on_after(0.1): + async with client.watch("d", "g"): + pytest.fail("the watch was not cancelled") + + assert configs.listeners == [] diff --git a/tests/unit/transport/nacos/sdk/test_connection.py b/tests/unit/transport/nacos/sdk/test_connection.py new file mode 100644 index 00000000..4369e33b --- /dev/null +++ b/tests/unit/transport/nacos/sdk/test_connection.py @@ -0,0 +1,62 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.transport.nacos.sdk.connection import client_config +from dubbo.url import URL + + +@pytest.fixture +def config(): + return client_config( + URL.parse("nacos://u:p@n1?backup=n2:9000,[::1],n3&namespace=dev&timeout=1500&accessKey=ak&secretKey=sk") + ) + + +def test_sdk_settings_name_each_server_with_its_port(config): + assert config.server_list == ["n1:8848", "n2:9000", "[::1]:8848", "n3:8848"] + + +def test_sdk_settings_bracket_an_ipv6_server_that_names_no_port(): + config = client_config(URL.parse("nacos://[::1]?backup=::2")) + + assert config.server_list == ["[::1]:8848", "[::2]:8848"] + + +def test_sdk_settings_take_the_namespace_and_credentials_of_the_url(config): + credentials = config.credentials_provider.get_credentials() + + assert (config.namespace_id, config.username, config.password) == ("dev", "u", "p") + assert (credentials.get_access_key_id(), credentials.get_access_key_secret()) == ("ak", "sk") + + +def test_sdk_settings_take_the_timeout_of_the_url(config): + assert (config.timeout_ms, config.grpc_config.grpc_timeout) == (1500, 1500) + + +def test_sdk_settings_keep_services_that_lose_every_instance(config): + assert config.update_cache_when_empty + + +def test_sdk_settings_read_no_disk_cache_at_start(config): + assert not config.load_cache_at_start + + +def test_sdk_rejects_a_timeout_that_is_not_positive(): + with pytest.raises(ValueError, match="positive"): + client_config(URL.parse("nacos://n?timeout=0")) diff --git a/tests/unit/transport/nacos/sdk/test_naming.py b/tests/unit/transport/nacos/sdk/test_naming.py new file mode 100644 index 00000000..148e1ab2 --- /dev/null +++ b/tests/unit/transport/nacos/sdk/test_naming.py @@ -0,0 +1,178 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +from types import SimpleNamespace + +import anyio +import pytest +from v2.nacos import Instance + +from dubbo.transport.nacos import NacosInstance +from dubbo.transport.nacos.sdk import naming +from dubbo.transport.nacos.sdk.naming import SdkNacosNamingClient +from dubbo.url import URL + + +@pytest.mark.anyio +async def test_sdk_watch_leaves_out_unhealthy_or_disabled_instances(monkeypatch): + class Naming: + grpc_client_proxy = None + + def __init__(self): + self.grpc_client_proxy = self + self.unsubscribed = [] + + async def start(self): + self.redo_service = SimpleNamespace(_listen_task=asyncio.create_task(anyio.sleep_forever())) + + async def shutdown(self): + pass + + async def subscribe(self, param): + pass + + async def unsubscribe(self, param): + self.unsubscribed.append((param.service_name, param.group_name)) + + async def list_instances(self, param): + return [ + Instance(ip="h", port=1, metadata={"a": "b"}), + Instance(ip="h", port=2, healthy=False), + Instance(ip="h", port=3, enabled=False), + ] + + service = Naming() + monkeypatch.setattr(naming, "NacosNamingService", lambda settings: service) + + async with SdkNacosNamingClient(URL.parse("nacos://n")) as client, client.watch("service", "group") as snapshots: + with anyio.fail_after(5): + assert await anext(snapshots) == [NacosInstance(host="h", port=1, metadata={"a": "b"})] + + assert service.unsubscribed == [("service", "group")] + + +class _Registering: + """A naming service that records what it holds of each service, by host and port, and fails when told.""" + + def __init__(self): + self.grpc_client_proxy = self + self.held = {} + self.failures = [] + # Whether a registration the server has taken waits, as the SDK does for its redo state. + self.hanging = False + + async def start(self): + self.redo_service = SimpleNamespace(_listen_task=asyncio.create_task(anyio.sleep_forever())) + + async def shutdown(self): + pass + + async def register_instance(self, param): + return await self.batch_register_instances(SimpleNamespace(instances=[param])) + + async def batch_register_instances(self, param): + if self.failures: + raise self.failures.pop() + self.held = {(instance.ip, instance.port): dict(instance.metadata) for instance in param.instances} + if self.hanging: + await anyio.sleep_forever() + return True + + async def deregister_instance(self, param): + self.held.pop((param.ip, param.port), None) + return True + + +@pytest.fixture +def registering(monkeypatch): + service = _Registering() + monkeypatch.setattr(naming, "NacosNamingService", lambda settings: service) + return service + + +@pytest.mark.anyio +async def test_sdk_leaves_an_instance_kept_again_at_its_address_as_the_earlier_keeper_exits(registering): + old = NacosInstance(host="h", port=1, metadata={"weight": "100"}) + new = NacosInstance(host="h", port=1, metadata={"weight": "50"}) + + async with SdkNacosNamingClient(URL.parse("nacos://n")) as client: + earlier = client.keep_registered("service", "group", old) + await earlier.__aenter__() + async with client.keep_registered("service", "group", new): + await earlier.__aexit__(None, None, None) + held = dict(registering.held) + + assert (held, registering.held) == ({("h", 1): {"weight": "50"}}, {}) + + +@pytest.mark.anyio +async def test_sdk_that_fails_to_keep_an_instance_holds_again_what_it_held_before(registering): + kept = NacosInstance(host="h", port=1, metadata={"weight": "100"}) + other = NacosInstance(host="h", port=2) + + async with SdkNacosNamingClient(URL.parse("nacos://n")) as client, client.keep_registered("s", "g", kept): + registering.failures.append(ConnectionError("the connection was lost after the request went out")) + registering.held[("h", 2)] = {} + with pytest.raises(ConnectionError): + async with client.keep_registered("s", "g", other): + pytest.fail("the instance was not registered") + + assert registering.held == {("h", 1): {"weight": "100"}} + + +@pytest.mark.anyio +async def test_sdk_cancelled_while_keeping_an_instance_holds_again_what_it_held_before(registering): + async with SdkNacosNamingClient(URL.parse("nacos://n")) as client: + registering.hanging = True + with anyio.move_on_after(0.1): + async with client.keep_registered("s", "g", NacosInstance(host="h", port=1)): + pytest.fail("the instance was not registered") + + assert registering.held == {} + + +@pytest.mark.anyio +async def test_sdk_watch_cancelled_while_subscribing_leaves_no_callback(monkeypatch): + class Naming: + def __init__(self): + self.grpc_client_proxy = self + self.callbacks = [] + + async def start(self): + self.redo_service = SimpleNamespace(_listen_task=asyncio.create_task(anyio.sleep_forever())) + + async def shutdown(self): + pass + + async def subscribe(self, param): + # The SDK holds the callback before the server answers. + self.callbacks.append(param.subscribe_callback) + await anyio.sleep_forever() + + async def unsubscribe(self, param): + self.callbacks.remove(param.subscribe_callback) + + service = Naming() + monkeypatch.setattr(naming, "NacosNamingService", lambda settings: service) + + async with SdkNacosNamingClient(URL.parse("nacos://n")) as client: + with anyio.move_on_after(0.1): + async with client.watch("service", "group"): + pytest.fail("the watch was not cancelled") + + assert service.callbacks == [] diff --git a/tests/unit/transport/nacos/test_base.py b/tests/unit/transport/nacos/test_base.py new file mode 100644 index 00000000..98449d36 --- /dev/null +++ b/tests/unit/transport/nacos/test_base.py @@ -0,0 +1,54 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from contextlib import asynccontextmanager + +import pytest + +from dubbo.extension import ApplicationScope, extensions +from dubbo.transport.nacos import NacosConfigClient, NacosNamingClient, get_nacos_config_client, get_nacos_naming_client +from dubbo.url import APPLICATION_SCOPE, URL + +pytestmark = pytest.mark.anyio + + +async def test_users_of_one_connection_share_a_client_of_each_kind_within_an_application(isolated_extensions): + opened, closed = [], [] + + @asynccontextmanager + async def connect(url): + client = object() + opened.append((url, client)) + yield client + closed.append(client) + + extensions.register(NacosNamingClient, "recorder", lambda url: connect(url)) + extensions.register(NacosConfigClient, "recorder", lambda url: connect(url)) + async with ApplicationScope() as scope: + url = URL.parse("nacos://n:8848?client=recorder&namespace=dev").replace(attributes={APPLICATION_SCOPE: scope}) + other = url.update_parameters({"namespace": "test"}) + + naming = await get_nacos_naming_client(url) + assert await get_nacos_naming_client(url.replace(path="x")) is naming + assert await get_nacos_naming_client(url.update_parameters({"timeout": "30000"})) is naming + config = await get_nacos_config_client(url) + assert config is not naming + assert await get_nacos_config_client(other) is not config + assert closed == [] + + assert [url for url, _ in opened] == [url, url, other] + assert set(closed) == {client for _, client in opened} diff --git a/tests/unit/transport/test_tls.py b/tests/unit/transport/test_tls.py new file mode 100644 index 00000000..5d5b1bcd --- /dev/null +++ b/tests/unit/transport/test_tls.py @@ -0,0 +1,144 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import os +import select +import ssl +import sys +import time +from pathlib import Path + +import pytest + +from dubbo.transport.tls import get_ssl_context +from dubbo.url import SSL_CONTEXT, URL + +_CERTIFICATES = Path(__file__).resolve().parents[2] / "certificates" + + +_CERT_FILE = str(_CERTIFICATES / "localhost-cert.pem") + + +_KEY_FILE = str(_CERTIFICATES / "localhost-key.pem") + + +# The key of _KEY_FILE encrypted with the password "dubbo", by `openssl pkey -aes256`. +_ENCRYPTED_KEY_FILE = str(_CERTIFICATES / "localhost-key-encrypted.pem") + + +def test_get_ssl_context_returns_none_without_tls() -> None: + assert get_ssl_context(URL.parse("tri://127.0.0.1:50051?ssl-enabled=false"), server=False) is None + + +@pytest.mark.parametrize( + ("query", "message"), + [ + ("ssl-enabled=maybe", "ssl-enabled.*bool"), + (f"ca-cert-file={_CERT_FILE}", "need ssl-enabled=true"), + (f"ssl-enabled=true&tls-key-file={_KEY_FILE}", "tls-cert-file"), + ], +) +def test_get_ssl_context_rejects_inconsistent_parameters(query: str, message: str) -> None: + with pytest.raises(ValueError, match=message): + get_ssl_context(URL.parse(f"tri://127.0.0.1:50051?{query}"), server=False) + + +def test_get_ssl_context_requires_a_server_certificate() -> None: + with pytest.raises(ValueError, match="tls-cert-file"): + get_ssl_context(URL.parse("tri://127.0.0.1:50051?ssl-enabled=true"), server=True) + + +def test_get_ssl_context_configures_tls_1_2_or_later() -> None: + client = get_ssl_context(URL.parse("tri://127.0.0.1:50051?ssl-enabled=true"), server=False) + server = get_ssl_context( + URL.parse(f"tri://127.0.0.1:50051?ssl-enabled=true&tls-cert-file={_CERT_FILE}&tls-key-file={_KEY_FILE}"), + server=True, + ) + + assert client is not None + assert server is not None + assert client.verify_mode == ssl.CERT_REQUIRED + assert client.check_hostname + assert server.verify_mode == ssl.CERT_NONE + for context in (client, server): + assert context.minimum_version == ssl.TLSVersion.TLSv1_2 + assert context.options & ssl.OP_NO_COMPRESSION + assert context.options & ssl.OP_NO_RENEGOTIATION + + +def test_get_ssl_context_lets_a_server_require_client_certificates() -> None: + url = URL.parse( + f"tri://127.0.0.1:50051?ssl-enabled=true&tls-cert-file={_CERT_FILE}" + f"&tls-key-file={_KEY_FILE}&ca-cert-file={_CERT_FILE}" + ) + + context = get_ssl_context(url, server=True) + + assert context is not None + assert context.verify_mode == ssl.CERT_REQUIRED + + +def test_get_ssl_context_returns_a_given_context_as_it_is() -> None: + given = ssl.create_default_context() + url = URL.parse(f"tri://127.0.0.1:50051?ssl-enabled=true&ca-cert-file={_CERT_FILE}").replace( + attributes={SSL_CONTEXT: given} + ) + + assert get_ssl_context(url, server=False) is given + assert given.minimum_version == ssl.create_default_context().minimum_version + + +def test_get_ssl_context_rejects_a_context_for_the_other_side_or_without_tls() -> None: + client = URL.parse("tri://127.0.0.1:50051?ssl-enabled=true").replace( + attributes={SSL_CONTEXT: ssl.create_default_context()} + ) + with pytest.raises(ValueError, match="PROTOCOL_TLS_CLIENT"): + get_ssl_context(client, server=True) + + cleartext = URL.parse("tri://127.0.0.1:50051").replace(attributes={SSL_CONTEXT: ssl.create_default_context()}) + with pytest.raises(ValueError, match="need ssl-enabled=true"): + get_ssl_context(cleartext, server=False) + + +@pytest.mark.skipif(sys.platform == "win32", reason="needs a pseudo-terminal") +def test_get_ssl_context_fails_an_encrypted_key_without_prompting_on_a_terminal() -> None: + code = ( + "from dubbo.transport.tls import get_ssl_context; from dubbo.url import URL\n" + "try:\n" + f" get_ssl_context(URL.parse('tri://127.0.0.1:0?ssl-enabled=true&tls-cert-file={_CERT_FILE}" + f"&tls-key-file={_ENCRYPTED_KEY_FILE}'), server=True)\n" + "except OSError as error:\n" + " print(type(error).__name__)\n" + ) + import pty # It imports termios, which Windows lacks. + + pid, terminal = pty.fork() + if pid == 0: + os.execv(sys.executable, [sys.executable, "-c", code]) + + output = b"" + deadline = time.monotonic() + 10 + try: + while time.monotonic() < deadline and b"\n" not in output: + if select.select([terminal], [], [], 0.05)[0]: + output += os.read(terminal, 1024) + finally: + os.kill(pid, 9) + os.waitpid(pid, 0) + os.close(terminal) + + assert output.strip() == b"SSLError" diff --git a/tests/unit/transport/zookeeper/test_base.py b/tests/unit/transport/zookeeper/test_base.py new file mode 100644 index 00000000..5ecf666f --- /dev/null +++ b/tests/unit/transport/zookeeper/test_base.py @@ -0,0 +1,86 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from collections.abc import AsyncIterator +from contextlib import asynccontextmanager + +import attrs +import pytest + +from dubbo.extension import ApplicationScope, extensions +from dubbo.transport import zookeeper +from dubbo.transport.zookeeper import ZookeeperClient +from dubbo.transport.zookeeper.kazoo import KazooZookeeperClient +from dubbo.url import APPLICATION_SCOPE, URL + + +@attrs.define(kw_only=False) +class _Recorder: + """A ZookeeperClient registered as ``recorder`` that keeps the URLs it is created with.""" + + urls: list[URL] = attrs.field(factory=list) + + @asynccontextmanager + async def create(self, url: URL) -> AsyncIterator[object]: + self.urls.append(url) + yield object() + + +@pytest.fixture +def recorder(isolated_extensions) -> _Recorder: + recorder = _Recorder() + extensions.register(ZookeeperClient, "recorder", recorder.create) + return recorder + + +@pytest.mark.anyio +async def test_users_of_the_same_connection_share_one_client_within_an_application(recorder): + # A registry, and the configuration center it serves as, which has a timeout of its own. + texts = [ + "zookeeper://zk?client=recorder&namespace=a", + "zookeeper://zk/path?client=recorder&group=b&timeout=30000", + "zookeeper://zk?client=recorder&session=5000", + ] + + async with ApplicationScope() as scope: + first, second, other = [URL.parse(text).replace(attributes={APPLICATION_SCOPE: scope}) for text in texts] + a, b, c = [await zookeeper.get_zookeeper_client(url) for url in (first, second, other)] + assert a is b + assert c is not a + + assert recorder.urls == [first, other] + + +@pytest.mark.anyio +async def test_a_client_belongs_to_an_application(recorder): + with pytest.raises(RuntimeError, match="belongs to no application"): + await zookeeper.get_zookeeper_client(URL.parse("zookeeper://zk?client=recorder")) + + assert recorder.urls == [] + + +@pytest.mark.anyio +async def test_connect_needs_a_host(recorder): + with pytest.raises(ValueError, match="needs a host"): + await zookeeper.get_zookeeper_client(URL.parse("zookeeper:///path?client=recorder")) + + assert recorder.urls == [] + + +def test_kazoo_is_the_installed_client_and_the_default(): + assert extensions.get(ZookeeperClient, "kazoo") is KazooZookeeperClient + assert extensions.get(ZookeeperClient, None) is KazooZookeeperClient diff --git a/tests/unit/transport/zookeeper/test_kazoo.py b/tests/unit/transport/zookeeper/test_kazoo.py new file mode 100644 index 00000000..6c65b05d --- /dev/null +++ b/tests/unit/transport/zookeeper/test_kazoo.py @@ -0,0 +1,497 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import itertools +import logging +import threading +from types import SimpleNamespace + +import anyio +import pytest +from kazoo.exceptions import KazooException, NoNodeError, SessionExpiredError +from kazoo.protocol.states import KazooState +from kazoo.security import CREATOR_ALL_ACL + +from dubbo.transport.zookeeper import ZookeeperError, kazoo +from dubbo.transport.zookeeper.kazoo import KazooZookeeperClient +from dubbo.url import URL + +# The client calls kazoo in threads, which these tests drive and wait for. +pytestmark = pytest.mark.real_clock + + +@pytest.mark.parametrize( + ("text", "message"), + [ + ("zookeeper://zk?timeout=1.5", "'timeout': must be whole milliseconds"), + ("zookeeper://zk?session=0", "'session' must be positive"), + ], +) +def test_kazoo_rejects_times_that_are_not_positive_milliseconds(text, message): + with pytest.raises(ValueError, match=message): + KazooZookeeperClient(URL.parse(text)) + + +class _Result: + def __init__(self, value=None, gate=None): + self.value = value + self.gate = gate + + def get(self, timeout): + # A gated result waits as a network call does, until its test opens the gate. + if self.gate is not None: + self.gate.waiting.set() + assert self.gate.wait(5) + return self.value + + +class _Gate(threading.Event): + def __init__(self): + super().__init__() + self.waiting = threading.Event() + + def open_later(self, seconds=1.0): + threading.Timer(seconds, self.set).start() + + +class _Kazoo: + def __init__(self, **settings): + self.settings = settings + self.listeners = [] + self.nodes = {} + self.created = [] + self.deleted = [] + self.failures = {} + self.gates = {} + self.jobs = [] + self.handler = SimpleNamespace(spawn=lambda function, *args: self.jobs.append((function, args))) + self.replaced = False + self.expired = False + self._data_watchers = {} + self._child_watchers = {} + + def start(self, timeout): + pass + + def stop(self): + pass + + def close(self): + pass + + def add_listener(self, listener): + self.listeners.append(listener) + + def remove_listener(self, listener): + pass + + def get_async(self, path): + return _Result((self.nodes.get(path), None), self.gates.get(path)) + + def create_async(self, path, data, **options): + if self.failures.get(path, 0): + self.failures[path] -= 1 + if self.replaced: + self.new_session() + raise KazooException("unreachable") + self.nodes[path] = data + self.created.append(path) + return _Result(path, self.gates.get(path)) + + def delete_async(self, path): + if self.expired: + raise SessionExpiredError() + if self.nodes.pop(path, None) is None: + raise NoNodeError(path) + self.deleted.append(path) + return _Result() + + def new_session(self): + self.nodes.clear() + for state in (KazooState.LOST, KazooState.CONNECTED): + for listener in self.listeners: + listener(state) + + def recover(self): + function, args = self.jobs.pop(0) + function(*args) + + +@pytest.fixture +def backend(monkeypatch): + backend = _Kazoo() + monkeypatch.setattr(kazoo, "KazooClient", lambda **settings: backend.settings.update(settings) or backend) + monkeypatch.setattr(kazoo, "backoff", lambda: itertools.repeat(0)) + return backend + + +@pytest.mark.parametrize( + ("text", "acl"), + [("zookeeper://alice:secret@zk", CREATOR_ALL_ACL), ("zookeeper://zk", None)], + ids=["with-user", "anonymous"], +) +def test_kazoo_creates_nodes_open_only_to_its_user(text, acl, backend): + KazooZookeeperClient(URL.parse(text)) + + assert backend.settings["default_acl"] == acl + + +def test_kazoo_waits_at_most_a_second_between_rounds_of_reconnecting(): + retry = KazooZookeeperClient(URL.parse("zookeeper://zk"))._kazoo._conn_retry + + assert (retry.max_tries, retry.max_delay) == (-1, 1.0) + + +@pytest.mark.anyio +async def test_ephemeral_recovery_retries_failed_nodes_without_delaying_the_others(backend): + async with ( + KazooZookeeperClient(URL.parse("zookeeper://zk")) as client, + client.keep_ephemeral("/a", b"a"), + client.keep_ephemeral("/b", b"b"), + ): + backend.created.clear() + backend.failures["/a"] = 2 + + backend.new_session() + await anyio.to_thread.run_sync(backend.recover) + + assert backend.created == ["/b", "/a"] + assert backend.nodes == {"/a": b"a", "/b": b"b"} + + +@pytest.mark.anyio +async def test_ephemeral_recovery_stops_when_another_session_replaces_it(backend): + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client, client.keep_ephemeral("/a"): + backend.failures["/a"] = 2 + backend.replaced = True + + backend.new_session() + await anyio.to_thread.run_sync(backend.recover) + + assert backend.failures["/a"] == 1 + assert backend.nodes == {} + + +@pytest.mark.anyio +async def test_a_node_kept_is_deleted_on_exit_and_no_longer_created_again(backend): + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client: + async with client.keep_ephemeral("/a", b"a"): + kept = dict(backend.nodes) + backend.created.clear() + + backend.new_session() + await anyio.to_thread.run_sync(backend.recover) + + assert (kept, backend.deleted, backend.created) == ({"/a": b"a"}, ["/a"], []) + + +@pytest.mark.anyio +async def test_a_node_kept_exits_quietly_once_its_session_has_expired(backend): + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client: + async with client.keep_ephemeral("/a"): + backend.expired = True + + backend.expired = False + backend.new_session() + await anyio.to_thread.run_sync(backend.recover) + + assert backend.nodes == {} + + +@pytest.mark.anyio +async def test_a_later_keeper_replaces_the_node_and_the_earlier_one_leaves_it_on_exit(backend): + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client: + earlier = client.keep_ephemeral("/a", b"old") + await earlier.__aenter__() + async with client.keep_ephemeral("/a", b"new"): + await earlier.__aexit__(None, None, None) + left = dict(backend.nodes) + + assert (left, backend.nodes, backend.deleted) == ({"/a": b"new"}, {}, ["/a"]) + + +@pytest.mark.anyio +async def test_a_keeper_that_fails_to_replace_a_node_restores_the_one_kept_before(backend): + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client, client.keep_ephemeral("/a", b"old"): + backend.failures["/a"] = 1 + with pytest.raises(ZookeeperError): + async with client.keep_ephemeral("/a", b"new"): + pytest.fail("the node was not created") + restored = dict(backend.nodes) + + backend.new_session() + await anyio.to_thread.run_sync(backend.recover) + + assert (restored, backend.nodes) == ({"/a": b"old"}, {"/a": b"old"}) + + +@pytest.mark.anyio +async def test_a_keeper_that_fails_is_not_created_again_in_a_new_session(backend): + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client: + backend.failures["/a"] = 1 + with pytest.raises(ZookeeperError): + async with client.keep_ephemeral("/a"): + pytest.fail("the node was not created") + + backend.new_session() + await anyio.to_thread.run_sync(backend.recover) + + assert (backend.nodes, backend.created) == ({}, []) + + +@pytest.mark.anyio +async def test_a_cancelled_watch_rejects_its_abandoned_registration_callback(backend): + registering, release, finished = threading.Event(), threading.Event(), threading.Event() + accepted = [] + + def register(path, changed): + registering.set() + assert release.wait(2) + accepted.append(changed(b"late", None)) + finished.set() + return object() + + backend.DataWatch = register + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client: + with anyio.fail_after(2): + async with anyio.create_task_group() as tasks: + + async def watch(): + async with client.watch("/a"): + pytest.fail("registration was not cancelled") + + tasks.start_soon(watch) + assert await anyio.to_thread.run_sync(registering.wait, 1) + tasks.cancel_scope.cancel() + + release.set() + assert await anyio.to_thread.run_sync(finished.wait, 1) + + assert accepted == [False] + + +@pytest.mark.anyio +async def test_leaving_a_kept_node_does_not_wait_while_another_is_being_created(backend): + backend.gates["/b"] = gate = _Gate() + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client: + kept = client.keep_ephemeral("/a") + await kept.__aenter__() + async with anyio.create_task_group() as tasks: + + async def keep_another(): + async with client.keep_ephemeral("/b"): + pass + + tasks.start_soon(keep_another) + assert await anyio.to_thread.run_sync(gate.waiting.wait, 5) + # Leaving "/a" deletes it while "/b" is still being created; were it waiting for that, the bound would end + # the test. + try: + with anyio.fail_after(5): + await kept.__aexit__(None, None, None) + assert "/a" in backend.deleted + assert not gate.is_set() + finally: + gate.set() + + +@pytest.mark.anyio +async def test_a_cancelled_exit_of_a_kept_node_returns_while_another_is_being_created(backend): + backend.gates["/b"] = gate = _Gate() + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client: + kept = client.keep_ephemeral("/a") + await kept.__aenter__() + async with anyio.create_task_group() as tasks: + + async def keep_another(): + async with client.keep_ephemeral("/b"): + pass + + tasks.start_soon(keep_another) + assert await anyio.to_thread.run_sync(gate.waiting.wait, 5) + # Deleting "/a" waits for "/b" to be created; a cancelled exit leaves that to the worker thread. + try: + with anyio.fail_after(5): + async with anyio.create_task_group() as leaving: + leaving.start_soon(kept.__aexit__, None, None, None) + await anyio.wait_all_tasks_blocked() + leaving.cancel_scope.cancel() + assert not gate.is_set() + finally: + gate.set() + + while "/a" not in backend.deleted: + await anyio.sleep(0.01) + backend.created.clear() + backend.new_session() + await anyio.to_thread.run_sync(backend.recover) + + assert backend.created == [] + + +@pytest.mark.anyio +async def test_leaving_a_watch_does_not_wait_for_a_read_in_progress(backend): + recipe = SimpleNamespace( + _run_lock=threading.Lock(), _stopped=False, _session_watcher=None, _path="/a", _watcher=None + ) + backend.DataWatch = lambda path, changed: recipe + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client: + watch = client.watch("/a") + await watch.__aenter__() + # kazoo holds the lock of a recipe while it reads; it is held until the watch has been left. + recipe._run_lock.acquire() + try: + with anyio.fail_after(5): + await watch.__aexit__(None, None, None) + finally: + recipe._run_lock.release() + + assert recipe._stopped + + +@pytest.mark.anyio +async def test_a_cancelled_read_returns_without_waiting_for_the_server(backend): + backend.gates["/a"] = gate = _Gate() + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client: + try: + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + + async def read(): + await client.get("/a") + + tasks.start_soon(read) + assert await anyio.to_thread.run_sync(gate.waiting.wait, 5) + tasks.cancel_scope.cancel() + + # It returned while the server still had not answered. + assert not gate.is_set() + finally: + gate.set() + + +@pytest.mark.anyio +async def test_a_cancelled_update_returns_without_waiting_for_the_server(backend): + backend.gates["/a"] = gate = _Gate() + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client: + try: + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + + async def update(): + await client.update("/a", lambda data: b"x") + + tasks.start_soon(update) + assert await anyio.to_thread.run_sync(gate.waiting.wait, 5) + tasks.cancel_scope.cancel() + + # It returned while the server still had not answered. + assert not gate.is_set() + finally: + gate.set() + + +@pytest.mark.anyio +async def test_a_keeper_cancelled_while_creating_returns_at_once_and_keeps_nothing(backend): + backend.gates["/a"] = gate = _Gate() + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client: + try: + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + + async def keep(): + async with client.keep_ephemeral("/a"): + pytest.fail("the node was kept") + + tasks.start_soon(keep) + assert await anyio.to_thread.run_sync(gate.waiting.wait, 5) + tasks.cancel_scope.cancel() + + # It returned while the server still had not answered. + assert not gate.is_set() + finally: + gate.set() + backend.created.clear() + backend.new_session() + await anyio.to_thread.run_sync(backend.recover) + + assert backend.created == [] + + +class _FirstHeldLock: + """A lock that holds back the first thread to take it until ``go`` is set, then sets ``first_done`` as it leaves.""" + + def __init__(self): + self.go, self.first_done = threading.Event(), threading.Event() + self._lock = threading.Lock() + self._first = None + + def __enter__(self): + if self._first is None: + self._first = threading.get_ident() + assert self.go.wait(5) + self._lock.acquire() + + def __exit__(self, *exc_info): + self._lock.release() + if threading.get_ident() == self._first: + self.first_done.set() + + +@pytest.mark.anyio +async def test_a_keeper_cancelled_before_its_call_begins_never_creates_the_node(backend): + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client: + lock = _FirstHeldLock() + client._path_locked = lambda path: lock + with anyio.move_on_after(0.1): + async with client.keep_ephemeral("/a"): + pytest.fail("the node was kept") + + lock.go.set() + assert await anyio.to_thread.run_sync(lock.first_done.wait, 5) + + assert backend.created == [] + + +@pytest.mark.anyio +async def test_failures_to_keep_a_node_name_its_parent_only(backend, caplog): + path = "/root/providers/tri%3A%2F%2Fhost%3Ftoken%3Dsecret" + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client: + backend.failures[path] = 1 + with pytest.raises(ZookeeperError, match="/root/providers") as caught: + async with client.keep_ephemeral(path): + pytest.fail("the node was not created") + + async with client.keep_ephemeral(path): + backend.failures[path] = 1 + backend.new_session() + with caplog.at_level(logging.DEBUG, logger=kazoo.__name__): + await anyio.to_thread.run_sync(backend.recover) + + assert "secret" not in str(caught.value) + assert "/root/providers" in caplog.text + assert "secret" not in caplog.text + + +@pytest.mark.anyio +async def test_the_lock_of_a_path_is_dropped_once_no_keeper_uses_it(backend): + async with KazooZookeeperClient(URL.parse("zookeeper://zk")) as client: + for path in ("/a", "/b", "/a"): + async with client.keep_ephemeral(path): + pass + + assert client._path_locks == {} diff --git a/tests/unit/utils/test_async.py b/tests/unit/utils/test_async.py new file mode 100644 index 00000000..5e3b2611 --- /dev/null +++ b/tests/unit/utils/test_async.py @@ -0,0 +1,303 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +import functools +import itertools +import logging +from collections.abc import AsyncIterator +from contextlib import asynccontextmanager + +import anyio +import pytest + +from dubbo.utils import Latest, create_background_task_group, follow, release_scope, wait_then_cancel + +pytestmark = pytest.mark.anyio + + +async def test_tasks_that_finish_within_the_grace_are_not_cancelled() -> None: + task = asyncio.get_running_loop().create_task(asyncio.sleep(0.01, "done")) + + await wait_then_cancel({task}, 1) + + assert task.result() == "done" + + +async def test_tasks_still_running_after_the_grace_are_cancelled() -> None: + task = asyncio.get_running_loop().create_task(asyncio.sleep(10)) + + await wait_then_cancel({task}, 0.01) + + assert task.cancelled() + + +async def test_cancelling_the_wait_cancels_the_tasks_at_once_and_waits_for_them() -> None: + finished = [] + + async def handler() -> None: + try: + await asyncio.sleep(10) + finally: + await asyncio.sleep(0) + finished.append(True) + + task = asyncio.get_running_loop().create_task(handler()) + + with anyio.move_on_after(0.01): + await wait_then_cancel({task}, 10) + + assert task.cancelled() + assert finished == [True] + + +async def test_a_task_that_ignores_cancellation_is_logged_and_left_running(caplog: pytest.LogCaptureFixture) -> None: + release = asyncio.Event() + + async def stubborn() -> None: + try: + await asyncio.sleep(10) + except asyncio.CancelledError: + await release.wait() + + task = asyncio.get_running_loop().create_task(stubborn()) + await asyncio.sleep(0) + + with caplog.at_level(logging.WARNING): + await wait_then_cancel({task}, 0.01) + + assert not task.done() + assert "1 tasks kept running after being cancelled" in caplog.text + release.set() + await task + + +async def test_each_iteration_of_a_latest_starts_with_the_current_value_and_skips_older_ones() -> None: + latest: Latest[int] = Latest() + latest.publish(1) + first, second = aiter(latest), aiter(latest) + + assert await anext(first) == 1 + latest.publish(2) + latest.publish(3) + + assert await anext(first) == 3 + assert await anext(second) == 3 + + +async def test_closing_a_latest_ends_its_iterations_after_the_last_value() -> None: + latest: Latest[int] = Latest() + latest.publish(1) + latest.close() + latest.publish(2) + + assert [value async for value in latest] == [1] + + +async def test_closing_a_latest_ends_an_iteration_waiting_for_a_value() -> None: + latest: Latest[int] = Latest() + values: list[int] = [] + + async def read() -> None: + values.extend([value async for value in latest]) + + with anyio.fail_after(5): + async with anyio.create_task_group() as task_group: + task_group.start_soon(read) + await anyio.wait_all_tasks_blocked() + latest.close() + + assert values == [] + + +async def test_closing_a_latest_with_an_error_raises_it_from_its_iterations() -> None: + latest: Latest[int] = Latest() + values = aiter(latest) + latest.close(RuntimeError("ended")) + + with pytest.raises(RuntimeError, match="ended"): + await anext(values) + + +class _Subscriptions: + """Subscriptions that each fail, end, or yield their values and then wait, in turn.""" + + def __init__(self, *outcomes: Exception | list[int]) -> None: + self.outcomes = list(outcomes) + self.count = 0 + + @asynccontextmanager + async def subscribe(self) -> AsyncIterator[AsyncIterator[int]]: + outcome = self.outcomes[min(self.count, len(self.outcomes) - 1)] + self.count += 1 + if isinstance(outcome, Exception): + raise outcome + + async def values() -> AsyncIterator[int]: + for value in outcome: + yield value + if self.count >= len(self.outcomes): + await anyio.sleep_forever() + + yield values() + + +async def _follow(subscriptions: _Subscriptions, received: list[int], **options: bool) -> None: + async def receive(value: int) -> None: + received.append(value) + + async with anyio.create_task_group() as task_group: + await task_group.start(functools.partial(follow, subscriptions.subscribe, receive, "numbers", **options)) + with anyio.fail_after(5): + while len(received) < 2: + await anyio.sleep(0) + task_group.cancel_scope.cancel() + + +async def test_follow_subscribes_again_when_a_subscription_fails_or_ends(monkeypatch) -> None: + monkeypatch.setattr("dubbo.utils.async_.backoff", lambda: itertools.repeat(0)) + subscriptions = _Subscriptions([1], RuntimeError("down"), [], [2]) + received: list[int] = [] + + await _follow(subscriptions, received) + + assert received == [1, 2] + assert subscriptions.count == 4 + + +async def test_follow_raises_a_failure_before_the_first_value() -> None: + async def receive(value: int) -> None: + pass + + with pytest.raises(RuntimeError, match="down"): + await follow(_Subscriptions(RuntimeError("down")).subscribe, receive, "numbers") + + +async def test_follow_may_retry_a_failure_before_the_first_value(monkeypatch) -> None: + monkeypatch.setattr("dubbo.utils.async_.backoff", lambda: itertools.repeat(0)) + received: list[int] = [] + + await _follow(_Subscriptions(RuntimeError("down"), [1, 2]), received, retry_first=True) + + assert received == [1, 2] + + +@pytest.mark.anyio +async def test_a_background_task_group_raises_the_body_exception_as_it_is() -> None: + cancelled = [] + + async def serve() -> None: + try: + await anyio.sleep_forever() + finally: + cancelled.append(True) + + async def start() -> None: + async with create_background_task_group() as task_group: + task_group.start_soon(serve) + await anyio.sleep(0) + raise ConnectionRefusedError + + with pytest.raises(ConnectionRefusedError): + await start() + + assert cancelled == [True] + + +@pytest.mark.anyio +async def test_a_background_task_group_groups_the_exceptions_of_its_tasks() -> None: + async def fail() -> None: + raise ConnectionRefusedError + + with pytest.raises(ExceptionGroup) as raised: + async with create_background_task_group() as task_group: + task_group.start_soon(fail) + + assert raised.group_contains(ConnectionRefusedError) + + +@pytest.mark.anyio +async def test_a_background_task_group_raises_the_body_exception_with_those_of_failed_tasks() -> None: + async def fail_when_cancelled() -> None: + try: + await anyio.sleep_forever() + finally: + raise ConnectionResetError + + async def start() -> None: + async with create_background_task_group() as task_group: + task_group.start_soon(fail_when_cancelled) + await anyio.sleep(0) + raise ConnectionRefusedError + + with pytest.raises(ExceptionGroup) as raised: + await start() + + assert raised.group_contains(ConnectionRefusedError) + assert raised.group_contains(ConnectionResetError) + + +async def test_an_iteration_of_latest_reads_on_after_a_cancelled_wait() -> None: + latest: Latest[int] = Latest() + reader = aiter(latest) + + with anyio.move_on_after(0.01): + await anext(reader) + latest.publish(1) + + with anyio.fail_after(5): + assert await anext(reader) == 1 + + +async def test_a_release_runs_to_its_end_unless_its_caller_is_cancelled_meanwhile() -> None: + finished = [] + + with release_scope(5): + await anyio.sleep(0.01) + finished.append("graceful") + + # A graceful release stays cancellable; a shielded one would hold up the task group past the bound. + with anyio.fail_after(5): + async with anyio.create_task_group() as tasks: + + async def endless_release() -> None: + with release_scope(10): + await anyio.sleep_forever() + + tasks.start_soon(endless_release) + await anyio.wait_all_tasks_blocked() + tasks.cancel_scope.cancel() + + assert finished == ["graceful"] + + +async def test_a_cancelled_caller_gives_a_release_a_shielded_moment() -> None: + finished = [] + + with anyio.CancelScope() as caller: + caller.cancel() + try: + await anyio.sleep(1) + finally: + # The release outlives the cancellation, but not by much. + with release_scope(10): + await anyio.sleep(0.05) + finished.append("short") + with release_scope(10): + await anyio.sleep_forever() + + assert finished == ["short"] diff --git a/tests/unit/utils/test_converters.py b/tests/unit/utils/test_converters.py new file mode 100644 index 00000000..fc8cc6fc --- /dev/null +++ b/tests/unit/utils/test_converters.py @@ -0,0 +1,43 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + +from dubbo.utils.converters import comma_separated, milliseconds, to_milliseconds + + +@pytest.mark.parametrize(("text", "seconds"), [("1500", 1.5), ("0", 0.0)], ids=["fractional-seconds", "zero"]) +def test_milliseconds_converts_whole_milliseconds_to_seconds(text, seconds): + assert milliseconds(text) == seconds + + +@pytest.mark.parametrize("text", ["-1", "1.5", "fast"], ids=["negative", "fractional-milliseconds", "non-number"]) +def test_milliseconds_rejects_what_is_not_whole_milliseconds(text): + with pytest.raises(ValueError, match=f"must be whole milliseconds, not {text!r}"): + milliseconds(text) + + +@pytest.mark.parametrize(("text", "items"), [("a:1, b:2,", ("a:1", "b:2")), (" , ", ())], ids=["trimmed", "empty"]) +def test_comma_separated_drops_spaces_and_empty_items(text, items): + assert comma_separated(text) == items + + +@pytest.mark.parametrize( + ("seconds", "text"), [(3, "3000"), (0.0001, "1"), (1.0005, "1001")], ids=["whole", "sub-millisecond", "round-up"] +) +def test_to_milliseconds_rounds_up(seconds, text): + assert to_milliseconds(seconds) == text diff --git a/tests/unit/utils/test_dialer.py b/tests/unit/utils/test_dialer.py new file mode 100644 index 00000000..d576ff48 --- /dev/null +++ b/tests/unit/utils/test_dialer.py @@ -0,0 +1,177 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import anyio +import pytest + +import dubbo.utils.dialer as dialer_module +from dubbo.utils import Dialer + +pytestmark = pytest.mark.anyio + + +class _Peer: + """A peer whose attempts wait for ``answer`` and then succeed or fail as ``refuse`` says.""" + + def __init__(self) -> None: + self.attempts = 0 + self.refuse = False + self.answer = anyio.Event() + self.answer.set() + + async def connect(self) -> int: + self.attempts += 1 + await self.answer.wait() + if self.refuse: + raise ConnectionRefusedError(f"refused {self.attempts}") + return self.attempts + + +async def _until(condition) -> None: + with anyio.fail_after(5): + while not condition(): + await anyio.sleep(0.001) + + +async def test_waiters_share_one_attempt_that_outlives_those_that_stop_waiting() -> None: + peer = _Peer() + peer.answer = anyio.Event() + dialer = Dialer(peer.connect) + results = [] + + async def wait() -> None: + results.append(await dialer.connect()) + + with anyio.move_on_after(0.01): + await dialer.connect() + async with anyio.create_task_group() as task_group: + task_group.start_soon(wait) + task_group.start_soon(wait) + await anyio.wait_all_tasks_blocked() + peer.answer.set() + + assert (peer.attempts, results) == (1, [1, 1]) + assert dialer.connected + await dialer.aclose() + + +async def test_each_waiter_raises_its_own_copy_of_the_failure() -> None: + peer = _Peer() + peer.answer = anyio.Event() + peer.refuse = True + dialer = Dialer(peer.connect) + raised = [] + + async def wait() -> None: + try: + await dialer.connect() + except ConnectionRefusedError as error: + raised.append(error) + + async with anyio.create_task_group() as task_group: + task_group.start_soon(wait) + task_group.start_soon(wait) + await anyio.wait_all_tasks_blocked() + peer.answer.set() + + first, second = raised + assert first is not second + assert str(first) == str(second) == "refused 1" + await dialer.aclose() + + +async def test_a_dialer_is_connected_from_a_success_until_a_failure(monkeypatch) -> None: + monkeypatch.setattr(dialer_module, "backoff", lambda: iter([0.01] * 10)) + peer = _Peer() + peer.refuse = True + dialer = Dialer(peer.connect) + assert not dialer.connected + + dialer.start() + # Connects again in the background after each backoff. + await _until(lambda: peer.attempts >= 3) + assert not dialer.connected + + peer.refuse = False + await _until(lambda: dialer.connected) + await dialer.aclose() + assert not dialer.connected + + +async def test_a_lost_connection_is_not_connected_until_the_attempt_after_the_backoff_succeeds(monkeypatch) -> None: + monkeypatch.setattr(dialer_module, "backoff", lambda: iter([0.05] * 10)) + peer = _Peer() + dialer = Dialer(peer.connect) + assert await dialer.connect() == 1 + assert dialer.connected + + dialer.lost() + + assert not dialer.connected + assert peer.attempts == 1 + await _until(lambda: dialer.connected) + assert peer.attempts == 2 + await dialer.aclose() + + +async def test_a_loss_reported_while_an_attempt_runs_is_left_to_that_attempt() -> None: + peer = _Peer() + peer.answer = anyio.Event() + dialer = Dialer(peer.connect) + dialer.start() + await anyio.wait_all_tasks_blocked() + + dialer.lost() + + assert not dialer.connected + peer.answer.set() + assert await dialer.connect() == 1 + assert (peer.attempts, dialer.connected) == (1, True) + await dialer.aclose() + + +async def test_closing_cancels_the_attempt_and_the_retry_and_connects_no_more(monkeypatch) -> None: + monkeypatch.setattr(dialer_module, "backoff", lambda: iter([0.01] * 10)) + peer = _Peer() + peer.answer = anyio.Event() + dialer = Dialer(peer.connect) + dialer.start() + await anyio.wait_all_tasks_blocked() + + await dialer.aclose() + dialer.start() + dialer.lost() + await anyio.sleep(0.05) + + assert peer.attempts == 1 + assert await dialer.connect() is None + + +async def test_a_failure_that_cannot_be_copied_reaches_the_waiter_as_it_is() -> None: + class _Keyword(Exception): + def __init__(self, message: str, *, code: int) -> None: + super().__init__(message) + self.code = code + + async def connect() -> int: + raise _Keyword("refused", code=3) + + dialer = Dialer(connect) + + with pytest.raises(_Keyword, match="refused"): + await dialer.connect() + await dialer.aclose() diff --git a/tests/unit/utils/test_net.py b/tests/unit/utils/test_net.py new file mode 100644 index 00000000..6f6aedab --- /dev/null +++ b/tests/unit/utils/test_net.py @@ -0,0 +1,132 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import socket +from types import SimpleNamespace + +import psutil +import pytest + +from dubbo.utils.net import local_host, match_address + + +def _interfaces(monkeypatch, interfaces, host_name_address="127.0.1.1"): + """Make the machine have ``interfaces``, by name its state and addresses, and resolve its host name to ``host_name_address``.""" + monkeypatch.setattr( + psutil, + "net_if_addrs", + lambda: { + name: [SimpleNamespace(family=family, address=address) for family, address in addresses] + for name, (_, addresses) in interfaces.items() + }, + ) + monkeypatch.setattr( + psutil, "net_if_stats", lambda: {name: SimpleNamespace(isup=up) for name, (up, _) in interfaces.items()} + ) + monkeypatch.setattr(socket, "gethostbyname", lambda name: host_name_address) + + +def test_without_targets_the_local_host_is_a_private_ipv4_address_of_an_interface_that_is_up(monkeypatch) -> None: + _interfaces( + monkeypatch, + { + "lo": (True, [(socket.AF_INET, "127.0.0.1"), (socket.AF_INET6, "::1")]), + "eth0": (False, [(socket.AF_INET, "10.0.0.9")]), + "eth1": ( + True, + [(socket.AF_INET, "169.254.1.1"), (socket.AF_INET, "203.0.113.5"), (socket.AF_INET, "192.168.1.7")], + ), + }, + ) + + assert local_host([]) == "192.168.1.7" + + +@pytest.mark.parametrize( + ("addresses", "expected"), + [ + ([(socket.AF_INET6, "2001:db8::5"), (socket.AF_INET, "203.0.113.5")], "203.0.113.5"), + ([(socket.AF_INET6, "fe80::1"), (socket.AF_INET6, "2001:db8::5")], "2001:db8::5"), + ], + ids=["public-ipv4", "ipv6"], +) +def test_without_a_private_ipv4_address_an_ipv4_address_comes_before_an_ipv6_one( + monkeypatch, addresses, expected +) -> None: + _interfaces(monkeypatch, {"eth0": (True, addresses)}) + + assert local_host([]) == expected + + +@pytest.mark.parametrize(("host_name_address", "expected"), [("127.0.1.1", "127.0.0.1"), ("10.1.2.3", "10.1.2.3")]) +def test_without_an_interface_address_the_host_name_gives_an_address_that_is_not_a_loopback( + monkeypatch, host_name_address, expected +) -> None: + _interfaces(monkeypatch, {"lo": (True, [(socket.AF_INET, "127.0.0.1")])}, host_name_address) + + assert local_host([]) == expected + + +@pytest.mark.parametrize("loopback", ["127.0.0.1", "::1"]) +def test_the_local_host_is_the_address_that_reaches_the_target(loopback: str) -> None: + assert local_host([("unresolvable.invalid", 2181), (loopback, None)]) == loopback + + +@pytest.mark.parametrize( + ("pattern", "host", "port", "matches"), + [ + ("*", "10.0.0.1", 1, True), + ("10.0.0.1", "10.0.0.1", 1, True), + ("10.0.0.1:2", "10.0.0.1", 1, False), + ("10.0.*.1-5", "10.0.9.3", 1, True), + ("10.0.*.1-5", "10.0.9.6", 1, False), + ("10.0.0.0/8", "10.9.9.9", 1, True), + ("*.*.*.*:7", "10.0.0.1", 7, True), + ("[fe80::1]:7", "fe80::1", 7, True), + ("fe80:0:0:0:0:0:0:*", "fe80::abcd", 7, True), + ("fe80:0:0:0:0:0:0:1-f", "fe80::abcd", 7, False), + ], + ids=[ + "any-address", + "exact-ipv4", + "different-port", + "ipv4-range-matches", + "ipv4-range-misses", + "ipv4-cidr", + "wildcard-with-port", + "ipv6-with-port", + "ipv6-wildcard", + "ipv6-range-misses", + ], +) +def test_an_address_pattern_matches_by_ip_expression(pattern: str, host: str, port: int, matches: bool) -> None: + assert match_address(pattern, host, port) is matches + + +def test_an_ipv4_pattern_needs_four_parts() -> None: + with pytest.raises(ValueError, match="not an IPv4 pattern"): + match_address("10.0.*", "10.0.0.1", 1) + + +@pytest.mark.parametrize( + ("pattern", "host"), + [("10.0.0.x-1", "10.0.0.1"), ("1.2.3.4", "h")], + ids=["invalid-ipv4-range", "non-ip-host"], +) +def test_a_malformed_pattern_or_host_raises(pattern: str, host: str) -> None: + with pytest.raises(ValueError): # noqa: PT011 - the standard library words these + match_address(pattern, host, 1) diff --git a/tests/unit/utils/test_optional.py b/tests/unit/utils/test_optional.py new file mode 100644 index 00000000..4f70c9a0 --- /dev/null +++ b/tests/unit/utils/test_optional.py @@ -0,0 +1,53 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pytest + + +def test_optional_import_helper_preserves_transitive_import_failures(): + from dubbo.utils import require_optional_dependency + + failure = ModuleNotFoundError("missing transitive dependency", name="dependency_internal") + with ( + pytest.raises(ModuleNotFoundError, match="transitive") as caught, + require_optional_dependency("yaml", extra="yaml"), + ): + raise failure + assert caught.value is failure + + +@pytest.mark.parametrize("missing", ["google", "google.protobuf"]) +def test_optional_import_helper_reports_a_missing_parent_package(missing): + from dubbo.utils import require_optional_dependency + + with ( + pytest.raises(ModuleNotFoundError, match=r"apache-dubbo\[protobuf\]"), + require_optional_dependency("google.protobuf", extra="protobuf"), + ): + raise ModuleNotFoundError("missing", name=missing) + + +def test_optional_import_helper_does_not_mistake_a_sibling_for_a_parent(): + from dubbo.utils import require_optional_dependency + + failure = ModuleNotFoundError("missing", name="google.proto") + with ( + pytest.raises(ModuleNotFoundError, match="missing") as caught, + require_optional_dependency("google.protobuf", extra="protobuf"), + ): + raise failure + assert caught.value is failure diff --git a/uv.lock b/uv.lock new file mode 100644 index 00000000..b2dce665 --- /dev/null +++ b/uv.lock @@ -0,0 +1,2827 @@ +version = 1 +revision = 3 +requires-python = ">=3.11" +resolution-markers = [ + "python_full_version >= '3.14'", + "python_full_version >= '3.12' and python_full_version < '3.14'", + "python_full_version < '3.12'", +] + +[[package]] +name = "a2a-sdk" +version = "0.3.26" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "google-api-core" }, + { name = "httpx" }, + { name = "httpx-sse" }, + { name = "protobuf" }, + { name = "pydantic" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/be/97/a6840e01795b182ce751ca165430d46459927cde9bfab838087cbb24aef7/a2a_sdk-0.3.26.tar.gz", hash = "sha256:44068e2d037afbb07ab899267439e9bc7eaa7ac2af94f1e8b239933c993ad52d", size = 274598, upload-time = "2026-04-09T15:21:13.902Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/dd/d5/51f4ee1bf3b736add42a542d3c8a3fd3fa85f3d36c17972127defc46c26f/a2a_sdk-0.3.26-py3-none-any.whl", hash = "sha256:754e0573f6d33b225c1d8d51f640efa69cbbed7bdfb06ce9c3540ea9f58d4a91", size = 151016, upload-time = "2026-04-09T15:21:12.35Z" }, +] + +[[package]] +name = "aiofiles" +version = "25.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/41/c3/534eac40372d8ee36ef40df62ec129bee4fdb5ad9706e58a29be53b2c970/aiofiles-25.1.0.tar.gz", hash = "sha256:a8d728f0a29de45dc521f18f07297428d56992a742f0cd2701ba86e44d23d5b2", size = 46354, upload-time = "2025-10-09T20:51:04.358Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/bc/8a/340a1555ae33d7354dbca4faa54948d76d89a27ceef032c8c3bc661d003e/aiofiles-25.1.0-py3-none-any.whl", hash = "sha256:abe311e527c862958650f9438e859c1fa7568a141b22abcd015e120e86a85695", size = 14668, upload-time = "2025-10-09T20:51:03.174Z" }, +] + +[[package]] +name = "aiohappyeyeballs" +version = "2.7.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/ce/f4/eec0465c2f67b2664688d0240b3212d5196fd89e741df67ddb81f8d35658/aiohappyeyeballs-2.7.1.tar.gz", hash = "sha256:065665c041c42a5938ed220bdcd7230f22527fbec085e1853d2402c8a3615d9d", size = 24757, upload-time = "2026-07-01T17:11:55.501Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/71/43/1947f06babed6b3f1d7f38b0c767f52df66bfb2bc10b468c4a7de9eceff2/aiohappyeyeballs-2.7.1-py3-none-any.whl", hash = "sha256:9243213661e29250eb41368e5daa826fc017156c3b8a11440826b2e3ed376472", size = 15038, upload-time = "2026-07-01T17:11:54.055Z" }, +] + +[[package]] +name = "aiohttp" +version = "3.14.5" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "aiohappyeyeballs" }, + { name = "aiosignal" }, + { name = "attrs" }, + { name = "frozenlist" }, + { name = "multidict" }, + { name = "propcache" }, + { name = "typing-extensions", marker = "python_full_version < '3.13'" }, + { name = "yarl" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/6c/4c/bdccd81e9ee225b69c60e7766c9a5b05364f118f4d383713b89a682d772d/aiohttp-3.14.5.tar.gz", hash = "sha256:5558a7f5a05af9ecf744af91e5baefc436f93c9333e656c27ec253f9a6bbe178", size = 8078052, upload-time = "2026-10-11T01:05:12.408Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d8/f3/8997f18890a92c79f77fcfbb4f78ca17c2d4ab109e9eb6d31b4e9de194a0/aiohttp-3.14.5-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:d51db97c96384fbfcaf8f4c65922183a68b94f891c3c10c862ef5f6df2adbb1f", size = 832358, upload-time = "2026-10-11T00:59:42.195Z" }, + { url = "https://files.pythonhosted.org/packages/8e/42/084651e9efb5cadb99265f786df60f2a7b353cead7bfd2c87003cb4867ad/aiohttp-3.14.5-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:ae53924aa853a7a2ca20ed4142c7c6b56338e4d4cd999e2980075b9efc2e257a", size = 559636, upload-time = "2026-10-11T00:59:43.677Z" }, + { url = "https://files.pythonhosted.org/packages/3d/fe/92838944e601f0fe195fd3f3ada37e29fbee3d19bfd323fe15937ec79d36/aiohttp-3.14.5-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:a2c473a355f9239efcb72c92d5abfd8fcdb0cc78c8e9af607e72ca12dbb36593", size = 552588, upload-time = "2026-10-11T00:59:45.592Z" }, + { url = "https://files.pythonhosted.org/packages/8f/b8/dd9b95c5c20ceae1b47738e656bd79e9883e3117a9cc8b143901eb604e9a/aiohttp-3.14.5-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:32e8fa6644e541fcd7e02430588c7fc93b602c1778ea0bc345505db76b61cfb4", size = 1928224, upload-time = "2026-10-11T00:59:47.294Z" }, + { url = "https://files.pythonhosted.org/packages/c6/47/70010cd2ba8746968d53d433ff328c33f06a66c99da5f3de759c64a6b2eb/aiohttp-3.14.5-cp311-cp311-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:579f97d5120f2971876d2ddca2968135f6944d00c44c3a6590ad7d86ca9b403f", size = 1877674, upload-time = "2026-10-11T00:59:49.472Z" }, + { url = "https://files.pythonhosted.org/packages/c5/a1/b026f071dbd87f0bdba86b92d47e46f3899e3ad7143b6e0fe7e7887090b4/aiohttp-3.14.5-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:24409db442e2fb6e766bc7f3943851a8381dec3098140e43bb2e843b79e31b12", size = 1985850, upload-time = "2026-10-11T00:59:51.296Z" }, + { url = "https://files.pythonhosted.org/packages/36/d1/f7b6f6f8c3cb5a71b53baeddc2e70c224c28b12a23a55c42994c504019b7/aiohttp-3.14.5-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:5e8f97c0488ffda3082766ac0f2c8150a9a58c4d05788330e479cfd449b37939", size = 2105471, upload-time = "2026-10-11T00:59:53.191Z" }, + { url = "https://files.pythonhosted.org/packages/42/74/2a2b22953de15c6c8a80debf26db3047e4e8a5a5db6dd7c2c6c01eec0605/aiohttp-3.14.5-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:50a195903119008fe9cc68710535eb37f556ffffd6a7759afe70a2c145587045", size = 1929915, upload-time = "2026-10-11T00:59:55.609Z" }, + { url = "https://files.pythonhosted.org/packages/33/ad/f80e8d33933d0eacd0217efa3b7fb32c9f48ed480ed0db53cf9948bf474f/aiohttp-3.14.5-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:0133c3c3b54a0bf1e71fa5c1ad95c93f07fd54e24ef1fe182f5122e1573d2bf1", size = 1773832, upload-time = "2026-10-11T00:59:57.611Z" }, + { url = "https://files.pythonhosted.org/packages/04/a4/0273d239f3e3bb69438f209c64c82e1f98dc60d5db264795e41f7dd05dcb/aiohttp-3.14.5-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:c172db893e516e1358e65a95ee20b7ce7173963eefe318b6ab2a2220688b999e", size = 1901001, upload-time = "2026-10-11T01:00:00.605Z" }, + { url = "https://files.pythonhosted.org/packages/16/ed/7dd439d26c654645bc34ca3c9a822fc11c1c51801fed1cefdfe1cc41c1f6/aiohttp-3.14.5-cp311-cp311-musllinux_1_2_armv7l.whl", hash = "sha256:f2a7966bda23dd85051f1661ce0ace38d6890e05ec6c357ecae9d2479cba377e", size = 1907218, upload-time = "2026-10-11T01:00:02.699Z" }, + { url = "https://files.pythonhosted.org/packages/32/dd/86249c3b8248562a17fd3e22ee0c164378d65766f01aceef62cf52783710/aiohttp-3.14.5-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:4887d130a7bbfed3a85493bb5a25e5b5b558d40c1d986dd16970d2bb26d63793", size = 1958650, upload-time = "2026-10-11T01:00:04.851Z" }, + { url = "https://files.pythonhosted.org/packages/bc/0b/ca4d53d68f683ce195807fd0aeb063bf6d1c6b39343fff234c9524e8d5a9/aiohttp-3.14.5-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:225c579c23b68b343cccea27a7e06e3bd8ec23a09c30b427eb3f1e4ca6239b20", size = 1760057, upload-time = "2026-10-11T01:00:06.978Z" }, + { url = "https://files.pythonhosted.org/packages/6b/42/005437ffd7fa56c2ce3347add40404b654a32754ce91f2e2a14b9e5ab2bc/aiohttp-3.14.5-cp311-cp311-musllinux_1_2_s390x.whl", hash = "sha256:ab52d8f1fc1b64821c1fbad64a647ed6203627004059a6d1ed4f0858a1499703", size = 1978081, upload-time = "2026-10-11T01:00:08.868Z" }, + { url = "https://files.pythonhosted.org/packages/03/71/3a5b66fe1b7b23d3c6524350817ed55de5feb7fbb4cccba7cbe044d118dd/aiohttp-3.14.5-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:cb131d775a1573c1aee66656bd78b023577bbdb6cb8349a07773bd4f73e68a6e", size = 1922954, upload-time = "2026-10-11T01:00:11.035Z" }, + { url = "https://files.pythonhosted.org/packages/69/84/d08a554f281d42fd7c6b2b6dd7738f3e3a7a9f657ddd87e11ca2091cdfe3/aiohttp-3.14.5-cp311-cp311-win32.whl", hash = "sha256:e87046c8ff77a8decdb6a41d8ab25824b47531b2da933aeab0c1e21c7acff329", size = 488101, upload-time = "2026-10-11T01:00:12.933Z" }, + { url = "https://files.pythonhosted.org/packages/0f/15/52b5e65f02b33686ae49f1518548ae4f5a7adaf31d9d3c54fa12a143137b/aiohttp-3.14.5-cp311-cp311-win_amd64.whl", hash = "sha256:6f275c11d1aa6d4c458e05a68be084efe3c55a113d99e3f46a318098e52948fc", size = 512575, upload-time = "2026-10-11T01:00:14.743Z" }, + { url = "https://files.pythonhosted.org/packages/b0/b9/bb75012635f3defb0f7cbb7c4ae391e36bb9cb3fbdca3b9944e2ebebf743/aiohttp-3.14.5-cp311-cp311-win_arm64.whl", hash = "sha256:b032a0023eb41d768ce77d83210ab2a3c389bc0b09313273c7e1eca48c10a755", size = 493179, upload-time = "2026-10-11T01:00:16.961Z" }, + { url = "https://files.pythonhosted.org/packages/d5/94/6ba86efddcb616c811b40e6a0dfdd862738f647e4e3860a961075d5e9ed8/aiohttp-3.14.5-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:df37b620684e19b5e25724412518ccafc3b1a49cdac706fdbd2f983fad943450", size = 817499, upload-time = "2026-10-11T01:00:18.901Z" }, + { url = "https://files.pythonhosted.org/packages/5e/e1/7bca6d84dabd228aa8eb4b7f9feac2586aaa9be5505d7d65bf287a615c43/aiohttp-3.14.5-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:ef60869969180ec2464f1349aff07138ae35ca2200f0946cb3552e49e8f301a8", size = 549467, upload-time = "2026-10-11T01:00:20.854Z" }, + { url = "https://files.pythonhosted.org/packages/64/91/11b89f45ca486252dd67dd5f3231fec04bf5518da39a95cb3997619f17fb/aiohttp-3.14.5-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:d079c0a0135c36e7beb6f1c88087c8f108dc5891cdd0b5eafa778421bda70ed2", size = 548067, upload-time = "2026-10-11T01:00:22.659Z" }, + { url = "https://files.pythonhosted.org/packages/22/ff/c6615806c14aab34f82b9424ccde8ce6e417315fd57ce1c5b4d4747888e1/aiohttp-3.14.5-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:abfda5cb094a829f7bc25216a32f7db2e85cc65bd59910f8e7b40b3d9b224764", size = 1896245, upload-time = "2026-10-11T01:00:24.638Z" }, + { url = "https://files.pythonhosted.org/packages/39/b2/25a8c971ae6a92c8394d77e42422d7f38989e05cf41a5ceb92d73d67ab7e/aiohttp-3.14.5-cp312-cp312-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:9cc882cf8619109583c906b4d4a85d6a111a98afa34b7a450d1e08118d016820", size = 1872180, upload-time = "2026-10-11T01:00:26.838Z" }, + { url = "https://files.pythonhosted.org/packages/2f/d5/99f93ea36cc5205e47c1e5a803e087f2ad21b5430b5db2e942cb6e988a37/aiohttp-3.14.5-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:7457580535e019e1247ea35d6a02bf081ad30c26d0cbc210c93f6c3ab67a0835", size = 1937261, upload-time = "2026-10-11T01:00:28.74Z" }, + { url = "https://files.pythonhosted.org/packages/40/a6/9ac9c9e6695040bd73d2584a1b59a9388f6433c76d5294a7bf591e21ffe5/aiohttp-3.14.5-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:c5ed596aedb9c42afd3fe0aae3117725378ac73d2cc5ddc735056fbdb96c5d02", size = 2064994, upload-time = "2026-10-11T01:00:30.623Z" }, + { url = "https://files.pythonhosted.org/packages/da/e4/aa172eb534b7f02f1f8ff1c3213347eaf3cf218db91a727c6863c22f1035/aiohttp-3.14.5-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:20f085697d7e911f1f73c43ed03fafbed1e7121797e2eb5428efa80398060584", size = 1919630, upload-time = "2026-10-11T01:00:32.548Z" }, + { url = "https://files.pythonhosted.org/packages/06/7d/4eedafc5bababa8932636c141e346806966eade12c0b7e5946d43bf8218b/aiohttp-3.14.5-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:74b0a9c8270f9b0a11410e124ff8d4f18bfc1f1837440ec84da5ae7b50927b5d", size = 1710016, upload-time = "2026-10-11T01:00:34.471Z" }, + { url = "https://files.pythonhosted.org/packages/b2/94/eee018537ba19da0ceb2ac79cab83faed4ac49568e08376e2799043f2538/aiohttp-3.14.5-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:19e2ba471507c34f8252402ab50f5ab512398b9ea8c8f1cb26beb3f75793ba30", size = 1858112, upload-time = "2026-10-11T01:00:36.581Z" }, + { url = "https://files.pythonhosted.org/packages/68/76/354653a306547238f3427283905972d796ba7c292ba9977abec9f2b6f260/aiohttp-3.14.5-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:d418ce2af40c6bb685b3f663e9e8de27cb0a22431d8e88a167348d7f01878073", size = 1896371, upload-time = "2026-10-11T01:00:38.478Z" }, + { url = "https://files.pythonhosted.org/packages/f2/ec/63e8c7136b570e356345ad3174e3820fdc973ea10712cb6c649bf875755a/aiohttp-3.14.5-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:70cb4008ac2ed1e0ca9e824deb4b53d3aa0d939109698ebf1e723a84337bd794", size = 1905836, upload-time = "2026-10-11T01:00:40.527Z" }, + { url = "https://files.pythonhosted.org/packages/57/d8/11365bda144b127928cd42533d0eff78a55613c9e28f81941bd6630ea887/aiohttp-3.14.5-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:a23fe35d776bc03cb495938b9594450d047e3bc08c5255315a82323e9cb7d2dd", size = 1696534, upload-time = "2026-10-11T01:00:42.686Z" }, + { url = "https://files.pythonhosted.org/packages/2f/3d/82df0461b18e00b2998f205c03e0d3010222478c43640aceb8e03dcd7e8f/aiohttp-3.14.5-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:3e0eb43bed3c6801a6cee315195377789e90b2a72c2277a475b578535312488d", size = 1933970, upload-time = "2026-10-11T01:00:44.71Z" }, + { url = "https://files.pythonhosted.org/packages/03/ad/6ddfe0aacd931c17b53533336d97e9d11a98b96d6ae815a9da0b19f82ccf/aiohttp-3.14.5-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:3be7dd397d64ca3e1869626fa9318aaebb54b7bf93bc72d7a205448d83e4f748", size = 1899501, upload-time = "2026-10-11T01:00:46.629Z" }, + { url = "https://files.pythonhosted.org/packages/9e/8e/189bdd9ae4793059bb09f6dc880f211a6c6c7859cebcbf33912dbfab7dd7/aiohttp-3.14.5-cp312-cp312-win32.whl", hash = "sha256:eb324e2009fb54db30a071dad7caf6998ee2879c4704007efb244514dad1fec1", size = 480370, upload-time = "2026-10-11T01:00:48.468Z" }, + { url = "https://files.pythonhosted.org/packages/ae/ce/1f08114679d49655b30a6e0a29858375c94b82c1de1a0bd0a20c2fee8b02/aiohttp-3.14.5-cp312-cp312-win_amd64.whl", hash = "sha256:2cc38a4f2b516bef1714e690df87a0e043faf1a7693c82d860091684453d5111", size = 506141, upload-time = "2026-10-11T01:00:50.272Z" }, + { url = "https://files.pythonhosted.org/packages/79/d4/c7b4f60b16a1b7e43249fa9031ae05e7e8c341ba4b7d1866f914dafeaa0e/aiohttp-3.14.5-cp312-cp312-win_arm64.whl", hash = "sha256:a63afd1f757de949028387e65a7127b61ad0f775432dbb0e62816ae619fe69ac", size = 488108, upload-time = "2026-10-11T01:00:52.321Z" }, + { url = "https://files.pythonhosted.org/packages/d3/e1/2841e020ebb7aefae5513586193e011e06313d9a6bdbd296622afbbce204/aiohttp-3.14.5-cp313-cp313-android_24_arm64_v8a.whl", hash = "sha256:9ad7e6aa38c20da1be697874349c4c273c8a03b7887169665081706398d0439a", size = 538932, upload-time = "2026-10-11T01:00:54.3Z" }, + { url = "https://files.pythonhosted.org/packages/f7/a6/7fb8ea8fe96bcc7b7c7a36d10f021d99d01a8dc8a4b3f0ddacecfad9a80e/aiohttp-3.14.5-cp313-cp313-android_24_x86_64.whl", hash = "sha256:f59c7673465908cbe506117176156c127f29f917677afceada34957179221d91", size = 553329, upload-time = "2026-10-11T01:00:56.442Z" }, + { url = "https://files.pythonhosted.org/packages/de/64/d056e3c27647dc25af1a592cf356245382ea7c808171b9dac7677afedfc8/aiohttp-3.14.5-cp313-cp313-ios_13_0_arm64_iphoneos.whl", hash = "sha256:1b5416552740edf07234cc9437d0706f2acb67b93c198670b1a68e1b2b587dec", size = 521367, upload-time = "2026-10-11T01:00:58.345Z" }, + { url = "https://files.pythonhosted.org/packages/3e/e4/95226147e11d4db916fd1d495dcf85af8e3816e38333e42718241196e848/aiohttp-3.14.5-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:43351bdb5e4c3cb7d1772368e988534e869a74db7778079a83782c11c69535c7", size = 528322, upload-time = "2026-10-11T01:01:00.211Z" }, + { url = "https://files.pythonhosted.org/packages/17/cd/1d3c9192cafdb51cad62b2d3ded96cff9cc8af51893210aadd448a325389/aiohttp-3.14.5-cp313-cp313-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:c8c4478bef6d57fcfda15dae461ea3c9f06aa7b257c58df3f2300174ccbb185a", size = 539874, upload-time = "2026-10-11T01:01:02.06Z" }, + { url = "https://files.pythonhosted.org/packages/f6/0c/dfa33aecc7d4d1dc75e05248f5eac5a0edf4d09e7b44d93ab62529b0c1db/aiohttp-3.14.5-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:c2c30484dd1417ef98b51021ffa2cc0d7f3c78918adaaaab7e70817335ab3e02", size = 813836, upload-time = "2026-10-11T01:01:04.01Z" }, + { url = "https://files.pythonhosted.org/packages/33/17/4a63738052d20567d55529d6daa1b9480d906fd52930fbcf6d3fbed618f0/aiohttp-3.14.5-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:dab9ac5a67c8d1f070c00fa8fccb7cbd1b8dcc1a8d6b42f37540df9b3d4cc603", size = 548070, upload-time = "2026-10-11T01:01:06.035Z" }, + { url = "https://files.pythonhosted.org/packages/15/e5/b57e58695a757fd4c02497c033fced96a69c631b13866c43d336530c9670/aiohttp-3.14.5-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:e1cc2bfaee8c214f06080a7c7d5772419b8a1108e8e5349236189811823fb02a", size = 545786, upload-time = "2026-10-11T01:01:07.817Z" }, + { url = "https://files.pythonhosted.org/packages/9a/68/8c2c67a3aedf46e00f3c42f04fbc6983de80d4ed5786151e33681ba45883/aiohttp-3.14.5-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:74efb69332b85675b1eabd760a8cfc2e2cf42c60607c66f88014c1bdfb40942d", size = 1886492, upload-time = "2026-10-11T01:01:09.834Z" }, + { url = "https://files.pythonhosted.org/packages/ab/4b/74aab5e8d28c62e8f795b4fe8f38cf5586fd264a9a27bd2141ef6490333d/aiohttp-3.14.5-cp313-cp313-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:42b5e616946dbaf505e2bff18c9af2cd4ef9e7ef300ee58a6e951a5b7cf147ae", size = 1870057, upload-time = "2026-10-11T01:01:12.045Z" }, + { url = "https://files.pythonhosted.org/packages/a8/f7/eafc3b1988302b1815d9fd4a21071be5c360d616c0a430d02fd92dc97688/aiohttp-3.14.5-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:f9033b43f511f27547c557dcaba0177649e10a3725336ccd2cce0fdc1dc4850d", size = 1925119, upload-time = "2026-10-11T01:01:14.09Z" }, + { url = "https://files.pythonhosted.org/packages/a1/04/78d8f294f74dd570f3898ff20402349fce524176045df98ba727d6846a68/aiohttp-3.14.5-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:15a310d3c71398e3d7bfc93a1a73fbe664315cd9e9016b8efc1cff85eeab7155", size = 2053137, upload-time = "2026-10-11T01:01:16.344Z" }, + { url = "https://files.pythonhosted.org/packages/32/51/395d225ef36f5a50d8e548dcd3141bfdbcd31fb6eed859022c573d2c4d66/aiohttp-3.14.5-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1ffa3a523a36d8628f98c06492ae16a31a23d14c0b4ec721757b477319f656d6", size = 1911038, upload-time = "2026-10-11T01:01:18.653Z" }, + { url = "https://files.pythonhosted.org/packages/ff/a4/2aec1aa06d82e8a244843b5dae31d78061e5e76744270a86dd0ee051c889/aiohttp-3.14.5-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:5fb6a6e919bfb703227bc1ce6579281b84b1a2ba57deb9794dfdbec7dcd1e40c", size = 1702205, upload-time = "2026-10-11T01:01:20.904Z" }, + { url = "https://files.pythonhosted.org/packages/16/27/6051bfde7b6f418f70edd60d655fa426abb3355fa0981764739d87ecf160/aiohttp-3.14.5-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:43e1b7994a8b038125f722bff07492ef501110722c2727c408995d9fb864c421", size = 1848588, upload-time = "2026-10-11T01:01:22.918Z" }, + { url = "https://files.pythonhosted.org/packages/9e/44/55efc06fc26c4e6e1c095f231b4c222bf2d86d64a8eebbc24b2bb5958ea8/aiohttp-3.14.5-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:5f3e96071686755d9cd3600c3880183eb94b012178e92746d68101800f0ed8a3", size = 1887540, upload-time = "2026-10-11T01:01:25.278Z" }, + { url = "https://files.pythonhosted.org/packages/48/dc/1502bfdc2a65760d386ac6a00090b0addaa8a3c9c60b3f8127fad3a9afb2/aiohttp-3.14.5-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:cd88b01f3d37b7a2a34f91d98f14720206f1ea3d540843fab2d649dd5fb91fec", size = 1895030, upload-time = "2026-10-11T01:01:27.316Z" }, + { url = "https://files.pythonhosted.org/packages/93/7e/44174bb6288264418c9eec07a5e35180969c0d5a796c7af544db3cb8a33a/aiohttp-3.14.5-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:f2ed8b64dc0c651c0f5a9c926777719770021251b8f336d97c4b80b660836ce1", size = 1693244, upload-time = "2026-10-11T01:01:29.39Z" }, + { url = "https://files.pythonhosted.org/packages/47/dd/b507d64e50db23888582fff08eda13998b12f9dea70c072edaac19218380/aiohttp-3.14.5-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:a9918e58faf62ba2c7147927d06057aec78f42475aff5048047ec47e7265a600", size = 1926308, upload-time = "2026-10-11T01:01:31.634Z" }, + { url = "https://files.pythonhosted.org/packages/98/4b/5b51b4f63e3f2793151f4aea49c48fe1e00baeb7cec9c7a206de499f8de0/aiohttp-3.14.5-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:42f320d4a5b00b9af0bddcfec5407dc6f2d9816f006b2f79ebbaa31f16895df3", size = 1888406, upload-time = "2026-10-11T01:01:33.715Z" }, + { url = "https://files.pythonhosted.org/packages/ff/13/d5e818a5eaba9f822016727299f41c0e1075799f82a6433ec508a93ab867/aiohttp-3.14.5-cp313-cp313-win32.whl", hash = "sha256:3ae800a20947e2c2e53088047d021e6bf7d51560cc49f6a0737a1f79d2e3a13c", size = 479970, upload-time = "2026-10-11T01:01:35.677Z" }, + { url = "https://files.pythonhosted.org/packages/8d/d0/8eca2c65aa467320990d78fb2005f38ed3588944280c39ff9deb6423fef1/aiohttp-3.14.5-cp313-cp313-win_amd64.whl", hash = "sha256:d05e94cdfe0d15d0206f970722d2554780ce562787b21b218b275447f8751319", size = 505985, upload-time = "2026-10-11T01:01:37.574Z" }, + { url = "https://files.pythonhosted.org/packages/7a/f8/4cdd65305d2fca14b886bea9ed2abb1fe726287872524e56e3d26692b47d/aiohttp-3.14.5-cp313-cp313-win_arm64.whl", hash = "sha256:f001b571ead90ca1770f1e616db255351a1703317f20374c361ef22f12c06d09", size = 487629, upload-time = "2026-10-11T01:01:39.477Z" }, + { url = "https://files.pythonhosted.org/packages/43/be/3184a1d34a8be665569eadb7e9e764b4629e4f3413e241cb2e4d6fecf3b3/aiohttp-3.14.5-cp314-cp314-android_24_arm64_v8a.whl", hash = "sha256:939042d5cda21d41a6f512e7cc8b8e33a2aebff863352251da495fbd91b673b5", size = 540673, upload-time = "2026-10-11T01:01:41.354Z" }, + { url = "https://files.pythonhosted.org/packages/60/2a/d35f3ba4cf157b072e3b674bf9983047ca5ea5173c995d32d877e1191d36/aiohttp-3.14.5-cp314-cp314-android_24_x86_64.whl", hash = "sha256:6da32b5ff3fd78d244e37300463434c7145162bfd2b6e9e915ab164da37f7343", size = 554087, upload-time = "2026-10-11T01:01:43.719Z" }, + { url = "https://files.pythonhosted.org/packages/fc/d2/61a33880ca4eaca95a9c60ca3f6beed15555af1028652dfaac601627787b/aiohttp-3.14.5-cp314-cp314-ios_13_0_arm64_iphoneos.whl", hash = "sha256:1b438b73c38111818d0c9d6a5c2bfed8584c8e503a49ef085d70e874ec846738", size = 522613, upload-time = "2026-10-11T01:01:46.154Z" }, + { url = "https://files.pythonhosted.org/packages/31/1d/de579b299d2225dc2c6fd99d579d91f16c02a913fb5af9a3cf2fe9bd88ba/aiohttp-3.14.5-cp314-cp314-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:755933b107ea7a6a9ac916f635a70595a5b1a32fac10a8ff0b9f2ab88555550c", size = 529682, upload-time = "2026-10-11T01:01:48.477Z" }, + { url = "https://files.pythonhosted.org/packages/f4/4a/ddb923564e15e053b6e060b0036e1694dcadcb13aa476c5a87dcad20e336/aiohttp-3.14.5-cp314-cp314-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:b3cc509327c7b27f6f4727a8830f4004f6df7766e179f2f4b8e54e65c0bec5d3", size = 540120, upload-time = "2026-10-11T01:01:50.474Z" }, + { url = "https://files.pythonhosted.org/packages/3d/36/a640fbecaa53727a5900b892bdbe17b5f3e8cc88903e22864fe41b654def/aiohttp-3.14.5-cp314-cp314-macosx_10_15_universal2.whl", hash = "sha256:7bd8ac754ebd6733a3e2a0dd1674c4d8ab086196803fd8dcd776f07b4e2607d9", size = 818795, upload-time = "2026-10-11T01:01:52.665Z" }, + { url = "https://files.pythonhosted.org/packages/ef/b6/d52ca608859e271b5fa7944074802dc45f60e52c318a4ddc34edbf73586e/aiohttp-3.14.5-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:e724a7b6091f0b1ac064f9d1b15ff9ec52e6033a86cdae649e5f086e32a3c0db", size = 549667, upload-time = "2026-10-11T01:01:54.65Z" }, + { url = "https://files.pythonhosted.org/packages/ce/b5/05b8ac39a76ff4bca89f42a4c2471560c71f894ff6e4bc16158c951874e3/aiohttp-3.14.5-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:c32e26310cc10e547f53cd13d39a369034f69dcb7d749d5cb0e5f67bc196b6ba", size = 548922, upload-time = "2026-10-11T01:01:56.547Z" }, + { url = "https://files.pythonhosted.org/packages/19/b0/5aa186d56ce2334dabe29b70bd99dc8ae926ee44184c0de64a53d415a4f3/aiohttp-3.14.5-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1eb8167961ec4dfcc8cb9dd50bd0ee72519f7ef496be95203e49e27b01618382", size = 1882422, upload-time = "2026-10-11T01:01:59.258Z" }, + { url = "https://files.pythonhosted.org/packages/db/f7/7d5c91bb9620db300c8ddb05337a9014301acb626223faff3abcb8ea47d7/aiohttp-3.14.5-cp314-cp314-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:c1d60eafd9c7e8e74abd03a5b00df44e7febfe6d9b89b559c0a6551eef0699d4", size = 1843621, upload-time = "2026-10-11T01:02:01.417Z" }, + { url = "https://files.pythonhosted.org/packages/30/0a/b208953b96d8f24b75f6da704f508e6c5cf3022f52b60c61933df082e89c/aiohttp-3.14.5-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:137351bf20bbed9a65e839f4a4452ac377389bdb2f2857d2acffef38f5e9f2d1", size = 1927915, upload-time = "2026-10-11T01:02:03.697Z" }, + { url = "https://files.pythonhosted.org/packages/f6/79/90ebcccb55e2d1e11a1fed581d83bb966e38fb35fb4b2577fdc980f8707a/aiohttp-3.14.5-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:fba47bc2c3d7303c3d027c6cf4d07626c37b1314ac81f5820c31032e0ca1f677", size = 2036339, upload-time = "2026-10-11T01:02:06.046Z" }, + { url = "https://files.pythonhosted.org/packages/a6/66/55a8904b3a129fafdf94f9cc0a2e4ca09a3c914650be52355db7ad0bbdb6/aiohttp-3.14.5-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:94684b879ac1d71e4238850c99b62dc1b28d9086b156a2555f082010b85a865c", size = 1888041, upload-time = "2026-10-11T01:02:08.384Z" }, + { url = "https://files.pythonhosted.org/packages/0b/b8/96b25da7329a52e42c812b1e8b076386039ec4fc312afa043d173d8147fc/aiohttp-3.14.5-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:56572c42e3ecd636de8d2c3dd54cf5fc939cb5c32eb56297f176a0d366fac622", size = 1703849, upload-time = "2026-10-11T01:02:10.903Z" }, + { url = "https://files.pythonhosted.org/packages/1b/43/fbf976e3ae4c038d6f5c84945ab2150298c2d71201674d4e53d158063e75/aiohttp-3.14.5-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:a95529a92a446db351675f4aab518feaf5e99842f63f5dd17160c2b74f382db3", size = 1849703, upload-time = "2026-10-11T01:02:13.15Z" }, + { url = "https://files.pythonhosted.org/packages/8b/7d/218e912f4c1d89bde7ac551409be57ad2f6121638e56942d395a7cb1fa58/aiohttp-3.14.5-cp314-cp314-musllinux_1_2_armv7l.whl", hash = "sha256:3edbece0379b8b4aaa67619b8aa2399bb66fce372cd5911098a434ea77220aa0", size = 1852695, upload-time = "2026-10-11T01:02:15.295Z" }, + { url = "https://files.pythonhosted.org/packages/5a/42/252a1b9287e3b6e393a1c3bd1776f36af30f5f25f071bbf2b0cb7eba9116/aiohttp-3.14.5-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:56d9828f204331a5ca8850fcfe2bcce95a149f1f223f60cc7216e5524978e480", size = 1893493, upload-time = "2026-10-11T01:02:17.93Z" }, + { url = "https://files.pythonhosted.org/packages/78/97/71cae83d5100556fad1521684f7cd1e3e578432644f850245ed3bd969310/aiohttp-3.14.5-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:20064a177a070d789ee64a50b01a9161d3468e989baacfc6c714aa685c4b332f", size = 1693468, upload-time = "2026-10-11T01:02:20.666Z" }, + { url = "https://files.pythonhosted.org/packages/1f/69/73d88e97a8b5f0ca7a946d0011c0de99fb188b1687c7948ecd0553dc5bf0/aiohttp-3.14.5-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:81c2b3dfd56c62bee6108e4852d5970b4cf9086390b6983f52b666e878c1f115", size = 1915398, upload-time = "2026-10-11T01:02:23.011Z" }, + { url = "https://files.pythonhosted.org/packages/05/f0/881644bcb15d4b258daea9b720a0af9dc4330496cc8d6ade9090cdd0cffc/aiohttp-3.14.5-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:09ec102b4b8c9a920275733bbc11fdbb615efe6f9231a06007c0218d336fb77a", size = 1871470, upload-time = "2026-10-11T01:02:25.278Z" }, + { url = "https://files.pythonhosted.org/packages/7f/de/19d9ebbcce5aedaa3242d8a99ff8816a60bdb7629fb0084bf4a45bfd1f62/aiohttp-3.14.5-cp314-cp314-win32.whl", hash = "sha256:9c428eb2bd8817588d16a0ab898aa4eb5d141f896aa2b394cc79a4cf61d9a8e2", size = 485517, upload-time = "2026-10-11T01:02:27.579Z" }, + { url = "https://files.pythonhosted.org/packages/a9/74/8cdaf0e58c2588371670d5a9a8215bbb971d36940b6e5d051967dd05c07d/aiohttp-3.14.5-cp314-cp314-win_amd64.whl", hash = "sha256:6f967dde489ca6a8c02d093ab245d2cbf50ccb5c36adf0188b17b0ca39d24b67", size = 511755, upload-time = "2026-10-11T01:02:29.685Z" }, + { url = "https://files.pythonhosted.org/packages/1a/6b/e0100e25502430a531c7cf1482a378d0b65bf728ab60c01ee270e56bc469/aiohttp-3.14.5-cp314-cp314-win_arm64.whl", hash = "sha256:1d2d981b53dd09a319e3570ef8cc3bbc3ef86f5a7abef0f6b2bff3867db3a9e7", size = 495151, upload-time = "2026-10-11T01:02:32.163Z" }, + { url = "https://files.pythonhosted.org/packages/9d/c2/ca2ead7b655688c53c03aeeb6e96e6851c9ff08d6be7b13802f53a6ae8fd/aiohttp-3.14.5-cp314-cp314t-macosx_10_15_universal2.whl", hash = "sha256:9ce66feae6ac65327379460380549bf1b8df8e17c4e25df2a2bcf168272e3bed", size = 855396, upload-time = "2026-10-11T01:02:34.443Z" }, + { url = "https://files.pythonhosted.org/packages/a7/70/22206fea409255a240c926ce11de48de354ae2bb90ca44f709c05497585d/aiohttp-3.14.5-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:27c2322e03f66101acb09869ce1cf1efc04994ee95e1735b69827bf8c8b9d781", size = 567734, upload-time = "2026-10-11T01:02:36.644Z" }, + { url = "https://files.pythonhosted.org/packages/ce/e5/79a36c118308b56f8667d67e05d2fb6dc638ab45985704cdb199631bedaa/aiohttp-3.14.5-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:ff75a7537413a86e7cafe98e0e1d6e3dc4b15c6349896e7d5c6b881bfdb6d550", size = 567379, upload-time = "2026-10-11T01:02:38.757Z" }, + { url = "https://files.pythonhosted.org/packages/63/a3/2ebec7dece3b1f02c30d2e484647f6f7b13952b1bb40a4cb285b849e8432/aiohttp-3.14.5-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9c061aa954daaf57d2a4b8374f9fca621ef0e1b603584431c220c22458c59b6d", size = 2050686, upload-time = "2026-10-11T01:02:41.169Z" }, + { url = "https://files.pythonhosted.org/packages/3a/d2/7e4d093db2f4450482652e7ef19a9e19919028f5135aa52bc4078c3beb80/aiohttp-3.14.5-cp314-cp314t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:1612fa5857b37bf32e5c1eaeefb96e3b01e9c70679eec81f0934e8a600080863", size = 1915077, upload-time = "2026-10-11T01:02:43.563Z" }, + { url = "https://files.pythonhosted.org/packages/a6/88/bd40d09958442a0a1df67da81de496361d6e2afc04f9db2950d835da750b/aiohttp-3.14.5-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:adbeee7d6fd4cf5fe0aece2fb3edc4243615d3180430ba8149d01a90670cac99", size = 2027204, upload-time = "2026-10-11T01:02:46.185Z" }, + { url = "https://files.pythonhosted.org/packages/63/eb/3a601c1f8d3103c1a60ea981f20924855da9f575d2007fc38f8898b792fb/aiohttp-3.14.5-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:b2966998927d7bed9db12c0a4647b0c7b179755878fc9c357fe1ffd3e3b0c1a5", size = 2149520, upload-time = "2026-10-11T01:02:48.812Z" }, + { url = "https://files.pythonhosted.org/packages/22/d0/4e41bfe1b1ce1cb6f6d2e59fa7a88ef5cf92c402b2d07e9018778ba9edbc/aiohttp-3.14.5-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8e317e0fb6b16212c881d2205a7d87414c29acd69320b3aa6dce9d9c7b86fe4f", size = 2002039, upload-time = "2026-10-11T01:02:51.293Z" }, + { url = "https://files.pythonhosted.org/packages/6f/5e/72067019545c502b881b031153c437752ecef48d7d213bc0218ccebb4bfb/aiohttp-3.14.5-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:50343c1757b4b6f6708eeaf24534b32f19dfb99fb1b762c00420867a62fc81e0", size = 1786164, upload-time = "2026-10-11T01:02:53.533Z" }, + { url = "https://files.pythonhosted.org/packages/d9/fe/7741efd6119bfb7a00827fe6f7b84b4409de58d888ae21adc5a9a6824992/aiohttp-3.14.5-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:083673c7a94c3ea035caaa5ca04288bdb44887abfe1f5ba23294e6a4b03efd2d", size = 1970689, upload-time = "2026-10-11T01:02:55.888Z" }, + { url = "https://files.pythonhosted.org/packages/43/e7/342a13bf67f34d269bf2f7e870ecd72b99c832cc6f0a271a9210c0ebfb84/aiohttp-3.14.5-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:2528cb4c6b92008c76ac9ac6298624069bb2db91ff4929905512d1d84485f658", size = 1951967, upload-time = "2026-10-11T01:02:58.467Z" }, + { url = "https://files.pythonhosted.org/packages/e7/d4/fdb3b27340617e5e64df18a70fa89097778652ea5c7c7e2f79def76999c3/aiohttp-3.14.5-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:b1b8ece1e71132d2afba4dbc0c3d62c766e25165990b25db1196c04969eb3d84", size = 1968511, upload-time = "2026-10-11T01:03:00.883Z" }, + { url = "https://files.pythonhosted.org/packages/83/b2/e8f88298de78d1a951f36f9f966d38ec6ed1d4721303ba02064a545e8aa6/aiohttp-3.14.5-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:fce9523df31cea6284f3e2c479876750d7687cf671d7b25d32b19effc0e86441", size = 1778497, upload-time = "2026-10-11T01:03:03.206Z" }, + { url = "https://files.pythonhosted.org/packages/22/68/9ccdb93d664345c546be7f34480b921774d8c0d98f47e70d7e03b115d475/aiohttp-3.14.5-cp314-cp314t-musllinux_1_2_s390x.whl", hash = "sha256:09e0eb18c7e0c8777e2f9149de63799195b9b3ca1b5c81ba6f32f2c6b8628210", size = 1999676, upload-time = "2026-10-11T01:03:05.829Z" }, + { url = "https://files.pythonhosted.org/packages/57/4a/a33cfa6dcb00e94194ae4fe710432ca4ed111e016356b4ba4d2f4c3a124c/aiohttp-3.14.5-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:6774814fd5c338e72ee0da5cbb9432816df450e69c019f72b5d29bdec2a1792d", size = 1963437, upload-time = "2026-10-11T01:03:08.196Z" }, + { url = "https://files.pythonhosted.org/packages/f4/20/eacbecfea3b5c3dcbfc9b023e3a5460f43e5dda16d06a2877ebe7184c3f3/aiohttp-3.14.5-cp314-cp314t-win32.whl", hash = "sha256:33f706574e32c6e694f352a856e05caf18f7f2c871b3e87b41c55ea452b409ab", size = 503973, upload-time = "2026-10-11T01:03:10.481Z" }, + { url = "https://files.pythonhosted.org/packages/ff/78/18eec294f6c8c5dc845dcf6d730a0147d8d0f17e86138a7bdb85e43a30fa/aiohttp-3.14.5-cp314-cp314t-win_amd64.whl", hash = "sha256:5ba14a839fbe87cf7c12a6b5661c05f324a296eb8363141edb3944ba63d4c9d3", size = 531190, upload-time = "2026-10-11T01:03:12.716Z" }, + { url = "https://files.pythonhosted.org/packages/9d/39/e53f8169acc85271ebd12b5b32ad7f1541b35639ccbe0f49034c64785d10/aiohttp-3.14.5-cp314-cp314t-win_arm64.whl", hash = "sha256:1061b364556e8172e8d46b0b183adeeb73e8c42d30ebc745591e1bd89acad52e", size = 510360, upload-time = "2026-10-11T01:03:15.08Z" }, + { url = "https://files.pythonhosted.org/packages/f3/1c/06d89f58b2db3ee92dd377217659d587e06f973e57bf0a97a0d8a4586c0c/aiohttp-3.14.5-cp315-cp315-android_24_arm64_v8a.whl", hash = "sha256:788ecaa9c10533b786ce5ba70c4f2df78ad41819fd00a6c99d92b66f9a32e1da", size = 540674, upload-time = "2026-10-11T01:03:17.483Z" }, + { url = "https://files.pythonhosted.org/packages/18/39/5e822e038f496f0540ada91e27099d48f9e7f919b6c6deb4cf6db36cc706/aiohttp-3.14.5-cp315-cp315-android_24_x86_64.whl", hash = "sha256:5c76f1802bab718a68ac3cce447160605c734551f95c67ae90fa1132b215cb29", size = 554183, upload-time = "2026-10-11T01:03:19.71Z" }, + { url = "https://files.pythonhosted.org/packages/9b/ff/0cf2619d902b5b160762422a7e5e02091295766a7fe4fcf5b9a655e386c1/aiohttp-3.14.5-cp315-cp315-ios_13_0_arm64_iphoneos.whl", hash = "sha256:a6d02b4c38de03d9c7617813433e6a0fb6b522797974177d69d9dad431900833", size = 523160, upload-time = "2026-10-11T01:03:22.193Z" }, + { url = "https://files.pythonhosted.org/packages/86/99/3553abfc53a40849dbaacc3f54c730ec58410809ffa2d05885ae56108f2d/aiohttp-3.14.5-cp315-cp315-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:20726f9782d5c2744c1c66255842d1d163bb3edcf768b8de25216bf47f7b6ccf", size = 530311, upload-time = "2026-10-11T01:03:24.435Z" }, + { url = "https://files.pythonhosted.org/packages/fe/a4/5d25f73754bc1e8f983ba704e86d641aea290c967f195f2aeebdaed2bd84/aiohttp-3.14.5-cp315-cp315-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:248d779ad720b49d4fb355720e60c9e5f444f95887bc16974fea48fc56c41789", size = 540274, upload-time = "2026-10-11T01:03:26.698Z" }, + { url = "https://files.pythonhosted.org/packages/29/a4/07eda5db2e3ee017d9590f36c12a94ec6f1f50516e8df78672373dfc7185/aiohttp-3.14.5-cp315-cp315-macosx_10_15_universal2.whl", hash = "sha256:0a8ea271867e360ac985ae607f4a23ad9a38414b9aca1d49ec98839ae660e49f", size = 819239, upload-time = "2026-10-11T01:03:29.481Z" }, + { url = "https://files.pythonhosted.org/packages/cb/aa/a8723dd987a696dd48d4cf2f0088e589ce77caebff0b96f2a78c20424380/aiohttp-3.14.5-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:823c910f046f23f4c713b8d99a2242dc65f591cb45ee86418fa11762a3c2963c", size = 549832, upload-time = "2026-10-11T01:03:32.02Z" }, + { url = "https://files.pythonhosted.org/packages/29/5c/969a1b72692055fd2a419590c41847ec9144fefb97b75ff1cde5b6372891/aiohttp-3.14.5-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:9b42db919715e91eb76acf3bc492a9a7ccd8bd9adc6745c1412b689735269f14", size = 549234, upload-time = "2026-10-11T01:03:34.469Z" }, + { url = "https://files.pythonhosted.org/packages/38/05/8e3e07fd8a0d33d06955ff4e54a1cb92f4bce347ff55e441dc3e25a7b5e5/aiohttp-3.14.5-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:d3112585250b199296c26ca6e0131640b6a8d01bab8b232d2eb3763ed469de11", size = 1891314, upload-time = "2026-10-11T01:03:36.899Z" }, + { url = "https://files.pythonhosted.org/packages/b6/b3/05a79ce2e25f024e93de30c94f39dc6aa6e2bc1e9c531a5c4b18dc61b7a4/aiohttp-3.14.5-cp315-cp315-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:c147451b4a58e7050f7f7394e6c467867c84161560001f9ad4fb2d1446743946", size = 1884372, upload-time = "2026-10-11T01:03:39.334Z" }, + { url = "https://files.pythonhosted.org/packages/94/52/0fd8af0717db109eea258191b326b5cb5847fb88928bfa6c862fd78b9ad3/aiohttp-3.14.5-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:bf163cc701f3d4ac43ba7d97771bf5fd955220ef5500ef3ee847bc0ecfbf4ec1", size = 1930957, upload-time = "2026-10-11T01:03:42.172Z" }, + { url = "https://files.pythonhosted.org/packages/4e/b3/fa78733da88812bf9fb193913fb0ce1548f8b6912047633fdf88a758ff8c/aiohttp-3.14.5-cp315-cp315-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:f8d40ce41991e9d56fab4f5dc4a51fe59bc3b5c77c27f4b148963064d00232e8", size = 2038886, upload-time = "2026-10-11T01:03:44.646Z" }, + { url = "https://files.pythonhosted.org/packages/cf/f5/2fcc5e30053a938286f17d0edf3f0850b8061b984256fa7c26850b9c8809/aiohttp-3.14.5-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:276a4fc00b1d9ae492b802763a789c5b86328b989c5ea169f2faa447d6a11c7c", size = 1894470, upload-time = "2026-10-11T01:03:47.304Z" }, + { url = "https://files.pythonhosted.org/packages/62/2a/f87feb42abe8e6a7c03814dbcb711540849a1e90aa392055f3183c643610/aiohttp-3.14.5-cp315-cp315-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:50983e3be33d8c0942ab88cec3905b10602f64c469b20153c48c5d4e558dd016", size = 1716273, upload-time = "2026-10-11T01:03:50.121Z" }, + { url = "https://files.pythonhosted.org/packages/81/b2/adf1f960dd977722ed1347d33da512a1624807114f57a3b91f5cc828e081/aiohttp-3.14.5-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:16c8abd5bca220a47efe667d26f8460124c81810787e79ee87b242677563d9dd", size = 1857513, upload-time = "2026-10-11T01:03:52.959Z" }, + { url = "https://files.pythonhosted.org/packages/d7/fd/ef8d910e641de4160026a513ace5888b7f92826bbc3fd90ced05d55a828e/aiohttp-3.14.5-cp315-cp315-musllinux_1_2_armv7l.whl", hash = "sha256:0790ec66fa4013e83c53b9025a45d454723da1a2fce28b3208c9b32d08af162f", size = 1887704, upload-time = "2026-10-11T01:03:55.641Z" }, + { url = "https://files.pythonhosted.org/packages/7e/db/6c9142f941cba8d35be8e1fae6ea2bd390e754fc14076b8147aee1a4592f/aiohttp-3.14.5-cp315-cp315-musllinux_1_2_ppc64le.whl", hash = "sha256:cb11a971a3aea10f9b8373be628f1df932964fc6c6b174516d318a48c3ac4412", size = 1895684, upload-time = "2026-10-11T01:03:58.18Z" }, + { url = "https://files.pythonhosted.org/packages/e6/7c/6a6bd9a72e576d376c668333b00c51c6147aba4fb863ed6c94996d497eca/aiohttp-3.14.5-cp315-cp315-musllinux_1_2_riscv64.whl", hash = "sha256:932ce7e694bbc29b2bf6f64f2343c27d148d4997c771d01bdade4639b6749ff4", size = 1706299, upload-time = "2026-10-11T01:04:00.8Z" }, + { url = "https://files.pythonhosted.org/packages/69/ec/d2cc494242f8c4d3d1cd70baf591742818a74386dc3b84af3195c5c4fced/aiohttp-3.14.5-cp315-cp315-musllinux_1_2_s390x.whl", hash = "sha256:a7d470cf7b206e6359fc77b1b860632fde400d5a2ed59cd0181b93a686bc81ee", size = 1916645, upload-time = "2026-10-11T01:04:03.892Z" }, + { url = "https://files.pythonhosted.org/packages/a3/6e/e852c53647e815db09a1b6b5ab634f54bd736412397e11940feef4d2c89a/aiohttp-3.14.5-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:6e1d8637cf73eebc92eba2e11d4cfff98a3b562f2505bd75bba766d908926e8d", size = 1875408, upload-time = "2026-10-11T01:04:06.922Z" }, + { url = "https://files.pythonhosted.org/packages/fe/f6/72ab6ef20c332399be593bac543d2c24a6d241e39d3540ce9f95a63e4bd2/aiohttp-3.14.5-cp315-cp315-win32.whl", hash = "sha256:fbdc5ec49f9ca3cd24955cf3520b10a4d4c901ba2572094c84274e9e7eb30534", size = 485590, upload-time = "2026-10-11T01:04:09.626Z" }, + { url = "https://files.pythonhosted.org/packages/06/eb/e9de75b8c6d2170c42c08ff303abf857ea8a6d9d9b6e99b5aba40f15e962/aiohttp-3.14.5-cp315-cp315-win_amd64.whl", hash = "sha256:a9d3983bd6ab7aa1cfd573544ae98df9b6cb6912a5185a198263e024a636861d", size = 511740, upload-time = "2026-10-11T01:04:12.277Z" }, + { url = "https://files.pythonhosted.org/packages/fc/25/455f3c2785eb0d50748cffd0abd07500815f419a9495b14610b7622d8d2d/aiohttp-3.14.5-cp315-cp315-win_arm64.whl", hash = "sha256:e29347c142cf6e99e0dff5e2995ead1d50fa3b51bf37a7c726a7ccfe5419745a", size = 495171, upload-time = "2026-10-11T01:04:14.667Z" }, + { url = "https://files.pythonhosted.org/packages/e7/6c/497f0a98782eebfcf0f02a7fbdef5428148bd426027140cbad494cf842b5/aiohttp-3.14.5-cp315-cp315t-macosx_10_15_universal2.whl", hash = "sha256:9bf1d5dcc15204d9ec8b8ea4c18fd66e6b80e5de1f4ecbafb3a2f2740f8039d4", size = 855638, upload-time = "2026-10-11T01:04:17.154Z" }, + { url = "https://files.pythonhosted.org/packages/9a/c5/55c0cef2572af9b1ee81608f7c0a1bf74e6c9151a73b04915d933f192335/aiohttp-3.14.5-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:14f04769cfefe4734016a856a83af36133cd17779cef9ae817f812b8ba9d6d51", size = 567455, upload-time = "2026-10-11T01:04:19.702Z" }, + { url = "https://files.pythonhosted.org/packages/4d/47/e1a0e39f4a2b881f6071225afaf94a6547001b5aefc1566734d73c685934/aiohttp-3.14.5-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:6e4251c0ba4624a68a2c11471a1ac54c3306876c21f0ae86de085cc9241c8905", size = 567836, upload-time = "2026-10-11T01:04:22.235Z" }, + { url = "https://files.pythonhosted.org/packages/c3/1d/817d85836f52b687160064a326e62e037dc42f1ad5b6b5188a70e5c134b5/aiohttp-3.14.5-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:e4f5cf4dc72a71c4cfa9751b4950be22f733626670230d46e7d606592aa22d59", size = 2051409, upload-time = "2026-10-11T01:04:24.821Z" }, + { url = "https://files.pythonhosted.org/packages/f7/25/e8ea6fc212a9aabce982917346ce8ecab0929c74b60232a056dd11c99da0/aiohttp-3.14.5-cp315-cp315t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:dbf53ae2601b7fd5a93c3944deea3a78d40f495226d582c35ef7a433425ce2b2", size = 1936493, upload-time = "2026-10-11T01:04:27.456Z" }, + { url = "https://files.pythonhosted.org/packages/24/33/de0517f71f1a19feea4aff78a2ec4ec2d98634129ec30ead78fce2f8f81b/aiohttp-3.14.5-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:657291433bf4dd3142f3abac495764cd47d0c7c92087751e6666c6447e65fcef", size = 2021405, upload-time = "2026-10-11T01:04:30.276Z" }, + { url = "https://files.pythonhosted.org/packages/c4/11/ddaf2e7930543e9f0cad3a1c54e1af0c1bd2fae3973d568c4263d3b010e9/aiohttp-3.14.5-cp315-cp315t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:3e51a27980c3788e6e6b3325d694fdd4898087fa8a86b2763af77b39353da41e", size = 2142017, upload-time = "2026-10-11T01:04:33.022Z" }, + { url = "https://files.pythonhosted.org/packages/1d/7b/58784353c06de8adc20f426daad3d85dd86fd55331c713a3f4b638c94573/aiohttp-3.14.5-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:82c7583cd3dfdc7dcc927835b4f6c7faae7ecc1ba3ca5879321621ae2e6f8e84", size = 2002482, upload-time = "2026-10-11T01:04:35.94Z" }, + { url = "https://files.pythonhosted.org/packages/b9/f0/417d9535caa9e165ffe6a53e2347a78107e7c87dcb0e10aca315c3af0344/aiohttp-3.14.5-cp315-cp315t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:6fdcd6af7e2e51d1ba1b4bea16e97b074bcb7b5dd0246a9d8201341bb28085a0", size = 1791774, upload-time = "2026-10-11T01:04:38.733Z" }, + { url = "https://files.pythonhosted.org/packages/98/01/25e49c2e8a01b9f0e19ca0a8448ad50aa2bdf96c8cd41e92bd45af044784/aiohttp-3.14.5-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:c8859a013ae0de1074660992139a1a440df3e6b219b86cf0d3f11c2692bb4fe3", size = 1970358, upload-time = "2026-10-11T01:04:41.66Z" }, + { url = "https://files.pythonhosted.org/packages/2d/fc/c132fd3465b6c7e4ce0193154f602c3e6c46b680e4da7eb3bd0d8a40d1c7/aiohttp-3.14.5-cp315-cp315t-musllinux_1_2_armv7l.whl", hash = "sha256:8966ecac808dd5f473c9c4cefd10cd3ffda71c18a4d3493b7c7d2ae1803bf2cc", size = 1969192, upload-time = "2026-10-11T01:04:44.66Z" }, + { url = "https://files.pythonhosted.org/packages/95/4e/d58b45e7dba4eb607eca11fc0a4aa77ae0f39c11afa804635a61ce18cff4/aiohttp-3.14.5-cp315-cp315t-musllinux_1_2_ppc64le.whl", hash = "sha256:3093b72c215bda16ce961a6d073f6e71d46e022962a9d5d457c5d4d421c78b57", size = 1963618, upload-time = "2026-10-11T01:04:47.505Z" }, + { url = "https://files.pythonhosted.org/packages/a2/d9/f6ac50946efb3490428ef52b56e62c1c6b7f9c6ff3ec6083535526c83e60/aiohttp-3.14.5-cp315-cp315t-musllinux_1_2_riscv64.whl", hash = "sha256:149fb56caf7acb67073126f675d0958d9c4b3125fcd3f6d4877df98aa8a97ce9", size = 1784817, upload-time = "2026-10-11T01:04:50.287Z" }, + { url = "https://files.pythonhosted.org/packages/d0/2f/f255eb63da788cd8a452fe350869c03266ccad7d884925f6963c87808f24/aiohttp-3.14.5-cp315-cp315t-musllinux_1_2_s390x.whl", hash = "sha256:293d3ae7c6a0ed176a42e59a1b5fde825ead65c835360f734148e96729f928d2", size = 1995956, upload-time = "2026-10-11T01:04:53.213Z" }, + { url = "https://files.pythonhosted.org/packages/d9/9b/241aa3393eaafda0034470add1625f82a4c252901108723b283a9b0b32ca/aiohttp-3.14.5-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:3f2dcc00191fd563e9075181a14ec31d7dd63223ced7582cc70a15a499de0c79", size = 1967794, upload-time = "2026-10-11T01:04:55.958Z" }, + { url = "https://files.pythonhosted.org/packages/5f/7f/a68e689288c9e4bfcf8d0979f2b12b774bf01861985420df6150eba5448e/aiohttp-3.14.5-cp315-cp315t-win32.whl", hash = "sha256:7779cd97e61ebe583ec2f1c5616cdd038aa08a4453b1848c67842176d054948e", size = 503876, upload-time = "2026-10-11T01:04:58.978Z" }, + { url = "https://files.pythonhosted.org/packages/a4/78/49b0299da6d54de19fc6fdc6889d50233ac47d192a461624f4fc010fde83/aiohttp-3.14.5-cp315-cp315t-win_amd64.whl", hash = "sha256:0e6f16f5e49c4b8267988c05ab07760d7064cea57d077c3d068d04b0fbb992cb", size = 530957, upload-time = "2026-10-11T01:05:02.23Z" }, + { url = "https://files.pythonhosted.org/packages/21/d4/b0afc936aeb6d2f93157e3408b069ec5d7934429ae7d023de5e0953b1887/aiohttp-3.14.5-cp315-cp315t-win_arm64.whl", hash = "sha256:1aead151c3abbac6b32942e452020cb66d7efc099d253cc6c20f748e926c858b", size = 510408, upload-time = "2026-10-11T01:05:05.362Z" }, + { url = "https://files.pythonhosted.org/packages/68/30/173960c42b05a6c59f7558e4b12a4b0d9ba376cf6aa9bde7f9e08a30ca8d/aiohttp-3.14.5-py3-none-any.whl", hash = "sha256:efc21a454892828368b11c2c780de0ff8bc991f73f6b99c6b66e56205470929b", size = 279517, upload-time = "2026-10-11T01:05:08.523Z" }, +] + +[[package]] +name = "aiosignal" +version = "1.4.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "frozenlist" }, + { name = "typing-extensions", marker = "python_full_version < '3.13'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/61/62/06741b579156360248d1ec624842ad0edf697050bbaf7c3e46394e106ad1/aiosignal-1.4.0.tar.gz", hash = "sha256:f47eecd9468083c2029cc99945502cb7708b082c232f9aca65da147157b251c7", size = 25007, upload-time = "2025-07-03T22:54:43.528Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/fb/76/641ae371508676492379f16e2fa48f4e2c11741bd63c48be4b12a6b09cba/aiosignal-1.4.0-py3-none-any.whl", hash = "sha256:053243f8b92b990551949e63930a839ff0cf0b0ebbe0597b0f3fb19e1a0fe82e", size = 7490, upload-time = "2025-07-03T22:54:42.156Z" }, +] + +[[package]] +name = "alibabacloud-credentials" +version = "0.3.6" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "alibabacloud-tea" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/fc/92/7cb0807d6d380fa09cbad6d4fe983781e657dcc16d60fc559d6575bf98be/alibabacloud_credentials-0.3.6.tar.gz", hash = "sha256:caa82cf258648dcbe1ca14aeba50ba21845567d6ac3cd48d318e0a445fff7f96", size = 18771, upload-time = "2024-10-28T03:40:03.806Z" } + +[[package]] +name = "alibabacloud-darabonba-array" +version = "0.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/50/be/1813d7553e11e20a1422ffaaead392cfa7239a855c7e67c6a6b5776cfa64/alibabacloud_darabonba_array-0.1.0.tar.gz", hash = "sha256:7f9a7c632518ff4f0cebb0d4e825a48c12e7cf0b9016ea25054dd73732e155aa", size = 2306, upload-time = "2022-11-01T06:32:47.928Z" } + +[[package]] +name = "alibabacloud-darabonba-encode-util" +version = "0.0.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/a7/62/5ad776035482fddb8831459c7072f25463f2cb06e5b8b1e93eb537c2a43e/alibabacloud_darabonba_encode_util-0.0.3.tar.gz", hash = "sha256:f293ed5f5933e97061a51d80aeb4bdc4d38bc67f6e0aca6eda7c5d7814b21c46", size = 4193, upload-time = "2026-07-17T10:27:32.937Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/c1/33/a2f254e5610b6b83b28c010c1c8e67c26d4ac0355f59f16cba25c9440567/alibabacloud_darabonba_encode_util-0.0.3-py3-none-any.whl", hash = "sha256:6a91c82f6cc4227091be39b65d1f6921d7330119bac7b911e5a26daf895cc9dc", size = 4295, upload-time = "2026-07-17T10:27:32Z" }, +] + +[[package]] +name = "alibabacloud-darabonba-map" +version = "0.0.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d5/bc/f11d56adffffade9a0d33ccca155ce82ca950b97cdce27a75228715c4639/alibabacloud_darabonba_map-0.0.1.tar.gz", hash = "sha256:adb17384658a1a8f72418f1838d4b6a5fd2566bfd392a3ef06d9dbb0a595a23f", size = 2056, upload-time = "2021-12-04T03:41:20.369Z" } + +[[package]] +name = "alibabacloud-darabonba-signature-util" +version = "0.0.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "cryptography" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/13/09/2118a2df631eaa06a291013ea61f31e449ba7a3cc3d6061477a43420e93a/alibabacloud_darabonba_signature_util-0.0.4.tar.gz", hash = "sha256:71d79b2ae65957bcfbf699ced894fda782b32f9635f1616635533e5a90d5feb0", size = 4170, upload-time = "2022-12-10T04:44:42.979Z" } + +[[package]] +name = "alibabacloud-darabonba-string" +version = "0.0.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f9/d4/3d22bd2ff88985f970a10f8cedf2ea326d11d4d95e244f7665dc83d26465/alibabacloud-darabonba-string-0.0.4.tar.gz", hash = "sha256:ec6614c0448dadcbc5e466485838a1f8cfdd911135bea739e20b14511270c6f7", size = 2852, upload-time = "2021-12-13T13:30:06.114Z" } + +[[package]] +name = "alibabacloud-endpoint-util" +version = "0.0.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/92/7d/8cc92a95c920e344835b005af6ea45a0db98763ad6ad19299d26892e6c8d/alibabacloud_endpoint_util-0.0.4.tar.gz", hash = "sha256:a593eb8ddd8168d5dc2216cd33111b144f9189fcd6e9ca20e48f358a739bbf90", size = 2813, upload-time = "2025-06-12T07:20:52.572Z" } + +[[package]] +name = "alibabacloud-gateway-pop" +version = "0.0.9" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "alibabacloud-credentials" }, + { name = "alibabacloud-darabonba-array" }, + { name = "alibabacloud-darabonba-encode-util" }, + { name = "alibabacloud-darabonba-map" }, + { name = "alibabacloud-darabonba-signature-util" }, + { name = "alibabacloud-darabonba-string" }, + { name = "alibabacloud-endpoint-util" }, + { name = "alibabacloud-gateway-spi" }, + { name = "alibabacloud-openapi-util" }, + { name = "alibabacloud-tea-util" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/18/7d/d521d803ee227499aa5a3044a0ab8bd4ba139a455d10c1a070e745d26b0c/alibabacloud_gateway_pop-0.0.9.tar.gz", hash = "sha256:50aec34abc47b3adc6e43da6fa036bbbd04477a0047435f3728129ede7641628", size = 5981, upload-time = "2025-07-23T07:06:06.717Z" } + +[[package]] +name = "alibabacloud-gateway-spi" +version = "0.0.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "alibabacloud-credentials" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/cd/67/7cd36a36bf0ec53efd3fe31eaf398713f375b7b1cdcd32c51b6c0fdc09e2/alibabacloud_gateway_spi-0.0.4.tar.gz", hash = "sha256:73d6e20d65b54eed26d89c19640d3a7572e18c45ecada627f806f5dbe8ed2130", size = 4253, upload-time = "2026-06-25T06:34:08.238Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/45/85/81170c45e9d1240736f9776a1c690b958c975509381221b5f8d960b5376d/alibabacloud_gateway_spi-0.0.4-py3-none-any.whl", hash = "sha256:0d5256e95d8719da8ec9611b7ffbb12c2d26fdf7ce52c8f64e4e06350731e893", size = 4290, upload-time = "2026-06-25T06:34:07.22Z" }, +] + +[[package]] +name = "alibabacloud-kms20160120" +version = "2.2.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "alibabacloud-endpoint-util" }, + { name = "alibabacloud-gateway-pop" }, + { name = "alibabacloud-openapi-util" }, + { name = "alibabacloud-tea-openapi" }, + { name = "alibabacloud-tea-util" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/18/39/dfb1043f2995523507b03bb23e5db6291508eccbb4f78ea02930ff95f137/alibabacloud_kms20160120-2.2.3.tar.gz", hash = "sha256:fa7991185e92d85f9d224ead0bf82e5673fcfd022714e6c3cd2b1894b59555bf", size = 77350, upload-time = "2024-08-30T10:18:44.012Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/cc/04/0668cbc62f3d9239e86d3d97b3de40b92e66730a90fc4c58f0ee38a81399/alibabacloud_kms20160120-2.2.3-py3-none-any.whl", hash = "sha256:51d3d04c75ba93c574ff4e368e51097f180fc05922fbd6336d290ea8113da99e", size = 76701, upload-time = "2024-08-30T10:18:42.524Z" }, +] + +[[package]] +name = "alibabacloud-openapi-util" +version = "0.2.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "alibabacloud-tea-util" }, + { name = "cryptography" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/f6/51/be5802851a4ed20ac2c6db50ac8354a6e431e93db6e714ca39b50983626f/alibabacloud_openapi_util-0.2.4.tar.gz", hash = "sha256:87022b9dcb7593a601f7a40ca698227ac3ccb776b58cb7b06b8dc7f510995c34", size = 7981, upload-time = "2026-01-15T08:05:03.947Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/08/46/9b217343648b366eb93447f5d93116e09a61956005794aed5ef95a2e9e2e/alibabacloud_openapi_util-0.2.4-py3-none-any.whl", hash = "sha256:a2474f230b5965ae9a8c286e0dc86132a887928d02d20b8182656cf6b1b6c5bd", size = 7661, upload-time = "2026-01-15T08:05:01.374Z" }, +] + +[[package]] +name = "alibabacloud-tea" +version = "0.4.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "aiohttp" }, + { name = "requests" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9a/7d/b22cb9a0d4f396ee0f3f9d7f26b76b9ed93d4101add7867a2c87ed2534f5/alibabacloud-tea-0.4.3.tar.gz", hash = "sha256:ec8053d0aa8d43ebe1deb632d5c5404339b39ec9a18a0707d57765838418504a", size = 8785, upload-time = "2025-03-24T07:34:42.958Z" } + +[[package]] +name = "alibabacloud-tea-openapi" +version = "0.3.14" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "alibabacloud-credentials" }, + { name = "alibabacloud-gateway-spi" }, + { name = "alibabacloud-openapi-util" }, + { name = "alibabacloud-tea-util" }, + { name = "alibabacloud-tea-xml" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/ff/f5/c7823490a1574d1e3c27c9641aa395710e89d0c15c5a436c96e999e6e2fe/alibabacloud_tea_openapi-0.3.14.tar.gz", hash = "sha256:1e0a67ab3450cf09e26ccc0fb5b0622a6b58fdde25dc3ccb99b45e167c5db717", size = 12993, upload-time = "2025-04-15T12:20:03.363Z" } + +[[package]] +name = "alibabacloud-tea-util" +version = "0.3.15" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "alibabacloud-tea" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/01/22/d3ce00317d9ba963bcc48234210bd718c42425267ecb05881cbb189b1c76/alibabacloud_tea_util-0.3.15.tar.gz", hash = "sha256:79f78e596f6be03fb9565e34ac45420f3730e52888376cc9713bd07432a4c6cc", size = 7548, upload-time = "2026-07-17T10:15:04.213Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/6b/29/6d05604c74f3b1326c317727c532e9054f56dca5299ff5b645f73425680d/alibabacloud_tea_util-0.3.15-py3-none-any.whl", hash = "sha256:afb3dd8ad5cd2f93804258fbbac4360c050462100499269795ea055c1644e193", size = 6709, upload-time = "2026-07-17T10:15:03.317Z" }, +] + +[[package]] +name = "alibabacloud-tea-xml" +version = "0.0.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "alibabacloud-tea" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/32/eb/5e82e419c3061823f3feae9b5681588762929dc4da0176667297c2784c1a/alibabacloud_tea_xml-0.0.3.tar.gz", hash = "sha256:979cb51fadf43de77f41c69fc69c12529728919f849723eb0cd24eb7b048a90c", size = 3466, upload-time = "2025-07-01T08:04:55.144Z" } + +[[package]] +name = "altair" +version = "6.3.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "jinja2" }, + { name = "jsonschema" }, + { name = "narwhals" }, + { name = "packaging" }, + { name = "typing-extensions", marker = "python_full_version < '3.15'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/e8/de/9731304fae332b5783fdc3ed18531dfaf4a3cc62a66aaaa74c047355b70f/altair-6.3.0.tar.gz", hash = "sha256:fa632121aca6d0fcb198a3d8a9f7d937fa5b7518ec947951cfffb44e736d97c8", size = 766362, upload-time = "2026-09-15T06:38:03.623Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ca/b9/10a8bb13a0462e0bc4e02c0b7b8237dc24ab590f5bb4be94bec5e8f1d532/altair-6.3.0-py3-none-any.whl", hash = "sha256:7defb6ca730676dfc99a299768e2769f51585fcb3dc960ea71aacc368929d65e", size = 797192, upload-time = "2026-09-15T06:38:01.791Z" }, +] + +[[package]] +name = "annotated-types" +version = "0.8.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/5f/56/a8120250d128bed162cd73c76d45f6ef9991f3e068f62a8ee060afa3104a/annotated_types-0.8.0.tar.gz", hash = "sha256:13b2beaad985e05e2d6407ee4c4f35590b11f8d693a258a561055cac8f64cab7", size = 15893, upload-time = "2026-07-23T20:16:13.995Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/99/91/8acff4f5e50511b911bbccb72b8628a49c68ce14148cd9f6431094859a90/annotated_types-0.8.0-py3-none-any.whl", hash = "sha256:f072f4d804ea359e4eaf198b1af7a8b0943881a87f31bb764f8bf219bb9419e0", size = 13427, upload-time = "2026-07-23T20:16:12.938Z" }, +] + +[[package]] +name = "anyio" +version = "4.16.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "idna" }, + { name = "typing-extensions", marker = "python_full_version < '3.15'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a1/98/7e457a3b014976887a050561955c0b76e1e7e2d6e27b78ecef2ef80518f2/anyio-4.16.0.tar.gz", hash = "sha256:59bb03251907983d1603d27c3087ddb1e93299ea2163adcdba37899a4fb12ffb", size = 310971, upload-time = "2026-11-01T11:20:07.282Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a9/16/7757fb84c819accc7d7e9af5291b261e4abb8627ee040f99e7d35ef2457a/anyio-4.16.0-py3-none-any.whl", hash = "sha256:c66ae634e0b8228396b801741beb3294326d4b6102f7bba4041c0dfb58c29026", size = 134521, upload-time = "2026-11-01T11:20:05.59Z" }, +] + +[[package]] +name = "apache-dubbo" +version = "3.0.0b2" +source = { editable = "." } +dependencies = [ + { name = "anyio" }, + { name = "attrs" }, + { name = "cattrs" }, + { name = "hessian2" }, + { name = "multidict" }, + { name = "ngh2" }, + { name = "protobuf" }, + { name = "psutil" }, +] + +[package.optional-dependencies] +nacos = [ + { name = "nacos-sdk-python" }, + { name = "pyyaml" }, +] +properties = [ + { name = "dotproperties" }, +] +protoc = [ + { name = "grpcio-tools" }, +] +uvloop = [ + { name = "uvloop", marker = "sys_platform != 'win32'" }, +] +yaml = [ + { name = "pyyaml" }, +] +zookeeper = [ + { name = "kazoo" }, + { name = "pyyaml" }, +] + +[package.dev-dependencies] +benchmark = [ + { name = "altair" }, + { name = "grpcio" }, + { name = "grpclib" }, + { name = "vl-convert-python" }, +] +dev = [ + { name = "grpcio" }, + { name = "pre-commit" }, + { name = "pytest" }, + { name = "ruff" }, + { name = "ty" }, + { name = "types-protobuf" }, +] +grpc = [ + { name = "grpcio" }, +] +lint = [ + { name = "pre-commit" }, + { name = "ruff" }, +] +proto = [ + { name = "grpcio-tools" }, +] +test = [ + { name = "grpcio" }, + { name = "pytest" }, +] +type = [ + { name = "ty" }, + { name = "types-protobuf" }, +] + +[package.metadata] +requires-dist = [ + { name = "anyio", specifier = ">=4.14,<5" }, + { name = "apache-dubbo", extras = ["yaml"], marker = "extra == 'nacos'" }, + { name = "apache-dubbo", extras = ["yaml"], marker = "extra == 'zookeeper'" }, + { name = "attrs", specifier = ">=26.1" }, + { name = "cattrs", specifier = ">=26.1" }, + { name = "dotproperties", marker = "extra == 'properties'", specifier = ">=0.2,<0.3" }, + { name = "grpcio-tools", marker = "extra == 'protoc'", specifier = ">=1.85" }, + { name = "hessian2", specifier = ">=0.2,<0.3" }, + { name = "kazoo", marker = "extra == 'zookeeper'", specifier = ">=2.11" }, + { name = "multidict", specifier = ">=7.2" }, + { name = "nacos-sdk-python", marker = "extra == 'nacos'", specifier = ">=3.2,<4" }, + { name = "ngh2", specifier = ">=0.5,<0.6" }, + { name = "protobuf", specifier = ">=7.36,<8" }, + { name = "psutil", specifier = ">=7" }, + { name = "pyyaml", marker = "extra == 'yaml'", specifier = ">=6" }, + { name = "uvloop", marker = "sys_platform != 'win32' and extra == 'uvloop'", specifier = ">=0.22,<1" }, +] +provides-extras = ["zookeeper", "nacos", "yaml", "properties", "uvloop", "protoc"] + +[package.metadata.requires-dev] +benchmark = [ + { name = "altair", specifier = ">=6.3,<7" }, + { name = "grpcio", specifier = ">=1.85,<2" }, + { name = "grpclib", specifier = ">=0.4,<0.5" }, + { name = "vl-convert-python", specifier = ">=1.9,<2" }, +] +dev = [ + { name = "grpcio", specifier = ">=1.85,<2" }, + { name = "pre-commit", specifier = ">=4.6,<5" }, + { name = "pytest", specifier = ">=9.1,<10" }, + { name = "ruff", specifier = ">=0.17,<0.18" }, + { name = "ty", specifier = "==0.0.104" }, + { name = "types-protobuf", specifier = ">=7.35,<8" }, +] +grpc = [{ name = "grpcio", specifier = ">=1.85,<2" }] +lint = [ + { name = "pre-commit", specifier = ">=4.6,<5" }, + { name = "ruff", specifier = ">=0.17,<0.18" }, +] +proto = [{ name = "grpcio-tools", specifier = "==1.85.0" }] +test = [ + { name = "grpcio", specifier = ">=1.85,<2" }, + { name = "pytest", specifier = ">=9.1,<10" }, +] +type = [ + { name = "ty", specifier = "==0.0.104" }, + { name = "types-protobuf", specifier = ">=7.35,<8" }, +] + +[[package]] +name = "attrs" +version = "26.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/9a/8e/82a0fe20a541c03148528be8cac2408564a6c9a0cc7e9171802bc1d26985/attrs-26.1.0.tar.gz", hash = "sha256:d03ceb89cb322a8fd706d4fb91940737b6642aa36998fe130a9bc96c985eff32", size = 952055, upload-time = "2026-03-19T14:22:25.026Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/64/b4/17d4b0b2a2dc85a6df63d1157e028ed19f90d4cd97c36717afef2bc2f395/attrs-26.1.0-py3-none-any.whl", hash = "sha256:c647aa4a12dfbad9333ca4e71fe62ddc36f4e63b2d260a37a8b83d2f043ac309", size = 67548, upload-time = "2026-03-19T14:22:23.645Z" }, +] + +[[package]] +name = "cattrs" +version = "26.2.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "attrs" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/23/75/e72b839c3dc869c990b4842f3dba730bdcdf5215f68fc7955edf849a1792/cattrs-26.2.1.tar.gz", hash = "sha256:679132bfdc225c5ee40c024fc42519954767c387f950dc6751946c586bccdc6d", size = 525617, upload-time = "2026-09-26T20:53:21.114Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e8/cf/22794a399d99480486120e26e879ef008e21f5e85274c2ed591d568bb326/cattrs-26.2.1-py3-none-any.whl", hash = "sha256:a12aaa3453dc8f633a815293179f08b7421ed18d2575c459c3c736f840beac24", size = 74843, upload-time = "2026-09-26T20:53:19.767Z" }, +] + +[[package]] +name = "certifi" +version = "2026.10.23" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/fd/11/b524cbd9bbdaca58608e4cf4053fd463417549e1959fa8d3aa18319f9555/certifi-2026.10.23.tar.gz", hash = "sha256:a9895e6e2758b371e0545e321a3a8fd1fcfd9829ada8824a936dfb16aaaf36cd", size = 136225, upload-time = "2026-10-23T11:36:16.478Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/32/d1/a3652fe2c19134d0d15922177821d863cbd7e842d53a21bbe7e8e3a1b5ac/certifi-2026.10.23-py3-none-any.whl", hash = "sha256:e9b54de76e530bb6cf0ccd036787103acb58fd42ba930ea8bf948ddbaa2f61d1", size = 135082, upload-time = "2026-10-23T11:36:14.763Z" }, +] + +[[package]] +name = "cffi" +version = "2.1.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pycparser", marker = "implementation_name != 'PyPy'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9e/ef/008a1939e372c06329a3fce4279c02f328488f3526744906eeec3da7ad5f/cffi-2.1.1.tar.gz", hash = "sha256:dd31f52ea1086513bb9df30f8fcee9b8918323ae067a3d5b78bc826a000712be", size = 530807, upload-time = "2026-08-03T21:21:18.939Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/70/d2/16d99a0c4948febc0ebd133a13b2f688ff7f8cb04da971e1128872ce0c03/cffi-2.1.1-cp311-cp311-macosx_10_15_x86_64.whl", hash = "sha256:c8d2c9fd1f2d16f780d15127abb050d13d1a76c03a4bd87d7e4980e45e511e12", size = 183838, upload-time = "2026-08-03T21:19:29.637Z" }, + { url = "https://files.pythonhosted.org/packages/cd/95/31b535a9f0220ae9f357de4a08d57ce89cb417653c2fd9f075f50822a388/cffi-2.1.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:398aff33cee2767e3e781d2554c54bd0dff386bb437581e0d8011fde1a942ec1", size = 184168, upload-time = "2026-08-03T21:19:30.764Z" }, + { url = "https://files.pythonhosted.org/packages/ad/5a/4707a0dc1f203f5dde5a907b0d4e3c25d71120241048bd5bc6f1bb9d4e71/cffi-2.1.1-cp311-cp311-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:154852545011f779917b11c78db2358d095da62a9a172b78ad0a583ee5adc0d0", size = 211805, upload-time = "2026-08-03T21:19:31.867Z" }, + { url = "https://files.pythonhosted.org/packages/ad/66/c19feabb28485b6e0bbaaafa90837a1ef5d302e90f2178bd33f17a49879b/cffi-2.1.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:3311ed60d36f83378794e1009ac6258bafbf81f7888b4caa7b35a521e3f95813", size = 218716, upload-time = "2026-08-03T21:19:32.896Z" }, + { url = "https://files.pythonhosted.org/packages/a7/92/500760486c8baab49a7a8a58ba7fc3355ec3974b454b8a09e528efde9e1d/cffi-2.1.1-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:6e192623c49c94421616a5778fba35cf0d5a8d000650c1967ef4448ee5cdd990", size = 205569, upload-time = "2026-08-03T21:19:34.142Z" }, + { url = "https://files.pythonhosted.org/packages/a5/a7/a67c733254d6e7373f7822f8082d8d6beade791e0cf12a7611f376fa61c7/cffi-2.1.1-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:a6e721d4b0e45d5b65e87534470e67b18dcd092c83f68fba09f152b9cbc061af", size = 204907, upload-time = "2026-08-03T21:19:35.174Z" }, + { url = "https://files.pythonhosted.org/packages/f7/a4/4399daaf8f7dfee9d7c3327fdb0426ee041cc63edc358b93911ceb2bfc7a/cffi-2.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:34e261f78cb6ceaaa36f42f2613f4380d94d9c759a9c73c769ee6e0247364632", size = 217807, upload-time = "2026-08-03T21:19:36.286Z" }, + { url = "https://files.pythonhosted.org/packages/28/f7/dabe6da2466ecbd82dc62e7342dc6b1065dad990c06f00f0ede9ebf2a0ed/cffi-2.1.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:7225e4514edb64eb6740324353e0da0711954fd8d7da4576755b1c6e09b697cd", size = 221252, upload-time = "2026-08-03T21:19:37.416Z" }, + { url = "https://files.pythonhosted.org/packages/ce/87/616202d8e51342c07d2534c510111c4cc37201775ce8f60802c9335d1edd/cffi-2.1.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:df913725b79db7bcf03448f36b7bf8815363417d5b58deecf9305e3e30f0f21a", size = 214214, upload-time = "2026-08-03T21:19:38.507Z" }, + { url = "https://files.pythonhosted.org/packages/b4/c6/ab025d75d2c26c19b087c0124e75ee31cb65032f4fe345d356d8c507ab97/cffi-2.1.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:f5cfbc5fe74540d335175b656c725d74d90e3730c626d92575eea35029d9afaa", size = 219408, upload-time = "2026-08-03T21:19:39.809Z" }, + { url = "https://files.pythonhosted.org/packages/db/e2/7e8109f65445bdc673a7b54f02c677de462db75674220fd1335efc8eb598/cffi-2.1.1-cp311-cp311-win32.whl", hash = "sha256:f8ec5e643a9a937f64e1999eb9f75d072263751912dc5cd06d3c85f8f44be7c3", size = 174470, upload-time = "2026-08-03T21:19:41.246Z" }, + { url = "https://files.pythonhosted.org/packages/73/c0/77ba02423c2f7d7091143c45cd49e0e6575c4c1967394bb542bd923a9b74/cffi-2.1.1-cp311-cp311-win_amd64.whl", hash = "sha256:42f6930c31dc7f50732c9ae793c2786c7b6b044195967bbdde40bb9be81c4cc0", size = 185096, upload-time = "2026-08-03T21:19:42.615Z" }, + { url = "https://files.pythonhosted.org/packages/7c/47/9f1f85f9672ceda4984dc6c4f8824e8558992a2972c3d3c81fb8eb28d4ba/cffi-2.1.1-cp311-cp311-win_arm64.whl", hash = "sha256:c7659f22557c5a0bc4855cd635f55edec690cc008a40768527762cb9fb263455", size = 179941, upload-time = "2026-08-03T21:19:43.747Z" }, + { url = "https://files.pythonhosted.org/packages/10/69/43965eccfdead3b9220015fd1320e117be8c6ed01a62ffab76eeb752f5d5/cffi-2.1.1-cp312-cp312-macosx_10_15_x86_64.whl", hash = "sha256:c8c69575568085ba0b1b10c0249d779a214aea6f6522e949a0fc9fb0fcb449d0", size = 184821, upload-time = "2026-08-03T21:19:44.887Z" }, + { url = "https://files.pythonhosted.org/packages/54/7d/16e5a096677b5e313ca80cd5e5170efa3ea44624a82bb111925522da64b1/cffi-2.1.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:f81b3b8f3d4e343550fa4baa0e479bba9f2d29ce9c2e9b51d1ce1718d7442fcf", size = 184719, upload-time = "2026-08-03T21:19:46.129Z" }, + { url = "https://files.pythonhosted.org/packages/56/e6/8941622732edec876dd17d0453dce07317ae96db34f2ec1436c9d3785986/cffi-2.1.1-cp312-cp312-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:811bd1e21d32de12efca32393a0ab3f5133b54fce9bd44b8bd77ab07da14bf6a", size = 214799, upload-time = "2026-08-03T21:19:47.218Z" }, + { url = "https://files.pythonhosted.org/packages/44/de/f98430906df1545ffde0d543dd124a7a439bc2cd32b36b9c53f805df7333/cffi-2.1.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:68e62fe11f30d5ca8289242866f0a5291402d8529ca2178ab8afc5c9694ae890", size = 222389, upload-time = "2026-08-03T21:19:48.331Z" }, + { url = "https://files.pythonhosted.org/packages/6a/5b/717f1526b9957b34456313c31645c5b82b8fb5c3fe9e4752999be7128bfc/cffi-2.1.1-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:4a7c934f7360e8cd64fe9efadcbd10c7c6364f531e432b9a4bf5ccbc9e0e8b50", size = 210249, upload-time = "2026-08-03T21:19:49.543Z" }, + { url = "https://files.pythonhosted.org/packages/64/b3/f8aa4f3e34986c7e4ec45072d1b1b9dd295b6b18007b45518d79726dd725/cffi-2.1.1-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:3143d81e29e1e20a9ce10901ec369012947876596f75a222235965f2b7ae832e", size = 208775, upload-time = "2026-08-03T21:19:50.918Z" }, + { url = "https://files.pythonhosted.org/packages/b1/db/dceb9dd5b231e1da801793f8acc9f3c52a7e1afe40bb1aae37e02b0faad5/cffi-2.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c1453022f490d2459a11819d83ad1d586e9ff65a12ac3e705ffebd46d3685dcf", size = 221822, upload-time = "2026-08-03T21:19:52.054Z" }, + { url = "https://files.pythonhosted.org/packages/a0/d2/6cd24ae3be000a634109c247d1475d62e5616d0dc78c82770942ec384248/cffi-2.1.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:208f941bb9d18e768138677f0a6d2ce01f590df56043dda1df1535ac57c88517", size = 225232, upload-time = "2026-08-03T21:19:53.109Z" }, + { url = "https://files.pythonhosted.org/packages/cb/52/3fa190537004dd7f0ab860a6dc7c0175b8667f68d1e618a46f5498d30250/cffi-2.1.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:210019b6c7cf07f081b4c54635c8cf744377001350e29cc0f81c4377b4797735", size = 223597, upload-time = "2026-08-03T21:19:54.515Z" }, + { url = "https://files.pythonhosted.org/packages/80/fb/0bb75b7039588c074b37ae99f40d9bfddf990ecb2fbc346ebccd2e56b9be/cffi-2.1.1-cp312-cp312-win32.whl", hash = "sha256:046bfc24911b37851ee1b51aab8bffe713d89c68c6a057b09484ce9fd5f69b4e", size = 175292, upload-time = "2026-08-03T21:19:55.566Z" }, + { url = "https://files.pythonhosted.org/packages/d9/79/615cc094e2fb508cade7de88d3b4f6c4ec2bab695c97bce9153dc65aadf5/cffi-2.1.1-cp312-cp312-win_amd64.whl", hash = "sha256:f53e442b08449d42821fa4a4fba000095af9f62742a500f978a9f557ec44339a", size = 185919, upload-time = "2026-08-03T21:19:56.89Z" }, + { url = "https://files.pythonhosted.org/packages/70/c6/d0ea84713fe46b243a436a18fcd47d639732747e21635c8a27191b06dc30/cffi-2.1.1-cp312-cp312-win_arm64.whl", hash = "sha256:7bde5e4cc5c10140859842b9d383af292b22639a4dffb725314baf45968cef80", size = 180093, upload-time = "2026-08-03T21:19:58.155Z" }, + { url = "https://files.pythonhosted.org/packages/9d/f4/035513d4117049066b4779dc3b7c0c0fdad175fa13731c9f4003f1cd1478/cffi-2.1.1-cp313-cp313-ios_13_0_arm64_iphoneos.whl", hash = "sha256:b5bdfd1c873d4e093aabc0ca84c4ca6dbc4f752afb5c86f146d9742580c9da2e", size = 194248, upload-time = "2026-08-03T21:19:59.399Z" }, + { url = "https://files.pythonhosted.org/packages/76/af/2aeb4dbb5fc41a04161ae9ff1518de7cec08e164f44a8ce6a4cf7fd2cd1d/cffi-2.1.1-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:31348097ff5bbe827ccc41795d4dd099d9f0625e7def00ee653c137a490c2a6c", size = 196908, upload-time = "2026-08-03T21:20:00.746Z" }, + { url = "https://files.pythonhosted.org/packages/a7/46/2e5fdde8555706dd98139a910ca11be02809f3f605ce956f655d0214e100/cffi-2.1.1-cp313-cp313-macosx_10_15_x86_64.whl", hash = "sha256:9d2055050ea716bd38b7f7f1579c275386646b4894c155a3e2f3cd62ed41b7c6", size = 184805, upload-time = "2026-08-03T21:20:02.02Z" }, + { url = "https://files.pythonhosted.org/packages/55/41/4c7042f317b9217502988f0873af87e16ad606dc20f84e546e3e6ce9764c/cffi-2.1.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:19ee6127ee34de7d83ce3d371ebc5ed91addbdcc39f9ab15ce4eb35a4e534971", size = 184764, upload-time = "2026-08-03T21:20:03.141Z" }, + { url = "https://files.pythonhosted.org/packages/43/1f/1c3d90d91811c8f86ced9ed637956c54bfe5b79ca98fe976d7f8c8979f6b/cffi-2.1.1-cp313-cp313-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:6a8dddef476fab96d066d578fc88526767b836ab5ab21754e1d5bf3879c31c7c", size = 214722, upload-time = "2026-08-03T21:20:04.377Z" }, + { url = "https://files.pythonhosted.org/packages/37/6f/3b5ce4c3b2192d250f04908f2bfd91ef34552ec8f7716a5d4abdb8d67bb2/cffi-2.1.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:f16c709686a78c727bbbf059f92b0bf41c6fc60deec706d2dc19f529175a6125", size = 222369, upload-time = "2026-08-03T21:20:05.544Z" }, + { url = "https://files.pythonhosted.org/packages/02/10/4b3c75dde3d9663c9e02ba05c2668b954f671d4bbe346413ca8c696b295a/cffi-2.1.1-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:fcd22650c908d7b7da162bbfaab594a1227a15d1643a98c68b122ac642fa2264", size = 210175, upload-time = "2026-08-03T21:20:06.75Z" }, + { url = "https://files.pythonhosted.org/packages/df/62/14f74b9543e605d17701dc797b815958b8bb70b7624ce1b832ddad48ed6c/cffi-2.1.1-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:aa9511c62d14da7aacc9b4bf51f3f697a621e83b2d6919008243c3aad168eea3", size = 208670, upload-time = "2026-08-03T21:20:08.04Z" }, + { url = "https://files.pythonhosted.org/packages/95/95/86342356ff5953b3fb06f7ef7c5bee212d45e770abc7218d451b9148313c/cffi-2.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:a931079504ecc49efed7744c476a5c343a92fabf66dec2db95edb1b2fdc770e2", size = 221824, upload-time = "2026-08-03T21:20:09.274Z" }, + { url = "https://files.pythonhosted.org/packages/eb/ff/7b3429ff53aafe931ed8a5fc69f481bbef7ba6de87ddcbb63d08f483f613/cffi-2.1.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:a2d7755bef5a12ed488f4ef1f1b69ee9191d7396083b755a5d2295f6edb4768b", size = 225148, upload-time = "2026-08-03T21:20:10.7Z" }, + { url = "https://files.pythonhosted.org/packages/34/34/a95870b9221e09cf4f2ce3178b1a210abdfe63a1bd357da940418d7b8d15/cffi-2.1.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:e0bcb7e0f677f543555d2adff3bf19c05f66cdb4796e5ff602442ab2fe3c4ef7", size = 223564, upload-time = "2026-08-03T21:20:12.165Z" }, + { url = "https://files.pythonhosted.org/packages/70/ea/839b50531021a647fb5e929f72cf97bc1ff702b5472166164b5b6e76b851/cffi-2.1.1-cp313-cp313-win32.whl", hash = "sha256:334644fbac4eff73d985a17a91226df55d0f394160c4cfb880e084c8f7161cac", size = 175263, upload-time = "2026-08-03T21:20:13.559Z" }, + { url = "https://files.pythonhosted.org/packages/60/a6/8b149b2c3f2e11aaa1618ef64500b45f50f22c57a977a4dff1aff1f91042/cffi-2.1.1-cp313-cp313-win_amd64.whl", hash = "sha256:1aa5645c30469b09530c4ebca77ebf8f17618293c58f8549cb1a543a50236e7d", size = 185688, upload-time = "2026-08-03T21:20:14.69Z" }, + { url = "https://files.pythonhosted.org/packages/01/9a/11f687cb39d6a3504060d5242f04f48c735afb4d3d533958a20594890cb2/cffi-2.1.1-cp313-cp313-win_arm64.whl", hash = "sha256:63bbfd5ded17c4840ac07cd8f1c21ba9d9708141f840b324f422f41b207e3973", size = 180078, upload-time = "2026-08-03T21:20:15.917Z" }, + { url = "https://files.pythonhosted.org/packages/d3/7b/d6bbf82b8b96e7391438898c42f5bd96dd02030fd5b64937d248220003e2/cffi-2.1.1-cp314-cp314-ios_13_0_arm64_iphoneos.whl", hash = "sha256:7dbb61fe3a7699468030f71bbe5f8a0e326a151daa91beb11a6fc1f980c55e1c", size = 194064, upload-time = "2026-08-03T21:20:17.148Z" }, + { url = "https://files.pythonhosted.org/packages/94/e6/bcc91b283be94735e268487a054004f0aa19947b6348fa367db53230abc8/cffi-2.1.1-cp314-cp314-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:f24fb43132a4c6b4cb4eb029492919b2db645be6808d738f244fd146c03c32cb", size = 196720, upload-time = "2026-08-03T21:20:18.268Z" }, + { url = "https://files.pythonhosted.org/packages/d9/99/c4b0c17cacdc9c3b8f280026286a9826d6a208c0f047591a3c3ce99b91fd/cffi-2.1.1-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:d28630f5854ab07ab1fd4aba756de52326c82e6be15d414b12793f1975048b54", size = 184964, upload-time = "2026-08-03T21:20:19.708Z" }, + { url = "https://files.pythonhosted.org/packages/b3/a9/9db617d05d7367c1ad0ab00b3aa6e6f9281edd689b4ee9ea0e5a84e89c97/cffi-2.1.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:661c298b4821edebead0c91edd2b00374d67ad7c5a1f7a91d4442633b79d6a72", size = 184962, upload-time = "2026-08-03T21:20:20.833Z" }, + { url = "https://files.pythonhosted.org/packages/67/b8/b42132ca113dc567d37684437b46ca1dafc885902b02a110a02d5b511857/cffi-2.1.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:58acb8ab8e295e6c5ea12f888cbb13cf21511ef2a3303a23f4325c29d17fe5c1", size = 222328, upload-time = "2026-08-03T21:20:22.118Z" }, + { url = "https://files.pythonhosted.org/packages/80/10/c5c0cbf0a657aecf59ef511409734230bf556f05a0d6c9eed7aa5c0a0166/cffi-2.1.1-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:456a61fa52d579ebf9df2e9552ead5129855dbaff6c1e5a9b1bc408809bdc062", size = 209985, upload-time = "2026-08-03T21:20:23.401Z" }, + { url = "https://files.pythonhosted.org/packages/d5/6c/bfa0b87b03b9238148beca990292843c9396ba069b54496596594173de7b/cffi-2.1.1-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:a4f00aa42f75d6e4595e8866e748cc1705adc0cddfeb2ca86d0d03993d63ba03", size = 208530, upload-time = "2026-08-03T21:20:24.628Z" }, + { url = "https://files.pythonhosted.org/packages/e9/02/4e7d553a7ac4b4238b38b3c1b80d486e9d4436f8d2acbf87a0997fe3f402/cffi-2.1.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:b0431303acaea1089ad4b3e9ce4e6518193def1118d4073ca848635ee4ea2e96", size = 221525, upload-time = "2026-08-03T21:20:25.758Z" }, + { url = "https://files.pythonhosted.org/packages/82/1d/a4aaf9babd75acb4d5f223bff71533bee748dd770a382619a798960ee9ba/cffi-2.1.1-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:64faea20f4e2613363a1a9b9c7dd73058f3ecd00133a511e72ad7c511658f527", size = 225053, upload-time = "2026-08-03T21:20:26.985Z" }, + { url = "https://files.pythonhosted.org/packages/81/10/5dc0e7bdd18e22107054288283380fc97a06ae3f1656a106908d666a3c88/cffi-2.1.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:5c58fe613dc5e5336357eff555824a314d8e43282600435c8d1cb6a7a2fedd13", size = 223213, upload-time = "2026-08-03T21:20:28.277Z" }, + { url = "https://files.pythonhosted.org/packages/0b/e9/d0061c364cde06ee43168a0d076ac1da512cbc380d44767b844ba34fe2b6/cffi-2.1.1-cp314-cp314-win32.whl", hash = "sha256:1a18a57b58cfb21fc28d72e876acf10eaed67a1ed96226f92af4df681d571c4c", size = 177682, upload-time = "2026-08-03T21:20:44.288Z" }, + { url = "https://files.pythonhosted.org/packages/a7/06/1c3e01e3ba14c39f6d10bfbac52753b7e22259e38088e5cfe1d704918690/cffi-2.1.1-cp314-cp314-win_amd64.whl", hash = "sha256:3222ba5d678f80a030e6afbcc33dc1ae5cb45facabb61cee2c7016b8432fde48", size = 187949, upload-time = "2026-08-03T21:20:45.623Z" }, + { url = "https://files.pythonhosted.org/packages/87/5b/da4e39efe18eeb89cf580ea9cfc66b6a7c3eadb808fc0cc1d3a295cb5a5d/cffi-2.1.1-cp314-cp314-win_arm64.whl", hash = "sha256:ab36d55f9ed2d067327667c2fea18dda018eb628dd6347aa01dda6cf1f5d3836", size = 182947, upload-time = "2026-08-03T21:20:46.955Z" }, + { url = "https://files.pythonhosted.org/packages/23/59/40338bf421c5accea1d45158170c87006ef1cd371b05c077e76476949728/cffi-2.1.1-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:7750c6449dff7864bb9bb27ddfb0267756189201a3afc911d82b3caacd70dfc3", size = 188504, upload-time = "2026-08-03T21:20:29.495Z" }, + { url = "https://files.pythonhosted.org/packages/7d/47/5ecf1023850036e674c77ec4de86182d309ae344e39e7cba984b7df5d647/cffi-2.1.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:0beceaabe56af686895136a2de78db54ecd8e4046b236b8fd6d6cb61389e9bf2", size = 188259, upload-time = "2026-08-03T21:20:31.291Z" }, + { url = "https://files.pythonhosted.org/packages/2a/9c/92934c3bea9f785b23eba304538c0b4d37a2a96d2431eb3a1bc87a11aa19/cffi-2.1.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:49cbc70e6542d4ccccb936558d1064a8012541e78f821f955cff24e357776c94", size = 223864, upload-time = "2026-08-03T21:20:32.571Z" }, + { url = "https://files.pythonhosted.org/packages/4d/45/ba4c93527bc38616a8bd36488acb69a2212d60486794f0c1f318949bbb76/cffi-2.1.1-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:e2d65b31f36619cda3999b78b2aa9632e76b78448e7a56fc4240824200e7c4fc", size = 211538, upload-time = "2026-08-03T21:20:33.808Z" }, + { url = "https://files.pythonhosted.org/packages/80/e9/b6ef565e452acb932fb0cb5443f44a78efbd1233e566f02b5a83855e9115/cffi-2.1.1-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:28907ab9bfb6aa13184cfc17c6b8e1023c5ab6fd7076d8c20a35e59fe04f8f29", size = 210688, upload-time = "2026-08-03T21:20:34.974Z" }, + { url = "https://files.pythonhosted.org/packages/9a/95/eff5f0cee78d2eabc7eebffec40d3fc1876b5f3c95582e018bb4b99601f2/cffi-2.1.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:51b31d1c98274844cfd7838ce00bfc27c7423a4dc00fc0772fc3331c2cc90676", size = 223803, upload-time = "2026-08-03T21:20:36.564Z" }, + { url = "https://files.pythonhosted.org/packages/fa/01/579d39fb8bef00a335a23d83757b44feb24cd6345a2c451b64cb67b9c362/cffi-2.1.1-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:5e7cecbaadb83884793e05828cee59b210b24583b9c7425d0ba6a754fe22eb4e", size = 226763, upload-time = "2026-08-03T21:20:37.816Z" }, + { url = "https://files.pythonhosted.org/packages/8d/b0/0b44f47c60b01b57b6e2bbd92343f13a85a1d93bc46ccf6e47e244acd99c/cffi-2.1.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:25792eac27877609e7bb06d42ff88278a6624fff2ba9bbb523c09616b117e80f", size = 225688, upload-time = "2026-08-03T21:20:38.959Z" }, + { url = "https://files.pythonhosted.org/packages/eb/d2/3b7176cb570a1d3e27faf67b72f591af508036e0d8b2be2ef9af9e8c84bb/cffi-2.1.1-cp314-cp314t-win32.whl", hash = "sha256:8ef53b2de9bcb9197d31854256575d59dbac0cba72ac627bb291ef5eceb74be4", size = 182868, upload-time = "2026-08-03T21:20:40.388Z" }, + { url = "https://files.pythonhosted.org/packages/56/78/31f00c1bcd97c9bbf55f1bfdf5bc809a5de8887473e90bb9960dca825e80/cffi-2.1.1-cp314-cp314t-win_amd64.whl", hash = "sha256:616f097f2fe415bc92a247f02e11f634e1f9e9a83d327e3c915c15089c87869e", size = 194104, upload-time = "2026-08-03T21:20:41.725Z" }, + { url = "https://files.pythonhosted.org/packages/7b/1b/58496f2ed0a35de575250c02a43ab3cc2c04d494a88fed31c1cabc0fd176/cffi-2.1.1-cp314-cp314t-win_arm64.whl", hash = "sha256:ad2c86c495b899d862ea0f4b42891b8713a3bd45dd4105c7fd51c2a72f39f3a5", size = 186402, upload-time = "2026-08-03T21:20:43.042Z" }, + { url = "https://files.pythonhosted.org/packages/c1/8f/9ebe220eab48a093d1a5a5e339ab0dc7316eef3bb04d63c42f0251b61f50/cffi-2.1.1-cp315-cp315-ios_13_0_arm64_iphoneos.whl", hash = "sha256:dddad92b554513a31f272570678ba307fb9f618f05e3d4a5eacafff9eae03e1d", size = 194043, upload-time = "2026-08-03T21:20:48.179Z" }, + { url = "https://files.pythonhosted.org/packages/ff/69/844bad3ece306c4782c2ecb93597035b6690d48704b803914c199da1e8b3/cffi-2.1.1-cp315-cp315-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:da0e573f9f97159390c89d9f1a9e41908b66d408cc5b58d08cf3847d844c531b", size = 196737, upload-time = "2026-08-03T21:20:49.457Z" }, + { url = "https://files.pythonhosted.org/packages/1b/8a/af668013284634733f02d683458a0728739c7d6ddb5e14cb0c20832266fe/cffi-2.1.1-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:fb92203a88b3d3053034db775110081c49d28be6551923805e039924093761e4", size = 184933, upload-time = "2026-08-03T21:20:50.639Z" }, + { url = "https://files.pythonhosted.org/packages/0c/75/2f5207ff6d1a613133b23a5203cc0c2a628313b5eb3974d7956ae3c57950/cffi-2.1.1-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:2ae64be792b8966f2c69538199728b290e34726562896df1e5dc8ffd8d8188e8", size = 185002, upload-time = "2026-08-03T21:20:52.173Z" }, + { url = "https://files.pythonhosted.org/packages/e2/31/9e1313b0a6e30e91b3b3d3fff51ae99c857c07738e3afcce1f7334e1b7ab/cffi-2.1.1-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:507a24c282e0f42f8ed737cf048572cbf580468da5555764a8331735e9c736b6", size = 222271, upload-time = "2026-08-03T21:20:53.462Z" }, + { url = "https://files.pythonhosted.org/packages/50/e3/f6234a833e6e08c7007003074723c406559eecf9b48dfc97471e5a8eb7a0/cffi-2.1.1-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:246fa40ce8645a614ff682e0b70f37134e460eaf93a775e0cbe3cca585a67a80", size = 209919, upload-time = "2026-08-03T21:20:54.783Z" }, + { url = "https://files.pythonhosted.org/packages/0d/fc/5f74e293fced6edb51af3a46c4ccf6c23c9943774ecb375ddbd522c76add/cffi-2.1.1-cp315-cp315-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:471cee653ae88de62096552e6d24ccb4a5adb8c8c9f10b5054d0122c15bf2779", size = 208529, upload-time = "2026-08-03T21:20:56.066Z" }, + { url = "https://files.pythonhosted.org/packages/44/16/29e6d01b388bef055ecd6ca8244b3f4d336bd09e92d5d892187b9601084e/cffi-2.1.1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:aeae0e330c9f6acd681f647d46cefd30c29f93e3392882e792e82080c9691399", size = 221630, upload-time = "2026-08-03T21:20:57.336Z" }, + { url = "https://files.pythonhosted.org/packages/a4/18/fa7f1f6857d5eb88a4ca99ffcbfb7c387a287ccc154c64a73e86314745d7/cffi-2.1.1-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:42a494cee34437f05546455144f2b5d9ac09b1face62bcfce597d2e521066688", size = 225134, upload-time = "2026-08-03T21:20:58.675Z" }, + { url = "https://files.pythonhosted.org/packages/e0/9f/e8e3dfa04a1b4c241f8c91faacad872b4d4efd051d49764ad4e2fd4b9fea/cffi-2.1.1-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:cc572dace3f60ef98d7b12ff411d20f5362feb31a0439eab0085bbfd349982d7", size = 223197, upload-time = "2026-08-03T21:20:59.968Z" }, + { url = "https://files.pythonhosted.org/packages/f8/7e/8debeb04f1ab9fe2a6963964cd6f1aaf7192627b83926586a6a4e089c9fa/cffi-2.1.1-cp315-cp315-win32.whl", hash = "sha256:4f42141fc14250de6dde5ee7ea4432be017252d91f19c5ad043c084cea629cac", size = 177683, upload-time = "2026-08-03T21:21:14.901Z" }, + { url = "https://files.pythonhosted.org/packages/e0/31/5158704cc474ab65c1647932e88be78dc0873f47130e253be38bcaf13d01/cffi-2.1.1-cp315-cp315-win_amd64.whl", hash = "sha256:e6e8cff14d6fb0be70a09c0bdc58096f501952d04624ebf867e0e56da2df8960", size = 187897, upload-time = "2026-08-03T21:21:16.108Z" }, + { url = "https://files.pythonhosted.org/packages/cc/4b/b3a2da8570c704ffc0f9762cdc3ec0f02c8573798e0b5cf7f11c82bbb70f/cffi-2.1.1-cp315-cp315-win_arm64.whl", hash = "sha256:27350daa11d4f10c540e6e89dada4c54feb7256ad03e9a4dc075ebad7ba360d1", size = 182935, upload-time = "2026-08-03T21:21:17.271Z" }, + { url = "https://files.pythonhosted.org/packages/d0/ef/5443574510a1207e6f6bc38ba6e1f1de36cb48fef07b2728bb896a21f430/cffi-2.1.1-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:c26608d2222fb1e94487e4a387d85f13eb55d5ed725cb25a0c589ac4ee60e7bc", size = 188464, upload-time = "2026-08-03T21:21:01.163Z" }, + { url = "https://files.pythonhosted.org/packages/7e/ae/a56fa8c4686ad50e148fcbc8d3ae0d03915ff5c30d795058988c24118cef/cffi-2.1.1-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:4be96343e422f2dfcd12ab5c9f5aebe03f82f737c6bffeca6830b3875cb44aab", size = 188262, upload-time = "2026-08-03T21:21:02.382Z" }, + { url = "https://files.pythonhosted.org/packages/53/b2/6187f46f2912276a3ae284076109cc5c8680482f11f766ccf26db4a86427/cffi-2.1.1-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:937c0052c05a31ca1daf18de3158eed4dbfcb9cc107adbea227728d647be701e", size = 223779, upload-time = "2026-08-03T21:21:03.553Z" }, + { url = "https://files.pythonhosted.org/packages/8a/f6/c3ad28bd19f77047a03084424fbd4cbe997303267c14423737324be0385d/cffi-2.1.1-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:df423d40ee8654634421812bc3b196da3f9bd7d32929da813f8394c4348a5358", size = 211520, upload-time = "2026-08-03T21:21:04.863Z" }, + { url = "https://files.pythonhosted.org/packages/a0/cd/ccac9013a5bd9fd764de118674ab9c805b5ca10c19270d90ee273f8b2240/cffi-2.1.1-cp315-cp315t-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:a730a083190634c65cca36ba5f489531576ebd79bcd5c8e172130f6453127231", size = 210673, upload-time = "2026-08-03T21:21:06.223Z" }, + { url = "https://files.pythonhosted.org/packages/52/86/2976131c639aead931c5bee5aba67e4b09fbeb8018b6f282f70803f923a7/cffi-2.1.1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:363e05fa78e15116c3c32c210ee36884fd6b9afa6d440e47112c3bd511d64cb6", size = 223835, upload-time = "2026-08-03T21:21:07.539Z" }, + { url = "https://files.pythonhosted.org/packages/ac/0c/33a7aeab2f9c76918c52e084beb39c570db3588133412929e8ec06fab90b/cffi-2.1.1-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:770de9db11e84213beec501cfcaa013b019820ca881e03344dea5844f7876d94", size = 226705, upload-time = "2026-08-03T21:21:08.774Z" }, + { url = "https://files.pythonhosted.org/packages/e3/26/2cde30fdde421130bfc18f70395731a6e6b2053c6a1978a5258ff04e72fa/cffi-2.1.1-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:7da0c5eff80f0197f3b3d1232ec5a682a9325f4ae9016a78f5f5ca35f9ced1f5", size = 225539, upload-time = "2026-08-03T21:21:09.911Z" }, + { url = "https://files.pythonhosted.org/packages/6d/cd/a361394c94b2129d604bb846f624a8e88255a3ee33129c434a00d715e64f/cffi-2.1.1-cp315-cp315t-win32.whl", hash = "sha256:06c72bb76605a4b0cd0aad6930b69d4baf7dd5d806cfc409b824191099700e66", size = 182707, upload-time = "2026-08-03T21:21:11.226Z" }, + { url = "https://files.pythonhosted.org/packages/9b/b5/ba2b299993c26577d529b6ae29841f9e15b9fcf004d65f423f4fcf94ade9/cffi-2.1.1-cp315-cp315t-win_amd64.whl", hash = "sha256:d9c275eaacd24aa73f94ffd6de08fc3f932424d8b6c376f4bed7cde376fe7bc3", size = 193772, upload-time = "2026-08-03T21:21:12.39Z" }, + { url = "https://files.pythonhosted.org/packages/aa/29/35e016098c814cd93de9cd320c66b5bfba14dc6ecedd3cb518fa7c408c69/cffi-2.1.1-cp315-cp315t-win_arm64.whl", hash = "sha256:d18e5ac0f2f03f4f518d3e23db0f0cad7faa1da8620e9c09461d443bbf6e6692", size = 186360, upload-time = "2026-08-03T21:21:13.636Z" }, +] + +[[package]] +name = "cfgv" +version = "3.5.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/4e/b5/721b8799b04bf9afe054a3899c6cf4e880fcf8563cc71c15610242490a0c/cfgv-3.5.0.tar.gz", hash = "sha256:d5b1034354820651caa73ede66a6294d6e95c1b00acc5e9b098e917404669132", size = 7334, upload-time = "2025-11-19T20:55:51.612Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/db/3c/33bac158f8ab7f89b2e59426d5fe2e4f63f7ed25df84c036890172b412b5/cfgv-3.5.0-py2.py3-none-any.whl", hash = "sha256:a8dc6b26ad22ff227d2634a65cb388215ce6cc96bbcc5cfde7641ae87e8dacc0", size = 7445, upload-time = "2025-11-19T20:55:50.744Z" }, +] + +[[package]] +name = "charset-normalizer" +version = "3.5.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/33/1c/f41d4e74c28ab327ff3acd36053f7ea506c55872d7a90b0fa71aa3ab0c89/charset_normalizer-3.5.2.tar.gz", hash = "sha256:39de2a259fc954455c57274dc94c79d5842774e1247a016aff30bc0efed0f4ef", size = 172659, upload-time = "2026-09-30T04:39:23.398Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/22/67/6a0b94a7960d5e1b5eacd2fb529f3fccc47db4644f7f0a7cfdcfc3be578a/charset_normalizer-3.5.2-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:3d21b8b13c7592db2ac5e544a6d83187b995257472b0c9e8351b6d507ae37ed6", size = 370642, upload-time = "2026-09-30T04:35:06.91Z" }, + { url = "https://files.pythonhosted.org/packages/fb/94/01009e13b94041599004edf32e56e382c24e570f60f79bab8efe45cfe1eb/charset_normalizer-3.5.2-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:d760fe2a4d7c3b226cb9026d6a842868d52a7901bd98420e1baf14e80da85cf5", size = 259280, upload-time = "2026-09-30T04:35:08.448Z" }, + { url = "https://files.pythonhosted.org/packages/66/85/3b5358f60a13210f0b67d3755c168ef758701b021e655d88d4da28554467/charset_normalizer-3.5.2-cp311-cp311-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:c9790464842f85f437dbbb54417eda1e0e6bfc52dd8d22d6fd1c994b73b2dc74", size = 245335, upload-time = "2026-09-30T04:35:10.104Z" }, + { url = "https://files.pythonhosted.org/packages/74/75/77c1c479b09ecd751d1e767b251ea5c14d4d50ff757bf404afab2692f600/charset_normalizer-3.5.2-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:4685902cf26edf013ed7a3da0f426ebba7a00ebb9541386d835afbf002c11cab", size = 291707, upload-time = "2026-09-30T04:35:11.575Z" }, + { url = "https://files.pythonhosted.org/packages/0b/0d/363f78cacb70f58f15f4b083961bbd9d292f335d3f5c66fc4f1cfe69cb90/charset_normalizer-3.5.2-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:4495c5002a7b28557e7e222e77e0b661183e432b7d6d2e788101e3f240e05b8c", size = 286747, upload-time = "2026-09-30T04:35:13.022Z" }, + { url = "https://files.pythonhosted.org/packages/e4/ed/cf505d3011ffceb12c2067a7a5d3cfe92b875d4d44bb0ff0d69375e2c184/charset_normalizer-3.5.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:211d5a3eb6af8f513b8d4ca19a8c1b7accab1b5f0d3175f9826b03c1a920dc1f", size = 269972, upload-time = "2026-09-30T04:35:14.606Z" }, + { url = "https://files.pythonhosted.org/packages/15/d8/f0a93a431d170e7ca681d4f6650fee3de934d18560e474e7267eb4b0f987/charset_normalizer-3.5.2-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:ef4fcbf3327382cd4c9f540babd61248208af7b93eec4de397b4d5f58a09e288", size = 269339, upload-time = "2026-09-30T04:35:16.087Z" }, + { url = "https://files.pythonhosted.org/packages/86/bd/9b2bd1c5b7af02462c9752d33994834ff972a96b4c483eefde9e594488e2/charset_normalizer-3.5.2-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:bd16aabe4a02a297c23417aa17ac6299dbd8c49f673bcd645b4929b11f5a4400", size = 261683, upload-time = "2026-09-30T04:35:17.488Z" }, + { url = "https://files.pythonhosted.org/packages/76/a5/cac540ab0fd61f3fec88ad3dbb64509e71424593d73cfdfff5ab3e4db279/charset_normalizer-3.5.2-cp311-cp311-musllinux_1_2_armv7l.whl", hash = "sha256:fb9e68df06293761f9fe66ade60a9bc6d0f5e42b8acf2939a9158af86ab0e5bd", size = 248143, upload-time = "2026-09-30T04:35:18.849Z" }, + { url = "https://files.pythonhosted.org/packages/71/7a/ff467301deef2089fad87f72df9e000a26a78fec7acbb18e1999371b8369/charset_normalizer-3.5.2-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:59f63901b0031c3136cf64704dcb21de0bbae62ce2c9529bc39d27665463de37", size = 292358, upload-time = "2026-09-30T04:35:20.326Z" }, + { url = "https://files.pythonhosted.org/packages/ad/77/22d7e785d1e210afc2e2f58600dd1799d17a35665faf84383f002826c5f8/charset_normalizer-3.5.2-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:304d5463e65a35d7bb0850550e0780395395f6fcf452f04db7d5ca7cecc425ac", size = 268766, upload-time = "2026-09-30T04:35:21.72Z" }, + { url = "https://files.pythonhosted.org/packages/ae/91/e8e946267f1c2d9e2bd651726e2fbd2addf02c4d36cea5069e32ca9d7bb5/charset_normalizer-3.5.2-cp311-cp311-musllinux_1_2_s390x.whl", hash = "sha256:9cf9b1a857e25c4baceeb3624e92a56df3668f398c4acba74e174d81fb4d1d3a", size = 287432, upload-time = "2026-09-30T04:35:23.273Z" }, + { url = "https://files.pythonhosted.org/packages/4e/88/7561d8a88d555e7df6623abe7c0070b4baf47549b9408783a2ae0a1a6cf7/charset_normalizer-3.5.2-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:114e4d0c92d618409ed82a99e22b5c5e768fe995f2973f78265f4524f49d4640", size = 272470, upload-time = "2026-09-30T04:35:24.655Z" }, + { url = "https://files.pythonhosted.org/packages/35/7e/578c702301ec036f01455f30744a08d2b42f6ab35b9b2d4bf8cae0ef2a80/charset_normalizer-3.5.2-cp311-cp311-win32.whl", hash = "sha256:2625388c6c754520c37abaf3b41eb34d1cc4a373f457898f08606c8e362b891d", size = 186688, upload-time = "2026-09-30T04:35:26.225Z" }, + { url = "https://files.pythonhosted.org/packages/e8/fc/fdf8cf52ff21cd5bf158f20978991cf985325842f74283eb6df26c8a39d8/charset_normalizer-3.5.2-cp311-cp311-win_amd64.whl", hash = "sha256:87e50a3e7cb90af586b6c5faf23e302a970415ac73bd7bd90a515a04b427ef96", size = 214932, upload-time = "2026-09-30T04:35:27.796Z" }, + { url = "https://files.pythonhosted.org/packages/97/66/3e45a506d8110b632541faf9a9470185aa9878f1ed44020f31346c1c5e5b/charset_normalizer-3.5.2-cp311-cp311-win_arm64.whl", hash = "sha256:254eb48b9fa5ee9898a3c445825a1f340fe53712a098904b39b0bddba8ea3cb1", size = 202828, upload-time = "2026-09-30T04:35:29.259Z" }, + { url = "https://files.pythonhosted.org/packages/e7/c8/693809898870237d82785a03f3b2b58fe4c9f14669f84a7d4e623c92a59e/charset_normalizer-3.5.2-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:ed2a239c0ea213acc1908150a3037257083c7c083128f1a4cec2ec4b97dca491", size = 367780, upload-time = "2026-09-30T04:35:30.888Z" }, + { url = "https://files.pythonhosted.org/packages/c9/87/2fea8c13dc24b3ca9c6f803a5b2dfdeae73eb4f9e12c7885ed908ff0433c/charset_normalizer-3.5.2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b91363207bd9dc966a691e959bb47f64b30f7ac4b072be9968b366982f7db77c", size = 246730, upload-time = "2026-09-30T04:35:32.286Z" }, + { url = "https://files.pythonhosted.org/packages/a8/9e/09efac30b937722f46d3110ba30b875b24b2e3a266ed746cc4e376a94d80/charset_normalizer-3.5.2-cp312-cp312-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:38a873987f3be698494da8b2e3085e29da02da7b633dce73e79c699a113d7bf0", size = 237707, upload-time = "2026-09-30T04:35:33.709Z" }, + { url = "https://files.pythonhosted.org/packages/9e/18/70d76670b13686237863a379928d60bd10e021f17d243ab3d7014c4a5f4e/charset_normalizer-3.5.2-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:355ad8011081dec5412240c087a9a0c9d4d5039f3ed11a3f13e18c2b29b56c51", size = 273050, upload-time = "2026-09-30T04:35:35.138Z" }, + { url = "https://files.pythonhosted.org/packages/54/e2/77a8b09d5adc013ed07b95b01b8b8fa5441c4e810e83ee7e4aae2fa4d91a/charset_normalizer-3.5.2-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:ee21e28f0430bd6dc9086c6e525d5e818a44a5ad19720c8a0ef766792f3eb5e5", size = 270345, upload-time = "2026-09-30T04:35:36.502Z" }, + { url = "https://files.pythonhosted.org/packages/7f/c5/38806a25ab5e65fc178f39affeda20858efafede2fce1ffc2556cfc9fe73/charset_normalizer-3.5.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3d31298449090ab8d47b7b1b2a555ff73cac7ed438a08b7ac160980c7ebed649", size = 257601, upload-time = "2026-09-30T04:35:37.919Z" }, + { url = "https://files.pythonhosted.org/packages/ae/8d/213565184708fdb263ae55e2c04ee1ff748129dd65d48ed0e3502da9c85a/charset_normalizer-3.5.2-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:5cde776b7cc66e4f6c99612cea4aa7269aa65863f7a15841b2c264f103822f4e", size = 252222, upload-time = "2026-09-30T04:35:39.544Z" }, + { url = "https://files.pythonhosted.org/packages/7e/24/76d2cefc25472531e4c5c7dfff68865eb1c39b78482f0fdc15b46f047830/charset_normalizer-3.5.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:ae4f5fea5b8b8ccff88238cc8569303e5ee95efae67fa62922a311397a71f346", size = 248482, upload-time = "2026-09-30T04:35:41.088Z" }, + { url = "https://files.pythonhosted.org/packages/7d/dc/65a801b66ab4c197e22c433ab25e7ac24324ac6f45a2269aca42cce309bf/charset_normalizer-3.5.2-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:f7d486c83842422badd511868fd8a9a20e9407ace71564b6af47ce7e60a336c1", size = 241206, upload-time = "2026-09-30T04:35:42.59Z" }, + { url = "https://files.pythonhosted.org/packages/a7/95/ca9b5eabde673002c6f1e7ada1b223916fe18f6d661da7aabd4d643718f1/charset_normalizer-3.5.2-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:11a4d68a6ecda3292cb1e50239e111543ba5d709bb62a6b4ea1afcfa729d8875", size = 273190, upload-time = "2026-09-30T04:35:44.347Z" }, + { url = "https://files.pythonhosted.org/packages/2d/8b/803b4d2a3f6e1740f63f1e87b04d14b42f3d4fdfe6ed7d4db2d34102b14f/charset_normalizer-3.5.2-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:d6734d2ef8a50fbf8445c139477da401f50d62a0606bf00e20ec6d87773fefb1", size = 253527, upload-time = "2026-09-30T04:35:45.915Z" }, + { url = "https://files.pythonhosted.org/packages/a9/55/93c0e5dbd085ae0471346026abbe7e0db9ea2d6fea74e51f0b5a46f233a7/charset_normalizer-3.5.2-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:a815775b6c38d4e0ff7bcffbeba67feded90202bb6a226b8dd35f1c855217413", size = 271285, upload-time = "2026-09-30T04:35:47.49Z" }, + { url = "https://files.pythonhosted.org/packages/95/69/0dbd0e0b9b16cfa816cdfcb3e2e3854a1f680dc07fb1245ea125e7448060/charset_normalizer-3.5.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:23851fb4e1b85ed3f6c2a27b777cdfe2e19fb5b38429a8faf38c7542b7665869", size = 260010, upload-time = "2026-09-30T04:35:48.996Z" }, + { url = "https://files.pythonhosted.org/packages/58/9d/e7b88e7b1bf403590c3b573277b5e1e488c68c7a6fbacca310a2c324e90c/charset_normalizer-3.5.2-cp312-cp312-win32.whl", hash = "sha256:db19d07e2e0129e974a0e65d0064fc222a446cd5122c2fd4184d2af9fc734a9e", size = 184125, upload-time = "2026-09-30T04:35:50.777Z" }, + { url = "https://files.pythonhosted.org/packages/eb/e6/e6e083884cbcfd49c64865af05027fe7011be7b2d9179524f099a1b611f3/charset_normalizer-3.5.2-cp312-cp312-win_amd64.whl", hash = "sha256:780fbe7cab297b81dad9fb8dc5eb003c0468ffb0d9e5f65068c53a34661a96bc", size = 207486, upload-time = "2026-09-30T04:35:52.194Z" }, + { url = "https://files.pythonhosted.org/packages/c4/e3/017aea0911ada7405a825c7d937eb3a13009664e2f5b38e8c4bbf2abf894/charset_normalizer-3.5.2-cp312-cp312-win_arm64.whl", hash = "sha256:e2af3aad578aa6bd1384bcf4750fc285e5a9de53f40b7d41e5a0bf748edeb2b3", size = 196734, upload-time = "2026-09-30T04:35:53.636Z" }, + { url = "https://files.pythonhosted.org/packages/c5/34/68292d68512768591aaff07c59bb53ee31341c87759433a859c4641a50c2/charset_normalizer-3.5.2-cp313-cp313-android_24_arm64_v8a.whl", hash = "sha256:ed905975ab14056a2e5eb1c376cb2e1ebc5396baf84163939c518556fccde9f5", size = 225946, upload-time = "2026-09-30T04:35:55.313Z" }, + { url = "https://files.pythonhosted.org/packages/e3/80/bee0b01b90ccd5322ae1d0abb33fab1bd95b7c2eadaf02aeccf22e04ee83/charset_normalizer-3.5.2-cp313-cp313-android_24_x86_64.whl", hash = "sha256:a66c3bc5ab1f0ff2164fc9965ddd611ff0802173f4b9d24554c563f6ab7e1d6e", size = 238619, upload-time = "2026-09-30T04:35:56.863Z" }, + { url = "https://files.pythonhosted.org/packages/78/6e/60ce52a85a7fd631ae8482ae6d74521014ca2f255892679484dc04d7ef56/charset_normalizer-3.5.2-cp313-cp313-ios_13_0_arm64_iphoneos.whl", hash = "sha256:d2374b62878abb00cd8309b32af6c0b715cd02dec0ca74ef12e5069bdc64144a", size = 206701, upload-time = "2026-09-30T04:35:58.639Z" }, + { url = "https://files.pythonhosted.org/packages/36/8c/71aafad23f971afc84c2b295bc0c560739ce1dac558aad9fec22e39f3639/charset_normalizer-3.5.2-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:d376bbd28b3a8999db1a103b3b388aee6f1ddeb3e51bc2172993efdcd86e064d", size = 210506, upload-time = "2026-09-30T04:36:00.147Z" }, + { url = "https://files.pythonhosted.org/packages/91/da/3c5a7798c046df7d2d68ad653cf5b6c5a8bfee225055a843c6f2f42aac1a/charset_normalizer-3.5.2-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:6045373d5a89a5ec71afde535db987ca28e76dfa276c2d4c818265b375d4b055", size = 366626, upload-time = "2026-09-30T04:36:01.77Z" }, + { url = "https://files.pythonhosted.org/packages/e1/16/710ac3de2ee354e2bd1a9c94efe45a2d27b5c6ad39b2d6a905be2c094b6c/charset_normalizer-3.5.2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:849df64e889b2e17230d58410a03dba311a65b163508fd33679b2b737d4b7858", size = 244624, upload-time = "2026-09-30T04:36:03.389Z" }, + { url = "https://files.pythonhosted.org/packages/d6/39/45c7439f5b63d24f7d5b2a1d760f34af7628782d7144b4cc8ded45c2d4bc/charset_normalizer-3.5.2-cp313-cp313-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:15c44f7edfd477b06f517a5cc317fc1707edb9de2c865f43d4b6513907473234", size = 235731, upload-time = "2026-09-30T04:36:04.987Z" }, + { url = "https://files.pythonhosted.org/packages/4d/34/38f3154785ce92e9f56eb226f4d35bdfae6b008480dd055f58837a89c810/charset_normalizer-3.5.2-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:a89012d6d5476ee112d20d998570ed58df2260a852afb1758809cd6900411d21", size = 270352, upload-time = "2026-09-30T04:36:06.412Z" }, + { url = "https://files.pythonhosted.org/packages/04/f3/859f74e7babc977705026b30593b3be04049632a522fb7000f83c033d747/charset_normalizer-3.5.2-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:0c951d5e6dd9c2ff60609476752bee49da4206adde960ebc247766937f72e718", size = 267393, upload-time = "2026-09-30T04:36:07.865Z" }, + { url = "https://files.pythonhosted.org/packages/4b/85/41d27f234b82e47c167a5f6c0f62501dc0c640585ff4aba79e08a390336a/charset_normalizer-3.5.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7218e8f32b0956cfcd048fd42d9d5779809745ca1d86113ca56f66e7ae1549c4", size = 254660, upload-time = "2026-09-30T04:36:09.248Z" }, + { url = "https://files.pythonhosted.org/packages/58/ca/5d1a997587febe5b26d8daffe363b5c1a091cece19828eec6502fd09c5ef/charset_normalizer-3.5.2-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:a19a731138fc27d5682277d3b9df22855cea1239bce7fcec5f78f42ef2d1f3c3", size = 249996, upload-time = "2026-09-30T04:36:10.73Z" }, + { url = "https://files.pythonhosted.org/packages/b3/1f/d1e78246f7ed60c8c8d606b4ac27f66ce49cc3e95f24893ccbeba9f77302/charset_normalizer-3.5.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:62603db9a7caa0802eaa28c1c46fecd7b3a263a774069c24c3c28c302448721c", size = 247028, upload-time = "2026-09-30T04:36:12.294Z" }, + { url = "https://files.pythonhosted.org/packages/8e/37/eba316edd4f0c4d3a5d945924c4eeeae59abac4056aa815d8a4268f863a2/charset_normalizer-3.5.2-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:b6856554c4f44d79fc2307d5768854310a8f0096e501c75637542c82292b0429", size = 240562, upload-time = "2026-09-30T04:36:13.887Z" }, + { url = "https://files.pythonhosted.org/packages/c8/8e/aaa037d40ca9ef045977f1a661048b1aa33f223adfce3452fe9be9f79d14/charset_normalizer-3.5.2-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:1bc0baf5ef96b6ede57d47f4b8fe4d9d84019c3bfcbeb20a41edc6a6ee341f1f", size = 271699, upload-time = "2026-09-30T04:36:15.41Z" }, + { url = "https://files.pythonhosted.org/packages/26/19/1c1c9f75974adf523b87f34b8a2adc5a435cd65916812bcbd0dfa45f9a29/charset_normalizer-3.5.2-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:56bc200a365efb37383b7852e4cc5898d3b2da5987289b543956cf8cad71018a", size = 252030, upload-time = "2026-09-30T04:36:16.839Z" }, + { url = "https://files.pythonhosted.org/packages/bc/90/0660ef18e18df0a4d2a1a0edff7dfbba42d4e50ef2425557a5bb7051f77b/charset_normalizer-3.5.2-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:2c9ad19a6cfcd5ea5c0d41161d22f9df1dcc277e9bef2751391334546a314c00", size = 268565, upload-time = "2026-09-30T04:36:18.468Z" }, + { url = "https://files.pythonhosted.org/packages/79/ba/57adc269824e8658f1a0f97a9e514c247445a9632b3419b97e0ba37f16dc/charset_normalizer-3.5.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:e243bd13217235fc7290c621941c3f5cc8b66e4872495be821d7436ba2fb838d", size = 257627, upload-time = "2026-09-30T04:36:19.938Z" }, + { url = "https://files.pythonhosted.org/packages/9a/85/33abd4315c052d3d4f54c92b1ee49bfbc0dc7115a981e462a793b6d2ab87/charset_normalizer-3.5.2-cp313-cp313-pyemscripten_2025_0_wasm32.whl", hash = "sha256:a090bb2c68df85450502e3e20d665e3a5af9c65a84d6508ed477badd49166fd3", size = 143407, upload-time = "2026-09-30T04:36:21.376Z" }, + { url = "https://files.pythonhosted.org/packages/4f/de/6435e18d1aaa5d910b896d551411c96af1f42a0c56c29afc2016c61ccc2e/charset_normalizer-3.5.2-cp313-cp313-win32.whl", hash = "sha256:2b7b3bbfb4fe8ef40600792d762fbaa9057559f9d3fad209525b7a22b99e91fd", size = 183207, upload-time = "2026-09-30T04:36:22.776Z" }, + { url = "https://files.pythonhosted.org/packages/9c/76/b8ec57f4e9ee3253541abf95e4a462c0175fe8032dcd070f1f2421240942/charset_normalizer-3.5.2-cp313-cp313-win_amd64.whl", hash = "sha256:78456a747de8dc58360ffa581f30a002baf5aa28cb262536545e91f113ed7639", size = 206489, upload-time = "2026-09-30T04:36:24.306Z" }, + { url = "https://files.pythonhosted.org/packages/3e/60/c647c6ae47480221e875ea5d743ff94946f7416e3c69415ab772928e8d32/charset_normalizer-3.5.2-cp313-cp313-win_arm64.whl", hash = "sha256:11912e4bb14baae7c5d8791aa55ba0a3a03ec6729073307b0f57270abaa713d3", size = 195501, upload-time = "2026-09-30T04:36:25.846Z" }, + { url = "https://files.pythonhosted.org/packages/58/ca/7aa91362a2f77ac8e9e28a9b902a74f7d0e11a851ef0d27a74308da8cd90/charset_normalizer-3.5.2-cp314-cp314-android_24_arm64_v8a.whl", hash = "sha256:1afb975bd5d68d5ce9f6b6d44fdf2f7e34b895a35e95708a7a91b20a3b51d187", size = 226010, upload-time = "2026-09-30T04:36:27.669Z" }, + { url = "https://files.pythonhosted.org/packages/a8/cf/ac8878d0322cf88a1aad4c7b147db32ca0bd806eb0060957b2e31486dbe6/charset_normalizer-3.5.2-cp314-cp314-android_24_x86_64.whl", hash = "sha256:bbbfc8e28816f19d7c0f1816664980c0a9875d01b27cdf8eedddb639d9e108ad", size = 239266, upload-time = "2026-09-30T04:36:29.434Z" }, + { url = "https://files.pythonhosted.org/packages/c9/6d/9a08d7e0b29b7208e2c6c01dc56c8e0520e7c7beadbbfb024b58fd69c8a5/charset_normalizer-3.5.2-cp314-cp314-ios_13_0_arm64_iphoneos.whl", hash = "sha256:7967d08cf06dee78443b874f98c98036f624f3a4e73e11f9f64f5be4d25393cf", size = 206783, upload-time = "2026-09-30T04:36:30.872Z" }, + { url = "https://files.pythonhosted.org/packages/82/44/b0aa350280e6ff5a5492d17cf10460dd39d5ee848f872f7ba2df10607f60/charset_normalizer-3.5.2-cp314-cp314-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:4c2b5031f63e331e3839b40aed2dd6f191e9c07edbde303e7876846ea1946995", size = 210449, upload-time = "2026-09-30T04:36:32.625Z" }, + { url = "https://files.pythonhosted.org/packages/7c/8a/40db9aa9f5907bb0e6f8b6d64064bf8852fb33d4b813ff9414911df7647c/charset_normalizer-3.5.2-cp314-cp314-macosx_10_15_universal2.whl", hash = "sha256:fcff63213e8e6e47770541a4607175404f47cbb3ebea7b6058cc82d524a0e424", size = 367815, upload-time = "2026-09-30T04:36:34.197Z" }, + { url = "https://files.pythonhosted.org/packages/7f/72/9c5e7707b57c8ddfa9ddf7b0b1d009d7fbab9e9e887d5b721060f37e307d/charset_normalizer-3.5.2-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:8d86d6fc60743dc916eb79e2eb1ec4818e21e427731543af40a3021851174a13", size = 247095, upload-time = "2026-09-30T04:36:35.803Z" }, + { url = "https://files.pythonhosted.org/packages/83/09/71e453691e927de4ddf792770cfaab3f49d494e222f66ea5e404bbd5e39c/charset_normalizer-3.5.2-cp314-cp314-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:7a881931aa470808df94a8c380eed2bbbc76cd9dc622310f99665658c821eb6d", size = 233942, upload-time = "2026-09-30T04:36:37.407Z" }, + { url = "https://files.pythonhosted.org/packages/9f/86/85c84e4da8b27dd409577d9437926ff581c5f9d3c66038dc68c1a526de51/charset_normalizer-3.5.2-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:8024d00c3faf3fc0c16e07a69f4405e8eac7cc0ab15f65fe6cf43827c4cf72b4", size = 273762, upload-time = "2026-09-30T04:36:38.904Z" }, + { url = "https://files.pythonhosted.org/packages/92/08/564955a4b5f2ccb410ab480bbe8c6a18063ff27f2d35458731c4a5335df9/charset_normalizer-3.5.2-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:4d48f2d08b9de5864e2c8744d4461b862fb149a18274abc8b698c45975573438", size = 269514, upload-time = "2026-09-30T04:36:40.469Z" }, + { url = "https://files.pythonhosted.org/packages/18/24/bad3ac4271589df29cf5ce2f5ae490518a5739358052bd0d61209e6fea54/charset_normalizer-3.5.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:34276fd796040bf0993ab33a369aa572e6979c7aab225a88893667ad8eac8f7a", size = 255056, upload-time = "2026-09-30T04:36:42.02Z" }, + { url = "https://files.pythonhosted.org/packages/d6/3e/350d89ad49916b86554d6f5f2d03ec1152148f87e5ff735106c6a03b1a36/charset_normalizer-3.5.2-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:0521c5665880b33d603717defa76c094048900010897909952397feb3039da56", size = 251311, upload-time = "2026-09-30T04:36:43.577Z" }, + { url = "https://files.pythonhosted.org/packages/56/5b/4970a2d154df502e133402906dd04e3ae7cada7b3011283c88d0479a2585/charset_normalizer-3.5.2-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:eff0ac9dbe711a4aee69bf04a83896aa9b85f19641264053a9f6d48573abb7dd", size = 250190, upload-time = "2026-09-30T04:36:45.185Z" }, + { url = "https://files.pythonhosted.org/packages/88/8c/f1a91bddc8fb47c2889e29ea7ea49a194eb0d9868675d786806519c00d76/charset_normalizer-3.5.2-cp314-cp314-musllinux_1_2_armv7l.whl", hash = "sha256:1503bccbeb36d5527790c3930327704c39af22de3112f1b1666a9f3ce15ee204", size = 237098, upload-time = "2026-09-30T04:36:46.689Z" }, + { url = "https://files.pythonhosted.org/packages/24/0e/bb5dace3cc7e79068425386a6589c19b5a2ab5fefc2a46abea6919683332/charset_normalizer-3.5.2-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:52aa6992700996af31f375de0c6bacd402b0097fe40b53c426b9f51a90ebabc7", size = 274228, upload-time = "2026-09-30T04:36:48.31Z" }, + { url = "https://files.pythonhosted.org/packages/9d/79/b849ad523017ea9f5a45581bbebed91439e0cf42fd2860a6f64e358eb5a6/charset_normalizer-3.5.2-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:e09a3942ecbdee5cce73ea9d42da82b81b72ac1bf031ce069b93b5adf4eac8cd", size = 252401, upload-time = "2026-09-30T04:36:50.091Z" }, + { url = "https://files.pythonhosted.org/packages/89/8c/75469d690cf47200bce8f6cad7655724fc23148e147abfc5ce78b5f65863/charset_normalizer-3.5.2-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:c7c9ab723cde841fefb34efbad91e87f00a674b1fe1cd0784fde742bf2c154dc", size = 271846, upload-time = "2026-09-30T04:36:51.719Z" }, + { url = "https://files.pythonhosted.org/packages/26/cd/6d52d3c7437cdcf2e310ce9f28f282e733d4ef60ed19105d1819c356255f/charset_normalizer-3.5.2-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:ddc7dacc8ece3a182e7f15cb862d1fd616b46d076cb1ae9dd232b2c38b655874", size = 258151, upload-time = "2026-09-30T04:36:53.234Z" }, + { url = "https://files.pythonhosted.org/packages/f7/4c/070b38bdb5f49a70199fce923ec0726a49536a63ab262abbfcaaf351110b/charset_normalizer-3.5.2-cp314-cp314-pyemscripten_2026_0_wasm32.whl", hash = "sha256:ee43c17b173d46a3212baa6ead3ae258eeabdae48c263a01ccf0218c366dd655", size = 143570, upload-time = "2026-09-30T04:36:54.816Z" }, + { url = "https://files.pythonhosted.org/packages/81/84/9ebfc8ed6c8c4fcd8e726ff6bf220cc8deb3966e31dce9be8dd8aa017e64/charset_normalizer-3.5.2-cp314-cp314-win32.whl", hash = "sha256:4f87960d57feabfb618e4e0af6e7371645fa26a277860739d6e5d6e0012c92f0", size = 186412, upload-time = "2026-09-30T04:36:56.643Z" }, + { url = "https://files.pythonhosted.org/packages/d1/78/5ed86f743d4bc350db307e7636419a0a5ee1d91806d30c7f667bd5c80dae/charset_normalizer-3.5.2-cp314-cp314-win_amd64.whl", hash = "sha256:e4e81e09c1578b8df602e3db08b0b3ea0a6947ad612f52bf8dc5ea8d47691f0c", size = 210965, upload-time = "2026-09-30T04:36:58.205Z" }, + { url = "https://files.pythonhosted.org/packages/53/94/a3a7698e9b1a395e1eb99ccd9a324be9347973bff4e72db2a06496d7cd27/charset_normalizer-3.5.2-cp314-cp314-win_arm64.whl", hash = "sha256:80d02b6f04e92601a081dd97b23d3128033098bff5d35d392ddcc0476ea11253", size = 200406, upload-time = "2026-09-30T04:36:59.764Z" }, + { url = "https://files.pythonhosted.org/packages/c1/48/c5dd00d5ef7791f02666de250a5bb6071e29b7e133cf4b835800b6d3bc27/charset_normalizer-3.5.2-cp314-cp314t-macosx_10_15_universal2.whl", hash = "sha256:dca9ab98072a5a54ebacebdc45f53e645336b320c667410b061be1ca588ae709", size = 396871, upload-time = "2026-09-30T04:37:01.543Z" }, + { url = "https://files.pythonhosted.org/packages/12/c8/8379554b42e8368161d898476686947a0fdbd3e8865170d7909dcabfdee8/charset_normalizer-3.5.2-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f0aa869112ef88429ae17820d99c3dd9504c9e9c671d3c246f3d7442cb051084", size = 249711, upload-time = "2026-09-30T04:37:03.111Z" }, + { url = "https://files.pythonhosted.org/packages/4a/eb/2ddb1035d17320caa9f41682935123a9a250277b261c3efc86b2d2a21343/charset_normalizer-3.5.2-cp314-cp314t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:c0afc6800ba57ccc350374c5bd6150419915d95ce93cdbab2d783d75eaf30ecb", size = 231146, upload-time = "2026-09-30T04:37:04.721Z" }, + { url = "https://files.pythonhosted.org/packages/4a/24/2ecb4bde104322cd7859d6594fcfa74649f8d90b3221c9feecbef149875b/charset_normalizer-3.5.2-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:7dcd882da75ef9adf94903b1e3b9419e8aa8fb4c7396822b834b9ef7fb96954f", size = 271552, upload-time = "2026-09-30T04:37:06.295Z" }, + { url = "https://files.pythonhosted.org/packages/3f/98/9d5f6ebc3aee9fef5d30b4aff11fb2ab7a1222b4064f8ef2c7c87cde217a/charset_normalizer-3.5.2-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:2e06a3a98f916dd41d27f3105e02e7a40181c98c94b9158733d03a6f80506c09", size = 269810, upload-time = "2026-09-30T04:37:07.905Z" }, + { url = "https://files.pythonhosted.org/packages/09/e1/a3b06a10461b1b7628853c934c644e03bc28e42767116afb52f19a56519b/charset_normalizer-3.5.2-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:6bd128f206a7752ae1f2ab6c61bf8a24ba28913a10df8b14c2637b973ff97a80", size = 259845, upload-time = "2026-09-30T04:37:09.554Z" }, + { url = "https://files.pythonhosted.org/packages/fd/d3/6f561f74a296cf27d61775a1dc665ad13f3bff6a798810ca05907f37a7c4/charset_normalizer-3.5.2-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:c8f3d67aeaf55f017982b73683f0e7342ba2f6635a78f69ce89ebb26aa411e5c", size = 252825, upload-time = "2026-09-30T04:37:11.274Z" }, + { url = "https://files.pythonhosted.org/packages/26/9f/69e13ca3b18f43e0eafcd34c04a45b732ae22a43b54a5fc9e119103356eb/charset_normalizer-3.5.2-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:fe9753dfee015c570d73df76f899f18444d41388bffcde097deba51c4fadbb9f", size = 252659, upload-time = "2026-09-30T04:37:12.941Z" }, + { url = "https://files.pythonhosted.org/packages/73/a9/ace29806a0dae18939919c76ba526472d83214afa101105fabff2cf30625/charset_normalizer-3.5.2-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:92888bb3187c5ba50500b00b3b310c9f2c651709d28036077680cb5255450a03", size = 238819, upload-time = "2026-09-30T04:37:14.659Z" }, + { url = "https://files.pythonhosted.org/packages/f8/c1/6116d52a2e3311ec80f21f5fb5e17b27405f10b9608af8f6e69516841a1b/charset_normalizer-3.5.2-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:d008d90a7f2471519aef0c90dfbe73b3e6e4d5e66ac48e19154c17e89e98b604", size = 272973, upload-time = "2026-09-30T04:37:16.346Z" }, + { url = "https://files.pythonhosted.org/packages/19/aa/9955c7e93bba10a9c7e8f7a5031b7ced66f3a1883a55c00712b8d5850ff3/charset_normalizer-3.5.2-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:31f3930700408d211f13378ccbe1c40845d8da54bd0681fac3a9b5aae81c7aa8", size = 253692, upload-time = "2026-09-30T04:37:18.212Z" }, + { url = "https://files.pythonhosted.org/packages/bb/33/2a6ae7fdc1b10cb581cef91addd8cdfc5f40d50abb5702309369d5834579/charset_normalizer-3.5.2-cp314-cp314t-musllinux_1_2_s390x.whl", hash = "sha256:2a925889534b3748302dae5dead07cc13480de1dac3aea80a941b729b471ef93", size = 268757, upload-time = "2026-09-30T04:37:19.877Z" }, + { url = "https://files.pythonhosted.org/packages/a2/22/80992720a0282cd39bba1db35868e6b9c22f41281160143a836544bc1d8a/charset_normalizer-3.5.2-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:f5ec61164adcec446f8969a3358ec3f9b26bbda3b9213e5586d219afa8df2915", size = 262220, upload-time = "2026-09-30T04:37:21.583Z" }, + { url = "https://files.pythonhosted.org/packages/92/9f/181fd07e1bffea1d95cd80c84ac537354f50699c22cfc4d3c02b6fc16208/charset_normalizer-3.5.2-cp314-cp314t-win32.whl", hash = "sha256:598a11a2c7ebaa5334bf698bf29568c9c390abac6a154d8170fedecd1cea38c5", size = 197797, upload-time = "2026-09-30T04:37:23.235Z" }, + { url = "https://files.pythonhosted.org/packages/49/1c/25d8415ec1c4f2f41f1680435e4c87cfb378ff2f677d950946f2a45d0632/charset_normalizer-3.5.2-cp314-cp314t-win_amd64.whl", hash = "sha256:7fdde2c9fd9e3eca40631e024664cf2584272cc8f96308cbe5fdfc930f51d8bc", size = 222765, upload-time = "2026-09-30T04:37:24.891Z" }, + { url = "https://files.pythonhosted.org/packages/3e/b4/46b48f013dadfc0d0d33b375438e31bdf5a989dc68389c6bf627054d4df9/charset_normalizer-3.5.2-cp314-cp314t-win_arm64.whl", hash = "sha256:d1befeed746d247c81127bb14de9dc3d30edb6e5976d34f83f86ed262b1d9105", size = 210985, upload-time = "2026-09-30T04:37:26.634Z" }, + { url = "https://files.pythonhosted.org/packages/ca/e9/34e597dee616d0b8ee4b34d29399e85c2204ade174157a48505d42baa4ff/charset_normalizer-3.5.2-cp315-cp315-macosx_10_15_universal2.whl", hash = "sha256:87475fabc8d9996fd9c27debb395e642e8c838d78a00b6e932227a0e06b81e26", size = 367676, upload-time = "2026-09-30T04:37:28.329Z" }, + { url = "https://files.pythonhosted.org/packages/60/9f/a5d1c91c0263745e2cd344c5a4415d787c575501ab1d449f1148ac6b495d/charset_normalizer-3.5.2-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9409a8bf35cf78353942504b24a57de3d75b708997a1e4bd8db71ac8633ce364", size = 248414, upload-time = "2026-09-30T04:37:30.167Z" }, + { url = "https://files.pythonhosted.org/packages/26/79/e697f77464748a3ee3cf490c83d592459400d4898380d66c38366b03080c/charset_normalizer-3.5.2-cp315-cp315-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:498dc3188ca05a68231ac3fdbfc7f57eb67e1343c30e0fea17f8218c1599b253", size = 244775, upload-time = "2026-09-30T04:37:31.964Z" }, + { url = "https://files.pythonhosted.org/packages/ca/87/3d42a42e18ea066e2513936fd678a00696e77878b5ae04528976abdbcb83/charset_normalizer-3.5.2-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:e242bb1c5e76e97dfa9e7f209a71e93a01d7f19ffdd5cfbb2e2d55b4f08f8ab0", size = 273877, upload-time = "2026-09-30T04:37:33.661Z" }, + { url = "https://files.pythonhosted.org/packages/c3/76/8a28136f3938ba9836f84280ce0c4d61ed1cf15a036b2034900c62634162/charset_normalizer-3.5.2-cp315-cp315-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:def79fa35ef0cef8d2accec024f4fdc7ead3012ff02f5215c783f39f03ef8cfc", size = 269455, upload-time = "2026-09-30T04:37:35.573Z" }, + { url = "https://files.pythonhosted.org/packages/a0/a1/4fbf5d0f0f1b2a080474c1cf9a2f12c4c6531bb0e8ba591055e846d2b4e9/charset_normalizer-3.5.2-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3df041de8887954562c9b261cba85ca0e9ded74048daf125f45edcfaa4832229", size = 257336, upload-time = "2026-09-30T04:37:37.397Z" }, + { url = "https://files.pythonhosted.org/packages/ba/a2/8b50aa320adb880ad579518e6f718f24944804b42a88b83d267d5d444125/charset_normalizer-3.5.2-cp315-cp315-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:04851f73ae72b8413dddadb16a49dfee95263553741fd42d546f7d66907e6be5", size = 257584, upload-time = "2026-09-30T04:37:39.522Z" }, + { url = "https://files.pythonhosted.org/packages/a5/57/50e3fed84e175f40349bd0da7a4fce94c87f0378f52d74f511d89e0bdc20/charset_normalizer-3.5.2-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:183b88127acdb4fabe59d951ab424faf1af7b63cdbb5f776186c1ea2ffcaed98", size = 251854, upload-time = "2026-09-30T04:37:41.23Z" }, + { url = "https://files.pythonhosted.org/packages/d6/54/f7fbb3493c9f49091213b9c2d6dd65800696f1ce1a3f196a4205f50417b1/charset_normalizer-3.5.2-cp315-cp315-musllinux_1_2_armv7l.whl", hash = "sha256:16fa0eccf81304b79c5cd87f9271c3b85dd9dd99245e4422ae9c0dd45e0f99d3", size = 248767, upload-time = "2026-09-30T04:37:42.883Z" }, + { url = "https://files.pythonhosted.org/packages/d9/37/b3a6385acc5a1e45b39ae9c90bfb9cf838a09b9dd37ef2740ab4c6b4a2eb/charset_normalizer-3.5.2-cp315-cp315-musllinux_1_2_ppc64le.whl", hash = "sha256:7441d755b7ab94f8d4eb3e43ec05482d760842fd263d003a99102d742cd835e2", size = 274479, upload-time = "2026-09-30T04:37:44.658Z" }, + { url = "https://files.pythonhosted.org/packages/89/44/809913e2cfd279e635a9294fdbbfb1b1dc62a8189d473d561f649fce98d8/charset_normalizer-3.5.2-cp315-cp315-musllinux_1_2_riscv64.whl", hash = "sha256:ca403d7e4798f525fdfc78e258820419cbbd0f0ecbab9de7840e3c017cf6b8cf", size = 258310, upload-time = "2026-09-30T04:37:46.529Z" }, + { url = "https://files.pythonhosted.org/packages/af/a2/f28400ab13359d91bd39179df8e149376b9bf36588e739a3a4f9de2b84b2/charset_normalizer-3.5.2-cp315-cp315-musllinux_1_2_s390x.whl", hash = "sha256:df29a0a7107f7011e77f4eebdddec4c7331e24d787a0b21a46d63bdf7445da95", size = 271100, upload-time = "2026-09-30T04:37:48.399Z" }, + { url = "https://files.pythonhosted.org/packages/e9/89/9bab37955edf0adb3b66f8a3a6617d9f2f487e0d56f295a6a286cb640aa6/charset_normalizer-3.5.2-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:f3c96f633825733f735c5a9cf21d21a257d8e1edf0b1cee0a064b9c424ca0f7d", size = 259936, upload-time = "2026-09-30T04:37:50.023Z" }, + { url = "https://files.pythonhosted.org/packages/23/b5/4459e08d45a679f903d50fea08bc52cfa728cca4d7bd02c757b5e5abda2e/charset_normalizer-3.5.2-cp315-cp315-win32.whl", hash = "sha256:281cb91036248400f4cc957495cccd44c275c2e0c5854f7e45ac5cf7dc193847", size = 186301, upload-time = "2026-09-30T04:37:51.722Z" }, + { url = "https://files.pythonhosted.org/packages/98/e8/55d5fd3935b4bce6da4fe0df61898e8c82653e317e677bd58aceb9c60f13/charset_normalizer-3.5.2-cp315-cp315-win_amd64.whl", hash = "sha256:89b53f3cda69831909888e0494f4fa0bcd3537e3e138dabeb620bd6ad946bae8", size = 210858, upload-time = "2026-09-30T04:37:53.427Z" }, + { url = "https://files.pythonhosted.org/packages/a9/5b/974423c2fd8e524c7a7f64318c1e02240ef954912fa2b4d70344107b9c68/charset_normalizer-3.5.2-cp315-cp315-win_arm64.whl", hash = "sha256:6be488a102b8cf28d0391d8c4ba7748938ae28b78ad901f8585520fca33ead1a", size = 200309, upload-time = "2026-09-30T04:37:55.015Z" }, + { url = "https://files.pythonhosted.org/packages/ee/f9/00ee0195db1013d8f7c416fd770fbeb560bb46eb2e36b054d05cb56f6cfa/charset_normalizer-3.5.2-cp315-cp315t-macosx_10_15_universal2.whl", hash = "sha256:915563965d418f986e7e145accc592eae9e1a1be3566ff98a05d7a9ec42a76e1", size = 395343, upload-time = "2026-09-30T04:37:56.743Z" }, + { url = "https://files.pythonhosted.org/packages/04/3a/c00b50e94c964cf934c7899cd47c97952fc11dad71cc5884b3c61795b09b/charset_normalizer-3.5.2-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:65cd72beeeca9d3aaea1201e5923859f308f952f9c71de93f06063c79f0f7a3b", size = 250114, upload-time = "2026-09-30T04:37:58.607Z" }, + { url = "https://files.pythonhosted.org/packages/50/27/d102dc880bbcffd0479ab64dfc1fb96777a854355a55e2bda72a71efadcb/charset_normalizer-3.5.2-cp315-cp315t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:b7fd005a73d9e657273b7a10dc71a9e03c8fb9ee6999798d6918ce095b81ac7f", size = 239997, upload-time = "2026-09-30T04:38:00.511Z" }, + { url = "https://files.pythonhosted.org/packages/a5/4a/bf7ef45794dd293fab5f98a9309817977fbb845b9998f171b8cc5d8437a3/charset_normalizer-3.5.2-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:e54da4baf05720032d527874d40b65fa4d7e5c6c6a43d0c3adbeffcaf275a2b3", size = 272313, upload-time = "2026-09-30T04:38:02.509Z" }, + { url = "https://files.pythonhosted.org/packages/e8/ee/008a2837737991474c5754bb3191010007663860979701990982a502cbaf/charset_normalizer-3.5.2-cp315-cp315t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:124fbf1a8ff966d87ae05bb8bd45a71f966055ed8bba320d0c7cf450bc5f4d0e", size = 269986, upload-time = "2026-09-30T04:38:04.435Z" }, + { url = "https://files.pythonhosted.org/packages/93/ad/bd74a283940dc910c5b14f8e4f80a248082bc9c0fcbe1f54530cb6d9cc5e/charset_normalizer-3.5.2-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:28b4f0d66fb834ff90f28209ac7bce77868c45d8c93e26f906709d9b7c2e1af9", size = 260202, upload-time = "2026-09-30T04:38:06.549Z" }, + { url = "https://files.pythonhosted.org/packages/8a/7b/ed341c66f69f688723501fac752be3d63c7159ca0d0d4174fc611e5710bb/charset_normalizer-3.5.2-cp315-cp315t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:58ca3755ee7ff7f59b57789ec9833c9de9ea275405cdd240eda1f193112e398a", size = 259083, upload-time = "2026-09-30T04:38:08.311Z" }, + { url = "https://files.pythonhosted.org/packages/cc/9d/e41588b777965e5031a43128a1e96173ebb35ac75fc53ec3b517e7c21cd4/charset_normalizer-3.5.2-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:443eae2bf318abeaf6f15d785138f71fd6de770e99a92158b8b814265e079115", size = 253081, upload-time = "2026-09-30T04:38:10.402Z" }, + { url = "https://files.pythonhosted.org/packages/81/35/b761eb6d8c1eb218b9b42b9b4d5ac902afdc399fb6dac6f9a9aac7bda589/charset_normalizer-3.5.2-cp315-cp315t-musllinux_1_2_armv7l.whl", hash = "sha256:58f361dcbab699cf8f42db3f47c8e7fd1036f138c23a5d08de9fde5f425a730c", size = 248712, upload-time = "2026-09-30T04:38:12.317Z" }, + { url = "https://files.pythonhosted.org/packages/4d/2c/147169a041b747759f37405c0a97157e8e92de967968373101ff14915cba/charset_normalizer-3.5.2-cp315-cp315t-musllinux_1_2_ppc64le.whl", hash = "sha256:1b4cbc7c3491ccb4aa17fcd8165649d01cf39f76de1696da8631b5f71b85401d", size = 274176, upload-time = "2026-09-30T04:38:14.138Z" }, + { url = "https://files.pythonhosted.org/packages/f0/2d/0ff8db0d373ba8538db686db11cd7e8912031490b9e4f383b41912e8d594/charset_normalizer-3.5.2-cp315-cp315t-musllinux_1_2_riscv64.whl", hash = "sha256:ba0b1d2620edf869789c3879223f52bf2afc5d31b3cb47cc57b3a12c05e2aa9d", size = 259413, upload-time = "2026-09-30T04:38:15.841Z" }, + { url = "https://files.pythonhosted.org/packages/8a/8e/b4a085fb47c9d3a7e43576a4784fdd8fe23f907514a972de8086edaf7a48/charset_normalizer-3.5.2-cp315-cp315t-musllinux_1_2_s390x.whl", hash = "sha256:5e2b6b57e9733d39f0c9fd3185efa6b8e29652c4cd8fe94180272cf6ed9a78c4", size = 269434, upload-time = "2026-09-30T04:38:17.626Z" }, + { url = "https://files.pythonhosted.org/packages/83/1c/d8d8d7322a7c3eecdf3237a4a419cf41d2eaad8e006ce7dfdd9d4c8fa2eb/charset_normalizer-3.5.2-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:51cf45226a9b588d0d2b4880c62d686934b63ab0bd79ca23ab0e9762eb27441b", size = 262716, upload-time = "2026-09-30T04:38:19.214Z" }, + { url = "https://files.pythonhosted.org/packages/a0/16/0e4c6ba9b44e97a2da150e52d331e8f9c968b21b358fbffa6c856cebcd89/charset_normalizer-3.5.2-cp315-cp315t-win32.whl", hash = "sha256:5fb29fb8cd1a46c27a1bf9613ad5ec2599310d46b4025d9556404a6b6a292800", size = 197159, upload-time = "2026-09-30T04:38:21.037Z" }, + { url = "https://files.pythonhosted.org/packages/be/33/e90bc2b1374f7f36ef106f56620de5a783907e19ca857efe2277e31cac3e/charset_normalizer-3.5.2-cp315-cp315t-win_amd64.whl", hash = "sha256:a192e2c40070d92c3ccf777e3a5c4ff515573cd2bb7ed0c537fdadbbec5bbf21", size = 221322, upload-time = "2026-09-30T04:38:22.886Z" }, + { url = "https://files.pythonhosted.org/packages/66/89/dfa6dcb08c200b7830ab56439e8c1890f2971d51aafbb3937894a2e7fcfc/charset_normalizer-3.5.2-cp315-cp315t-win_arm64.whl", hash = "sha256:749e97e1b32313717a565abbe321bc2190bc8b35f1a67e4cdbc7c56c8d8ffe58", size = 209192, upload-time = "2026-09-30T04:38:24.648Z" }, + { url = "https://files.pythonhosted.org/packages/8c/ab/176fbfd5b64939c55d652366aa5b9ef1d767af207a3aa6ebeb0d226c484d/charset_normalizer-3.5.2-cp37-abi3-macosx_10_9_universal2.whl", hash = "sha256:4275811936e2f06feff5e598fb42a1b7ae852da8e39605211892b56b81a34efd", size = 331815, upload-time = "2026-09-30T04:38:26.216Z" }, + { url = "https://files.pythonhosted.org/packages/7e/84/371eac6b30bdbcbf2d632a1a01809103459216fcaae61b8b8d922c1bfb8a/charset_normalizer-3.5.2-cp37-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:1c50fe28bbc2ced33386f298650d91218076c05420e6cbd790b913adc41659e7", size = 253276, upload-time = "2026-09-30T04:38:28.032Z" }, + { url = "https://files.pythonhosted.org/packages/43/6f/c4fbae58febff71709c51bc7e18fdfa55341dc382704740f9f0cbf03817b/charset_normalizer-3.5.2-cp37-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:d19fbd981a488e22cd04883659ca6b08f50b5974f9fd7c95655ef6a043e5893f", size = 241239, upload-time = "2026-09-30T04:38:29.732Z" }, + { url = "https://files.pythonhosted.org/packages/61/71/458c3f42164a07d0c5210798e9e704b39e540a6793b05aba67f3a35243a9/charset_normalizer-3.5.2-cp37-abi3-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:0fed1d06615f022ee3b13caf5e8b180cfea32bb2c5aded8a9d44277afc040f93", size = 231121, upload-time = "2026-09-30T04:38:31.462Z" }, + { url = "https://files.pythonhosted.org/packages/09/54/ab9e89367076f6331bb6c65c4bf14a5361fa5191cb6561bf534f18504e1b/charset_normalizer-3.5.2-cp37-abi3-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:838dcc90063569a0448120554591a1d6c4a4ffe11babf048908793154ab86ade", size = 260350, upload-time = "2026-09-30T04:38:33.239Z" }, + { url = "https://files.pythonhosted.org/packages/7c/c1/061431ecc688d9d76602502cb57cc01e691e682c18f1beb45f9673b5bbd2/charset_normalizer-3.5.2-cp37-abi3-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:2ce45c6627b22c47e390bc91a41c3d13032192e699fa0bea96e9671b373d69b0", size = 255430, upload-time = "2026-09-30T04:38:34.865Z" }, + { url = "https://files.pythonhosted.org/packages/8d/1f/20c8949f0676f7ab811abdeb7f4d7f1cbc6e61ff20bef08b44edeb092bc8/charset_normalizer-3.5.2-cp37-abi3-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:0774bf9bf620249fee3e0b8b9fd3065de213be30f3aa94ce2494b3b638949e26", size = 250612, upload-time = "2026-09-30T04:38:36.649Z" }, + { url = "https://files.pythonhosted.org/packages/2b/9e/46f2fa4c431fc98c4ae76a8cb5bdca54e0341e3cfc3fcfd8e82740250818/charset_normalizer-3.5.2-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:1db38f4c5496827c1a501846d64d14c3b80c7e6714e406cd7dc36a9899fa1011", size = 242083, upload-time = "2026-09-30T04:38:38.26Z" }, + { url = "https://files.pythonhosted.org/packages/bd/39/559be29a0c0f086e0bba6922babd38916cc5e0b58ced4de13ee01ea05508/charset_normalizer-3.5.2-cp37-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:304d8e4d493af723536393eee0c689eb7813f4a474c8b479dee63f1fdd98f621", size = 232738, upload-time = "2026-09-30T04:38:39.81Z" }, + { url = "https://files.pythonhosted.org/packages/ff/6c/387b0e4f756a282831c1d9fc6aeb6c51ca4507ca202767c8de15ce9b12e2/charset_normalizer-3.5.2-cp37-abi3-musllinux_1_2_ppc64le.whl", hash = "sha256:9b7f416ff0978e2f2249330527f0ad6fa02f4932e6199692d3b52da2048c19e4", size = 260703, upload-time = "2026-09-30T04:38:41.346Z" }, + { url = "https://files.pythonhosted.org/packages/96/92/1fdf015f09ef449f50d3ac4b67c90887c9c318b727daa95cc4f866e6521d/charset_normalizer-3.5.2-cp37-abi3-musllinux_1_2_riscv64.whl", hash = "sha256:01077390b03f7988f11d700a2194e69b119741a86b1a638b1db88891e3eced8e", size = 247622, upload-time = "2026-09-30T04:38:42.937Z" }, + { url = "https://files.pythonhosted.org/packages/dc/3c/8e7b8a5671ad5d433669fb2a76f1a0164df2d9b1718b0206bc2a16d840cc/charset_normalizer-3.5.2-cp37-abi3-musllinux_1_2_s390x.whl", hash = "sha256:7e841fb9010836c992c9f12fcbd43a831de93a5f726fc1ccd8ca1d0268c5014c", size = 257500, upload-time = "2026-09-30T04:38:44.604Z" }, + { url = "https://files.pythonhosted.org/packages/b4/f0/45b579df5cabc1d5d53ea1cc35e8437d3ca768c0acccc7041517cb6fbb32/charset_normalizer-3.5.2-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:9cae88599c7219005d879f98e5ed53341e9a122af585e1091200358a3003d2a0", size = 255100, upload-time = "2026-09-30T04:38:46.289Z" }, + { url = "https://files.pythonhosted.org/packages/31/68/fdec18a343f5fb3f310588dd478b09ac4799e0b187dbade3a8cd776f03ef/charset_normalizer-3.5.2-cp37-abi3-win32.whl", hash = "sha256:01b0c0d2262a9e28e8484a278c7e1b5d650e3ac8cf2683d2967e25899f208bdf", size = 174499, upload-time = "2026-09-30T04:38:47.999Z" }, + { url = "https://files.pythonhosted.org/packages/9d/8a/b618149cc5207943a0242068d7a27897f56a62947b5a039085f2a22029f8/charset_normalizer-3.5.2-cp37-abi3-win_amd64.whl", hash = "sha256:9f56f72050826f63dcee7a7f55b0a77168cb3bfc553fd405e7f8f9ece75a4036", size = 200092, upload-time = "2026-09-30T04:38:49.707Z" }, + { url = "https://files.pythonhosted.org/packages/03/cf/4c66866fa9e2b1c78e3c911516d1de497a677b7ac60f1eceda74ce777ca3/charset_normalizer-3.5.2-cp37-abi3-win_arm64.whl", hash = "sha256:40ab6bffa02ae10a0581e6c198be7d2d8ca5c2a0c64e4ed3465d766df457573e", size = 294363, upload-time = "2026-09-30T04:38:51.312Z" }, + { url = "https://files.pythonhosted.org/packages/fc/ad/d07d7862a62ffa6d79d68074d14823243dd235a77c45262acbf6adeb28bf/charset_normalizer-3.5.2-py3-none-any.whl", hash = "sha256:b6b751274acb69d77b3323d6b7dbaa3c7fdfc1eb829b7eb61d262f32e1af9685", size = 68872, upload-time = "2026-09-30T04:39:21.828Z" }, +] + +[[package]] +name = "colorama" +version = "0.4.6" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" }, +] + +[[package]] +name = "cryptography" +version = "50.0.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "cffi", marker = "platform_python_implementation != 'PyPy'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9d/af/182eb91b0df3fe75c4d9f26fe70684569566745f6ba7e5c9c73a862c5252/cryptography-50.0.2.tar.gz", hash = "sha256:7b46165bb56eb4704e2eaaf86f3c940d19154535d9b0ca7d6d590b04060e00d5", size = 880623, upload-time = "2026-09-30T15:30:04.884Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e5/56/d194340cc4a57535e82e1bee9e89667ac4b7c13b5d3f59686deae3094dd5/cryptography-50.0.2-cp311-abi3-macosx_11_0_arm64.whl", hash = "sha256:fa8f5efb344d6908a1ce62f4a24e2e5780f825d6f53f5f50ec5ffacac72936cb", size = 3914904, upload-time = "2026-09-30T14:43:44.339Z" }, + { url = "https://files.pythonhosted.org/packages/d9/69/c9bd862c3bf43d6399c433caf002df16e2dffd4be49bdf515cda38038711/cryptography-50.0.2-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:79def8d059362e7831389ed3be0ecdf58a89386e1271e35dd9f5af84e81bffd0", size = 4731146, upload-time = "2026-09-30T14:43:47.113Z" }, + { url = "https://files.pythonhosted.org/packages/21/69/64cef1f702bf6657e0cc186ed1a2891d50d29fb41586b254e1c07adea261/cryptography-50.0.2-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:630ebfea3bf689d075f82316324ff7433dc447fe6bc1bfc76524b74b4a9567d2", size = 4719841, upload-time = "2026-09-30T14:43:49.01Z" }, + { url = "https://files.pythonhosted.org/packages/38/6b/61a3f8d8c5e1e49a6cddccafc4015cc1c0021360ab0acb4080e7a423644a/cryptography-50.0.2-cp311-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:f9f6143a8c75945eb960d9eb98905a441394abfa24afaae239d514ffb2586480", size = 4738340, upload-time = "2026-09-30T14:43:50.932Z" }, + { url = "https://files.pythonhosted.org/packages/7b/2e/7212ca32fd43dc91f2f41db20160b268098874b4c9a0e7be94d6835f5b2e/cryptography-50.0.2-cp311-abi3-manylinux_2_28_ppc64le.whl", hash = "sha256:a582ab2ae1d34f67112cadc86702774c9ea4374df6bca6afe672817203c99134", size = 5367029, upload-time = "2026-09-30T14:43:52.911Z" }, + { url = "https://files.pythonhosted.org/packages/1a/f1/b474e930c4d910328780e3940da76f5aa5cbc48ce1fc14e44d239d9ea9db/cryptography-50.0.2-cp311-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:4061c0079120205fb760c58acab6443e217307dcf05e3702cf970e0689972856", size = 4753050, upload-time = "2026-09-30T14:43:55.272Z" }, + { url = "https://files.pythonhosted.org/packages/7c/52/9af10e80ac16b0fcc2123f9cbd5e7afbd0fd5075bb7a607c592258a39cda/cryptography-50.0.2-cp311-abi3-manylinux_2_31_armv7l.whl", hash = "sha256:ac9ed99d81760c62fe89d5f0815cdfa1ba9a35141cf30f1c2d044f04b4803d2e", size = 4376724, upload-time = "2026-09-30T14:43:57.24Z" }, + { url = "https://files.pythonhosted.org/packages/71/37/6202e488cc1eb625ea110c292c6bda92823176e023f427d8d5660ce8d632/cryptography-50.0.2-cp311-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:87e9ce85beb6b328ba370cc6e6aea483c92617b4c95b1d33a49297eb662bfb04", size = 4737859, upload-time = "2026-09-30T14:43:59.541Z" }, + { url = "https://files.pythonhosted.org/packages/8f/30/e86d7d518489b0ae2497091a35287abcb1a2ce4037837a34afbe9b1d6964/cryptography-50.0.2-cp311-abi3-manylinux_2_34_ppc64le.whl", hash = "sha256:f265528741e048bce55c3463ed721fb0aa45a5888d8add8cfeccb3035451bbdc", size = 5324103, upload-time = "2026-09-30T14:44:01.901Z" }, + { url = "https://files.pythonhosted.org/packages/d3/69/2c833a049475e0a3444e94c7d0aca0aa51d166374a449b09e92ac98138de/cryptography-50.0.2-cp311-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:9dab55f57c74c3cad24c323bacbbd04be4705ba6eb0d92e920b1fc4837ed5079", size = 4752576, upload-time = "2026-09-30T14:44:04.545Z" }, + { url = "https://files.pythonhosted.org/packages/6c/5d/906970b83bbfc1f5bbfb677a143c181f2801f23b6a7204a3b47c42c97e65/cryptography-50.0.2-cp311-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:25784ce8b9621c90c643efb9e1e2162ab3b0224cae446ad5e70e7fcb1ce18b51", size = 4870819, upload-time = "2026-09-30T14:44:06.884Z" }, + { url = "https://files.pythonhosted.org/packages/68/e3/f2298d3bb55e0c4a91841ec4d01b3f020ba8c5fbf15ccdcc6dcf03f97025/cryptography-50.0.2-cp311-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:85d0d9a31b9098e98534226d5686b47264b95e62ce459dc2e62fdfc809f9fe93", size = 5030152, upload-time = "2026-09-30T14:44:09.443Z" }, + { url = "https://files.pythonhosted.org/packages/9a/4f/adfc442765721292fff86d314ce385d3249d22db42295c0dd057727b60f3/cryptography-50.0.2-cp311-abi3-win_amd64.whl", hash = "sha256:7afa5a6602a9f29af1f3a2965f831bae7c9d5d597b7cbb716d41ab3b7d89879c", size = 3824692, upload-time = "2026-09-30T14:44:11.671Z" }, + { url = "https://files.pythonhosted.org/packages/ce/cb/52eb3770c0d0be2702a98c6e96065ddc0a2877cf0845aa9c23397c142cd4/cryptography-50.0.2-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:f785f6161f202ab04d8ca194158968798e480ca058943907972da5f12e2881e8", size = 3892731, upload-time = "2026-09-30T14:44:13.485Z" }, + { url = "https://files.pythonhosted.org/packages/19/8e/aa1fc533d4546b127b45de8aa024eb5933d23eff9debfe25931e56861095/cryptography-50.0.2-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:0ecbc5652bdb6fc9eaf89a7d196e20941adfe812f43bc4ca05d9150496821047", size = 4710431, upload-time = "2026-09-30T14:44:15.427Z" }, + { url = "https://files.pythonhosted.org/packages/6a/64/72bc3f75176e7e406b748a3e3830432b8c51297b38368713df04dc04898a/cryptography-50.0.2-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:ab50ee449bf968271e820086f10a33d101dd060370abc10bcd22279be2656539", size = 4694824, upload-time = "2026-09-30T14:44:17.69Z" }, + { url = "https://files.pythonhosted.org/packages/4e/c6/62c77550edfa5ca3f14bf44a1e6739b9fa09d6e998a11d97ed8213bccc98/cryptography-50.0.2-cp314-cp314t-manylinux_2_28_aarch64.whl", hash = "sha256:a9f7355e6fab51f6c369b86fb7571cffa05edee2c2121e0380a37fb9ac1cd5c1", size = 4716967, upload-time = "2026-09-30T14:44:19.661Z" }, + { url = "https://files.pythonhosted.org/packages/f4/37/cce70f150c432914460157a6ecc161752e053aa5ec0ef3b3f7dc6e31039a/cryptography-50.0.2-cp314-cp314t-manylinux_2_28_ppc64le.whl", hash = "sha256:94e5e9f108ee10471288214d3d233fbfbb492840a8457eb85178d643ddeb32c7", size = 5328676, upload-time = "2026-09-30T14:44:21.744Z" }, + { url = "https://files.pythonhosted.org/packages/aa/9a/6f2f0304d634ceafdeaf23e84537336664ac419b5d07611675c2ad3f6b7a/cryptography-50.0.2-cp314-cp314t-manylinux_2_28_x86_64.whl", hash = "sha256:241449bf940a5d27309bd317e6f9a2af6932113818bb2b8f5c59ddc7ef16da18", size = 4727698, upload-time = "2026-09-30T14:44:24.178Z" }, + { url = "https://files.pythonhosted.org/packages/1d/de/66bcf9244d118663b2e1aaded8990f4640e3d7b7411870a5765f252074d2/cryptography-50.0.2-cp314-cp314t-manylinux_2_31_armv7l.whl", hash = "sha256:d8947001be83df1394050758ce0e745dd74fb134eef0a4b5124208dfc3a68c37", size = 4354821, upload-time = "2026-09-30T14:44:26.263Z" }, + { url = "https://files.pythonhosted.org/packages/bd/e6/db28a28c7b6c676addce89136de3d8db49ea825a8c863472e36e42ead4ad/cryptography-50.0.2-cp314-cp314t-manylinux_2_34_aarch64.whl", hash = "sha256:4a20ce1e5cb4284a86692fdcba7cb8754185c6b2e5c56fcef3751cf451d3cdc2", size = 4716748, upload-time = "2026-09-30T14:44:28.447Z" }, + { url = "https://files.pythonhosted.org/packages/30/96/01546c7f69ea0e2ab790a2e4f0934a4052fb9b388147fbf83c2fd72f1e57/cryptography-50.0.2-cp314-cp314t-manylinux_2_34_ppc64le.whl", hash = "sha256:84f964e537f916e2cc85199e5a88742e964939b575ac8598b3f9d6cc416cdaf1", size = 5285085, upload-time = "2026-09-30T14:44:30.704Z" }, + { url = "https://files.pythonhosted.org/packages/6c/01/03263395f74d50b071e9e66daace3f8bef80493e5d410726f2ba8554736b/cryptography-50.0.2-cp314-cp314t-manylinux_2_34_x86_64.whl", hash = "sha256:828d49b0ff5a0e3975865571c5d91dbbdd0d38d8289b249a163e9425413a5e05", size = 4727268, upload-time = "2026-09-30T14:44:32.92Z" }, + { url = "https://files.pythonhosted.org/packages/eb/94/2bfe8f29ec0cc9c0d99359c4161adf32858e4934b72c6d100d2ac0bbe962/cryptography-50.0.2-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:deb9fde5c60e437ee4821bc9bc39ff31b42135c27e1dc61ef0a629389c1de62e", size = 4849503, upload-time = "2026-09-30T14:44:34.969Z" }, + { url = "https://files.pythonhosted.org/packages/54/44/e80651ecbf0e42b62e2bb5f5768916e07eea72e1297338956a61df361f88/cryptography-50.0.2-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:8c71ba2cd31fc93748c38e1b613200ff1c2665cbfd5341fe3a61cfde35a1430e", size = 5004057, upload-time = "2026-09-30T14:44:37.064Z" }, + { url = "https://files.pythonhosted.org/packages/f8/cc/1d33befb3cd7ea7e77d2d73f43f2066471da1b21f24a6156efcaabf6d2e8/cryptography-50.0.2-cp314-cp314t-win_amd64.whl", hash = "sha256:78198641e5be9521beea5aa782bb551a58068d10e6eb04c9c680c1b69f2e7d45", size = 3795868, upload-time = "2026-09-30T14:44:39.71Z" }, + { url = "https://files.pythonhosted.org/packages/2d/49/93f6a6e7a87c9aa68d44d3e1cdb5fe8f60c90d5d2f46acae9a56892816b8/cryptography-50.0.2-cp315-abi3.abi3t-macosx_11_0_arm64.whl", hash = "sha256:edc3342adf8f697fc5f59c887a304356f147b397809440ed64e2fa6af2f50f37", size = 4133708, upload-time = "2026-09-30T14:44:41.807Z" }, + { url = "https://files.pythonhosted.org/packages/8c/75/32ac2a56243d778805c16ca6a32b8f74fb757df7e28d7ecb560afafb59cf/cryptography-50.0.2-cp315-abi3.abi3t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:d370b8d1dfcdf7130178137f6fbee6140774a1acc6cacefc4b42643ec11d0a3a", size = 4956267, upload-time = "2026-09-30T14:44:43.693Z" }, + { url = "https://files.pythonhosted.org/packages/aa/a4/2c8d734e43d97f0842ee9f1b7b4bfb3d0cf5e19edebf43c2afe6675c2320/cryptography-50.0.2-cp315-abi3.abi3t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:f2f9bd7f90c64fe89253f0a2c05e3c4856072660429ce8831b4235bf29403a67", size = 4966465, upload-time = "2026-09-30T14:44:45.769Z" }, + { url = "https://files.pythonhosted.org/packages/c2/58/ee288c829a6f41f6235ae9dd33d82fd19b45442b65b4c8a3da36963d9f7a/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl", hash = "sha256:e275096ea1e60cc595cda2836fd4a6c725d1125108b868be17f53684d164e2cc", size = 4959356, upload-time = "2026-09-30T14:44:48.211Z" }, + { url = "https://files.pythonhosted.org/packages/92/20/9ded6d51ddd9897f6b6e81fb9ebea7951d7cc5d6c890b0ed8abf77a51a80/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_28_ppc64le.whl", hash = "sha256:b13478603dcd0a2479ff8e87e2c19a7d525734686fe3c49542472293a204212d", size = 5548822, upload-time = "2026-09-30T14:44:50.86Z" }, + { url = "https://files.pythonhosted.org/packages/02/a8/8df951850d6b31d2a00218f19e2b3f999523437ed7a819df7fa427942fca/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl", hash = "sha256:58a0c478eeca76fe5e07993c5a0703def34a6dc6a0cda4f5564639b33112ffe7", size = 5001199, upload-time = "2026-09-30T14:44:53.379Z" }, + { url = "https://files.pythonhosted.org/packages/8b/f9/36b3022218ce75b7cdf068fb95f809f9bd0d820e4955ef43b90c255cc7ac/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_31_armv7l.whl", hash = "sha256:d38cdff612d06fa6a32840d5e1b1f7a27cee4a349aa9085d94a67789d6bfd408", size = 4629333, upload-time = "2026-09-30T14:44:55.635Z" }, + { url = "https://files.pythonhosted.org/packages/8c/72/20f99a219f6af47cdd1cbd978c243b92d71496e168a746138af44ded4f29/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_34_aarch64.whl", hash = "sha256:fdd28f912fccfec1846a94e2e1e8f9b0012f557f0c46fe4f3eb0d7a87afcf90b", size = 4958822, upload-time = "2026-09-30T14:44:59.639Z" }, + { url = "https://files.pythonhosted.org/packages/f2/20/196f112617fb08eb4d608a2a6c422373d46f9cc2857f38fc0667033c0899/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_34_ppc64le.whl", hash = "sha256:cbc8738fd8526d80f35cb3a40d41f41a2e7030bb3b18b09a6778ef63d291c2fd", size = 5506351, upload-time = "2026-09-30T14:45:02.267Z" }, + { url = "https://files.pythonhosted.org/packages/24/95/83378121ef3eaaaf71d4b781577ff794acb39b9e1b87a3f156898c8497ed/cryptography-50.0.2-cp315-abi3.abi3t-manylinux_2_34_x86_64.whl", hash = "sha256:e105ab60406787da31fccc883fc0f733af1efd78f0136a4599692c4083a73d0c", size = 5000859, upload-time = "2026-09-30T14:45:05.009Z" }, + { url = "https://files.pythonhosted.org/packages/22/f7/70fd7ae4d1dbfa7ba29b02e1b9068771519a86027756510b700ce81086a8/cryptography-50.0.2-cp315-abi3.abi3t-musllinux_1_2_aarch64.whl", hash = "sha256:6f8700550aa1474a91e5dc07049c46f98b423b5b1ddd0483e0b51362eeeaf5be", size = 5092151, upload-time = "2026-09-30T15:29:15.932Z" }, + { url = "https://files.pythonhosted.org/packages/d4/be/688367b74de86984bd58d8efacfc7c9e68b89a6a22ced0fb4f38db50254a/cryptography-50.0.2-cp315-abi3.abi3t-musllinux_1_2_x86_64.whl", hash = "sha256:c71be1cbfa5cd9a41ee452acf1eccd82b2c05950358b106ec8ceb83411d1a020", size = 5286120, upload-time = "2026-09-30T15:29:18.309Z" }, + { url = "https://files.pythonhosted.org/packages/39/d1/55f8a3f2ef5d1529e16835ef10cf0fe3d559ce237b46dddc440c0bba3649/cryptography-50.0.2-cp315-abi3.abi3t-win_amd64.whl", hash = "sha256:c423ab384a46c4dff7217b2ea5ba2e11cffdeab6441acd04cf65a369caf0366c", size = 4111557, upload-time = "2026-09-30T15:29:20.155Z" }, + { url = "https://files.pythonhosted.org/packages/23/ad/ac987755d00e1e64273760228d2635ae38dae2be83e3c6e0d3289d91dec3/cryptography-50.0.2-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:0ec5f09541743261e66e291b4a0cbf0fb2997aeaab6d9e9c740b9dba1b58d1c2", size = 3943588, upload-time = "2026-09-30T15:29:22.265Z" }, + { url = "https://files.pythonhosted.org/packages/d5/8d/6d585339bedf85d45044c85d8412dac53f2bb6f918e8b7777efba1787844/cryptography-50.0.2-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:c5e67125c7dca78d199ec4e116aa93dbb83494808ecbb8211a2cb09b1bf41dbd", size = 4756166, upload-time = "2026-09-30T15:29:24.58Z" }, + { url = "https://files.pythonhosted.org/packages/bf/f1/1c1f6874e8550cfddd4b688ceb38cefb6ed15ceed224d56f133f3d88c214/cryptography-50.0.2-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:ee247f5c245c9a2fe7c8e2214e295918838e44e00a45a6718451e4004219e767", size = 4749145, upload-time = "2026-09-30T15:29:26.807Z" }, + { url = "https://files.pythonhosted.org/packages/c1/63/61b15dc1a8de03fe0adbe3fd7608b3ad5c73bf50993bbcb1faaa930afe33/cryptography-50.0.2-cp39-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:dfe9763530994147d9af1def057a5b9658b00e8f8fe8743d144d1e0911c2e454", size = 4763638, upload-time = "2026-09-30T15:29:28.588Z" }, + { url = "https://files.pythonhosted.org/packages/fc/35/b345bdfa40c9126df1a9d33236aa98418367931b8725f84fc3ae2b98dc59/cryptography-50.0.2-cp39-abi3-manylinux_2_28_ppc64le.whl", hash = "sha256:58ddb5a8e3179d12f19e4ea34d2d32e9d63a4baa142c875c1eb59f41b7243acd", size = 5382217, upload-time = "2026-09-30T15:29:30.589Z" }, + { url = "https://files.pythonhosted.org/packages/4f/87/ef344a9e616871f2519c22d6afcda79ddd5d35e9592d95eb6e677608d055/cryptography-50.0.2-cp39-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:f21e8a22c8605750c7af886bab299a363721264061b4ac0a30efb73cfd58efc5", size = 4781387, upload-time = "2026-09-30T15:29:32.605Z" }, + { url = "https://files.pythonhosted.org/packages/90/5b/f2fdb13cd0b96f6f932c8627bb292a45f11c64d21620a8e120aee9a3b848/cryptography-50.0.2-cp39-abi3-manylinux_2_31_armv7l.whl", hash = "sha256:9c8402a82ea0dc4ceeab793db05f0fafa8ca139ca34fcde5df0f596103c74107", size = 4403790, upload-time = "2026-09-30T15:29:34.374Z" }, + { url = "https://files.pythonhosted.org/packages/bc/ce/7e4f662b1e3c393513569e402cfc85ac7da0bd3d5435e122a3140219eb2d/cryptography-50.0.2-cp39-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:0ddc924c04591c2811ca024d62ecad4f7f6f08af8939c211438f48a16bd23602", size = 4764319, upload-time = "2026-09-30T15:29:36.149Z" }, + { url = "https://files.pythonhosted.org/packages/3c/3f/86ff33ce34cc0de6847fb96e035a1a760d81652e38643f617c02ad32ef7a/cryptography-50.0.2-cp39-abi3-manylinux_2_34_ppc64le.whl", hash = "sha256:a6557e5f38e065ca9fbdaf7cfc7435ecb1d113aa81a022d1b51921ee7432e227", size = 5338560, upload-time = "2026-09-30T15:29:39.053Z" }, + { url = "https://files.pythonhosted.org/packages/40/cf/6b5c8e2fd9202d98988ab7cb5cc5c991704c4ad55f492ff408e4969f83f1/cryptography-50.0.2-cp39-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:1981f1db4630889b9ef7803fadef12b056f428cb6b85c27ba57b774793b6093c", size = 4780973, upload-time = "2026-09-30T15:29:41.251Z" }, + { url = "https://files.pythonhosted.org/packages/10/bf/8d6ebc7dded797bd0f0160d52188021211f011a2b164ef0ae1dac4587465/cryptography-50.0.2-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:7a8701d6b584d76e909e3d305b7d126b41439876a5aaf76cddc67fc230eafa2e", size = 4897738, upload-time = "2026-09-30T15:29:43.106Z" }, + { url = "https://files.pythonhosted.org/packages/d4/aa/f3f6e0de7e6253b8baa8b2d8fb9d50924fa75cee3d4624bd4bc1208ee923/cryptography-50.0.2-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:ce47f66801c20ec6c6632453bb5960fe38939e9306970b48b3a5a26de7745d94", size = 5058280, upload-time = "2026-09-30T15:29:44.827Z" }, + { url = "https://files.pythonhosted.org/packages/f6/b6/a1faf3a27ae9405fb34b1713cc73b2d8a26b04d5c561578fa2e6ef3e5bb9/cryptography-50.0.2-cp39-abi3-win_amd64.whl", hash = "sha256:4e81d95e5bafc2d6e34e4bed780e53e4d5b9a2f928573428aa4d35fbec1eb0de", size = 3854095, upload-time = "2026-09-30T15:29:46.782Z" }, + { url = "https://files.pythonhosted.org/packages/1d/7a/f08d34ce09d60f89ebd391e2ebc6ba2b995e6dd7552f41820f8085f94e53/cryptography-50.0.2-pp311-pypy311_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:92e665960f25fcdc73725b9cec7a3824f279ba97a98653afe9ffac2e43668f67", size = 4716035, upload-time = "2026-09-30T15:29:48.681Z" }, + { url = "https://files.pythonhosted.org/packages/45/67/e18fb65592451a2acb76e9f2fbe14e0f47a8318b4c5430f1633851d03daa/cryptography-50.0.2-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:eef4c2f3423810b3070ab391f85436d2f8bbfcb286ac15cbc73190b3563b1f1a", size = 4726917, upload-time = "2026-09-30T15:29:50.608Z" }, + { url = "https://files.pythonhosted.org/packages/83/28/38fdce17e60f6b825e69fc3b7f75e70a6612759980704697e1de4cbfaf6e/cryptography-50.0.2-pp311-pypy311_pp73-manylinux_2_34_aarch64.whl", hash = "sha256:7c6d0330c472d96f6a6afe24d80dfdf15176c33096f0a4397ae4c60f3dd3be48", size = 4715341, upload-time = "2026-09-30T15:29:52.522Z" }, + { url = "https://files.pythonhosted.org/packages/b6/b1/d9121a717e0f893c64bd6ca7702614778d7df2a5c309128a002421788516/cryptography-50.0.2-pp311-pypy311_pp73-manylinux_2_34_x86_64.whl", hash = "sha256:1ba34f04897fcdaa73f74145c25f3ec146fbd56593853e88adc2e811303c5f42", size = 4726322, upload-time = "2026-09-30T15:29:54.263Z" }, + { url = "https://files.pythonhosted.org/packages/36/8b/e6d153808bf353e152abd2fd4d8f09670d956ac78379ac46e60d7efbf04c/cryptography-50.0.2-pp311-pypy311_pp80-macosx_11_0_arm64.whl", hash = "sha256:3dc4fd8058cea1644971207d530e1a03a184a805ffc8ebdddf0599d78a331b81", size = 3873097, upload-time = "2026-09-30T15:29:56.097Z" }, + { url = "https://files.pythonhosted.org/packages/ca/1d/1271f287ff7170ddafc2aad36260c4eec20ccd2fea70f38455e9d56d427b/cryptography-50.0.2-pp311-pypy311_pp80-win_amd64.whl", hash = "sha256:7b75de3c8b3be1cdb1052747c929440c3eea46c1bc2cb8a6e3a48388e9b7b452", size = 3805376, upload-time = "2026-09-30T15:29:58.729Z" }, +] + +[[package]] +name = "distlib" +version = "0.4.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/68/bc/d36966de7304047a1001a7559fbf266c464bb5d8cc85464536ef8c9bcc32/distlib-0.4.4.tar.gz", hash = "sha256:ca4175b4ac7f71223cc30ed7248c45d2b38c2439d8ee6e498ab67ed63cf3508d", size = 621304, upload-time = "2026-10-16T13:56:34.203Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/c1/2b/238f02a4927fa2e27aa995371d240a468b52e42eae44a678434aff736b38/distlib-0.4.4-py2.py3-none-any.whl", hash = "sha256:cf09d55b1e85a89576b036aeb71550bfd68320f3f21761ca329eadadad918638", size = 472099, upload-time = "2026-10-16T13:56:32.053Z" }, +] + +[[package]] +name = "dotproperties" +version = "0.2.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/6f/be/b823198ccae26ada927f1788de19feaec542823a2fdbb4f40469dc14fa9b/dotproperties-0.2.0.tar.gz", hash = "sha256:36b453f3a2460bb18ff7260bbd839fbdecb1f5aaac9fa4c82787846a976ab1cd", size = 47453, upload-time = "2026-07-31T04:37:43.539Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/62/08/1ccf98b398e7cdc710de1a3999df70261328bbe0b5c412ce11fde9b01c48/dotproperties-0.2.0-py3-none-any.whl", hash = "sha256:52d8ed9e75624146ac53b839e52f53133077600aaf8ca9c52164fb22dee79881", size = 10140, upload-time = "2026-07-31T04:37:42.395Z" }, +] + +[[package]] +name = "filelock" +version = "4.2.10" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/a1/cf/05bcdacabdc0aec7dc8e19d76281bd82325df62dae3b6430e9ba57397689/filelock-4.2.10.tar.gz", hash = "sha256:fcc3c0cb8bfe7f4b3bb0e231c04b15dbad068cb3c2515f343d8fde4dce93bd5d", size = 670595, upload-time = "2026-11-09T18:58:00.54Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ef/90/5d0096a325aa0f83ba7a3968bfb485b67e32c947bdf9cd0fcb4b485be718/filelock-4.2.10-py3-none-any.whl", hash = "sha256:9479aaeb4db20b5a53e3da28493edd24720b66b8a0b84030aa56ccdf243d6857", size = 218040, upload-time = "2026-11-09T18:57:59.088Z" }, +] + +[[package]] +name = "frozenlist" +version = "1.8.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/2d/f5/c831fac6cc817d26fd54c7eaccd04ef7e0288806943f7cc5bbf69f3ac1f0/frozenlist-1.8.0.tar.gz", hash = "sha256:3ede829ed8d842f6cd48fc7081d7a41001a56f1f38603f9d49bf3020d59a31ad", size = 45875, upload-time = "2025-10-06T05:38:17.865Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/bc/03/077f869d540370db12165c0aa51640a873fb661d8b315d1d4d67b284d7ac/frozenlist-1.8.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:09474e9831bc2b2199fad6da3c14c7b0fbdd377cce9d3d77131be28906cb7d84", size = 86912, upload-time = "2025-10-06T05:35:45.98Z" }, + { url = "https://files.pythonhosted.org/packages/df/b5/7610b6bd13e4ae77b96ba85abea1c8cb249683217ef09ac9e0ae93f25a91/frozenlist-1.8.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:17c883ab0ab67200b5f964d2b9ed6b00971917d5d8a92df149dc2c9779208ee9", size = 50046, upload-time = "2025-10-06T05:35:47.009Z" }, + { url = "https://files.pythonhosted.org/packages/6e/ef/0e8f1fe32f8a53dd26bdd1f9347efe0778b0fddf62789ea683f4cc7d787d/frozenlist-1.8.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:fa47e444b8ba08fffd1c18e8cdb9a75db1b6a27f17507522834ad13ed5922b93", size = 50119, upload-time = "2025-10-06T05:35:48.38Z" }, + { url = "https://files.pythonhosted.org/packages/11/b1/71a477adc7c36e5fb628245dfbdea2166feae310757dea848d02bd0689fd/frozenlist-1.8.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:2552f44204b744fba866e573be4c1f9048d6a324dfe14475103fd51613eb1d1f", size = 231067, upload-time = "2025-10-06T05:35:49.97Z" }, + { url = "https://files.pythonhosted.org/packages/45/7e/afe40eca3a2dc19b9904c0f5d7edfe82b5304cb831391edec0ac04af94c2/frozenlist-1.8.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:957e7c38f250991e48a9a73e6423db1bb9dd14e722a10f6b8bb8e16a0f55f695", size = 233160, upload-time = "2025-10-06T05:35:51.729Z" }, + { url = "https://files.pythonhosted.org/packages/a6/aa/7416eac95603ce428679d273255ffc7c998d4132cfae200103f164b108aa/frozenlist-1.8.0-cp311-cp311-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:8585e3bb2cdea02fc88ffa245069c36555557ad3609e83be0ec71f54fd4abb52", size = 228544, upload-time = "2025-10-06T05:35:53.246Z" }, + { url = "https://files.pythonhosted.org/packages/8b/3d/2a2d1f683d55ac7e3875e4263d28410063e738384d3adc294f5ff3d7105e/frozenlist-1.8.0-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:edee74874ce20a373d62dc28b0b18b93f645633c2943fd90ee9d898550770581", size = 243797, upload-time = "2025-10-06T05:35:54.497Z" }, + { url = "https://files.pythonhosted.org/packages/78/1e/2d5565b589e580c296d3bb54da08d206e797d941a83a6fdea42af23be79c/frozenlist-1.8.0-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:c9a63152fe95756b85f31186bddf42e4c02c6321207fd6601a1c89ebac4fe567", size = 247923, upload-time = "2025-10-06T05:35:55.861Z" }, + { url = "https://files.pythonhosted.org/packages/aa/c3/65872fcf1d326a7f101ad4d86285c403c87be7d832b7470b77f6d2ed5ddc/frozenlist-1.8.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:b6db2185db9be0a04fecf2f241c70b63b1a242e2805be291855078f2b404dd6b", size = 230886, upload-time = "2025-10-06T05:35:57.399Z" }, + { url = "https://files.pythonhosted.org/packages/a0/76/ac9ced601d62f6956f03cc794f9e04c81719509f85255abf96e2510f4265/frozenlist-1.8.0-cp311-cp311-musllinux_1_2_armv7l.whl", hash = "sha256:f4be2e3d8bc8aabd566f8d5b8ba7ecc09249d74ba3c9ed52e54dc23a293f0b92", size = 245731, upload-time = "2025-10-06T05:35:58.563Z" }, + { url = "https://files.pythonhosted.org/packages/b9/49/ecccb5f2598daf0b4a1415497eba4c33c1e8ce07495eb07d2860c731b8d5/frozenlist-1.8.0-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:c8d1634419f39ea6f5c427ea2f90ca85126b54b50837f31497f3bf38266e853d", size = 241544, upload-time = "2025-10-06T05:35:59.719Z" }, + { url = "https://files.pythonhosted.org/packages/53/4b/ddf24113323c0bbcc54cb38c8b8916f1da7165e07b8e24a717b4a12cbf10/frozenlist-1.8.0-cp311-cp311-musllinux_1_2_s390x.whl", hash = "sha256:1a7fa382a4a223773ed64242dbe1c9c326ec09457e6b8428efb4118c685c3dfd", size = 241806, upload-time = "2025-10-06T05:36:00.959Z" }, + { url = "https://files.pythonhosted.org/packages/a7/fb/9b9a084d73c67175484ba2789a59f8eebebd0827d186a8102005ce41e1ba/frozenlist-1.8.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:11847b53d722050808926e785df837353bd4d75f1d494377e59b23594d834967", size = 229382, upload-time = "2025-10-06T05:36:02.22Z" }, + { url = "https://files.pythonhosted.org/packages/95/a3/c8fb25aac55bf5e12dae5c5aa6a98f85d436c1dc658f21c3ac73f9fa95e5/frozenlist-1.8.0-cp311-cp311-win32.whl", hash = "sha256:27c6e8077956cf73eadd514be8fb04d77fc946a7fe9f7fe167648b0b9085cc25", size = 39647, upload-time = "2025-10-06T05:36:03.409Z" }, + { url = "https://files.pythonhosted.org/packages/0a/f5/603d0d6a02cfd4c8f2a095a54672b3cf967ad688a60fb9faf04fc4887f65/frozenlist-1.8.0-cp311-cp311-win_amd64.whl", hash = "sha256:ac913f8403b36a2c8610bbfd25b8013488533e71e62b4b4adce9c86c8cea905b", size = 44064, upload-time = "2025-10-06T05:36:04.368Z" }, + { url = "https://files.pythonhosted.org/packages/5d/16/c2c9ab44e181f043a86f9a8f84d5124b62dbcb3a02c0977ec72b9ac1d3e0/frozenlist-1.8.0-cp311-cp311-win_arm64.whl", hash = "sha256:d4d3214a0f8394edfa3e303136d0575eece0745ff2b47bd2cb2e66dd92d4351a", size = 39937, upload-time = "2025-10-06T05:36:05.669Z" }, + { url = "https://files.pythonhosted.org/packages/69/29/948b9aa87e75820a38650af445d2ef2b6b8a6fab1a23b6bb9e4ef0be2d59/frozenlist-1.8.0-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:78f7b9e5d6f2fdb88cdde9440dc147259b62b9d3b019924def9f6478be254ac1", size = 87782, upload-time = "2025-10-06T05:36:06.649Z" }, + { url = "https://files.pythonhosted.org/packages/64/80/4f6e318ee2a7c0750ed724fa33a4bdf1eacdc5a39a7a24e818a773cd91af/frozenlist-1.8.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:229bf37d2e4acdaf808fd3f06e854a4a7a3661e871b10dc1f8f1896a3b05f18b", size = 50594, upload-time = "2025-10-06T05:36:07.69Z" }, + { url = "https://files.pythonhosted.org/packages/2b/94/5c8a2b50a496b11dd519f4a24cb5496cf125681dd99e94c604ccdea9419a/frozenlist-1.8.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:f833670942247a14eafbb675458b4e61c82e002a148f49e68257b79296e865c4", size = 50448, upload-time = "2025-10-06T05:36:08.78Z" }, + { url = "https://files.pythonhosted.org/packages/6a/bd/d91c5e39f490a49df14320f4e8c80161cfcce09f1e2cde1edd16a551abb3/frozenlist-1.8.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:494a5952b1c597ba44e0e78113a7266e656b9794eec897b19ead706bd7074383", size = 242411, upload-time = "2025-10-06T05:36:09.801Z" }, + { url = "https://files.pythonhosted.org/packages/8f/83/f61505a05109ef3293dfb1ff594d13d64a2324ac3482be2cedc2be818256/frozenlist-1.8.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:96f423a119f4777a4a056b66ce11527366a8bb92f54e541ade21f2374433f6d4", size = 243014, upload-time = "2025-10-06T05:36:11.394Z" }, + { url = "https://files.pythonhosted.org/packages/d8/cb/cb6c7b0f7d4023ddda30cf56b8b17494eb3a79e3fda666bf735f63118b35/frozenlist-1.8.0-cp312-cp312-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:3462dd9475af2025c31cc61be6652dfa25cbfb56cbbf52f4ccfe029f38decaf8", size = 234909, upload-time = "2025-10-06T05:36:12.598Z" }, + { url = "https://files.pythonhosted.org/packages/31/c5/cd7a1f3b8b34af009fb17d4123c5a778b44ae2804e3ad6b86204255f9ec5/frozenlist-1.8.0-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:c4c800524c9cd9bac5166cd6f55285957fcfc907db323e193f2afcd4d9abd69b", size = 250049, upload-time = "2025-10-06T05:36:14.065Z" }, + { url = "https://files.pythonhosted.org/packages/c0/01/2f95d3b416c584a1e7f0e1d6d31998c4a795f7544069ee2e0962a4b60740/frozenlist-1.8.0-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:d6a5df73acd3399d893dafc71663ad22534b5aa4f94e8a2fabfe856c3c1b6a52", size = 256485, upload-time = "2025-10-06T05:36:15.39Z" }, + { url = "https://files.pythonhosted.org/packages/ce/03/024bf7720b3abaebcff6d0793d73c154237b85bdf67b7ed55e5e9596dc9a/frozenlist-1.8.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:405e8fe955c2280ce66428b3ca55e12b3c4e9c336fb2103a4937e891c69a4a29", size = 237619, upload-time = "2025-10-06T05:36:16.558Z" }, + { url = "https://files.pythonhosted.org/packages/69/fa/f8abdfe7d76b731f5d8bd217827cf6764d4f1d9763407e42717b4bed50a0/frozenlist-1.8.0-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:908bd3f6439f2fef9e85031b59fd4f1297af54415fb60e4254a95f75b3cab3f3", size = 250320, upload-time = "2025-10-06T05:36:17.821Z" }, + { url = "https://files.pythonhosted.org/packages/f5/3c/b051329f718b463b22613e269ad72138cc256c540f78a6de89452803a47d/frozenlist-1.8.0-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:294e487f9ec720bd8ffcebc99d575f7eff3568a08a253d1ee1a0378754b74143", size = 246820, upload-time = "2025-10-06T05:36:19.046Z" }, + { url = "https://files.pythonhosted.org/packages/0f/ae/58282e8f98e444b3f4dd42448ff36fa38bef29e40d40f330b22e7108f565/frozenlist-1.8.0-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:74c51543498289c0c43656701be6b077f4b265868fa7f8a8859c197006efb608", size = 250518, upload-time = "2025-10-06T05:36:20.763Z" }, + { url = "https://files.pythonhosted.org/packages/8f/96/007e5944694d66123183845a106547a15944fbbb7154788cbf7272789536/frozenlist-1.8.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:776f352e8329135506a1d6bf16ac3f87bc25b28e765949282dcc627af36123aa", size = 239096, upload-time = "2025-10-06T05:36:22.129Z" }, + { url = "https://files.pythonhosted.org/packages/66/bb/852b9d6db2fa40be96f29c0d1205c306288f0684df8fd26ca1951d461a56/frozenlist-1.8.0-cp312-cp312-win32.whl", hash = "sha256:433403ae80709741ce34038da08511d4a77062aa924baf411ef73d1146e74faf", size = 39985, upload-time = "2025-10-06T05:36:23.661Z" }, + { url = "https://files.pythonhosted.org/packages/b8/af/38e51a553dd66eb064cdf193841f16f077585d4d28394c2fa6235cb41765/frozenlist-1.8.0-cp312-cp312-win_amd64.whl", hash = "sha256:34187385b08f866104f0c0617404c8eb08165ab1272e884abc89c112e9c00746", size = 44591, upload-time = "2025-10-06T05:36:24.958Z" }, + { url = "https://files.pythonhosted.org/packages/a7/06/1dc65480ab147339fecc70797e9c2f69d9cea9cf38934ce08df070fdb9cb/frozenlist-1.8.0-cp312-cp312-win_arm64.whl", hash = "sha256:fe3c58d2f5db5fbd18c2987cba06d51b0529f52bc3a6cdc33d3f4eab725104bd", size = 40102, upload-time = "2025-10-06T05:36:26.333Z" }, + { url = "https://files.pythonhosted.org/packages/2d/40/0832c31a37d60f60ed79e9dfb5a92e1e2af4f40a16a29abcc7992af9edff/frozenlist-1.8.0-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:8d92f1a84bb12d9e56f818b3a746f3efba93c1b63c8387a73dde655e1e42282a", size = 85717, upload-time = "2025-10-06T05:36:27.341Z" }, + { url = "https://files.pythonhosted.org/packages/30/ba/b0b3de23f40bc55a7057bd38434e25c34fa48e17f20ee273bbde5e0650f3/frozenlist-1.8.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:96153e77a591c8adc2ee805756c61f59fef4cf4073a9275ee86fe8cba41241f7", size = 49651, upload-time = "2025-10-06T05:36:28.855Z" }, + { url = "https://files.pythonhosted.org/packages/0c/ab/6e5080ee374f875296c4243c381bbdef97a9ac39c6e3ce1d5f7d42cb78d6/frozenlist-1.8.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:f21f00a91358803399890ab167098c131ec2ddd5f8f5fd5fe9c9f2c6fcd91e40", size = 49417, upload-time = "2025-10-06T05:36:29.877Z" }, + { url = "https://files.pythonhosted.org/packages/d5/4e/e4691508f9477ce67da2015d8c00acd751e6287739123113a9fca6f1604e/frozenlist-1.8.0-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:fb30f9626572a76dfe4293c7194a09fb1fe93ba94c7d4f720dfae3b646b45027", size = 234391, upload-time = "2025-10-06T05:36:31.301Z" }, + { url = "https://files.pythonhosted.org/packages/40/76/c202df58e3acdf12969a7895fd6f3bc016c642e6726aa63bd3025e0fc71c/frozenlist-1.8.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:eaa352d7047a31d87dafcacbabe89df0aa506abb5b1b85a2fb91bc3faa02d822", size = 233048, upload-time = "2025-10-06T05:36:32.531Z" }, + { url = "https://files.pythonhosted.org/packages/f9/c0/8746afb90f17b73ca5979c7a3958116e105ff796e718575175319b5bb4ce/frozenlist-1.8.0-cp313-cp313-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:03ae967b4e297f58f8c774c7eabcce57fe3c2434817d4385c50661845a058121", size = 226549, upload-time = "2025-10-06T05:36:33.706Z" }, + { url = "https://files.pythonhosted.org/packages/7e/eb/4c7eefc718ff72f9b6c4893291abaae5fbc0c82226a32dcd8ef4f7a5dbef/frozenlist-1.8.0-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:f6292f1de555ffcc675941d65fffffb0a5bcd992905015f85d0592201793e0e5", size = 239833, upload-time = "2025-10-06T05:36:34.947Z" }, + { url = "https://files.pythonhosted.org/packages/c2/4e/e5c02187cf704224f8b21bee886f3d713ca379535f16893233b9d672ea71/frozenlist-1.8.0-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:29548f9b5b5e3460ce7378144c3010363d8035cea44bc0bf02d57f5a685e084e", size = 245363, upload-time = "2025-10-06T05:36:36.534Z" }, + { url = "https://files.pythonhosted.org/packages/1f/96/cb85ec608464472e82ad37a17f844889c36100eed57bea094518bf270692/frozenlist-1.8.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:ec3cc8c5d4084591b4237c0a272cc4f50a5b03396a47d9caaf76f5d7b38a4f11", size = 229314, upload-time = "2025-10-06T05:36:38.582Z" }, + { url = "https://files.pythonhosted.org/packages/5d/6f/4ae69c550e4cee66b57887daeebe006fe985917c01d0fff9caab9883f6d0/frozenlist-1.8.0-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:517279f58009d0b1f2e7c1b130b377a349405da3f7621ed6bfae50b10adf20c1", size = 243365, upload-time = "2025-10-06T05:36:40.152Z" }, + { url = "https://files.pythonhosted.org/packages/7a/58/afd56de246cf11780a40a2c28dc7cbabbf06337cc8ddb1c780a2d97e88d8/frozenlist-1.8.0-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:db1e72ede2d0d7ccb213f218df6a078a9c09a7de257c2fe8fcef16d5925230b1", size = 237763, upload-time = "2025-10-06T05:36:41.355Z" }, + { url = "https://files.pythonhosted.org/packages/cb/36/cdfaf6ed42e2644740d4a10452d8e97fa1c062e2a8006e4b09f1b5fd7d63/frozenlist-1.8.0-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:b4dec9482a65c54a5044486847b8a66bf10c9cb4926d42927ec4e8fd5db7fed8", size = 240110, upload-time = "2025-10-06T05:36:42.716Z" }, + { url = "https://files.pythonhosted.org/packages/03/a8/9ea226fbefad669f11b52e864c55f0bd57d3c8d7eb07e9f2e9a0b39502e1/frozenlist-1.8.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:21900c48ae04d13d416f0e1e0c4d81f7931f73a9dfa0b7a8746fb2fe7dd970ed", size = 233717, upload-time = "2025-10-06T05:36:44.251Z" }, + { url = "https://files.pythonhosted.org/packages/1e/0b/1b5531611e83ba7d13ccc9988967ea1b51186af64c42b7a7af465dcc9568/frozenlist-1.8.0-cp313-cp313-win32.whl", hash = "sha256:8b7b94a067d1c504ee0b16def57ad5738701e4ba10cec90529f13fa03c833496", size = 39628, upload-time = "2025-10-06T05:36:45.423Z" }, + { url = "https://files.pythonhosted.org/packages/d8/cf/174c91dbc9cc49bc7b7aab74d8b734e974d1faa8f191c74af9b7e80848e6/frozenlist-1.8.0-cp313-cp313-win_amd64.whl", hash = "sha256:878be833caa6a3821caf85eb39c5ba92d28e85df26d57afb06b35b2efd937231", size = 43882, upload-time = "2025-10-06T05:36:46.796Z" }, + { url = "https://files.pythonhosted.org/packages/c1/17/502cd212cbfa96eb1388614fe39a3fc9ab87dbbe042b66f97acb57474834/frozenlist-1.8.0-cp313-cp313-win_arm64.whl", hash = "sha256:44389d135b3ff43ba8cc89ff7f51f5a0bb6b63d829c8300f79a2fe4fe61bcc62", size = 39676, upload-time = "2025-10-06T05:36:47.8Z" }, + { url = "https://files.pythonhosted.org/packages/d2/5c/3bbfaa920dfab09e76946a5d2833a7cbdf7b9b4a91c714666ac4855b88b4/frozenlist-1.8.0-cp313-cp313t-macosx_10_13_universal2.whl", hash = "sha256:e25ac20a2ef37e91c1b39938b591457666a0fa835c7783c3a8f33ea42870db94", size = 89235, upload-time = "2025-10-06T05:36:48.78Z" }, + { url = "https://files.pythonhosted.org/packages/d2/d6/f03961ef72166cec1687e84e8925838442b615bd0b8854b54923ce5b7b8a/frozenlist-1.8.0-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:07cdca25a91a4386d2e76ad992916a85038a9b97561bf7a3fd12d5d9ce31870c", size = 50742, upload-time = "2025-10-06T05:36:49.837Z" }, + { url = "https://files.pythonhosted.org/packages/1e/bb/a6d12b7ba4c3337667d0e421f7181c82dda448ce4e7ad7ecd249a16fa806/frozenlist-1.8.0-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:4e0c11f2cc6717e0a741f84a527c52616140741cd812a50422f83dc31749fb52", size = 51725, upload-time = "2025-10-06T05:36:50.851Z" }, + { url = "https://files.pythonhosted.org/packages/bc/71/d1fed0ffe2c2ccd70b43714c6cab0f4188f09f8a67a7914a6b46ee30f274/frozenlist-1.8.0-cp313-cp313t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:b3210649ee28062ea6099cfda39e147fa1bc039583c8ee4481cb7811e2448c51", size = 284533, upload-time = "2025-10-06T05:36:51.898Z" }, + { url = "https://files.pythonhosted.org/packages/c9/1f/fb1685a7b009d89f9bf78a42d94461bc06581f6e718c39344754a5d9bada/frozenlist-1.8.0-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:581ef5194c48035a7de2aefc72ac6539823bb71508189e5de01d60c9dcd5fa65", size = 292506, upload-time = "2025-10-06T05:36:53.101Z" }, + { url = "https://files.pythonhosted.org/packages/e6/3b/b991fe1612703f7e0d05c0cf734c1b77aaf7c7d321df4572e8d36e7048c8/frozenlist-1.8.0-cp313-cp313t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:3ef2d026f16a2b1866e1d86fc4e1291e1ed8a387b2c333809419a2f8b3a77b82", size = 274161, upload-time = "2025-10-06T05:36:54.309Z" }, + { url = "https://files.pythonhosted.org/packages/ca/ec/c5c618767bcdf66e88945ec0157d7f6c4a1322f1473392319b7a2501ded7/frozenlist-1.8.0-cp313-cp313t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:5500ef82073f599ac84d888e3a8c1f77ac831183244bfd7f11eaa0289fb30714", size = 294676, upload-time = "2025-10-06T05:36:55.566Z" }, + { url = "https://files.pythonhosted.org/packages/7c/ce/3934758637d8f8a88d11f0585d6495ef54b2044ed6ec84492a91fa3b27aa/frozenlist-1.8.0-cp313-cp313t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:50066c3997d0091c411a66e710f4e11752251e6d2d73d70d8d5d4c76442a199d", size = 300638, upload-time = "2025-10-06T05:36:56.758Z" }, + { url = "https://files.pythonhosted.org/packages/fc/4f/a7e4d0d467298f42de4b41cbc7ddaf19d3cfeabaf9ff97c20c6c7ee409f9/frozenlist-1.8.0-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:5c1c8e78426e59b3f8005e9b19f6ff46e5845895adbde20ece9218319eca6506", size = 283067, upload-time = "2025-10-06T05:36:57.965Z" }, + { url = "https://files.pythonhosted.org/packages/dc/48/c7b163063d55a83772b268e6d1affb960771b0e203b632cfe09522d67ea5/frozenlist-1.8.0-cp313-cp313t-musllinux_1_2_armv7l.whl", hash = "sha256:eefdba20de0d938cec6a89bd4d70f346a03108a19b9df4248d3cf0d88f1b0f51", size = 292101, upload-time = "2025-10-06T05:36:59.237Z" }, + { url = "https://files.pythonhosted.org/packages/9f/d0/2366d3c4ecdc2fd391e0afa6e11500bfba0ea772764d631bbf82f0136c9d/frozenlist-1.8.0-cp313-cp313t-musllinux_1_2_ppc64le.whl", hash = "sha256:cf253e0e1c3ceb4aaff6df637ce033ff6535fb8c70a764a8f46aafd3d6ab798e", size = 289901, upload-time = "2025-10-06T05:37:00.811Z" }, + { url = "https://files.pythonhosted.org/packages/b8/94/daff920e82c1b70e3618a2ac39fbc01ae3e2ff6124e80739ce5d71c9b920/frozenlist-1.8.0-cp313-cp313t-musllinux_1_2_s390x.whl", hash = "sha256:032efa2674356903cd0261c4317a561a6850f3ac864a63fc1583147fb05a79b0", size = 289395, upload-time = "2025-10-06T05:37:02.115Z" }, + { url = "https://files.pythonhosted.org/packages/e3/20/bba307ab4235a09fdcd3cc5508dbabd17c4634a1af4b96e0f69bfe551ebd/frozenlist-1.8.0-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:6da155091429aeba16851ecb10a9104a108bcd32f6c1642867eadaee401c1c41", size = 283659, upload-time = "2025-10-06T05:37:03.711Z" }, + { url = "https://files.pythonhosted.org/packages/fd/00/04ca1c3a7a124b6de4f8a9a17cc2fcad138b4608e7a3fc5877804b8715d7/frozenlist-1.8.0-cp313-cp313t-win32.whl", hash = "sha256:0f96534f8bfebc1a394209427d0f8a63d343c9779cda6fc25e8e121b5fd8555b", size = 43492, upload-time = "2025-10-06T05:37:04.915Z" }, + { url = "https://files.pythonhosted.org/packages/59/5e/c69f733a86a94ab10f68e496dc6b7e8bc078ebb415281d5698313e3af3a1/frozenlist-1.8.0-cp313-cp313t-win_amd64.whl", hash = "sha256:5d63a068f978fc69421fb0e6eb91a9603187527c86b7cd3f534a5b77a592b888", size = 48034, upload-time = "2025-10-06T05:37:06.343Z" }, + { url = "https://files.pythonhosted.org/packages/16/6c/be9d79775d8abe79b05fa6d23da99ad6e7763a1d080fbae7290b286093fd/frozenlist-1.8.0-cp313-cp313t-win_arm64.whl", hash = "sha256:bf0a7e10b077bf5fb9380ad3ae8ce20ef919a6ad93b4552896419ac7e1d8e042", size = 41749, upload-time = "2025-10-06T05:37:07.431Z" }, + { url = "https://files.pythonhosted.org/packages/f1/c8/85da824b7e7b9b6e7f7705b2ecaf9591ba6f79c1177f324c2735e41d36a2/frozenlist-1.8.0-cp314-cp314-macosx_10_13_universal2.whl", hash = "sha256:cee686f1f4cadeb2136007ddedd0aaf928ab95216e7691c63e50a8ec066336d0", size = 86127, upload-time = "2025-10-06T05:37:08.438Z" }, + { url = "https://files.pythonhosted.org/packages/8e/e8/a1185e236ec66c20afd72399522f142c3724c785789255202d27ae992818/frozenlist-1.8.0-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:119fb2a1bd47307e899c2fac7f28e85b9a543864df47aa7ec9d3c1b4545f096f", size = 49698, upload-time = "2025-10-06T05:37:09.48Z" }, + { url = "https://files.pythonhosted.org/packages/a1/93/72b1736d68f03fda5fdf0f2180fb6caaae3894f1b854d006ac61ecc727ee/frozenlist-1.8.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:4970ece02dbc8c3a92fcc5228e36a3e933a01a999f7094ff7c23fbd2beeaa67c", size = 49749, upload-time = "2025-10-06T05:37:10.569Z" }, + { url = "https://files.pythonhosted.org/packages/a7/b2/fabede9fafd976b991e9f1b9c8c873ed86f202889b864756f240ce6dd855/frozenlist-1.8.0-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:cba69cb73723c3f329622e34bdbf5ce1f80c21c290ff04256cff1cd3c2036ed2", size = 231298, upload-time = "2025-10-06T05:37:11.993Z" }, + { url = "https://files.pythonhosted.org/packages/3a/3b/d9b1e0b0eed36e70477ffb8360c49c85c8ca8ef9700a4e6711f39a6e8b45/frozenlist-1.8.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:778a11b15673f6f1df23d9586f83c4846c471a8af693a22e066508b77d201ec8", size = 232015, upload-time = "2025-10-06T05:37:13.194Z" }, + { url = "https://files.pythonhosted.org/packages/dc/94/be719d2766c1138148564a3960fc2c06eb688da592bdc25adcf856101be7/frozenlist-1.8.0-cp314-cp314-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:0325024fe97f94c41c08872db482cf8ac4800d80e79222c6b0b7b162d5b13686", size = 225038, upload-time = "2025-10-06T05:37:14.577Z" }, + { url = "https://files.pythonhosted.org/packages/e4/09/6712b6c5465f083f52f50cf74167b92d4ea2f50e46a9eea0523d658454ae/frozenlist-1.8.0-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:97260ff46b207a82a7567b581ab4190bd4dfa09f4db8a8b49d1a958f6aa4940e", size = 240130, upload-time = "2025-10-06T05:37:15.781Z" }, + { url = "https://files.pythonhosted.org/packages/f8/d4/cd065cdcf21550b54f3ce6a22e143ac9e4836ca42a0de1022da8498eac89/frozenlist-1.8.0-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:54b2077180eb7f83dd52c40b2750d0a9f175e06a42e3213ce047219de902717a", size = 242845, upload-time = "2025-10-06T05:37:17.037Z" }, + { url = "https://files.pythonhosted.org/packages/62/c3/f57a5c8c70cd1ead3d5d5f776f89d33110b1addae0ab010ad774d9a44fb9/frozenlist-1.8.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:2f05983daecab868a31e1da44462873306d3cbfd76d1f0b5b69c473d21dbb128", size = 229131, upload-time = "2025-10-06T05:37:18.221Z" }, + { url = "https://files.pythonhosted.org/packages/6c/52/232476fe9cb64f0742f3fde2b7d26c1dac18b6d62071c74d4ded55e0ef94/frozenlist-1.8.0-cp314-cp314-musllinux_1_2_armv7l.whl", hash = "sha256:33f48f51a446114bc5d251fb2954ab0164d5be02ad3382abcbfe07e2531d650f", size = 240542, upload-time = "2025-10-06T05:37:19.771Z" }, + { url = "https://files.pythonhosted.org/packages/5f/85/07bf3f5d0fb5414aee5f47d33c6f5c77bfe49aac680bfece33d4fdf6a246/frozenlist-1.8.0-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:154e55ec0655291b5dd1b8731c637ecdb50975a2ae70c606d100750a540082f7", size = 237308, upload-time = "2025-10-06T05:37:20.969Z" }, + { url = "https://files.pythonhosted.org/packages/11/99/ae3a33d5befd41ac0ca2cc7fd3aa707c9c324de2e89db0e0f45db9a64c26/frozenlist-1.8.0-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:4314debad13beb564b708b4a496020e5306c7333fa9a3ab90374169a20ffab30", size = 238210, upload-time = "2025-10-06T05:37:22.252Z" }, + { url = "https://files.pythonhosted.org/packages/b2/60/b1d2da22f4970e7a155f0adde9b1435712ece01b3cd45ba63702aea33938/frozenlist-1.8.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:073f8bf8becba60aa931eb3bc420b217bb7d5b8f4750e6f8b3be7f3da85d38b7", size = 231972, upload-time = "2025-10-06T05:37:23.5Z" }, + { url = "https://files.pythonhosted.org/packages/3f/ab/945b2f32de889993b9c9133216c068b7fcf257d8595a0ac420ac8677cab0/frozenlist-1.8.0-cp314-cp314-win32.whl", hash = "sha256:bac9c42ba2ac65ddc115d930c78d24ab8d4f465fd3fc473cdedfccadb9429806", size = 40536, upload-time = "2025-10-06T05:37:25.581Z" }, + { url = "https://files.pythonhosted.org/packages/59/ad/9caa9b9c836d9ad6f067157a531ac48b7d36499f5036d4141ce78c230b1b/frozenlist-1.8.0-cp314-cp314-win_amd64.whl", hash = "sha256:3e0761f4d1a44f1d1a47996511752cf3dcec5bbdd9cc2b4fe595caf97754b7a0", size = 44330, upload-time = "2025-10-06T05:37:26.928Z" }, + { url = "https://files.pythonhosted.org/packages/82/13/e6950121764f2676f43534c555249f57030150260aee9dcf7d64efda11dd/frozenlist-1.8.0-cp314-cp314-win_arm64.whl", hash = "sha256:d1eaff1d00c7751b7c6662e9c5ba6eb2c17a2306ba5e2a37f24ddf3cc953402b", size = 40627, upload-time = "2025-10-06T05:37:28.075Z" }, + { url = "https://files.pythonhosted.org/packages/c0/c7/43200656ecc4e02d3f8bc248df68256cd9572b3f0017f0a0c4e93440ae23/frozenlist-1.8.0-cp314-cp314t-macosx_10_13_universal2.whl", hash = "sha256:d3bb933317c52d7ea5004a1c442eef86f426886fba134ef8cf4226ea6ee1821d", size = 89238, upload-time = "2025-10-06T05:37:29.373Z" }, + { url = "https://files.pythonhosted.org/packages/d1/29/55c5f0689b9c0fb765055629f472c0de484dcaf0acee2f7707266ae3583c/frozenlist-1.8.0-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:8009897cdef112072f93a0efdce29cd819e717fd2f649ee3016efd3cd885a7ed", size = 50738, upload-time = "2025-10-06T05:37:30.792Z" }, + { url = "https://files.pythonhosted.org/packages/ba/7d/b7282a445956506fa11da8c2db7d276adcbf2b17d8bb8407a47685263f90/frozenlist-1.8.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:2c5dcbbc55383e5883246d11fd179782a9d07a986c40f49abe89ddf865913930", size = 51739, upload-time = "2025-10-06T05:37:32.127Z" }, + { url = "https://files.pythonhosted.org/packages/62/1c/3d8622e60d0b767a5510d1d3cf21065b9db874696a51ea6d7a43180a259c/frozenlist-1.8.0-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:39ecbc32f1390387d2aa4f5a995e465e9e2f79ba3adcac92d68e3e0afae6657c", size = 284186, upload-time = "2025-10-06T05:37:33.21Z" }, + { url = "https://files.pythonhosted.org/packages/2d/14/aa36d5f85a89679a85a1d44cd7a6657e0b1c75f61e7cad987b203d2daca8/frozenlist-1.8.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:92db2bf818d5cc8d9c1f1fc56b897662e24ea5adb36ad1f1d82875bd64e03c24", size = 292196, upload-time = "2025-10-06T05:37:36.107Z" }, + { url = "https://files.pythonhosted.org/packages/05/23/6bde59eb55abd407d34f77d39a5126fb7b4f109a3f611d3929f14b700c66/frozenlist-1.8.0-cp314-cp314t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:2dc43a022e555de94c3b68a4ef0b11c4f747d12c024a520c7101709a2144fb37", size = 273830, upload-time = "2025-10-06T05:37:37.663Z" }, + { url = "https://files.pythonhosted.org/packages/d2/3f/22cff331bfad7a8afa616289000ba793347fcd7bc275f3b28ecea2a27909/frozenlist-1.8.0-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:cb89a7f2de3602cfed448095bab3f178399646ab7c61454315089787df07733a", size = 294289, upload-time = "2025-10-06T05:37:39.261Z" }, + { url = "https://files.pythonhosted.org/packages/a4/89/5b057c799de4838b6c69aa82b79705f2027615e01be996d2486a69ca99c4/frozenlist-1.8.0-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:33139dc858c580ea50e7e60a1b0ea003efa1fd42e6ec7fdbad78fff65fad2fd2", size = 300318, upload-time = "2025-10-06T05:37:43.213Z" }, + { url = "https://files.pythonhosted.org/packages/30/de/2c22ab3eb2a8af6d69dc799e48455813bab3690c760de58e1bf43b36da3e/frozenlist-1.8.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:168c0969a329b416119507ba30b9ea13688fafffac1b7822802537569a1cb0ef", size = 282814, upload-time = "2025-10-06T05:37:45.337Z" }, + { url = "https://files.pythonhosted.org/packages/59/f7/970141a6a8dbd7f556d94977858cfb36fa9b66e0892c6dd780d2219d8cd8/frozenlist-1.8.0-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:28bd570e8e189d7f7b001966435f9dac6718324b5be2990ac496cf1ea9ddb7fe", size = 291762, upload-time = "2025-10-06T05:37:46.657Z" }, + { url = "https://files.pythonhosted.org/packages/c1/15/ca1adae83a719f82df9116d66f5bb28bb95557b3951903d39135620ef157/frozenlist-1.8.0-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:b2a095d45c5d46e5e79ba1e5b9cb787f541a8dee0433836cea4b96a2c439dcd8", size = 289470, upload-time = "2025-10-06T05:37:47.946Z" }, + { url = "https://files.pythonhosted.org/packages/ac/83/dca6dc53bf657d371fbc88ddeb21b79891e747189c5de990b9dfff2ccba1/frozenlist-1.8.0-cp314-cp314t-musllinux_1_2_s390x.whl", hash = "sha256:eab8145831a0d56ec9c4139b6c3e594c7a83c2c8be25d5bcf2d86136a532287a", size = 289042, upload-time = "2025-10-06T05:37:49.499Z" }, + { url = "https://files.pythonhosted.org/packages/96/52/abddd34ca99be142f354398700536c5bd315880ed0a213812bc491cff5e4/frozenlist-1.8.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:974b28cf63cc99dfb2188d8d222bc6843656188164848c4f679e63dae4b0708e", size = 283148, upload-time = "2025-10-06T05:37:50.745Z" }, + { url = "https://files.pythonhosted.org/packages/af/d3/76bd4ed4317e7119c2b7f57c3f6934aba26d277acc6309f873341640e21f/frozenlist-1.8.0-cp314-cp314t-win32.whl", hash = "sha256:342c97bf697ac5480c0a7ec73cd700ecfa5a8a40ac923bd035484616efecc2df", size = 44676, upload-time = "2025-10-06T05:37:52.222Z" }, + { url = "https://files.pythonhosted.org/packages/89/76/c615883b7b521ead2944bb3480398cbb07e12b7b4e4d073d3752eb721558/frozenlist-1.8.0-cp314-cp314t-win_amd64.whl", hash = "sha256:06be8f67f39c8b1dc671f5d83aaefd3358ae5cdcf8314552c57e7ed3e6475bdd", size = 49451, upload-time = "2025-10-06T05:37:53.425Z" }, + { url = "https://files.pythonhosted.org/packages/e0/a3/5982da14e113d07b325230f95060e2169f5311b1017ea8af2a29b374c289/frozenlist-1.8.0-cp314-cp314t-win_arm64.whl", hash = "sha256:102e6314ca4da683dca92e3b1355490fed5f313b768500084fbe6371fddfdb79", size = 42507, upload-time = "2025-10-06T05:37:54.513Z" }, + { url = "https://files.pythonhosted.org/packages/9a/9a/e35b4a917281c0b8419d4207f4334c8e8c5dbf4f3f5f9ada73958d937dcc/frozenlist-1.8.0-py3-none-any.whl", hash = "sha256:0c18a16eab41e82c295618a77502e17b195883241c563b00f0aa5106fc4eaa0d", size = 13409, upload-time = "2025-10-06T05:38:16.721Z" }, +] + +[[package]] +name = "google-api-core" +version = "2.44.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "google-auth" }, + { name = "googleapis-common-protos" }, + { name = "opentelemetry-api" }, + { name = "proto-plus" }, + { name = "protobuf" }, + { name = "requests" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/72/ef/63d89cb580f3a42c51db53b3d151352aa61b9c87ea8cfdd8d24ee6caa09d/google_api_core-2.44.0.tar.gz", hash = "sha256:5ab9a396965c1227d7dea4581e562b7018aa2bca96d2de0be5eb70dc9c8ab3a1", size = 288859, upload-time = "2026-11-05T18:39:43.265Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/c9/73/4068d4b123d206f42e44d476b6ed4de773d81efc4e88101ff82e318b9a7a/google_api_core-2.44.0-py3-none-any.whl", hash = "sha256:8cb9ad8af28de9bc75121686d69b697ce0937e21fad2ad80c9a7e89f22b26e1f", size = 225627, upload-time = "2026-11-05T18:39:01.342Z" }, +] + +[[package]] +name = "google-auth" +version = "2.62.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "cryptography" }, + { name = "pyasn1-modules" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/4a/d4/87353e950d653d87360176363d51f316e8e368e1ddbb7ba7aa5503c30c3e/google_auth-2.62.2.tar.gz", hash = "sha256:046c61a72d3a847d6df6417a7f0d5cf054e3b82bbcb54fb1e69d47880964049c", size = 404543, upload-time = "2026-11-10T15:50:55.102Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a0/d4/0f8481baa50f75db3bb19a0df79fe19615e66eccfc3afb0b946dcb8791b3/google_auth-2.62.2-py3-none-any.whl", hash = "sha256:e9bcdb0679b6a4369ac327c5c59f06d92f7b4cd2624e7100294c14632f55a36b", size = 270150, upload-time = "2026-11-10T15:50:53.408Z" }, +] + +[[package]] +name = "googleapis-common-protos" +version = "1.76.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "protobuf" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/62/b6/bc095b23a3e0d978e75c8c18cabe4c11f791837410670e4486f0d539bfba/googleapis_common_protos-1.76.0.tar.gz", hash = "sha256:71db0e44a1d4c2dd024ebad44ca67129cc1e2892e4861df466764749d5ef8642", size = 156250, upload-time = "2026-10-22T23:43:36.263Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/05/6d/78dc67a9e779e594b49bf62604034d3a6aa428a55afc729cafda4b7333e1/googleapis_common_protos-1.76.0-py3-none-any.whl", hash = "sha256:59e13344a9f3651aa201a03e2bee815a3bf43a4baf1f9ff8a9b62a840ce25fac", size = 307707, upload-time = "2026-10-22T23:43:10.445Z" }, +] + +[[package]] +name = "grpcio" +version = "1.85.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/f0/03/f9e805772d4d01da2a1754a5f63c58601eacaf8f1e878729217188de7d16/grpcio-1.85.1.tar.gz", hash = "sha256:5f530287d5de5f7f66089ead81de44f6787162944dab3922efa65dfdff108a1d", size = 14091456, upload-time = "2026-10-30T16:01:16.909Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/47/3c/ab73cb485967ac57f00350fef66c8180400c6a832436cf39811cc7d41f8d/grpcio-1.85.1-cp311-cp311-linux_armv7l.whl", hash = "sha256:d2a776b113e7bd6d139e679f5da281193d6410cce361e4180c9da0d553e01927", size = 6823898, upload-time = "2026-10-30T15:59:12.079Z" }, + { url = "https://files.pythonhosted.org/packages/81/0f/80bd2a767a8cb78e9c257b9062f9786b67c3ce26d403825545ba2e9a79ad/grpcio-1.85.1-cp311-cp311-macosx_11_0_universal2.whl", hash = "sha256:cfa9bf4daed57dd5bd5fac4be3276f5dc1703f41abf4df0737f4e7952705cbc6", size = 12654220, upload-time = "2026-10-30T15:59:14.324Z" }, + { url = "https://files.pythonhosted.org/packages/f8/a0/efb97c6639f59907fe3c17270904918b37cdc406eba2dbe97feacf309a86/grpcio-1.85.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:9885436e83eab92dd0d476642baf08a17c55ef2b1db430adcba3e89bb6938a5d", size = 7215807, upload-time = "2026-10-30T15:59:17.395Z" }, + { url = "https://files.pythonhosted.org/packages/f7/f2/2b0900585deed45e126a1d5939acbaba94f6f4c62a787949cdc03329979d/grpcio-1.85.1-cp311-cp311-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:3bbf7ae798e38eccb1b7abf169d9e228514418da6f68caec69a295fde899ec17", size = 8200549, upload-time = "2026-10-30T15:59:19.657Z" }, + { url = "https://files.pythonhosted.org/packages/1a/4f/30f66cedfec6c03bc304b28fbe073ed53179cf37a511b8ee8e8e7e2d3f17/grpcio-1.85.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:83aced2a1c05648cee0de34e531351118b14c58238f0a61b43559ac8851647a8", size = 7392335, upload-time = "2026-10-30T15:59:21.917Z" }, + { url = "https://files.pythonhosted.org/packages/4a/ad/5dee0e6e5a57f88379bc2820aa6e3098a2174e21a40bfb961c6d5f5b28d0/grpcio-1.85.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:b364bc3daa601eb1cb0023e90b1309cbf6da0de6ca40a19f2d5a31edeb9990e3", size = 7955183, upload-time = "2026-10-30T15:59:24.197Z" }, + { url = "https://files.pythonhosted.org/packages/43/d8/93b729c8fc1aee6232906cffd44a9dfcb6f8387e6279a1238cd972ff468a/grpcio-1.85.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:c9a4a4e504bd914e10c0d6190ffac59b9e21f1c962366b72293075ade097793d", size = 9212733, upload-time = "2026-10-30T15:59:26.388Z" }, + { url = "https://files.pythonhosted.org/packages/08/4d/d6339c51032649a90c347a67ad41b56f2f1a564f4960efcc72409fe03eba/grpcio-1.85.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:83b09ca3f9602caf4f1b4295b4bb002b10477789ff9797feeedc811b9a6be0b7", size = 8332651, upload-time = "2026-10-30T15:59:29.113Z" }, + { url = "https://files.pythonhosted.org/packages/b4/bf/085116e89db4f758af02eca2da9ad3a1890fb1691f5e2fc882c402ed9622/grpcio-1.85.1-cp311-cp311-win32.whl", hash = "sha256:bbc678a2b8d10e0dea666d948f36237e681be3686079564937df689bac386bc5", size = 4779959, upload-time = "2026-10-30T15:59:31.001Z" }, + { url = "https://files.pythonhosted.org/packages/9b/b8/fb80401f9eaf51eb2fc8c5dbf8e4f8cbfeebc21bf837f7c6576790ce433e/grpcio-1.85.1-cp311-cp311-win_amd64.whl", hash = "sha256:27b519f6594da04cf2dda1378f46811b2b6160d60a01f88a0ec4de009bbbfa46", size = 5615553, upload-time = "2026-10-30T15:59:33.252Z" }, + { url = "https://files.pythonhosted.org/packages/31/8c/b6d9ea0bf02a6b47ba34c5f936da2921d76f5e40cbb411e9abb246b70d2d/grpcio-1.85.1-cp312-cp312-linux_armv7l.whl", hash = "sha256:1a10d337967ec2be049c6a2345320f6a59f71bf9f54febfd80e5a966cffaa945", size = 6797195, upload-time = "2026-10-30T15:59:35.364Z" }, + { url = "https://files.pythonhosted.org/packages/c6/ee/f60cfacd679fe811944be391c899955c3d9c7e07db922b47e535ddda550c/grpcio-1.85.1-cp312-cp312-macosx_11_0_universal2.whl", hash = "sha256:658a9d89c5736bf4aa3ef4ecbc79528e26d8e23c5e1c83417d2870a1a06063e5", size = 12633025, upload-time = "2026-10-30T15:59:37.66Z" }, + { url = "https://files.pythonhosted.org/packages/f1/0d/5dbe225f0ceb208538dc8c16c5f52b0c402b91611f981604b5e280439dfb/grpcio-1.85.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:843aa281a48188621f50880496d35defed51298bcb66d5345d5f282fd3f87354", size = 7170616, upload-time = "2026-10-30T15:59:40.138Z" }, + { url = "https://files.pythonhosted.org/packages/54/35/ce972a4e5bb721ba85f5c9e20a0029253ae0b2deb5276dafa3383e025133/grpcio-1.85.1-cp312-cp312-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:e768556a2346d1d2921f511f3145e2462e4fe68095c31e4db407558bcd3f1d4f", size = 8180786, upload-time = "2026-10-30T15:59:42.7Z" }, + { url = "https://files.pythonhosted.org/packages/00/8d/74a8649d2787dae0a661855cdf09a8e2238fa741689bb368ca1b4f6d5b6f/grpcio-1.85.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:a1a72d19c0ab84b4b73b6c47eeaade76d84b1973a51593ff1160a73df33d03d9", size = 7362744, upload-time = "2026-10-30T15:59:45.076Z" }, + { url = "https://files.pythonhosted.org/packages/03/72/87ef13aba6bd2c5c6d4c5117238b17b1e3c1c1efa26c66cb377053124eb7/grpcio-1.85.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:0e07f477e1d1a05bdbe71d63add964c5457e7ab2e3f5fd32859639ed8ecb976e", size = 7929643, upload-time = "2026-10-30T15:59:47.294Z" }, + { url = "https://files.pythonhosted.org/packages/09/f1/2e75b2906c9643e0be81a74bf23ae10c29661e0199c8f3a6e2c23707e882/grpcio-1.85.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:b2846c70ed58c8e149e8e5d867af40805a13b151d84157d8272952d711a77c5c", size = 9181161, upload-time = "2026-10-30T15:59:49.399Z" }, + { url = "https://files.pythonhosted.org/packages/c1/d9/6b9127e8fa3ef14a3ec199436bec6c1a54a0bb429ca261b1a2fb518938d1/grpcio-1.85.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:9998f03ac0dfed226eead6e93cee1b547d7a32e47e1915dee94eff0e113b167e", size = 8318829, upload-time = "2026-10-30T15:59:52.09Z" }, + { url = "https://files.pythonhosted.org/packages/21/46/ff3374d33efee490a0e50e3c3fc59280b7f7fc2ed3ab1ee8c4e9873dc83d/grpcio-1.85.1-cp312-cp312-win32.whl", hash = "sha256:2670c03d154f6bec66a0fef97c607116761b032183187dfdfe229b5975820a4f", size = 4768056, upload-time = "2026-10-30T15:59:54.132Z" }, + { url = "https://files.pythonhosted.org/packages/dd/48/4030a63540089d00a36cea15282623bcf084a5ea4c0ffc4685a42ef0f342/grpcio-1.85.1-cp312-cp312-win_amd64.whl", hash = "sha256:eaad7e6aa9ac3aded4f6bc86a18bf2cff3de356f972bf32a5558df9788085b85", size = 5607218, upload-time = "2026-10-30T15:59:56.721Z" }, + { url = "https://files.pythonhosted.org/packages/c1/05/2d40be7dbfd8e66e8e5675ec695fafacc69823dcd2ef5d387ad7431c7af7/grpcio-1.85.1-cp313-cp313-linux_armv7l.whl", hash = "sha256:e117b074d707d418ff411e0ad6fc86e97e83047b742488b41d7a5b7a62953cd3", size = 6801759, upload-time = "2026-10-30T15:59:58.834Z" }, + { url = "https://files.pythonhosted.org/packages/b0/98/530af74d704dc8e79c79b26888af44ccbdd1827bfabc9cb405b3d4cc184e/grpcio-1.85.1-cp313-cp313-macosx_11_0_universal2.whl", hash = "sha256:6bb4bbb5cb46010687db552fd88852c405595814fb7d435b072124bd6b93f827", size = 12629341, upload-time = "2026-10-30T16:00:01.159Z" }, + { url = "https://files.pythonhosted.org/packages/21/cb/bac12e6c7ab3b1c6b50816fdcbf7f97aec1bd0992cc0d193e332aff716a5/grpcio-1.85.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:0bde4264ca71aaf3bc56c587380c426b1c959d1db0ab0a3f632bc66515f9726f", size = 7174387, upload-time = "2026-10-30T16:00:04.847Z" }, + { url = "https://files.pythonhosted.org/packages/90/0a/7770a652508a3a6c7d16fbb81db0f0b2be8a73a469af88a6cdfdc3d29cf2/grpcio-1.85.1-cp313-cp313-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:7b931335c163510fb054c30007fe3556ef3bf354a1c37b5da403f2e52c6bbd95", size = 8185778, upload-time = "2026-10-30T16:00:07.009Z" }, + { url = "https://files.pythonhosted.org/packages/bf/cb/52417fb272b7603d13ec8688e843dfd8df64584da1951ad954b9120d7c80/grpcio-1.85.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:de520b1555ae445cdc4f8f1cc7ccba12a19992bfafa7c292ebe7fe1fe5da6c53", size = 7364062, upload-time = "2026-10-30T16:00:09.777Z" }, + { url = "https://files.pythonhosted.org/packages/ba/86/9329799fa9defe9327084b9ca7b9a9745e83e7174bb90f2bfb2f37063967/grpcio-1.85.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:2b20ba567ca818b8393fd4668878b5688cab32a46e8e7a4d1a58641fc0072df9", size = 7932775, upload-time = "2026-10-30T16:00:11.956Z" }, + { url = "https://files.pythonhosted.org/packages/48/e4/826e0ae8f89a3d2ab3a15b91ee4ef486bdd7a09fd1ff72e12d01505341dc/grpcio-1.85.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:f0ebfbd8ba42497e0ff7229c8c5e166e07c2b348462c1481dbd90faa978ad8af", size = 9173461, upload-time = "2026-10-30T16:00:15.696Z" }, + { url = "https://files.pythonhosted.org/packages/88/2d/d4baf37bf1a9ba8222dcb133c6aeb09119b183bd7b471061762a1198461c/grpcio-1.85.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:000999ea9bba80217b1625782d638e7a688790f6154e845e18826f7da859bfc7", size = 8311104, upload-time = "2026-10-30T16:00:18.533Z" }, + { url = "https://files.pythonhosted.org/packages/e4/02/b07af232a583727fa84665d11165bbd7be6ddd31d84c2b8cb62a7b69062f/grpcio-1.85.1-cp313-cp313-win32.whl", hash = "sha256:b3722f4e01820f4d2422679a567fe33f31b6f14eba4352657a1078f4b4ed323e", size = 4769351, upload-time = "2026-10-30T16:00:21.165Z" }, + { url = "https://files.pythonhosted.org/packages/f9/f0/d2448e860d884e8c89dd9135cd9373df064c10227d90973d822c2125428d/grpcio-1.85.1-cp313-cp313-win_amd64.whl", hash = "sha256:c17d61af28b322c48ab3881c685e5f6e7e367c56844cf589ee7707be9477b969", size = 5606831, upload-time = "2026-10-30T16:00:23.621Z" }, + { url = "https://files.pythonhosted.org/packages/39/cc/da49c22b9c571b5315acc507e2ff6568e5ff9d4c99895285910283bf87e3/grpcio-1.85.1-cp314-cp314-linux_armv7l.whl", hash = "sha256:2a378eb60ea42996be5a8c7167302fb30d968fcfcf9edd7b3fa6c985906c4500", size = 6803626, upload-time = "2026-10-30T16:00:26.587Z" }, + { url = "https://files.pythonhosted.org/packages/12/92/35bcee92bcfc2b0f66290a5dd6dd23ced7b9423fe269cf4495136e73d55b/grpcio-1.85.1-cp314-cp314-macosx_11_0_universal2.whl", hash = "sha256:90a7e0f26de39d15f5c741b8848bb2065c9ab7351c57d4fc973ff5cbda0cb9c7", size = 12640307, upload-time = "2026-10-30T16:00:28.969Z" }, + { url = "https://files.pythonhosted.org/packages/f2/b5/469b69dadb2c413706f16e0c3e7a2749cc70abaab10d718873603bec29b2/grpcio-1.85.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:421925365f9a665830eded01b8053033abbc2fbabc9bb4e9c59c3b5b12acbab9", size = 7187308, upload-time = "2026-10-30T16:00:31.652Z" }, + { url = "https://files.pythonhosted.org/packages/c4/df/2fcb1567d37e91ce26bddfca30f39fe6c39cbc5a2f4a210cfb1246ced1b2/grpcio-1.85.1-cp314-cp314-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:8a921a98ed6142a29651b4a6f4c7b8e051d115f1e78c31655a9642dcf6356dd9", size = 8188002, upload-time = "2026-10-30T16:00:33.893Z" }, + { url = "https://files.pythonhosted.org/packages/7b/b2/c67c1d8c7b70a094d404b28233458887bc1ca1319daa95d8952621216717/grpcio-1.85.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:e0e6d5829b50a2ffcfcd2dbf08d02ac0d6919051a2e97c2ee27c99bc9916a245", size = 7368045, upload-time = "2026-10-30T16:00:36.675Z" }, + { url = "https://files.pythonhosted.org/packages/80/48/5cf6c704be4b059d508e8f6c981154223533595ba7a3ee531211ef8be62e/grpcio-1.85.1-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:58b5ebe509da292bec5a1913c1e4c14d842a33f6cb330a87d3713c5089dd0f55", size = 7941330, upload-time = "2026-10-30T16:00:39.173Z" }, + { url = "https://files.pythonhosted.org/packages/67/96/5ef14edb784ea2053610753993601e98a76a18b541a8a74103dc390540ab/grpcio-1.85.1-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:016982ebd21d2b48e955aa808e9db8d628708a35c6eba852cd0e70765826ab06", size = 9176909, upload-time = "2026-10-30T16:00:41.335Z" }, + { url = "https://files.pythonhosted.org/packages/50/01/4264ae95364bdeede4c8a5f0d83df83a21b477935f9ab8c829ae5606e1d4/grpcio-1.85.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:0fa3d7b8b95e8a609967991c3b0a302b2f9d510fe417efadfa7c7d2d044a99ba", size = 8316226, upload-time = "2026-10-30T16:00:44.199Z" }, + { url = "https://files.pythonhosted.org/packages/75/b8/79dace38eb4bb904751b804cfdc71609a3840f34084af7475169059dce20/grpcio-1.85.1-cp314-cp314-win32.whl", hash = "sha256:39b1965266b579f3758db20d74f9075b130d1b1edcf0464cda316e403a15da9b", size = 4853260, upload-time = "2026-10-30T16:00:47.098Z" }, + { url = "https://files.pythonhosted.org/packages/48/c9/68a6bbd2450f08942c3056acd8995ac28af2b4eeb0574c0a8e59fa59b140/grpcio-1.85.1-cp314-cp314-win_amd64.whl", hash = "sha256:5f015600190124813032da0560ec950c13c257f77c1307abd77c393c0994f76f", size = 5758958, upload-time = "2026-10-30T16:00:49.145Z" }, + { url = "https://files.pythonhosted.org/packages/1b/bd/1a2481b354ab4528eb8b3462937904c9206e2a54748f3f74a2576205ef3e/grpcio-1.85.1-cp315-cp315-linux_armv7l.whl", hash = "sha256:07bfef5df75875d8481d3403f864785e30096594162e8041c53a84fb11ee4f8e", size = 6803392, upload-time = "2026-10-30T16:00:51.782Z" }, + { url = "https://files.pythonhosted.org/packages/40/45/1868c12c18058d778fcecee0e04c867891a82d983d2dd0de2639158aa960/grpcio-1.85.1-cp315-cp315-macosx_10_15_universal2.whl", hash = "sha256:e909e0f9145a555d3968dd2a448616b0d3cb58748b9e2053de3e7974b3e429bc", size = 12657793, upload-time = "2026-10-30T16:00:55.335Z" }, + { url = "https://files.pythonhosted.org/packages/ed/af/c283032a42df5217913b98bd0113738b68dd94b91cea16b2209565fefe67/grpcio-1.85.1-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:1f3064e209167e5fcb75a72cbc18918c06027b92b29fa06eaff0126f9a2aab5a", size = 7209146, upload-time = "2026-10-30T16:00:58.279Z" }, + { url = "https://files.pythonhosted.org/packages/45/64/8a72fd6c20c206cff07eaa49b2ca63bb15d7ed9b6bf7c653ea10ec578e4b/grpcio-1.85.1-cp315-cp315-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:07675c635a2da0c772e58ac736a7fb10c7c7c1613157766441e6866ad97d25b4", size = 7511067, upload-time = "2026-10-30T16:01:00.806Z" }, + { url = "https://files.pythonhosted.org/packages/5d/b8/32afa404288c7eea4c6034d031f1a07eff772a8cdbfc7751314382e7b724/grpcio-1.85.1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:759f7df78954e3ac0ed4c87612eff9125021b9271be37be8c88167aa533e29ee", size = 7410227, upload-time = "2026-10-30T16:01:02.966Z" }, + { url = "https://files.pythonhosted.org/packages/89/a4/1c51e2c2d0d9e4d37e8e8a7be412c5dfb3fd5c80ab100dd531fd81b44d43/grpcio-1.85.1-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:7cd08bd5ad063ad9639dbebf95d3a6b8c8aa2c9d49049bc0e8f47e73ecf1c1a2", size = 7964886, upload-time = "2026-10-30T16:01:05.208Z" }, + { url = "https://files.pythonhosted.org/packages/07/f3/e26f570129c162d8f15a02af6edb49e592ac1c88a63490cd3ec9142d8c67/grpcio-1.85.1-cp315-cp315-musllinux_1_2_i686.whl", hash = "sha256:2198269c8b69cb1e9d5d20628029245e40b7227d5f6fc6f298a420701d8fb652", size = 8504060, upload-time = "2026-10-30T16:01:07.82Z" }, + { url = "https://files.pythonhosted.org/packages/16/e1/e334cf7442c01892ed813563b21b2a8ab5b042e34f33ad76cf64526d1de8/grpcio-1.85.1-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:7bc5de50374416223bc35332aa8185567ec065f86190ff0ca6e13176ed39a3b4", size = 8346563, upload-time = "2026-10-30T16:01:10.394Z" }, + { url = "https://files.pythonhosted.org/packages/66/bb/cf72913ce0baae1fed95445f1ba8ac309184ac16b4f20fb5f88219eff72c/grpcio-1.85.1-cp315-cp315-win32.whl", hash = "sha256:5740aedf1e6acde538d7b80a2507eb6ee0b8983c577a36890d27a0e2b62cc1eb", size = 4853404, upload-time = "2026-10-30T16:01:12.239Z" }, + { url = "https://files.pythonhosted.org/packages/ea/b8/b7cff7b9e1ff7b6a8d36a19ce8b9c575963e71fcbb3878b276cff6748b05/grpcio-1.85.1-cp315-cp315-win_amd64.whl", hash = "sha256:b32f39c56d22d2e8722eececd4376074d94e01595a29f4f944ae0b6cea1caa70", size = 5758584, upload-time = "2026-10-30T16:01:14.325Z" }, +] + +[[package]] +name = "grpcio-tools" +version = "1.85.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "grpcio" }, + { name = "protobuf" }, + { name = "setuptools" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a8/86/a71d768b0098bc57ff89a4e8dd19f4947cad9c7991d6578c32aa88fb1d1c/grpcio_tools-1.85.0.tar.gz", hash = "sha256:1583807d0245a7c4e12837b652516b7a62683f9c9174889b4ad1001ec30a74d6", size = 6579337, upload-time = "2026-10-26T06:22:21.256Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/cc/bc/2107ebbf3eb13490b12a846b402604cbd4b5b606ce1974d12df2c96eec6e/grpcio_tools-1.85.0-cp311-cp311-linux_armv7l.whl", hash = "sha256:da6c18e2a7d8c2035db20ef3f29cf0f8ce3a3f09fc0e6db01f067ba61074e0ab", size = 2706699, upload-time = "2026-10-26T06:20:44.201Z" }, + { url = "https://files.pythonhosted.org/packages/00/a3/ae861c16b72892734afe357febf140d76cee4ad07025b4c9ad679670a885/grpcio_tools-1.85.0-cp311-cp311-macosx_11_0_universal2.whl", hash = "sha256:555d17ee02d03497fe0b02f37fe8dcf4a222559b7a862dda1c4cd96ea8ee831f", size = 5977952, upload-time = "2026-10-26T06:20:46.627Z" }, + { url = "https://files.pythonhosted.org/packages/71/e7/a1982438dc7a777c878afecf1baf248bcfb4c62e543597994b9bd380c747/grpcio_tools-1.85.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:00738caaaee0827b2da0e6dbc76166067b27813b47d8dc817f4ef665d743c049", size = 2746512, upload-time = "2026-10-26T06:20:48.401Z" }, + { url = "https://files.pythonhosted.org/packages/fb/7c/fc8c8046c0e9d839ad529863ea2822ba6d490f69a109d5c2507a769ee67b/grpcio_tools-1.85.0-cp311-cp311-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:60ace7f8c00e43adde8125f5c398c6d9e891909f2bf31340481a854335f305c7", size = 3083798, upload-time = "2026-10-26T06:20:51.429Z" }, + { url = "https://files.pythonhosted.org/packages/3f/67/1a8aac7bc6ad08649fd3370c7515c0882c283a6dda47090d784b1aa9d98d/grpcio_tools-1.85.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:0d81d493212ec87f919d2de41c37a91e54065a916a1ee0c5849fce39bef78765", size = 2812857, upload-time = "2026-10-26T06:20:53.648Z" }, + { url = "https://files.pythonhosted.org/packages/48/dc/681cdde7d5d0f56a8b18490bc017845732c5cd4a114d074354267270d567/grpcio_tools-1.85.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:eb4388290bd25c4ecc3978831c8fd145e6f00b89a28b8c1b78e1a3318a8cb1b6", size = 3257015, upload-time = "2026-10-26T06:20:55.883Z" }, + { url = "https://files.pythonhosted.org/packages/ca/3c/51f39e4751b6dc900ecb9ee45a8f97ba472f9266f85370937bd3ea73c12d/grpcio_tools-1.85.0-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:7707479abb1169b8935e740699673f6e0ec0eb14f5ea92ce167a46ab0cd55c60", size = 3850399, upload-time = "2026-10-26T06:20:58.084Z" }, + { url = "https://files.pythonhosted.org/packages/5b/3f/f398c365651ebb2e80e6188af971e1ca2948d46727adf0ef165143dcd6b3/grpcio_tools-1.85.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:d08cf27319533a8046321b713710b9dae1b6021e8edef852b554df581af7014c", size = 3485551, upload-time = "2026-10-26T06:20:59.902Z" }, + { url = "https://files.pythonhosted.org/packages/0a/f3/17575a75662452b52eda3fb4b74f906c30aab37b048da333753a8650b484/grpcio_tools-1.85.0-cp311-cp311-win32.whl", hash = "sha256:b8ba719ebb28aae5073ac70e4b7ee765441f8b6af788ca83b2004f5ab622f7c0", size = 1044328, upload-time = "2026-10-26T06:21:01.5Z" }, + { url = "https://files.pythonhosted.org/packages/10/95/b9ae44fb69000e8a313e7af849d7ae6e20ca91701d903f288dd0ed903710/grpcio_tools-1.85.0-cp311-cp311-win_amd64.whl", hash = "sha256:2eedc78a2ad5ffac9a9811903c35eda533d9335fdeaa8211d425e615dcdece20", size = 1212902, upload-time = "2026-10-26T06:21:03.103Z" }, + { url = "https://files.pythonhosted.org/packages/03/6f/7c6e97e775c3e8f3c9eb9aac39db06ef9d9744ec0d621810a4abcd76a6e7/grpcio_tools-1.85.0-cp312-cp312-linux_armv7l.whl", hash = "sha256:37c9b1025707283d033c5675a0081fed73f9ac2d52ba275740386943b7c45ba5", size = 2708373, upload-time = "2026-10-26T06:21:05.213Z" }, + { url = "https://files.pythonhosted.org/packages/40/00/c4d248d6c36f2fbdd17b717d91c273a253e09cdf123f28ca95726db5539f/grpcio_tools-1.85.0-cp312-cp312-macosx_11_0_universal2.whl", hash = "sha256:7023b2dd4c9addfefd09a86728bad917c151aca5b72931532feb031b42f4a90c", size = 5977135, upload-time = "2026-10-26T06:21:07.382Z" }, + { url = "https://files.pythonhosted.org/packages/ff/d9/cac9559b9ae20b9281e91339908e2c231ca5e9dcd34bbe22edf6b3573c3f/grpcio_tools-1.85.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:2108ae8df01b6ba84907562c9c6547f58c4c530e6f77dfbd4e786ba3dc86e928", size = 2749296, upload-time = "2026-10-26T06:21:09.097Z" }, + { url = "https://files.pythonhosted.org/packages/29/02/683e03c4b1975f6d7eff5f88ac49aca148cd194db96c37fe7e2049448a08/grpcio_tools-1.85.0-cp312-cp312-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:e413474f82b7a8b177bf4e130a92a43e481f9553d00b9ec4769dd1987940fdcf", size = 3085403, upload-time = "2026-10-26T06:21:11.094Z" }, + { url = "https://files.pythonhosted.org/packages/13/bb/e8163b173daf8df7aa0dee8431453340c75632c813f85084b9782de46278/grpcio_tools-1.85.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:421fef974047b7aa95406373d0514cc888a6ffbc42812a15282ed56c520e0a7a", size = 2813688, upload-time = "2026-10-26T06:21:13.003Z" }, + { url = "https://files.pythonhosted.org/packages/f8/a3/ae1cb2d922f6ad61497fb2e8c773fea3e04c0956db001e4999fd0aac6225/grpcio_tools-1.85.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:29d281aa7d8773d4f993f04d0417239a5bd37df237090f5c245be2e81220a663", size = 3260912, upload-time = "2026-10-26T06:21:14.959Z" }, + { url = "https://files.pythonhosted.org/packages/a2/e0/27ae2fa8bd8004677afb67cfe5571b7232fa2e92298fc415f02d91e1879b/grpcio_tools-1.85.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:6f9659c2b6380f62d00658d2272a7650cc7f61b9f52996e4cecbcb29522cc117", size = 3851426, upload-time = "2026-10-26T06:21:16.904Z" }, + { url = "https://files.pythonhosted.org/packages/b2/1e/e9fc7bd76eed44bba49f32ed2f211f6a7ad5267c81bb1e94ecb470c9697c/grpcio_tools-1.85.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:177d32833814d530778270c999ee6dacbd5f97377b3dbc3da33e4ebc96593350", size = 3489815, upload-time = "2026-10-26T06:21:18.862Z" }, + { url = "https://files.pythonhosted.org/packages/e5/e8/f5705f763e0dae2122497636f50e790549a887e6703451e13247fe4a194b/grpcio_tools-1.85.0-cp312-cp312-win32.whl", hash = "sha256:f39a1d4e34e9822a72951bfcbaff7693753af62a99be340cdb020efa6cf6333c", size = 1044469, upload-time = "2026-10-26T06:21:20.441Z" }, + { url = "https://files.pythonhosted.org/packages/bf/d0/2336f2478eb6965f7a32d299030bef1b02484c5d1cc721183fbc2a817ba7/grpcio_tools-1.85.0-cp312-cp312-win_amd64.whl", hash = "sha256:674dc2603426a9540d7514cedbdd1836deea9e327d47f7aaf5746ca72c3ba075", size = 1213158, upload-time = "2026-10-26T06:21:22.122Z" }, + { url = "https://files.pythonhosted.org/packages/a6/85/566ef67d5deb2e12a97f52b132b411856ca9dd2b962e59c869c19ee8c914/grpcio_tools-1.85.0-cp313-cp313-linux_armv7l.whl", hash = "sha256:e51e3f58a03b048d4ede87b172caa9000d57e304157290667512c8421d6861b4", size = 2707890, upload-time = "2026-10-26T06:21:23.877Z" }, + { url = "https://files.pythonhosted.org/packages/f7/4c/55715a52afccb264ee883ac2497997a819118a909bd84d3804ef65c7c25e/grpcio_tools-1.85.0-cp313-cp313-macosx_11_0_universal2.whl", hash = "sha256:3246ed14cc86136723febc9671723cb80b2a03cb3ef30c410b106ce252b31546", size = 5975714, upload-time = "2026-10-26T06:21:26.138Z" }, + { url = "https://files.pythonhosted.org/packages/bc/10/3e44d1b12456cd4f3b53f44f9a1ab279edb1d49d02799ba4adcaf495b76c/grpcio_tools-1.85.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:f74c46d24b3ca4b81595633db5ebe9ad502adba8e7772de4ed66a1481afcfb70", size = 2748300, upload-time = "2026-10-26T06:21:27.88Z" }, + { url = "https://files.pythonhosted.org/packages/62/0a/7d7c5fec6a0330cebb122939780ad5069a77d272cfe4c1d23e5118b5b089/grpcio_tools-1.85.0-cp313-cp313-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:2678b767235979c481b1020ac3a59e79243cacfce9f1aebed6510e27b0f462fa", size = 3085051, upload-time = "2026-10-26T06:21:29.729Z" }, + { url = "https://files.pythonhosted.org/packages/89/14/6f40b9a0432988602c6ab2e50b81520a9ee91e9a66f23c4dd9cd759f180b/grpcio_tools-1.85.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:ded3e21934f566cc9bdb265b9f425ab2cd640e9295639b89c0c3d0441e60df56", size = 2813054, upload-time = "2026-10-26T06:21:31.421Z" }, + { url = "https://files.pythonhosted.org/packages/db/8c/8d68ad64ab2d24b977b5c1b5b5bc9a0830acccb785f125b030471614b821/grpcio_tools-1.85.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:d5995c18864d88a91aac6b9540dfe5ad9f4cacf1bf7a6a41fb1ee5882cbbe62d", size = 3259672, upload-time = "2026-10-26T06:21:33.323Z" }, + { url = "https://files.pythonhosted.org/packages/e5/ba/9bebf612ce4e3e7060ba87ce47c9bfac088c76e40ca889950e1b2e27ca89/grpcio_tools-1.85.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:c760f9c9508f9c60c144ca3859502c05a7cd71fdbb345a4191011b47cf251a8f", size = 3850861, upload-time = "2026-10-26T06:21:35.567Z" }, + { url = "https://files.pythonhosted.org/packages/13/a6/1ed898c5626376f7d10639c41e120d9c380dbb0f8369851dd0ddba89aff5/grpcio_tools-1.85.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:736e222b29d2a3297dc3830485114dc14cc290cddf611ab4d454e5b835ae4bab", size = 3489583, upload-time = "2026-10-26T06:21:37.527Z" }, + { url = "https://files.pythonhosted.org/packages/7e/99/1408ab7edac2eddcac4f45583b22a18517c4c4ec0dd2ea14e6d6c079322f/grpcio_tools-1.85.0-cp313-cp313-win32.whl", hash = "sha256:e25e2974333abe850b594054f36dee4589957f2aabdd8c98ba8c7060c2dd9b65", size = 1044388, upload-time = "2026-10-26T06:21:39.285Z" }, + { url = "https://files.pythonhosted.org/packages/b7/46/16dfe7c84ed3cac92f74ceefb427f1af04a57436fbf228579071bf548ebe/grpcio_tools-1.85.0-cp313-cp313-win_amd64.whl", hash = "sha256:93d979b6d44c822380a84fe54e995ca085449d3ed33f871e93138963643badce", size = 1212582, upload-time = "2026-10-26T06:21:40.901Z" }, + { url = "https://files.pythonhosted.org/packages/fb/da/f2c2dfb64c09989cd41c0c8b23c2fc20466b139745dc5dad9ee9e8602164/grpcio_tools-1.85.0-cp314-cp314-linux_armv7l.whl", hash = "sha256:11ec760ba73ae9948a18ce04fed08c0d899408f4fe5dccb342eda986dda0e874", size = 2707987, upload-time = "2026-10-26T06:21:42.809Z" }, + { url = "https://files.pythonhosted.org/packages/49/59/74ad1079ff83184515a34d538d19357e08c6da7f51f93391b81c496afb06/grpcio_tools-1.85.0-cp314-cp314-macosx_11_0_universal2.whl", hash = "sha256:0bd6e7508cba5d37e933fe93f05019ac483858fbff954a6145715b729a6b1d15", size = 5975552, upload-time = "2026-10-26T06:21:44.658Z" }, + { url = "https://files.pythonhosted.org/packages/1a/a1/a70d7d203ede5b56bf98a4547f891a1ca7c27f823851ba1fc6671bcb80ae/grpcio_tools-1.85.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:998edfc52a7894c419c645d879835342dece34c397b60b756b2c7006cbbee50c", size = 2748730, upload-time = "2026-10-26T06:21:46.447Z" }, + { url = "https://files.pythonhosted.org/packages/4c/b1/43b14a23ddb5cc9e14004ca5f91eb0fbb0e5ab6f15e93525320bdd7d1387/grpcio_tools-1.85.0-cp314-cp314-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:8f1fb03fac0ce0821e8d089dd65e94ad965d1207bec560512c5f40c614b63b8c", size = 3085236, upload-time = "2026-10-26T06:21:48.28Z" }, + { url = "https://files.pythonhosted.org/packages/b0/84/07b19b1b1dd5f0946db3db91139b8bd7857ed5899823e6a90c9b020a5ed9/grpcio_tools-1.85.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:711ef3d561d0ca7ab52a1bd8de0c2a2dd34140cbd8d1ad5c5f366bcef3f122e7", size = 2813187, upload-time = "2026-10-26T06:21:50Z" }, + { url = "https://files.pythonhosted.org/packages/08/4f/e37a7ee97cafe1aaa6eaa4b509862f989686596e9019f6d80a566608ce87/grpcio_tools-1.85.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:40b83867c3709f46f690790c9146c63f3ea6e433aa2747d1463521b8a29bfb88", size = 3260544, upload-time = "2026-10-26T06:21:51.964Z" }, + { url = "https://files.pythonhosted.org/packages/80/f3/a0fed76b29bdc397d468bf7139aa169090e5ed4c425d4badf5207b8d6fd4/grpcio_tools-1.85.0-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:1a066afb1e67eedbf75dfd68722a4e3d3983a8bafded1167fc9b0b048cea95e5", size = 3850885, upload-time = "2026-10-26T06:21:54.099Z" }, + { url = "https://files.pythonhosted.org/packages/23/07/ca2e1f9dc14b026fef210cc9b31045d97fd385f0a8ca5550e6a100fbd658/grpcio_tools-1.85.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:c97d1f312b6fb56703e43505f0e1a47a32ae7273e98c79a5a913e0e061f8602d", size = 3489533, upload-time = "2026-10-26T06:21:56.02Z" }, + { url = "https://files.pythonhosted.org/packages/66/9a/462e5b7eff4a9f80a756bddeb9acfd7a7c5338042bf80e814fd0fe8d1f99/grpcio_tools-1.85.0-cp314-cp314-win32.whl", hash = "sha256:1726373ac7f37ab23a79c895f6f9eb80b3414c6fe8da628139bd1736186fa36e", size = 1067643, upload-time = "2026-10-26T06:21:57.576Z" }, + { url = "https://files.pythonhosted.org/packages/15/cc/f4f4c4a944b02f42f7896b7e67b2ca42501116f1e5d7166256565fb4ab2d/grpcio_tools-1.85.0-cp314-cp314-win_amd64.whl", hash = "sha256:05e060cc23752f9caeb9af9b514b88187f546246b729ee4287add7e54d398836", size = 1247626, upload-time = "2026-10-26T06:21:59.254Z" }, + { url = "https://files.pythonhosted.org/packages/58/76/059238d9c0e771c54c5684c42bcfac3522b4c5476993d6094e829ccb3c86/grpcio_tools-1.85.0-cp315-cp315-linux_armv7l.whl", hash = "sha256:1f24615b638a82cc21320143d3d9d681fc845f153dc8edc42e87d6e2b61c8746", size = 2707885, upload-time = "2026-10-26T06:22:01.219Z" }, + { url = "https://files.pythonhosted.org/packages/13/63/dcfb1ae93342d8e2b98a7d66bdf6270d9f2f3180d8a9417dfc1e2fcc7d64/grpcio_tools-1.85.0-cp315-cp315-macosx_10_15_universal2.whl", hash = "sha256:60882d882c969cd0f6ef72be4b226485671208374e89882322c2abb9d7b031ee", size = 5984306, upload-time = "2026-10-26T06:22:03.617Z" }, + { url = "https://files.pythonhosted.org/packages/94/df/0d4ebbd50d77f80776a48224a6245cd3901456d9bbe1cef73c37560908cd/grpcio_tools-1.85.0-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:85c9dbaa04832786ae8cf520bfcf0d10c6d7ced59a30f3c4715131d27ee5c056", size = 2750745, upload-time = "2026-10-26T06:22:05.642Z" }, + { url = "https://files.pythonhosted.org/packages/7f/82/d32c195f20f67b8784e24a3ccfd1f37e58a0e1122ec4a66450cbf839931c/grpcio_tools-1.85.0-cp315-cp315-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:00b55fbd8444d5184b81d1ed69572e8ba6644bbb9177e852a5c938f9664458d2", size = 2954775, upload-time = "2026-10-26T06:22:07.576Z" }, + { url = "https://files.pythonhosted.org/packages/39/37/097b24b2fd9cd0bd3480194d704bf330f9701945b36288367d9e498a9f56/grpcio_tools-1.85.0-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:ded26aae71db736ac1cd804998eba92f881c8230bf7e6fcf71ea086fb922a397", size = 2798117, upload-time = "2026-10-26T06:22:09.37Z" }, + { url = "https://files.pythonhosted.org/packages/6a/07/9b42d333c63b5d5ebaf7016885e0ce131d26b6527132ce97710e4dfe5333/grpcio_tools-1.85.0-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:22fd9a1a03e81d67ef5e93914ceeb7846a9d2d7db0a2998e7c919c5088b551d9", size = 3262156, upload-time = "2026-10-26T06:22:11.468Z" }, + { url = "https://files.pythonhosted.org/packages/dc/74/61dadbca3d9e13866a227321d850dc5c6b1c3e459a279ae337b7c84f6595/grpcio_tools-1.85.0-cp315-cp315-musllinux_1_2_i686.whl", hash = "sha256:57d2049a0b34114a79ac4cdece948bacc1de118ce1ee966dcf8adaf30ba8c231", size = 3729054, upload-time = "2026-10-26T06:22:13.439Z" }, + { url = "https://files.pythonhosted.org/packages/02/d3/14890211b12dfad182a0cfc773a27a4309a93b9bdaa8d2017f008aa1196e/grpcio_tools-1.85.0-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:2c7f18ab8ab413d950bfd3c5b08db4b942907cf7ee7744558c63da651f58ddf5", size = 3463044, upload-time = "2026-10-26T06:22:15.765Z" }, + { url = "https://files.pythonhosted.org/packages/0c/eb/228100fc52548a1b3e4c9731578737ea86d0ee6b5d11cfd967f889da2056/grpcio_tools-1.85.0-cp315-cp315-win32.whl", hash = "sha256:ccffc910e5b3fa60bb49ed69330ff1a221735415bc5cdcaa3b33f0dbb928fe30", size = 1067473, upload-time = "2026-10-26T06:22:17.538Z" }, + { url = "https://files.pythonhosted.org/packages/0f/79/62ea6ccc4585c8e72ecd7bba26e4757a30fa565db895d5c18d5a98ee76f5/grpcio_tools-1.85.0-cp315-cp315-win_amd64.whl", hash = "sha256:a8bde97aea0dd025ff7b7137b318f5fb7fc219eb12fcde6666dfb4bd1cb1ba25", size = 1247466, upload-time = "2026-10-26T06:22:19.222Z" }, +] + +[[package]] +name = "grpclib" +version = "0.4.9" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "h2" }, + { name = "multidict" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/5b/28/5a2c299ec82a876a252c5919aa895a6f1d1d35c96417c5ce4a4660dc3a80/grpclib-0.4.9.tar.gz", hash = "sha256:cc589c330fa81004c6400a52a566407574498cb5b055fa927013361e21466c46", size = 84798, upload-time = "2025-12-14T22:23:14.349Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/5c/90/b0cbbd9efcc82816c58f31a34963071aa19fb792a212a5d9caf8e0fc3097/grpclib-0.4.9-py3-none-any.whl", hash = "sha256:7762ec1c8ed94dfad597475152dd35cbd11aecaaca2f243e29702435ca24cf0e", size = 77063, upload-time = "2025-12-14T22:23:13.224Z" }, +] + +[[package]] +name = "h11" +version = "0.16.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/01/ee/02a2c011bdab74c6fb3c75474d40b3052059d95df7e73351460c8588d963/h11-0.16.0.tar.gz", hash = "sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1", size = 101250, upload-time = "2025-04-24T03:35:25.427Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/04/4b/29cac41a4d98d144bf5f6d33995617b185d14b22401f75ca86f384e87ff1/h11-0.16.0-py3-none-any.whl", hash = "sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86", size = 37515, upload-time = "2025-04-24T03:35:24.344Z" }, +] + +[[package]] +name = "h2" +version = "4.4.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "hpack" }, + { name = "hyperframe" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/e7/85/7c366e69d84c17bb778fe41419e1fbcce3033d5b7ce29bbffff0a98b859f/h2-4.4.1.tar.gz", hash = "sha256:4e866ffb1a869ae14dd9b5e6beb5c24a13da0495ad72b65925ded182521c1516", size = 2157281, upload-time = "2026-08-03T11:45:09.509Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7e/22/e85faf23bd72a92d1921e37d674ca56eb298a3c8be31fdecef0ff2b3aaac/h2-4.4.1-py3-none-any.whl", hash = "sha256:0e25f1462b23c9cb82d9eb02e28bc706dac2a68cb457c6a0d74d63c8a2a5d0e6", size = 62636, upload-time = "2026-08-03T11:44:59.164Z" }, +] + +[[package]] +name = "hessian2" +version = "0.2.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/6c/45/38ddd05937443e6b544d64119f8f30486bc3b444e2ed37eed8616acddbdf/hessian2-0.2.0.tar.gz", hash = "sha256:1b4c5b05a6f7ba32d3c32833b485d8954911514e08e03ad8027fc4e9f160ab4f", size = 201005, upload-time = "2026-11-14T07:33:38.372Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/8a/98/bae08bf727f4597ad75d294e4206944f8c418cdaa66de591b7aac1b076ae/hessian2-0.2.0-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:00f9afe33572ffbffebb426d0a212eb98f64109a98b13593cc1e0487a4701af8", size = 455832, upload-time = "2026-11-14T07:32:07.999Z" }, + { url = "https://files.pythonhosted.org/packages/6e/dd/ee116d17fd823ccbcae30d37de2cad19afae3875cd34929de05eeb934208/hessian2-0.2.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:1320f62960219ef9ad26ce5f022c7116a43e9a507c58d50eed9ecafb00248ad7", size = 448765, upload-time = "2026-11-14T07:32:10.061Z" }, + { url = "https://files.pythonhosted.org/packages/36/e4/505417faaa4e07269638dec97a04888ea9d049aac3443f8f7a36bc3df5e0/hessian2-0.2.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:28fd7fe03ed72b3b05c0c203e93cf94f4d1fa55f9ad77f3af35ff1eaa403d739", size = 468143, upload-time = "2026-11-14T07:32:11.838Z" }, + { url = "https://files.pythonhosted.org/packages/4e/25/62853372dc3f92d62f027c7fee2f7adc68d68f763c8bbb4171f8fc6ef575/hessian2-0.2.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:de1cb592d88e09426b6a24ec60c5754653c3d9e5c57ae819e7ffda28134d774a", size = 474785, upload-time = "2026-11-14T07:32:13.346Z" }, + { url = "https://files.pythonhosted.org/packages/7c/ea/110a0be52b472c2a458e52e1f54c2892363e3570a732792d1a3bb3f62e8f/hessian2-0.2.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:ea72909d9b024ea2c5cbf11a811cc283da69e46a835b8d815c4b17c02b985d54", size = 537030, upload-time = "2026-11-14T07:32:15.102Z" }, + { url = "https://files.pythonhosted.org/packages/7d/41/e9d4d3e418c0a11b8912a4582c537c7b776c843f16fa5cc3a3a50961dc77/hessian2-0.2.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:172e9e3a2aeee0f09273173a4378c4a43a329283a704399f573e691d4a094487", size = 557887, upload-time = "2026-11-14T07:32:16.575Z" }, + { url = "https://files.pythonhosted.org/packages/fe/ef/5ea6eb611f6c0e7c7b168375efc15681cd2e969c28582c92a1d86c3f11e4/hessian2-0.2.0-cp311-cp311-win_amd64.whl", hash = "sha256:4568063ef4cb2cbd5ffa326ff3d51e126342bf258e5aeb9696094e0e2ab668eb", size = 368074, upload-time = "2026-11-14T07:32:18.273Z" }, + { url = "https://files.pythonhosted.org/packages/f7/b6/c2bcf1c3edbf30842447d6a5f0c55dd86e931c2397719096c308f68d3dd3/hessian2-0.2.0-cp311-cp311-win_arm64.whl", hash = "sha256:c9d8966af1f2bbbd703d8c65f375cb3543b163b1173283f0baff0cce417f133e", size = 354199, upload-time = "2026-11-14T07:32:19.794Z" }, + { url = "https://files.pythonhosted.org/packages/5a/14/7ff531fb369a6c817dfc8ca7cd6eadff97704cd94b81485940980cf67746/hessian2-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:a886f88c3f9fdf22364fde2e1449eba5bea4628db4a513c709e776ac2807f229", size = 469283, upload-time = "2026-11-14T07:32:21.585Z" }, + { url = "https://files.pythonhosted.org/packages/71/60/71cb84eb9d5a1e5b86518181f993252e5663adc0edc662daa2fa3cc777ca/hessian2-0.2.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:82a7e9c17e840c39df40aadee5b45281609fffb25883261c5d03dcbded1bb9fc", size = 443818, upload-time = "2026-11-14T07:32:23.237Z" }, + { url = "https://files.pythonhosted.org/packages/b6/29/9dcec52dd725052b9233119ae6a4298509b7345eef63cd4a0d75c7eb33f8/hessian2-0.2.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:c107afb065523b4be91165207cce84148936e4a7cca09899058cd13fc478b42f", size = 463860, upload-time = "2026-11-14T07:32:24.739Z" }, + { url = "https://files.pythonhosted.org/packages/12/16/04238e02e6bd34bd6a6c2eb9d4f4c6f8f94659b487ba379619e952e67ff4/hessian2-0.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:6b53e6be31358f9bd8c40840a5702c9302c33120d47ebc5d08ebf29c237efb8d", size = 472961, upload-time = "2026-11-14T07:32:26.318Z" }, + { url = "https://files.pythonhosted.org/packages/1a/ae/bbc7804c549d4522edcedd989d03803f4182b2eb1b046cc7a73cdd498e70/hessian2-0.2.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:896ae338c8009be639e1de530a688f8d3bbf533f9139d2ca535d25aff1e88678", size = 534976, upload-time = "2026-11-14T07:32:27.795Z" }, + { url = "https://files.pythonhosted.org/packages/05/57/34aadb2d08c97f836a6a53aadf1e86788374e3ca53ba8a69838218ad4eb7/hessian2-0.2.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:9ac017fa28a36a605de3d6cf9140d5c8f5f20b0955ec9348806201a2b944d8e7", size = 555548, upload-time = "2026-11-14T07:32:29.912Z" }, + { url = "https://files.pythonhosted.org/packages/de/0d/4451bd350ca1815510a3584c44c40e6d3a1f6775b013559b4de2e8bc8b20/hessian2-0.2.0-cp312-cp312-win_amd64.whl", hash = "sha256:efc92c7e4a1e7a78f104e7c7a0f4989d1f829b4ba73bce72a1b51d66a362928f", size = 362691, upload-time = "2026-11-14T07:32:32.035Z" }, + { url = "https://files.pythonhosted.org/packages/d8/4f/65e0b0f474449686ed7c56d9e5cb02ae8ba48f3708fcfb4049f0048dbffc/hessian2-0.2.0-cp312-cp312-win_arm64.whl", hash = "sha256:dc12a938673ad0acbb9344765c79f2934e922f345d9f48dbcfed5d15a1680770", size = 349014, upload-time = "2026-11-14T07:32:33.663Z" }, + { url = "https://files.pythonhosted.org/packages/85/a1/903d358a9a3595b656d8f0af7dd82d28a27d890e425e9e46a2093eb72298/hessian2-0.2.0-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:1823b87963ed815897c2690cfbf324bb193de453dfd540b340e461715db60db7", size = 469595, upload-time = "2026-11-14T07:32:35.325Z" }, + { url = "https://files.pythonhosted.org/packages/74/55/9a62cebf526bf19e2841ee4e22af284742e2462634e5fcdae6b1985335fa/hessian2-0.2.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:2020a26f024321e7a9617f6f285cdf6936b2df0cebcdbb8dbb5506963c05e1ab", size = 443966, upload-time = "2026-11-14T07:32:37.403Z" }, + { url = "https://files.pythonhosted.org/packages/b8/18/ee55bc022de97b9a28c126ef4bef3c70673fa1764eded5859089ac7260db/hessian2-0.2.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:1e989a37be3dc29abad6aa8081a61b1a647f9d027259e72d011b467df8f3577d", size = 464413, upload-time = "2026-11-14T07:32:38.892Z" }, + { url = "https://files.pythonhosted.org/packages/d6/63/29e94b066f76d89893ed565c341dae6342ec5ab33a57a157750981c46e70/hessian2-0.2.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:f688aab4a56eb30ce49674df21b8934e622155a5fb626bfb32970669975ada1a", size = 472992, upload-time = "2026-11-14T07:32:40.561Z" }, + { url = "https://files.pythonhosted.org/packages/d7/24/797f2f7560c077f731c0cdf8a279cc280d87d4e1ad739a0b6e673a4be652/hessian2-0.2.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:4899d71d7afe7970b72fa508cc35b7a9e28020a451dc14c81da154ff3e7efaec", size = 535164, upload-time = "2026-11-14T07:32:42.051Z" }, + { url = "https://files.pythonhosted.org/packages/be/b9/95635a2c4ec56dd440aa702d24455b2610a76b056ac0105dff841ad158e7/hessian2-0.2.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:3d6fa50a827fd7bf701d223c5e88624bc26bfbabd4171843ffe7654609e497b7", size = 555646, upload-time = "2026-11-14T07:32:43.741Z" }, + { url = "https://files.pythonhosted.org/packages/77/37/6908323a3e3ccdb9e460ea017d433545499382add67d218c668be62fe81f/hessian2-0.2.0-cp313-cp313-win_amd64.whl", hash = "sha256:9ef0da300d65fd5bfba5e398ac779a62ddc7f8c0204297a00b6ea8086a8ffd1c", size = 362842, upload-time = "2026-11-14T07:32:45.307Z" }, + { url = "https://files.pythonhosted.org/packages/4f/b4/965dbb46af8c959b19e093f6dc494241d64023d5ca93245d0a43bd11cd82/hessian2-0.2.0-cp313-cp313-win_arm64.whl", hash = "sha256:7c5fb7e71e51b66c668aec67c5471306e411ebec5cdb7eaf403f4380afbc2ca6", size = 348941, upload-time = "2026-11-14T07:32:46.928Z" }, + { url = "https://files.pythonhosted.org/packages/4d/7a/b3d7178fb1b1c67e7d83b4e539ffaf8546ad4b8a204e73dd758fe957a545/hessian2-0.2.0-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:bec020949844c1d7e39541168bdc1e599e7f2ab31532da2d8295e84ff525114c", size = 471350, upload-time = "2026-11-14T07:32:48.338Z" }, + { url = "https://files.pythonhosted.org/packages/04/53/bffe9d46ebb8c5ec9b559cb34ed5a8ab3c8568a90f56395b88c3df1f68de/hessian2-0.2.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:7c2dee8f7eb30e9887c8563f6b359deb52498e190c6090f83b4e79229593d3bd", size = 445064, upload-time = "2026-11-14T07:32:49.793Z" }, + { url = "https://files.pythonhosted.org/packages/fe/8d/2f31e26222e08151a8aa4ed40bcc66cea6ea78e82e53deedf686c4ce92a4/hessian2-0.2.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:895506f5307d15fef51aa7d11c84b496ef623635ddc2f514a2ee22f7a59b6ffa", size = 465350, upload-time = "2026-11-14T07:32:51.704Z" }, + { url = "https://files.pythonhosted.org/packages/d5/de/db09148ec2b69b6477595aede0c60db129cb5b778f11d54857a76947b388/hessian2-0.2.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c0493608163a357827317dca0a7d365ffee99e52675ec3b83d44987b4bc31677", size = 474940, upload-time = "2026-11-14T07:32:53.185Z" }, + { url = "https://files.pythonhosted.org/packages/ba/3c/b1a8c75f6ca2d5b87f4e88f704cc623e5b9694627f0ef92035cabe9c519d/hessian2-0.2.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:e5059370a135879c2fa31317cd423462268e6671f4a628371d053b5d9d85d178", size = 536221, upload-time = "2026-11-14T07:32:54.673Z" }, + { url = "https://files.pythonhosted.org/packages/c5/ff/eea1692ebe8341db666955be3f37470db71134cc0c68bda27a2ec524cfe0/hessian2-0.2.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:9a01d0ad177d1ec55407def4cf098602511072414205692a489d11859e5fce71", size = 557821, upload-time = "2026-11-14T07:32:56.417Z" }, + { url = "https://files.pythonhosted.org/packages/1f/62/bdf672624b11935a3e5f817a08744446bd8c956f0c52b9edc481cdffafe7/hessian2-0.2.0-cp314-cp314-win_amd64.whl", hash = "sha256:046ec71ce3ebc81477958cc38a0a8e062c3a0d42bf9476203ca064f681ee94e9", size = 363578, upload-time = "2026-11-14T07:32:58.034Z" }, + { url = "https://files.pythonhosted.org/packages/42/1f/5b990dbd34b5ad43fa829bf7fe8e8b63fdcdb47f384855824c08d6663ea8/hessian2-0.2.0-cp314-cp314-win_arm64.whl", hash = "sha256:17115af0e6f68e9c90f991db12471acd1ec2a69887dba489fb89be9d262b95c0", size = 349477, upload-time = "2026-11-14T07:32:59.407Z" }, + { url = "https://files.pythonhosted.org/packages/d6/18/7ca61f92833638b725eecc4c5e9792859f6e114f240f832e0570df78389f/hessian2-0.2.0-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:1fc1b9b9dd9a715035ee753c84eebb51864f331d279bdf66fc91f7cf8265172b", size = 462783, upload-time = "2026-11-14T07:33:00.845Z" }, + { url = "https://files.pythonhosted.org/packages/fe/8b/99034115d1d64fa038848c90c5c825a357d97c5b7c996e5d19163f65fe87/hessian2-0.2.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:0472da2718bb5f0dcb72404a20f4b9cbedba21119204fbb3fcd01a1542f5f9fb", size = 439213, upload-time = "2026-11-14T07:33:02.292Z" }, + { url = "https://files.pythonhosted.org/packages/13/84/00900eb7bb7e38f8cc5e33f6a4f62dab06db273ac85414d1a1d61cbc2aba/hessian2-0.2.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:3c4596b323104af540b80265db5355df3cfc8a5b27eecc199f7e918a83127c1b", size = 461722, upload-time = "2026-11-14T07:33:04.057Z" }, + { url = "https://files.pythonhosted.org/packages/b3/34/4f610ed39a1801914a993f67d44ae4f8cd03395c154ec8e945e5e3991f27/hessian2-0.2.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:91a0857d6a49807e5923d2d3e3d93517c3a3d4a2f90ffde118235701fd65c6af", size = 473941, upload-time = "2026-11-14T07:33:05.835Z" }, + { url = "https://files.pythonhosted.org/packages/4b/00/56f9e886026f64dd5cd040175451bdac505fca0943d349c992948bfa1b43/hessian2-0.2.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:6cf96bbce34274d1c4fbb21079cc6b172a90d2d3a98395de649470609d6adbce", size = 532718, upload-time = "2026-11-14T07:33:07.511Z" }, + { url = "https://files.pythonhosted.org/packages/e2/d5/d755b34fc1f8d64be422386eaaf8237570e1ba9dd9f156247c8f94f15d58/hessian2-0.2.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:1668fb267b8c88b2efb7141bc9286c0b79af2728367aa4387a339c7a066b05e2", size = 556793, upload-time = "2026-11-14T07:33:08.945Z" }, + { url = "https://files.pythonhosted.org/packages/d9/7e/3b0dd9fc056ead467365a15547a4eb892c7789eb692f587165629abd3453/hessian2-0.2.0-cp314-cp314t-win_amd64.whl", hash = "sha256:d87bd572d889cef37a2e97eb5fca2d93039d56a4ce92ee334b31949d52d37317", size = 359558, upload-time = "2026-11-14T07:33:10.377Z" }, + { url = "https://files.pythonhosted.org/packages/dc/ad/0e722e5f83e1fbbc1c93e5d5191a21fb18374a38ab48b0fc674fb15e1bf3/hessian2-0.2.0-cp314-cp314t-win_arm64.whl", hash = "sha256:b4bd83c49e0bae732e76ad141238bb35dbd7eb012db01dba8cc876a8b2cc5800", size = 344520, upload-time = "2026-11-14T07:33:11.787Z" }, + { url = "https://files.pythonhosted.org/packages/f2/5e/c7436f1f516b16404dd85a6bc8773c56c93fca06ae1379e290c3a7bb7566/hessian2-0.2.0-cp315-cp315-macosx_10_12_x86_64.whl", hash = "sha256:13c5f4b1d0619deb053c2c6dadba485defcb4afc6943f9d71e8d1d400834d4df", size = 471452, upload-time = "2026-11-14T07:33:13.273Z" }, + { url = "https://files.pythonhosted.org/packages/a1/d7/7be4dd37626e11144eb3377a724d087d3b8c2cbc808ed011c672af0f7ff9/hessian2-0.2.0-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:4db7121ea6823e77e31c73c206d9b6aaf09f81848247476c49a8a5c2791501db", size = 444977, upload-time = "2026-11-14T07:33:14.685Z" }, + { url = "https://files.pythonhosted.org/packages/66/4d/3fab3d8c17eb4988ceea0523a17b8401f5ba43baf7e5c97b19aa5eb0062f/hessian2-0.2.0-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:95b9d04a30cbaf883eb267e0aaa9d214f58e86375bfd8b9e03591297d04a9843", size = 465188, upload-time = "2026-11-14T07:33:16.19Z" }, + { url = "https://files.pythonhosted.org/packages/69/11/f407d632c51fbe06f005753c45e839f3556ef532ab0c7bc156e50937ba80/hessian2-0.2.0-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:23371eeda6abf436aed0b4a55fe79812f46ee360c0a892c24eeb5259bff65a51", size = 474885, upload-time = "2026-11-14T07:33:17.815Z" }, + { url = "https://files.pythonhosted.org/packages/ed/29/c8afe258db555c5735ea723c7d64788cc3d3a8bfb6843fe36da229e4ef3e/hessian2-0.2.0-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:3a9ee1d598aca031e67242dc0a880c942b49da928655a7bded9a4de83b22cd34", size = 536236, upload-time = "2026-11-14T07:33:19.396Z" }, + { url = "https://files.pythonhosted.org/packages/27/ca/2ca4287484a153dd36f7f687a18e325a2d958c66117272a37030d4867c9f/hessian2-0.2.0-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:0a0218d35eb7d38436295375b995cda9b01eb68f4c000beb48b5d12c347c0960", size = 557731, upload-time = "2026-11-14T07:33:20.982Z" }, + { url = "https://files.pythonhosted.org/packages/91/95/cd16e3f7f7ead475876aa685c91d6d0a64b7063ceb397826da1b58000fff/hessian2-0.2.0-cp315-cp315-win_amd64.whl", hash = "sha256:5019f42ecac545758ce3a2ac19291165e3abf535b6cf0038fbdde259600508b5", size = 363685, upload-time = "2026-11-14T07:33:22.602Z" }, + { url = "https://files.pythonhosted.org/packages/92/35/037ebaf73c02acd70f8fab5214301b46263fe220dc17c015614229596c33/hessian2-0.2.0-cp315-cp315-win_arm64.whl", hash = "sha256:d523add9570ae44110194ddee50e32dd4718fc749e1ef680784ae7288fcb0271", size = 349622, upload-time = "2026-11-14T07:33:24.219Z" }, + { url = "https://files.pythonhosted.org/packages/7e/a4/5513fcd9c3c295aa45aafdcd8c8fc7891719420dad39068c19b295e6769b/hessian2-0.2.0-cp315-cp315t-macosx_10_12_x86_64.whl", hash = "sha256:5949c25c8178609e3d2d5e4a5d8bf6549ab4c3e0cee719115abba47b43aa5b83", size = 462903, upload-time = "2026-11-14T07:33:25.661Z" }, + { url = "https://files.pythonhosted.org/packages/1a/38/24c48f398432cbe8238f7e1975877746a6703334712445a6e51290a2b585/hessian2-0.2.0-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:100cd4376366d2a6401af714fedece6583b2959224e7593f044267cd9e4e35d1", size = 439191, upload-time = "2026-11-14T07:33:27.16Z" }, + { url = "https://files.pythonhosted.org/packages/27/2a/95ff935e40f942310b721aca4521a0b50fae63c4fe101dd7f8376b39eebc/hessian2-0.2.0-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:29cda97c7dda732ec7d9d58674fa6901edae60e290d1fc6c648525f27566bc98", size = 461730, upload-time = "2026-11-14T07:33:28.646Z" }, + { url = "https://files.pythonhosted.org/packages/89/41/3c538b329f5f67451d58999519c367741a2e3cb6b5ed1339c3f2df672f0d/hessian2-0.2.0-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:ce704fca36b3ae37fca0a90903ef0ecfdc7fb3cf2d45137f9fe113a4c87d93b1", size = 473961, upload-time = "2026-11-14T07:33:30.465Z" }, + { url = "https://files.pythonhosted.org/packages/c4/c5/b12d48c3901a58b66113d75477cbac8f1f2b34f7418f214571cb3d4e268b/hessian2-0.2.0-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:9ff49b0b16cc3e4165de96e980ab541330dd8e67ae5e7e91fd685b836924aa51", size = 532883, upload-time = "2026-11-14T07:33:31.946Z" }, + { url = "https://files.pythonhosted.org/packages/fe/53/b1f4887e6de289cbe161dd721be43d86141ce29f9c2772d394ef56d274d8/hessian2-0.2.0-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:c2187a1831dba02385fd6db92e7792ddd64c4a58021866b1b2d2e00bd3cc488b", size = 556888, upload-time = "2026-11-14T07:33:33.618Z" }, + { url = "https://files.pythonhosted.org/packages/bb/58/d95f41e1f71a1b2ab51c4da902ad61cc2736bd0150452590e9c39c60fc84/hessian2-0.2.0-cp315-cp315t-win_amd64.whl", hash = "sha256:1bae988b72e8fc434fc946f44c5691ea7d4a1bd655231c69a471d11e6fded4ea", size = 359550, upload-time = "2026-11-14T07:33:35.007Z" }, + { url = "https://files.pythonhosted.org/packages/93/8b/23b80f41e787da563659aa576604f71e8bf95f9a9c953a4f093ba58f8da9/hessian2-0.2.0-cp315-cp315t-win_arm64.whl", hash = "sha256:fcd57d9736ad89e32625dc8066f6810699c6a938b2fcab8df3a1287116a0fcf4", size = 344885, upload-time = "2026-11-14T07:33:36.801Z" }, +] + +[[package]] +name = "hpack" +version = "4.2.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/26/5b/fcabf6028144a8723726318b07a32c2f3314acdff6265743cf08a344b18e/hpack-4.2.0.tar.gz", hash = "sha256:0895cfa3b5531fc65fe439c05eb65144f123bf7a394fcaa56aa423548d8e45c0", size = 51300, upload-time = "2026-06-23T18:34:46.667Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/71/b4/4a9fcfb2aef6ba44d9073ecd301443aa00b3dac95de5619f2a7de7ec8a91/hpack-4.2.0-py3-none-any.whl", hash = "sha256:858ac0b02280fa582b5080d68db0899c62a80375e0e5413a74970c5e518b6986", size = 34246, upload-time = "2026-06-23T18:34:45.472Z" }, +] + +[[package]] +name = "httpcore" +version = "1.0.9" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "certifi" }, + { name = "h11" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/06/94/82699a10bca87a5556c9c59b5963f2d039dbd239f25bc2a63907a05a14cb/httpcore-1.0.9.tar.gz", hash = "sha256:6e34463af53fd2ab5d807f399a9b45ea31c3dfa2276f15a2c3f00afff6e176e8", size = 85484, upload-time = "2025-04-24T22:06:22.219Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7e/f5/f66802a942d491edb555dd61e3a9961140fd64c90bce1eafd741609d334d/httpcore-1.0.9-py3-none-any.whl", hash = "sha256:2d400746a40668fc9dec9810239072b40b4484b640a8c38fd654a024c7a1bf55", size = 78784, upload-time = "2025-04-24T22:06:20.566Z" }, +] + +[[package]] +name = "httpx" +version = "0.28.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "anyio" }, + { name = "certifi" }, + { name = "httpcore" }, + { name = "idna" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/b1/df/48c586a5fe32a0f01324ee087459e112ebb7224f646c0b5023f5e79e9956/httpx-0.28.1.tar.gz", hash = "sha256:75e98c5f16b0f35b567856f597f06ff2270a374470a5c2392242528e3e3e42fc", size = 141406, upload-time = "2024-12-06T15:37:23.222Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/2a/39/e50c7c3a983047577ee07d2a9e53faf5a69493943ec3f6a384bdc792deb2/httpx-0.28.1-py3-none-any.whl", hash = "sha256:d909fcccc110f8c7faf814ca82a9a4d816bc5a6dbfea25d6591d6985b8ba59ad", size = 73517, upload-time = "2024-12-06T15:37:21.509Z" }, +] + +[[package]] +name = "httpx-sse" +version = "0.4.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/0f/4c/751061ffa58615a32c31b2d82e8482be8dd4a89154f003147acee90f2be9/httpx_sse-0.4.3.tar.gz", hash = "sha256:9b1ed0127459a66014aec3c56bebd93da3c1bc8bb6618c8082039a44889a755d", size = 15943, upload-time = "2025-10-10T21:48:22.271Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d2/fd/6668e5aec43ab844de6fc74927e155a3b37bf40d7c3790e49fc0406b6578/httpx_sse-0.4.3-py3-none-any.whl", hash = "sha256:0ac1c9fe3c0afad2e0ebb25a934a59f4c7823b60792691f779fad2c5568830fc", size = 8960, upload-time = "2025-10-10T21:48:21.158Z" }, +] + +[[package]] +name = "hyperframe" +version = "6.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/02/e7/94f8232d4a74cc99514c13a9f995811485a6903d48e5d952771ef6322e30/hyperframe-6.1.0.tar.gz", hash = "sha256:f630908a00854a7adeabd6382b43923a4c4cd4b821fcb527e6ab9e15382a3b08", size = 26566, upload-time = "2025-01-22T21:41:49.302Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/48/30/47d0bf6072f7252e6521f3447ccfa40b421b6824517f82854703d0f5a98b/hyperframe-6.1.0-py3-none-any.whl", hash = "sha256:b03380493a519fce58ea5af42e4a42317bf9bd425596f7a0835ffce80f1a42e5", size = 13007, upload-time = "2025-01-22T21:41:47.295Z" }, +] + +[[package]] +name = "identify" +version = "2.6.20" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/53/35/d70c0006c7cee65999ea94a6273e60b2094f600a3d8b71b04318253fc643/identify-2.6.20.tar.gz", hash = "sha256:ad729860a923858d26917c2f4fb0a1d83d27a75b1e090c06440c573f048f3285", size = 99681, upload-time = "2026-09-26T20:29:07.187Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/fa/70/fffc9613501877c0a10a1ef73a165e6ded3e53f6e7502227fef56d973933/identify-2.6.20-py2.py3-none-any.whl", hash = "sha256:6a16b69b93187244e0548cbfd25b3e4a6f9a7a2ad784625c3bec2b8d27b81aaa", size = 99506, upload-time = "2026-09-26T20:29:06.054Z" }, +] + +[[package]] +name = "idna" +version = "3.20" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f5/08/8eea9d4b8302028f3abb2c0813953f7aec26d33b7a8960ed760e65ff29fa/idna-3.20.tar.gz", hash = "sha256:a7db850025b95ded1eae8a46181a1a6c56c92c96f0e2b005d9ff8dc0210cab44", size = 216463, upload-time = "2026-09-17T14:11:04.752Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/58/a2/bb081bab032533a855d44de1d56f8e8426114ff1ba5d1f07a438a0a654f8/idna-3.20-py3-none-any.whl", hash = "sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c", size = 69583, upload-time = "2026-09-17T14:11:03.168Z" }, +] + +[[package]] +name = "iniconfig" +version = "2.3.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/01/e1/2069291243c926a2ff1cd706c7f3eeb9b62144bf60f77c9fb9ff2fb26bd3/iniconfig-2.3.1.tar.gz", hash = "sha256:67f4b9c50da0dedf52af349e7749a80a9057a5031199791b906c3bb3ae878960", size = 21209, upload-time = "2026-10-06T22:48:38.076Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/56/43/4ca9e49d27a1fcf6bece6f6aec0ea46bb9112489b93d4b688fb415457bdb/iniconfig-2.3.1-py3-none-any.whl", hash = "sha256:9121e2c1fdb355232495be3194c8dfe87ccc2d5dee45947b78e68f499790d7a7", size = 7552, upload-time = "2026-10-06T22:48:36.959Z" }, +] + +[[package]] +name = "jinja2" +version = "3.1.6" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markupsafe" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/df/bf/f7da0350254c0ed7c72f3e33cef02e048281fec7ecec5f032d4aac52226b/jinja2-3.1.6.tar.gz", hash = "sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d", size = 245115, upload-time = "2025-03-05T20:05:02.478Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl", hash = "sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67", size = 134899, upload-time = "2025-03-05T20:05:00.369Z" }, +] + +[[package]] +name = "jsonschema" +version = "4.26.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "attrs" }, + { name = "jsonschema-specifications" }, + { name = "referencing" }, + { name = "rpds-py" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/b3/fc/e067678238fa451312d4c62bf6e6cf5ec56375422aee02f9cb5f909b3047/jsonschema-4.26.0.tar.gz", hash = "sha256:0c26707e2efad8aa1bfc5b7ce170f3fccc2e4918ff85989ba9ffa9facb2be326", size = 366583, upload-time = "2026-01-07T13:41:07.246Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/69/90/f63fb5873511e014207a475e2bb4e8b2e570d655b00ac19a9a0ca0a385ee/jsonschema-4.26.0-py3-none-any.whl", hash = "sha256:d489f15263b8d200f8387e64b4c3a75f06629559fb73deb8fdfb525f2dab50ce", size = 90630, upload-time = "2026-01-07T13:41:05.306Z" }, +] + +[[package]] +name = "jsonschema-specifications" +version = "2025.9.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "referencing" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/19/74/a633ee74eb36c44aa6d1095e7cc5569bebf04342ee146178e2d36600708b/jsonschema_specifications-2025.9.1.tar.gz", hash = "sha256:b540987f239e745613c7a9176f3edb72b832a4ac465cf02712288397832b5e8d", size = 32855, upload-time = "2025-09-08T01:34:59.186Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/41/45/1a4ed80516f02155c51f51e8cedb3c1902296743db0bbc66608a0db2814f/jsonschema_specifications-2025.9.1-py3-none-any.whl", hash = "sha256:98802fee3a11ee76ecaca44429fda8a41bff98b00a0f2838151b113f210cc6fe", size = 18437, upload-time = "2025-09-08T01:34:57.871Z" }, +] + +[[package]] +name = "kazoo" +version = "2.11.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/ac/07/2cdc0daaa2199fecaee28ee9051afedeccb46c818b2c47fc32b7383905d5/kazoo-2.11.0.tar.gz", hash = "sha256:57e7e6f69295c8f922511488eeb79680729e14bb8eb382d5cad83aa11345c36c", size = 186460, upload-time = "2026-03-21T19:08:53.702Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/91/b9/5328ff14f7d637ac90f7144d4aad27b17bdd063325c9fb4b88c4e1f109fe/kazoo-2.11.0-py2.py3-none-any.whl", hash = "sha256:aa6be17159540dae4087661b8d4e24c7b58d4dc26170a2d5b8468b06712d84a9", size = 150943, upload-time = "2026-03-21T19:08:52.575Z" }, +] + +[[package]] +name = "markupsafe" +version = "3.0.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/38/9b/e422a865e1d5d57d0e509b4e0bf1c1a70a7f6382c29a5aa428df994c8bc8/markupsafe-3.0.4.tar.gz", hash = "sha256:2e9ad7dd851bf45fab9f75cbff4cb493fee9979e8d8c7c9c3ee119022518edd6", size = 153777, upload-time = "2026-10-02T23:07:22.29Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/32/55/18dbb4778b30ada5ce071608503cc3edc9e14e13d868c17a6d178fc30f7a/markupsafe-3.0.4-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:9e25feb9e330b63edb0278a0acdf85e50d0cb0fbf49c3084abbe4e24ae195346", size = 11520, upload-time = "2026-10-02T23:04:36.299Z" }, + { url = "https://files.pythonhosted.org/packages/6c/14/0b05f79b4733e264a18d08fe08fa1df7347630ff32a6cb82180d9dccec55/markupsafe-3.0.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:7d3391b2188d18737cb2fa147028b1096236eaa7e156446c650a489fa2cadc91", size = 12063, upload-time = "2026-10-02T23:04:37.291Z" }, + { url = "https://files.pythonhosted.org/packages/ca/3a/63ba10b6c1463216b3e4df669a9f0e5a3b0c3071557d2e8229e3968c79fb/markupsafe-3.0.4-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:849dd2bb0e5e4ab2b71c7191726a4a8d5aa8a610daa584728cbee0b710ddc4ef", size = 24321, upload-time = "2026-10-02T23:04:38.262Z" }, + { url = "https://files.pythonhosted.org/packages/1a/2e/5f015261b76ad633d187ef6f388b413aedd64a8773c4df59e530a0be5525/markupsafe-3.0.4-cp311-cp311-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:befb4158af32106b9a93db8d6d1d1cbbd418c0d5aca0cabb7b1780abf0c89169", size = 28845, upload-time = "2026-10-02T23:04:39.295Z" }, + { url = "https://files.pythonhosted.org/packages/33/cf/26e594b26be40c2f1fec63ccf8a8b99d0335a5b2cbe84835c7d82a994375/markupsafe-3.0.4-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:71f88e749ea29f67f21f3b36433c1dc54c7729ed2a6d9e2da2e0d9e0d7b224eb", size = 24701, upload-time = "2026-10-02T23:04:40.348Z" }, + { url = "https://files.pythonhosted.org/packages/81/a5/a513b76c139a3915b43404324e55c0b7979ae4f0d39eb6f075b0282e90a8/markupsafe-3.0.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:6da83a088f8ef93b2d483a8232a4dbf4d69d3d8496b568a03c56becac43e1808", size = 22961, upload-time = "2026-10-02T23:04:41.372Z" }, + { url = "https://files.pythonhosted.org/packages/46/cf/4c66192c100b4542bcbe392ae06696b670f66927be3ac38a213234778ff9/markupsafe-3.0.4-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:8f0fac8b13d14bb06c68195f849371924ae53dd7b1c00fed24650f704383b692", size = 21920, upload-time = "2026-10-02T23:04:42.429Z" }, + { url = "https://files.pythonhosted.org/packages/cb/17/ac3662678bfbad649893117ada2ba44dc30bf56884e84f13154a792b10f1/markupsafe-3.0.4-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:4a7cdc2a420ca01058182da4253329764d4bfa055564d1eced90e6ba1e8b1d3d", size = 23726, upload-time = "2026-10-02T23:04:43.531Z" }, + { url = "https://files.pythonhosted.org/packages/f7/af/fe47cee339180a69ebca3c57fb3483d0f5cbd1e8337d1871fb1d9c1aebee/markupsafe-3.0.4-cp311-cp311-musllinux_1_2_armv7l.whl", hash = "sha256:83b3944fea42a8400edf92fd1770fb8d0d4f7de651353bd2d8525a92dba69a21", size = 22539, upload-time = "2026-10-02T23:04:44.618Z" }, + { url = "https://files.pythonhosted.org/packages/12/32/d55440ba140442800e02d799c9cb5ab597bf6ebdb1177b5ea39a11f797bd/markupsafe-3.0.4-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:8138eb83940ec7299024d92d4dee45f601b9e6c5ffde9d25f4e35e326203c707", size = 23963, upload-time = "2026-10-02T23:04:45.656Z" }, + { url = "https://files.pythonhosted.org/packages/50/9d/9c86042cb364c2ad4c971e6d1247929effd25f714cd7ee11b05e6316445b/markupsafe-3.0.4-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:811d02d5122171c1941357efd8f9bf4ffe907b7f0a1a4e729a880e4be3f46e3e", size = 21506, upload-time = "2026-10-02T23:04:46.671Z" }, + { url = "https://files.pythonhosted.org/packages/75/ef/5b824f03ba40c3b3652b6272d083d2fc4fcdd440de519a3a39ba2c3e7262/markupsafe-3.0.4-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:50b5bedc9ed8a94fc8857a42ef4f84a81ea88f8d4f05dc8705fb23ee6d8dcca7", size = 22955, upload-time = "2026-10-02T23:04:47.698Z" }, + { url = "https://files.pythonhosted.org/packages/1e/e8/44cfcb5ea40e5e43cec7793ef90704ed0c475280839076c4345757eb8e59/markupsafe-3.0.4-cp311-cp311-win32.whl", hash = "sha256:2e5a7cd7fdd14fcb1ae5d7d8bf23d24fbd1daefd1fbca2580132e1ea75f098b5", size = 14094, upload-time = "2026-10-02T23:04:48.788Z" }, + { url = "https://files.pythonhosted.org/packages/91/89/f2b509f7bf79352e40117824c1070dbeafd4df67031d3fa98165a3134228/markupsafe-3.0.4-cp311-cp311-win_amd64.whl", hash = "sha256:fdb4ca07ab75ffadab4a8b135ad59cdbb3156b99310f3d565370da74a15d6bd3", size = 14328, upload-time = "2026-10-02T23:04:49.801Z" }, + { url = "https://files.pythonhosted.org/packages/2b/5a/ccf22672a0f64dc682306e288f0dabcb06c7a201f3bb6e6cbf86d9e8ad03/markupsafe-3.0.4-cp311-cp311-win_arm64.whl", hash = "sha256:569d65055d367e3dcdf30c3f41119467b73d9ee9faf332bdf40402644f5ac08e", size = 14188, upload-time = "2026-10-02T23:04:50.847Z" }, + { url = "https://files.pythonhosted.org/packages/81/09/4c59d56b8461ae8eb0d8ba34bb25b7e618547044679d58a82ef9b2479fc1/markupsafe-3.0.4-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:61631e08084be9e21a8967ec3139c7616ed7c5e9368e05c86d1b39562c8a57b6", size = 11658, upload-time = "2026-10-02T23:04:51.876Z" }, + { url = "https://files.pythonhosted.org/packages/a2/f0/d6613774d86fbf6d145751d43c59875e47a6f9f17daee0aef173bd36d90e/markupsafe-3.0.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:0930db9bdc62d22944e10b066448bb65dc9abe9112880c7cab8da54db4284d5f", size = 12050, upload-time = "2026-10-02T23:04:52.931Z" }, + { url = "https://files.pythonhosted.org/packages/0d/f2/8f18e0b806eb13c1f8d07d917a720831ead54253a6dec011fbc78098a6f8/markupsafe-3.0.4-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6a45c3d514f2436064db00d7fc8778d888f0236ebfed649b53d13a59e69ad51b", size = 24363, upload-time = "2026-10-02T23:04:53.895Z" }, + { url = "https://files.pythonhosted.org/packages/60/ce/fa07dbe8a5675558fa36dea033e19995bc783de2dec5f540ccb9030b06aa/markupsafe-3.0.4-cp312-cp312-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:1e1451fab512d1bcc3dc26988ec1edb0b82c2db909132872cd9356070a6b63df", size = 28525, upload-time = "2026-10-02T23:04:54.905Z" }, + { url = "https://files.pythonhosted.org/packages/85/40/be87c01f3868ec217f8a2015089d71c22c8c5a75324822e5ed1cdd87210d/markupsafe-3.0.4-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:bd3ce56ae2cbae3ba82b683bc425cd7e48d2ed8b10f3e818186b6f5646d9271c", size = 24733, upload-time = "2026-10-02T23:04:56.229Z" }, + { url = "https://files.pythonhosted.org/packages/4f/a7/aeedb5140afa41fc74c225e9184ab96723a6e873b6ee1c9fede7283456d8/markupsafe-3.0.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8e124f974786f831d6043728e38296969d3579db8896fe004682f5758e613581", size = 22985, upload-time = "2026-10-02T23:04:57.521Z" }, + { url = "https://files.pythonhosted.org/packages/c3/fc/e91352bb08c6a59da3ef0909d457bf95a5f5908fbf151b30a06d9dbcfbb4/markupsafe-3.0.4-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:c02e8f18bdedba082cef725942ac823b9b60656db07f7e265cb31618dfd00d77", size = 22001, upload-time = "2026-10-02T23:04:58.597Z" }, + { url = "https://files.pythonhosted.org/packages/5d/f8/bffee5e7d2a3deb59748a797650a48af7e672025cf641a79344a771ad106/markupsafe-3.0.4-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:9f098115c247e11d138ab83a28fa0323c77015007ea2df73ba5fd714dfefd67c", size = 23793, upload-time = "2026-10-02T23:04:59.686Z" }, + { url = "https://files.pythonhosted.org/packages/ed/59/b853d6628ecb4d658e1d637224846d5e9bb4adf4f8df97f3be9f29dce2ec/markupsafe-3.0.4-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:d5f93ebbeb8032d47e349328ec8662d973d9b05a70b3c35df1f91fe419b84749", size = 22640, upload-time = "2026-10-02T23:05:00.768Z" }, + { url = "https://files.pythonhosted.org/packages/09/b2/1506df394f0f075797c418d0301498f49e43be194e3ffcb49e6fe6ccf022/markupsafe-3.0.4-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:64511c54db4e4987aef4c41923235927428729e8174c5dba488429be70a998ed", size = 24074, upload-time = "2026-10-02T23:05:01.813Z" }, + { url = "https://files.pythonhosted.org/packages/c7/81/5ed69cda630ac69ef60d06c09ba5a7f84ff66a2e28cf986fd5614ab3c6e6/markupsafe-3.0.4-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:e1a622f13970d81f95d0c72f9dc090dce9085fccfa4c9f2174377ee32bd15786", size = 21563, upload-time = "2026-10-02T23:05:03.239Z" }, + { url = "https://files.pythonhosted.org/packages/0c/fe/fb1e79be0fea60aa32602ebefc9c35a82bb42b4df157285ab7dfec12341a/markupsafe-3.0.4-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:c9a7f43c0b202b334cc9184af09bb8f21d3a209e038efaf106936fb69e6b026e", size = 23048, upload-time = "2026-10-02T23:05:04.479Z" }, + { url = "https://files.pythonhosted.org/packages/c8/52/7632a53360671a9b750cdbabaf9cdd89f18b42248b8e4cb42c0b0296e459/markupsafe-3.0.4-cp312-cp312-win32.whl", hash = "sha256:f0ec3b750b59375eab5b0fb2b9254810c00a3375be6d789899f1055a1d556237", size = 14108, upload-time = "2026-10-02T23:05:05.513Z" }, + { url = "https://files.pythonhosted.org/packages/3f/bf/62495e180b7000aaf30000fff849e933f74264638057176cf46852500adc/markupsafe-3.0.4-cp312-cp312-win_amd64.whl", hash = "sha256:11935df9bf455ed0c04eb87bcd720f02b1fe5e02128a9430f23aed6f93336fc7", size = 14303, upload-time = "2026-10-02T23:05:06.538Z" }, + { url = "https://files.pythonhosted.org/packages/c5/8e/4c24208776a65878d656996945aacfbfe010d3720d1a98fc0eb8491fc03b/markupsafe-3.0.4-cp312-cp312-win_arm64.whl", hash = "sha256:a4bbd2d87dd233b9fc5812160c3d0ffbe42edc22a26ce0469f58479ede633fe9", size = 14174, upload-time = "2026-10-02T23:05:07.617Z" }, + { url = "https://files.pythonhosted.org/packages/6d/18/4bc5ba32499e87bb2b0ef5b3a9bb9c00a131fa961ddf0be548cb550f548b/markupsafe-3.0.4-cp313-cp313-android_24_arm64_v8a.whl", hash = "sha256:de8b364c423ef0a4bad9069657d617f9a5d2b2062457a89b1fa16ee199c399c1", size = 12786, upload-time = "2026-10-02T23:05:08.709Z" }, + { url = "https://files.pythonhosted.org/packages/4e/6f/17f0c099bf25f3e31e63cc19244d9f6af861a9a4ab778c203997903cfdd0/markupsafe-3.0.4-cp313-cp313-android_24_x86_64.whl", hash = "sha256:34bdde374c5932765d7dc685c4a1d191a3207852d67e8e0a9eb6ea85156181f1", size = 12510, upload-time = "2026-10-02T23:05:09.93Z" }, + { url = "https://files.pythonhosted.org/packages/11/af/1a141081b905036ee904ec4bd945e1f70b4e1b32d33c4e59e8cf1d58b247/markupsafe-3.0.4-cp313-cp313-ios_13_0_arm64_iphoneos.whl", hash = "sha256:6bd9e1788e15bfcf6a9082de42e30387e7b85d211ab21e57a939bb8cfaaf8d96", size = 11583, upload-time = "2026-10-02T23:05:10.884Z" }, + { url = "https://files.pythonhosted.org/packages/e7/0a/a89385ae590232622a03e091805cff12f24fabe6c11e0e8bae096cece81c/markupsafe-3.0.4-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:5066b244f576f91afc8ee3ba029a89f99d39c79b1853fe9d39bea9f0afbec148", size = 11801, upload-time = "2026-10-02T23:05:11.913Z" }, + { url = "https://files.pythonhosted.org/packages/ed/85/ea548dc013962eb73653124bc595635fbf9e0fa41d1f181a967ccb784dfb/markupsafe-3.0.4-cp313-cp313-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:7a83aa6e4805df46fed18e989d3d16f86ef60cb50bbc8d9ce3a6be89165fbf6e", size = 11443, upload-time = "2026-10-02T23:05:12.887Z" }, + { url = "https://files.pythonhosted.org/packages/cc/72/15f2e5ec9cf2eb00d5cdfe968d94e4156a7bd7303832c3f3b2c403a36839/markupsafe-3.0.4-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:2d1b7d9308288661f56672b1b157d75fc536714d3638487bbea17b6318a78248", size = 11665, upload-time = "2026-10-02T23:05:13.829Z" }, + { url = "https://files.pythonhosted.org/packages/ca/e0/4030bea613677e333c8a2c901fd405055f657f9d06acba5b7357984b6ef7/markupsafe-3.0.4-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:73e77980c7207854f00fc4e71fb1626868d5740ab4012623d55c7a99ad122a72", size = 12061, upload-time = "2026-10-02T23:05:14.807Z" }, + { url = "https://files.pythonhosted.org/packages/f3/a5/28b76a7449eb702966b88bef599e2360b411fbb3afeee8fe560939be06ec/markupsafe-3.0.4-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:7018d4af1cd272e847aa5917983ab5e83e4f6579f9dbfecd4a79c0ca80b144c2", size = 24395, upload-time = "2026-10-02T23:05:15.909Z" }, + { url = "https://files.pythonhosted.org/packages/07/6c/21232811afc3a063b5e934b1ae2efda52f46154ec382f585149c020e61fe/markupsafe-3.0.4-cp313-cp313-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:c90d5b3d4e944e065a301d741b3c1d784f6bd1f503aa68b4967e32b2ba313d85", size = 27183, upload-time = "2026-10-02T23:05:16.976Z" }, + { url = "https://files.pythonhosted.org/packages/14/38/6ccdfa5b59049cb36fb80cbc80aee9cf1fc9bb77d1335ad435f2070b08cf/markupsafe-3.0.4-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:18a801868a884f216e784d7d14db2a4077143ce7610440aee2ce8f734e7cfcde", size = 24772, upload-time = "2026-10-02T23:05:18.209Z" }, + { url = "https://files.pythonhosted.org/packages/63/e0/cec6865dfe88cb48fedd4b20aed6af5158e41092adcbf3e028bcc6ec2108/markupsafe-3.0.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:434139499bb20b502ed3baa1f169e618f924a97e7a777fea1a49446d80106cf6", size = 23017, upload-time = "2026-10-02T23:05:19.286Z" }, + { url = "https://files.pythonhosted.org/packages/ee/76/6ed4940bb7648a9aac457c14f870cfdd5105f139a0fb1f29cd61fafa47d1/markupsafe-3.0.4-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:9e227f3dbe6bde7491cf0a9965d00b88c6b1a4a95d11480ddf88bb96d397c19f", size = 22036, upload-time = "2026-10-02T23:05:20.352Z" }, + { url = "https://files.pythonhosted.org/packages/a1/4f/ed476226d4fe46a09090a36025bf319296810028df55eb12f1253b540f3a/markupsafe-3.0.4-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:b8cd1f918b26fd7b1832ece557cc18f2d8747309ff8b3f0ef9d4250c5ad67a39", size = 23786, upload-time = "2026-10-02T23:05:21.576Z" }, + { url = "https://files.pythonhosted.org/packages/9a/35/66ff30450e35ef5fba9ebc930c9411747e537fd9447b65e44f5007e2b84d/markupsafe-3.0.4-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:a5fcffb37e602b0b3c1638a97746b9b96125caa9bcf6fa41d337a9261de231ee", size = 22672, upload-time = "2026-10-02T23:05:22.922Z" }, + { url = "https://files.pythonhosted.org/packages/32/0b/72f45ce4b4efcbca4b80cf1b06703eff0be8d37e82abb78f66c85a7ead1e/markupsafe-3.0.4-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:5989cb26b2e1efc6a42216a9f6b5ee495ce5ace2e5b352a9af489976b32d1ee2", size = 24107, upload-time = "2026-10-02T23:05:24.175Z" }, + { url = "https://files.pythonhosted.org/packages/d2/03/71776e5fdcba04614b384cc102e8a4198208579d896fd1394cb7cb9aa900/markupsafe-3.0.4-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:add96447a86d205ab616665d53b2950ee81083757f56e6ea833c8b2917646b46", size = 21615, upload-time = "2026-10-02T23:05:25.215Z" }, + { url = "https://files.pythonhosted.org/packages/ab/5f/801ce02a02e7aee0f784b1ec7843026178f6adeb9c93ac67eb1992a9a84d/markupsafe-3.0.4-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:2628d3a8cb648ecebb3c5d6b0a1052d400e4d8b7ac0fb786be8d285b50040d17", size = 23076, upload-time = "2026-10-02T23:05:26.423Z" }, + { url = "https://files.pythonhosted.org/packages/4a/85/c43776625428f3bb4a61e8633940400e3efe6409e3c6f5bff26de5e45618/markupsafe-3.0.4-cp313-cp313-win32.whl", hash = "sha256:672d207103e6b16ca098611b0f9efad6bc00afd47c03d6ef62186495ca677dc0", size = 14118, upload-time = "2026-10-02T23:05:27.716Z" }, + { url = "https://files.pythonhosted.org/packages/6f/36/163da64de88a13db79214ef75fa041be7fa13bdb42261cf5b7484de14bfb/markupsafe-3.0.4-cp313-cp313-win_amd64.whl", hash = "sha256:1f1f9477e174582b0a1b583d60b66e1f2cf5d3fe12cee985e4aedf44766600e5", size = 14313, upload-time = "2026-10-02T23:05:28.749Z" }, + { url = "https://files.pythonhosted.org/packages/9f/a8/9b662783ffaa1149221432a923cee562f78b9cbbb8baa3df9b3753e63e1e/markupsafe-3.0.4-cp313-cp313-win_arm64.whl", hash = "sha256:06de8ef6331f6e822c28d577dc8bf43fe398800477c49498f38fc38b67ff33fc", size = 14189, upload-time = "2026-10-02T23:05:29.917Z" }, + { url = "https://files.pythonhosted.org/packages/5c/c3/a944f3b0df22bd129e96915b9f4e98d2eeca6516687d7618304a966c3c74/markupsafe-3.0.4-cp314-cp314-android_24_arm64_v8a.whl", hash = "sha256:4ed644d75aa94a2baf7ec3a96eaa160ea58c742eb9d27c6506053c5c40fc84ed", size = 12787, upload-time = "2026-10-02T23:05:30.971Z" }, + { url = "https://files.pythonhosted.org/packages/d4/d6/a44863f69d88b6c7e27889108f70d47aed259edf89d5df3c5fca1eac87d6/markupsafe-3.0.4-cp314-cp314-android_24_x86_64.whl", hash = "sha256:6d2a9efe686f9de00d0d1ea32a4a5a86d558a2277501bd78d964214eab625e59", size = 12525, upload-time = "2026-10-02T23:05:32.263Z" }, + { url = "https://files.pythonhosted.org/packages/17/8f/168ba80e532dd6a93f96f8f706f1ad41d7990b6e1aeedc1cc0d211a33497/markupsafe-3.0.4-cp314-cp314-ios_13_0_arm64_iphoneos.whl", hash = "sha256:8781a792a070cf2bd1b86d3aa943894115faaba6e88122a7bf32d62072742453", size = 11589, upload-time = "2026-10-02T23:05:33.251Z" }, + { url = "https://files.pythonhosted.org/packages/32/b3/aa2c95a574d3af39403a469b295886eb9b6d448da568cbebb5a2cbfdc2e5/markupsafe-3.0.4-cp314-cp314-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:971a3bbb75d97ae4e2e8f7d4834236f86f85f0c85e04ab2e191db1123b04f80b", size = 11801, upload-time = "2026-10-02T23:05:34.315Z" }, + { url = "https://files.pythonhosted.org/packages/60/d0/34b810107d83840e768bf485de795893ebbae35b26ab061b487adfa0a692/markupsafe-3.0.4-cp314-cp314-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:8909c2f1c6dd65e054ac4b573a91c8384d1492281e55d82d159d653f7a13adf6", size = 11447, upload-time = "2026-10-02T23:05:35.302Z" }, + { url = "https://files.pythonhosted.org/packages/6c/ab/2f8488f0f817a39fca068d2b17daf446bf5cdb3eae28c3720af534d873b4/markupsafe-3.0.4-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:4cf3468d5ec187ffffcaca8e61929a37448f215dafc1386a12c750a72fe53634", size = 11722, upload-time = "2026-10-02T23:05:36.363Z" }, + { url = "https://files.pythonhosted.org/packages/ad/40/e2d117b048d47282ade906fbfd92814cbee5647afc13fda88a3406039372/markupsafe-3.0.4-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:52704c5d36eb6dda8866493decd61111fff86244c9b1ad225ca01b9e91e5970f", size = 12061, upload-time = "2026-10-02T23:05:37.397Z" }, + { url = "https://files.pythonhosted.org/packages/9a/a8/73a81135e85ba66217f5af7facb03bbb386807e1a729ab64532e4c802652/markupsafe-3.0.4-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1caa2fa5a6184fb233153b35f654e6687bd555476f6170f29d8ee9be1a8b0af9", size = 24434, upload-time = "2026-10-02T23:05:38.407Z" }, + { url = "https://files.pythonhosted.org/packages/ac/ca/fa9216dd01efee2dfdacafe7df32b4d0170fbac694b0c258a193d6e53999/markupsafe-3.0.4-cp314-cp314-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:387d8cd30e69b3f0a72877b9ae717033396404e19095b17fe89753a981fda44f", size = 27183, upload-time = "2026-10-02T23:05:39.581Z" }, + { url = "https://files.pythonhosted.org/packages/fa/4e/a469509e538d37af51103b17b073126973f2b1cbf197ff32c7ddf025cfe5/markupsafe-3.0.4-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:051417f74bcaaefa316276e0ff723f541616ca51043d070da00249d9bddd3e3c", size = 24813, upload-time = "2026-10-02T23:05:40.671Z" }, + { url = "https://files.pythonhosted.org/packages/8f/db/d7282caf7ab03af44d5d6fdbaa019b35c7d7f1c90588b839c07cba640d6a/markupsafe-3.0.4-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:a8e9f292fcda89b324f2f5c91d13f1424a153e40fc2756f38ee23b15835ff300", size = 23049, upload-time = "2026-10-02T23:05:41.864Z" }, + { url = "https://files.pythonhosted.org/packages/30/f3/b6a425206e6964efda6acee544d0eb01d1501784d0b8e2dcc74986f33b17/markupsafe-3.0.4-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:df1ae86ff54725a01fa1a0510b914ca53a161b7050be74f6204e24aded5971d0", size = 22088, upload-time = "2026-10-02T23:05:43.014Z" }, + { url = "https://files.pythonhosted.org/packages/ea/8a/84d3582fc1f0d5bd466cdf2eebf175e172158a6e70701aacec1de1b35430/markupsafe-3.0.4-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:8965520ac587c94a4ac48b729be3d8b8de00af39699b17585dfb599babe77977", size = 23846, upload-time = "2026-10-02T23:05:44.098Z" }, + { url = "https://files.pythonhosted.org/packages/1c/65/db101cce51b7ba4864ac491a9859d297dd1adf0e55b103fee9db9c47c527/markupsafe-3.0.4-cp314-cp314-musllinux_1_2_armv7l.whl", hash = "sha256:340cbb1957ba99929cbf19a75626d36ba1ae21d1730b287d1cf7f824a20c4fc7", size = 22674, upload-time = "2026-10-02T23:05:45.23Z" }, + { url = "https://files.pythonhosted.org/packages/e0/49/ddee9813d71db0c7a5c9d97c832125e6758a0c844777f1cf076569bb0e22/markupsafe-3.0.4-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:3a93d9616ddecfb393727a0041a562cf0b15a244e20f2bd25efc7949be4c4f17", size = 24104, upload-time = "2026-10-02T23:05:46.398Z" }, + { url = "https://files.pythonhosted.org/packages/aa/0e/7d8518d726726870a2399d69fd30d0fa36c5e57a2132c336b58d7c491073/markupsafe-3.0.4-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:d2e56fd3b00222722abfb3f5f0759ddbae4b90811b5ad4343c64030ad1bde70c", size = 21637, upload-time = "2026-10-02T23:05:47.48Z" }, + { url = "https://files.pythonhosted.org/packages/b4/b0/b505e8a361ba557dbf3b3aa7331ea39b00d2022a26e925ff8463b9714bb3/markupsafe-3.0.4-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:0d9c47709875fdb321452056622e930c52afbc07a7d780762fbb8b4d91ce6fa4", size = 23081, upload-time = "2026-10-02T23:05:48.611Z" }, + { url = "https://files.pythonhosted.org/packages/1c/ea/9cc3cea873f980c75cbdb6f4277ce30ee955de38be0b3d02f14c108e0698/markupsafe-3.0.4-cp314-cp314-win32.whl", hash = "sha256:38fc55594dab834470b6733dead2ee9e3f657fb0608c769dcafa0ba5ab52f45c", size = 14272, upload-time = "2026-10-02T23:05:49.707Z" }, + { url = "https://files.pythonhosted.org/packages/80/f0/5792ff768a410f93ee3f84fc19345295ffc352d2c936b424cb37e514714c/markupsafe-3.0.4-cp314-cp314-win_amd64.whl", hash = "sha256:c1bc67752d5f21013cfe430df4062441714eab79f65a6a05e01505957e9c35fe", size = 14501, upload-time = "2026-10-02T23:05:50.788Z" }, + { url = "https://files.pythonhosted.org/packages/5f/cf/3d074a8edffcc6899355232ff2543ae8d929733239596423b7db79698bc9/markupsafe-3.0.4-cp314-cp314-win_arm64.whl", hash = "sha256:7e1636da3d8dfc220b6dd10264db5f2b165e4888c4518594898fbe381049af8a", size = 14364, upload-time = "2026-10-02T23:05:51.857Z" }, + { url = "https://files.pythonhosted.org/packages/d9/31/87ce42159aae2163cf3bbbd0c44bc87780510eecab1ea3859099aed95dcb/markupsafe-3.0.4-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:805c8b84534fa10891890f0e4be39f3a99e94615d93e8836bf9fa1fdca2feeb2", size = 11759, upload-time = "2026-10-02T23:05:52.951Z" }, + { url = "https://files.pythonhosted.org/packages/5f/53/b047207eeb7752e960aca3eb1df5fb7eefa7dd4c62ac49bb156456c8a702/markupsafe-3.0.4-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:fa95848c929b6a75f6848d3c9793e59db365ee436776e57db835cdbfa79ba977", size = 12096, upload-time = "2026-10-02T23:05:54.066Z" }, + { url = "https://files.pythonhosted.org/packages/ee/51/4326c88a13c7b755657d44b4bb986f8c3d9843ecba7e22d98661d87f9a57/markupsafe-3.0.4-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:e916035e3e9930cbdfdd10abf48861340221857f45509565898e012263f7b289", size = 25699, upload-time = "2026-10-02T23:05:55.15Z" }, + { url = "https://files.pythonhosted.org/packages/f2/bb/990581b7474bfcf2cf34bed6ba5ea23bd87adb9d671213d68e88620e7a6b/markupsafe-3.0.4-cp314-cp314t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:b4d12837e0203bbace818ff4a7461afdcd78bcd782351cea148139180d7bcffe", size = 27804, upload-time = "2026-10-02T23:05:56.29Z" }, + { url = "https://files.pythonhosted.org/packages/6b/89/89491878c28e8291f5aa2fffe2c2d57230d10ae366d55dd810b840513d78/markupsafe-3.0.4-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:5086f9975abb1ab531ee6afca1761e4b59a19b446f3f6522ed776963228cfe5a", size = 25912, upload-time = "2026-10-02T23:05:57.416Z" }, + { url = "https://files.pythonhosted.org/packages/30/77/680998b54efdea06fc114565cd739b6d059f826a0279219b218dfa750d29/markupsafe-3.0.4-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b4a635a0487774f841cb1fb62e907e7195cc95bc761e053184b8acc3ceb20733", size = 23623, upload-time = "2026-10-02T23:05:58.557Z" }, + { url = "https://files.pythonhosted.org/packages/ae/75/2709f5ac5de9467b40b10e2bb8f89cc63dfb74582e09aa734b1124a217de/markupsafe-3.0.4-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:cb96e6e088d6cf71c1ea977510948320234824cf226e32f6f6e044f7a9c82b34", size = 23301, upload-time = "2026-10-02T23:05:59.94Z" }, + { url = "https://files.pythonhosted.org/packages/a0/c8/39eadc6c5b14c9c7679bfb98f4d4c6a97863b5beb91839aca4d2d6e16e55/markupsafe-3.0.4-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:8b5d563170ff8ba3181caa967c99a3c804d1dedb702c7cb93a6a7c32247da978", size = 24950, upload-time = "2026-10-02T23:06:01.289Z" }, + { url = "https://files.pythonhosted.org/packages/1a/5e/01037f8a43e8ccb0bffb4fbdc5212db05bf080fdd7286cd392332d58128a/markupsafe-3.0.4-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:396ec4e65cc889f69786b3b89478b471cee5a3bcf468b9d9bb03e1a30fb291fc", size = 23330, upload-time = "2026-10-02T23:06:02.441Z" }, + { url = "https://files.pythonhosted.org/packages/d4/f4/23e83ce0596bb0cbe670502d31df8f757bbd01a392aa486fa3b40d1ed399/markupsafe-3.0.4-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:15ba9e28640feef770374b116a6f019c21f52404aeabe516aa7f800587b98cfc", size = 25239, upload-time = "2026-10-02T23:06:03.579Z" }, + { url = "https://files.pythonhosted.org/packages/88/5b/3708897368073cc683d524750474f41a77d2986152c380dcc55b20fdf340/markupsafe-3.0.4-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:d920abdfa61279ba1a2ef9484aab07bf03331f8c08a10120fa332353d06e6932", size = 22767, upload-time = "2026-10-02T23:06:04.699Z" }, + { url = "https://files.pythonhosted.org/packages/c6/61/ebda1307864b409e6b3115757a3d4a09cca46cfb6cc65191b5de226b424b/markupsafe-3.0.4-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:a9f54054101545a9a9cccefddf54316aa6e4491611fcbef9e91b3b6bebec04f6", size = 23668, upload-time = "2026-10-02T23:06:05.9Z" }, + { url = "https://files.pythonhosted.org/packages/09/15/98075cceac3b5ba0dbb8e4762a847be967d2befc349a2cf2d0ac77f62c9d/markupsafe-3.0.4-cp314-cp314t-win32.whl", hash = "sha256:12a606a492de952afcb43b59a14aaaaad120e708d3663dd0fdf2d738d427a691", size = 14301, upload-time = "2026-10-02T23:06:07.109Z" }, + { url = "https://files.pythonhosted.org/packages/0b/a3/768b560fcc4156685cb563d922b217810cfa7bc135773367f62f1f9d2078/markupsafe-3.0.4-cp314-cp314t-win_amd64.whl", hash = "sha256:a18f38cafc329bac5e3c2b96c765b4c96d3d103421ed22ab7988c1e3fce27464", size = 14526, upload-time = "2026-10-02T23:06:08.276Z" }, + { url = "https://files.pythonhosted.org/packages/93/63/da554b4c97a6b0ea3229ca7fe8cbfb620be81613d517f482e85958550537/markupsafe-3.0.4-cp314-cp314t-win_arm64.whl", hash = "sha256:eba154571c16e032112afac0dc2dfe9e63c2ceb7aedd07bb7eecf2ce26d4dd4c", size = 14421, upload-time = "2026-10-02T23:06:09.402Z" }, + { url = "https://files.pythonhosted.org/packages/a9/30/54d11c8ca027114898cab97421fb39e4ffd9ddf47cdbc44df2ec76722da9/markupsafe-3.0.4-cp315-cp315-android_24_arm64_v8a.whl", hash = "sha256:737c9c3981998eba27f11786f84fddcbabc74068b72a4a1f454ea02094b57b65", size = 12791, upload-time = "2026-10-02T23:06:10.485Z" }, + { url = "https://files.pythonhosted.org/packages/10/6d/97c913e253a14bd3cd0e15a5c56d13203b823fa7ee32498342896a072dc4/markupsafe-3.0.4-cp315-cp315-android_24_x86_64.whl", hash = "sha256:489505b03f692c3f376394e49194fa7a7f9e8558d6e293a7056a0032b0c38163", size = 12527, upload-time = "2026-10-02T23:06:11.834Z" }, + { url = "https://files.pythonhosted.org/packages/26/f9/b86d032042a4d597d9e1997f0e5f63a3eedaf11258e0a05760b0a0a826ea/markupsafe-3.0.4-cp315-cp315-ios_13_0_arm64_iphoneos.whl", hash = "sha256:077293e425f28ec737dbcad442a71752e28f8ae27cde3d68acd1fb212091cd92", size = 11602, upload-time = "2026-10-02T23:06:13.122Z" }, + { url = "https://files.pythonhosted.org/packages/f2/dc/73c14c1eedf0ac5fa3292ba43435e6c49d2c2050f33cebde541f8f4807f1/markupsafe-3.0.4-cp315-cp315-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:9348cbb300d224fe3b89793262cb093504d4ae927004468463f745188a193e4a", size = 11817, upload-time = "2026-10-02T23:06:14.227Z" }, + { url = "https://files.pythonhosted.org/packages/8f/69/2c2fcaa5fcee22d72c7819c0d536fd181c74a688e6143845419579cd2863/markupsafe-3.0.4-cp315-cp315-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:b807e598953730f82e4eae3bd30f6a122cf6b31c398c6b504c0e04c13c170429", size = 11446, upload-time = "2026-10-02T23:06:15.574Z" }, + { url = "https://files.pythonhosted.org/packages/88/54/9e5ec76c62e6e2834d5a93623018c943e8b3bb41d663e3fd4c03303b9b85/markupsafe-3.0.4-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:799c39bdf5e2f1292fedd3009f7b3c9e760f10b2420cb9638d56920840ff6db8", size = 11719, upload-time = "2026-10-02T23:06:16.701Z" }, + { url = "https://files.pythonhosted.org/packages/96/24/3ec292b44064c16229e064d770b2625bd8ea941aa61f44905a9fa44942c0/markupsafe-3.0.4-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:ae9dcb8fbe244cb82f8a6458b455b927a03685e383d9bacf1ea5ce180b96dc97", size = 12075, upload-time = "2026-10-02T23:06:17.855Z" }, + { url = "https://files.pythonhosted.org/packages/aa/85/b64fdb1f304848518742136983c24e96d967bfb59a0ea160e92736901ab0/markupsafe-3.0.4-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:4bced6e2a6dba6a28f7dd3c6ce14df1b2dd495923f16ea484cad03decd463b2b", size = 24656, upload-time = "2026-10-02T23:06:18.963Z" }, + { url = "https://files.pythonhosted.org/packages/9c/18/23997d4c65b355da6390d61cd56e0ab3befd6ba8dda25cb40c602bd0fa6b/markupsafe-3.0.4-cp315-cp315-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:3882fb412298575bae3b9c46868251f15cc69307359f87bb1b382e53d6e5a2c9", size = 27737, upload-time = "2026-10-02T23:06:20.117Z" }, + { url = "https://files.pythonhosted.org/packages/d4/36/35998dead3c6af88c38265a56e58100211f036234ab88eb2283fd4cbce44/markupsafe-3.0.4-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:04e7902ba80ee4bac1d50a549606527a1dcf0476cd81403db41099d3b60ec653", size = 25003, upload-time = "2026-10-02T23:06:21.284Z" }, + { url = "https://files.pythonhosted.org/packages/82/96/ef49135ce260db4ca4a12b119ed468449cd248db6b1468e2112b546d7a2e/markupsafe-3.0.4-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:925f929d6b59a8b3f8b8c6ac363cd0af7eecc81efb3071770b3c6717c450a369", size = 23111, upload-time = "2026-10-02T23:06:22.524Z" }, + { url = "https://files.pythonhosted.org/packages/50/7d/83126e338bd88c17a220668235368ad719fd4638e426739858cbb8508f77/markupsafe-3.0.4-cp315-cp315-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:f68edfc67aabac33708941f26f22a7b8e9f81429bc0cf249fcf7d66b23af8d19", size = 22403, upload-time = "2026-10-02T23:06:23.785Z" }, + { url = "https://files.pythonhosted.org/packages/83/dd/daf7e420de23c8206c365204e7b85e1251d8e19d34196a56336f316e5ed2/markupsafe-3.0.4-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:e5c802729725bd07e2bc3ab7b76dc7e0bbfc53129d8f1eb1c002c24cf774717e", size = 24083, upload-time = "2026-10-02T23:06:25.037Z" }, + { url = "https://files.pythonhosted.org/packages/19/3c/11eecdc06bc44ad5570350085b572ebf049e8f9a38d1ece6d76640b739cd/markupsafe-3.0.4-cp315-cp315-musllinux_1_2_armv7l.whl", hash = "sha256:55ffd6ce583d97dc71dc92e930324c8c0d25aea7e3ade6ae54ef77cedb096811", size = 22931, upload-time = "2026-10-02T23:06:26.328Z" }, + { url = "https://files.pythonhosted.org/packages/0d/9e/ac0fd77f2a726e56ecc3ca0235d095feace1358d1b822406c2a2ef26a4dc/markupsafe-3.0.4-cp315-cp315-musllinux_1_2_ppc64le.whl", hash = "sha256:2cb3dd71fc6be918ad4264346a8ed69485f9b7ed7bf35495d8e22807cd6b8bea", size = 24299, upload-time = "2026-10-02T23:06:27.742Z" }, + { url = "https://files.pythonhosted.org/packages/d7/09/c6bd842ad58ff5b3bc76eeed7e9a42a6f11adc5d090ec697b72c9672731e/markupsafe-3.0.4-cp315-cp315-musllinux_1_2_riscv64.whl", hash = "sha256:94f5407f7bc64fa6463906b896f9904beeeb7dd8dc116ee8e9056c8714ff9916", size = 21948, upload-time = "2026-10-02T23:06:29.274Z" }, + { url = "https://files.pythonhosted.org/packages/a3/46/82f586711fed61e86faa1ee1bc317d68cd45a10c8bdbe3f7d1fdf9026ad8/markupsafe-3.0.4-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:2dad610540cb2e6272855c178f08ae9a1c7ac258a7fb71660553a5f104b42741", size = 23150, upload-time = "2026-10-02T23:06:30.583Z" }, + { url = "https://files.pythonhosted.org/packages/19/2d/2dfdce99318abbfa26925195fbc17db188c46a1ec6457be121b6f9cfeb42/markupsafe-3.0.4-cp315-cp315-win32.whl", hash = "sha256:03470d1a8268e692ecf79ecd565593e59d44219377a7ead61f1f1b94c1f7ff6b", size = 14269, upload-time = "2026-10-02T23:06:31.949Z" }, + { url = "https://files.pythonhosted.org/packages/5b/ec/6000fd82e8791e58fcd0456ec20f098957e2b03d5ed02eb73241a577c0ba/markupsafe-3.0.4-cp315-cp315-win_amd64.whl", hash = "sha256:d882a373d8093c2941e01291b7ced96e9cbe4781da9a7751ca7e6c70385e5214", size = 14496, upload-time = "2026-10-02T23:06:33.258Z" }, + { url = "https://files.pythonhosted.org/packages/bc/66/e73bd5016421d5d6e2fb6de7dd609f9de020942ac8c626526bd8c6eeaf82/markupsafe-3.0.4-cp315-cp315-win_arm64.whl", hash = "sha256:353bd63081912ab8cfa6a0c7d185934cdf8426f04c618bba6bc4b394f2069b67", size = 14361, upload-time = "2026-10-02T23:06:34.539Z" }, + { url = "https://files.pythonhosted.org/packages/90/df/cb8c3dc98d313a951df2f8968f44e4cb5643df6d3cab749a530ce2f7d972/markupsafe-3.0.4-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:c61750fadcd119d0825bcb7d7d675dd264dcc89cc05292aab5be68ebdbb374ad", size = 11760, upload-time = "2026-10-02T23:06:35.807Z" }, + { url = "https://files.pythonhosted.org/packages/d6/bb/4af9b3ca0753d654ac75f9531d5bd741bb77ca6e696f36807c475ffc099a/markupsafe-3.0.4-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:1c0df495a977d10460a94941799c72d5b5ab03d3858d949b55b5a66c8f371c99", size = 12108, upload-time = "2026-10-02T23:06:37.089Z" }, + { url = "https://files.pythonhosted.org/packages/3f/d4/b56429313aee5fd59b079c3df5615299959e25e7113eb6d8caadbdd7d38a/markupsafe-3.0.4-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:02fa4acbc6a3fc5c693c34d4dd8c1130b7fe99cc915181b0ddd6f72aeb296002", size = 25762, upload-time = "2026-10-02T23:06:38.419Z" }, + { url = "https://files.pythonhosted.org/packages/65/f5/34c181e891aa4f7d59c918584672e0c5eb7fffe76c1387d1246008bf4081/markupsafe-3.0.4-cp315-cp315t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:05295589e619b9bed252a86b532b8e27350abc372d18ba89b59375325e91ec1e", size = 28400, upload-time = "2026-10-02T23:06:39.819Z" }, + { url = "https://files.pythonhosted.org/packages/ce/b5/ad14694fd0ac9a5ce30bc6498f2999378f418583dd1679cca5a1b512957e/markupsafe-3.0.4-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:be6cb0c799abb0e2ba3e618e6d28ddddf7e485f6c2ce938dfa237daf3905072c", size = 25946, upload-time = "2026-10-02T23:06:41.381Z" }, + { url = "https://files.pythonhosted.org/packages/d6/a8/26b606445387d0ceb1eb1f21840094b84e4e3c3c3983d80d10b89823b490/markupsafe-3.0.4-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:26e9867520db70d37f7fb421a7f0d8adb40171011fb84ce869afa1a83370dfa8", size = 23634, upload-time = "2026-10-02T23:06:42.748Z" }, + { url = "https://files.pythonhosted.org/packages/39/a2/b8814de672f1f0094d498bf646f2fec9d6356b503d28ef500b71c5095377/markupsafe-3.0.4-cp315-cp315t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:f03460ff076f70ab595bb45a0205ccea1971443575b6920c52e755dec2b3fbfe", size = 23488, upload-time = "2026-10-02T23:06:44.176Z" }, + { url = "https://files.pythonhosted.org/packages/db/c7/287223376fb73335a3cc5d6eb22c6ab01358cf33945a9c39c06b9dac3f4b/markupsafe-3.0.4-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:436e3ffc6310d3c41878c601db29098102fe5d8a467c49da4a4125254e0980f2", size = 25037, upload-time = "2026-10-02T23:06:45.646Z" }, + { url = "https://files.pythonhosted.org/packages/f9/29/4df8355e313426d19e62ba33e0253c009ca12a0894ee77d67fa67255361c/markupsafe-3.0.4-cp315-cp315t-musllinux_1_2_armv7l.whl", hash = "sha256:4e2c4809c14559aa7ef426f27fb35afbb38104c349a903bf8f3600456764bb38", size = 23543, upload-time = "2026-10-02T23:06:47.264Z" }, + { url = "https://files.pythonhosted.org/packages/71/e5/8377731e8495668dcc768f645e717df18318c841edaf023a99395f6da9b4/markupsafe-3.0.4-cp315-cp315t-musllinux_1_2_ppc64le.whl", hash = "sha256:da2af0d7aebfc2074080d72efa6ab8317c62481ef1f896f65d9999c1c01f4494", size = 25282, upload-time = "2026-10-02T23:06:48.795Z" }, + { url = "https://files.pythonhosted.org/packages/ed/5f/373456e37ceb1478d657d6fe769cbe0a39f0a8dfc1548eeb19c471eefdd9/markupsafe-3.0.4-cp315-cp315t-musllinux_1_2_riscv64.whl", hash = "sha256:aa2c838cc024642cc04c6854232f32b43e5e22833dd11119c1766c7873b8370d", size = 22993, upload-time = "2026-10-02T23:06:50.31Z" }, + { url = "https://files.pythonhosted.org/packages/d7/93/2cbd5628435afb6f541bbaced4bce0c2edac4b09a142e6e928b8b0da9858/markupsafe-3.0.4-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:b91cc9d336957239ff200f30097e6fea2dc6d6fb3c81e853eaa09eac904fd894", size = 23712, upload-time = "2026-10-02T23:06:51.759Z" }, + { url = "https://files.pythonhosted.org/packages/81/99/157e10966b033b363aeda5263e82596ee232a0b1d082fdbf90aa417ff083/markupsafe-3.0.4-cp315-cp315t-win32.whl", hash = "sha256:e49fb0d1ce92cfa0cb198cc5b1b11cdf9d0638658e2a2db2687e39db7c87fc78", size = 14300, upload-time = "2026-10-02T23:06:53.241Z" }, + { url = "https://files.pythonhosted.org/packages/33/05/55884815414c9706a23deca150b72c25a62109e65b0b6ce232077802c719/markupsafe-3.0.4-cp315-cp315t-win_amd64.whl", hash = "sha256:4f6e0852a0283b1b1fd776eeb7b766a5f440b3e2bd31ab51af3b400585f3965c", size = 14522, upload-time = "2026-10-02T23:06:54.729Z" }, + { url = "https://files.pythonhosted.org/packages/92/f9/ecbde7149e95b8a0f18e16d5d747f7dc06049d5da2e4f77f6f5e4a1f46a8/markupsafe-3.0.4-cp315-cp315t-win_arm64.whl", hash = "sha256:39dbacefc411633db5b4378b066a9aca70a3d7e2922c9e578d825f844026eeba", size = 14417, upload-time = "2026-10-02T23:06:56.246Z" }, +] + +[[package]] +name = "multidict" +version = "7.2.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/7b/6b/29ef8e752f5854dcc267ded0652c475bec99b86f255957a0d4fcad657b18/multidict-7.2.1.tar.gz", hash = "sha256:e8af3e6f1bdbc31fd762b094133b478b89988eaebc63cbe82b1d9e3bbd15cede", size = 369994, upload-time = "2026-10-24T20:41:35.457Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ef/24/4347a7502ad47cb05a1b8d4e219514b4f0b1e38d4e4734c053c20328949f/multidict-7.2.1-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:fd24c4425fdb8e822601335602375c6d0cb020f7a368e1d5842eb7925a9c8748", size = 173141, upload-time = "2026-10-24T20:40:02.481Z" }, + { url = "https://files.pythonhosted.org/packages/8d/f2/2a8fcfe4c2c435101f9227b7f7ea81d786ffef993cadd2394e6926020ca9/multidict-7.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:cecb2c778f00a65c6ca01410dd194d0e797a9eebb7c6dea0db87718719f293c7", size = 97197, upload-time = "2026-10-24T20:40:06.534Z" }, + { url = "https://files.pythonhosted.org/packages/7a/57/39be4ac4fa9c20e3af7dd7e89adf7dd404b4547fb4453c5c96082e197b9c/multidict-7.2.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:0d852d3d9638f852158d7de7200dd77f7ff8d77fc8f3d396032f3d847883f631", size = 104843, upload-time = "2026-10-24T20:40:05.829Z" }, + { url = "https://files.pythonhosted.org/packages/63/da/6a5c78daa34e458ced17573b7527395c4c39ebb253220274382d361a1493/multidict-7.2.1-cp311-cp311-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:76a4f5132b8dc29eb3c768ee9b47e132a1d24fbc2e9259854c01af9beaff1d49", size = 490713, upload-time = "2026-10-24T20:40:41.715Z" }, + { url = "https://files.pythonhosted.org/packages/8a/75/b8252bc6411f7f4b9649b83e143789b7bc1dda44f656b09ce74f894ca027/multidict-7.2.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:295a15ccb8cfde9351dd6062b80af4e839460636b3c46813b4aa443905ded86a", size = 504189, upload-time = "2026-10-24T20:40:04.042Z" }, + { url = "https://files.pythonhosted.org/packages/c0/45/38e8191d0a7c7b56015dfc4c2910b731aa719c5ad3f369b2357567f03434/multidict-7.2.1-cp311-cp311-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:987f65f6c9321402bc7012f6c6d09ba501b88ddb1640f5b0b4a19f2caafe24a5", size = 465834, upload-time = "2026-10-24T20:40:08.058Z" }, + { url = "https://files.pythonhosted.org/packages/9f/55/378869573886f7efcac24d2c698938dadf973e0da40b812c8b0df847fc46/multidict-7.2.1-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:36b868758fb11cfa748c788b793994e73660abec90f83c780a678539c2c468bf", size = 522423, upload-time = "2026-10-24T20:40:07.427Z" }, + { url = "https://files.pythonhosted.org/packages/af/c5/8936fe02c11196994ac05c4876ad62336a66ef353ea2d1a2ca3adce71678/multidict-7.2.1-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:5b944091cfa7da4f7a9bd2587569cd90c94b89ec4721f8e87fe62504f2432b67", size = 544512, upload-time = "2026-10-24T20:40:43.362Z" }, + { url = "https://files.pythonhosted.org/packages/d0/38/b8403d97ae5273002fa664c3c440c5cc186082fa0ba20fcc93885d13a686/multidict-7.2.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3b7542fad2706595c1b1853b46f2c3c4ae5cc5a6252b7225f294d607a29e1bdf", size = 510054, upload-time = "2026-10-24T20:40:05.525Z" }, + { url = "https://files.pythonhosted.org/packages/18/5d/473e1436ea8577cdfb42371c0507a244d51f8d8ef08bea0f9e6e63906478/multidict-7.2.1-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:363e5db93fc3f65f3218a79fe108d217b9d264181a4e993c77552bfe275d0393", size = 452816, upload-time = "2026-10-24T20:40:09.49Z" }, + { url = "https://files.pythonhosted.org/packages/1e/b7/67376e6821fb28c21de1fb37731efd2e3a6a523bdefc4af6997bd043da7a/multidict-7.2.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:5deadf03fb4a7842696d551f9f9a06dd4445bb43ca06b5f9736e4e1885561333", size = 490712, upload-time = "2026-10-24T20:40:09.097Z" }, + { url = "https://files.pythonhosted.org/packages/1a/89/5144d8b36f133109ff36408089a475b9a3a3c1840176a39a9a8fb67a0000/multidict-7.2.1-cp311-cp311-musllinux_1_2_armv7l.whl", hash = "sha256:0ec95a02f9f08246cc7f1d85ac425e4d5c233fd3f098f5be1b2cca16aa690186", size = 462856, upload-time = "2026-10-24T20:40:44.771Z" }, + { url = "https://files.pythonhosted.org/packages/ff/7f/38310388c4c5e351dfc419a04e4c7a26cde14b0e1019bc72bbd1b0d95613/multidict-7.2.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:3d6fce7cc4ef63d9a7633cbae43e737798412805a4c3ba876cdf472dc6ff9c51", size = 490108, upload-time = "2026-10-24T20:40:06.965Z" }, + { url = "https://files.pythonhosted.org/packages/ce/0d/94162600e5bbf24bf33398f3b33ae2f78211375313dbdaaf1513b2554a66/multidict-7.2.1-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:37b161535e92776788957a165fcf38a80b33c1efde7b18cab287db4e4574df78", size = 508935, upload-time = "2026-10-24T20:40:10.882Z" }, + { url = "https://files.pythonhosted.org/packages/1d/40/a0cae932493346cb0d442ffa380e65491fdae8df338d8cdf2f39695c0947/multidict-7.2.1-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:e47d058c2db95010f5d2e1f6037acebdfb0e2fa4507650e1041437985c91db38", size = 447620, upload-time = "2026-10-24T20:40:10.548Z" }, + { url = "https://files.pythonhosted.org/packages/5e/a5/6ec5cd1c15574aca277ab08920f7e78a6a1e1c15912bfaf59b48683230f7/multidict-7.2.1-cp311-cp311-musllinux_1_2_s390x.whl", hash = "sha256:7238f7135481926d52a94c18a8cca633a9e72c1cbfccd5796548298a479b0656", size = 523896, upload-time = "2026-10-24T20:40:46.258Z" }, + { url = "https://files.pythonhosted.org/packages/ae/60/d164a2583548561f7e596f13bbd1c3492ea33a77d499d3ceaa2acf76d850/multidict-7.2.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:c10ac5e3e76837180656079008f71add8339b00c3c26314092bcd1e8e449049f", size = 502961, upload-time = "2026-10-24T20:40:08.732Z" }, + { url = "https://files.pythonhosted.org/packages/30/6b/474aee537e0c87210ce8f4fd21558b461e8a8e74c79440de036022a9eeda/multidict-7.2.1-cp311-cp311-win32.whl", hash = "sha256:2b4d0c4e13d329ffee73d46128e32dd3b4aeb2f9c6ac9c8a89eb28d3b82dcea8", size = 84159, upload-time = "2026-10-24T20:40:12.222Z" }, + { url = "https://files.pythonhosted.org/packages/1f/02/41d769148f32c9bd535fd0ddd946c4e42f38acaddf7899f3bf49d9e67703/multidict-7.2.1-cp311-cp311-win_amd64.whl", hash = "sha256:a789e3d27fc5665cc0477f10a35a89383313e4c9cf8b5e6af7ea71f039cdcc0e", size = 94895, upload-time = "2026-10-24T20:40:12.036Z" }, + { url = "https://files.pythonhosted.org/packages/23/be/e04fcf29542d0db25cdec79acbe5662481c3ba6b760353c393f9c46156f2/multidict-7.2.1-cp311-cp311-win_arm64.whl", hash = "sha256:2022bd3194968a027f64ed16f9779e62e71a823a9df3971a7328c1d45dfeb9ab", size = 92384, upload-time = "2026-10-24T20:40:47.827Z" }, + { url = "https://files.pythonhosted.org/packages/27/21/53c299f1ea289f5fd438e70d4f1f053f59b4485f5a410bcc85eecb553394/multidict-7.2.1-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:cb43bb34346155d479acdc5423afccdff79ce1fc66adfcc9de995cbec8a13acf", size = 172948, upload-time = "2026-10-24T20:40:10.189Z" }, + { url = "https://files.pythonhosted.org/packages/9d/17/faacc27a01e364abed3c6218d8a32bc42fa0688c95f82c6b11e3ffe99a07/multidict-7.2.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:dbda2baafe08f8431fd3333be02c261023fd454607e3bde5e7dc00565f7bebcb", size = 98039, upload-time = "2026-10-24T20:40:13.633Z" }, + { url = "https://files.pythonhosted.org/packages/bf/e4/bd8838244fd1309165c79e74af9a6b9e9e42fd0f2c24c75bee665fc9ba69/multidict-7.2.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:d37773029ba034a2cc970b6eeb67dad3bff9d894393c51f6bb1c6b4f563a032c", size = 103911, upload-time = "2026-10-24T20:40:13.517Z" }, + { url = "https://files.pythonhosted.org/packages/0c/39/21dbe0be29cd44de626736c6f0915c0b75f153e0155340a253f375ac5747/multidict-7.2.1-cp312-cp312-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:c85a0a54a19429a17ef449e967baffe7b5089cb4f6ef2894c9168a69fa024d05", size = 493430, upload-time = "2026-10-24T20:40:49.104Z" }, + { url = "https://files.pythonhosted.org/packages/72/13/c081a1af93258029471636ea1c741141ece10f1045578a5f73ba99b694a0/multidict-7.2.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:fa0ecd064b0ae18d235283abb5adbc4e07304dba8f2aa7c0d61f28bebcc70d4c", size = 506972, upload-time = "2026-10-24T20:40:11.68Z" }, + { url = "https://files.pythonhosted.org/packages/3d/3e/e9982c6b1e0d4bb19c4551cd56e50c1fbe90492bdf7893adf8d1ea39f373/multidict-7.2.1-cp312-cp312-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:f278f118f9fdb5faba5a6792be397fbda094d1568efa4dfe8c3595ce4ce89eea", size = 470406, upload-time = "2026-10-24T20:40:14.984Z" }, + { url = "https://files.pythonhosted.org/packages/6d/2e/ab4136028044825995b3c9de4cf8f9ef82c2076b09b5c44c65e7e3eef0a1/multidict-7.2.1-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:a3d28ac22fe658ad7486d1532b3a9084fbf65b428db31f47212c5b0b6da826f1", size = 524691, upload-time = "2026-10-24T20:40:15.205Z" }, + { url = "https://files.pythonhosted.org/packages/f7/ed/0a57de7a6b6444f301fc4cfc4b8eb0d1c36a33b8ff05717fab7700f205b1/multidict-7.2.1-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:2f3cf710144b1859f4128051cc27ea86eee83caac5648cf2ca0c1b835261cbbe", size = 549512, upload-time = "2026-10-24T20:40:50.756Z" }, + { url = "https://files.pythonhosted.org/packages/43/50/6bd8600b4843f0a9d939e0cc0f4160f4c727bd6c69e4f7e294a1caa93db8/multidict-7.2.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1fb8c1a3480c130c3a6422d5f16f3cad6552bf08c2089dd288ba7134649183b5", size = 516796, upload-time = "2026-10-24T20:40:13.481Z" }, + { url = "https://files.pythonhosted.org/packages/c2/77/31e78862081f54a06115927c1c3d81b1a57522fa0209fe1992fac25c6e75/multidict-7.2.1-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:b81ff0f2d375988152614eaea4d5023c98ecb08f77df4bb1d96762504bb86fca", size = 451174, upload-time = "2026-10-24T20:40:16.492Z" }, + { url = "https://files.pythonhosted.org/packages/e8/bf/30a0c0911e4b61accb9995165acfdc5107dd335ad3ce003007afaf168dec/multidict-7.2.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:b4821bd30b38144d8ab75df56af0b07e9d71327c9cf94c0c7a1965f865bb9615", size = 492916, upload-time = "2026-10-24T20:40:16.619Z" }, + { url = "https://files.pythonhosted.org/packages/5a/80/2192317e096489e9361f732beeee2dd213b827de71b038011dd8176e262f/multidict-7.2.1-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:0eb7fa012ab47b13e96bffc1369642f520adcc4e3d3e170d7f1a2b39fb953bce", size = 468924, upload-time = "2026-10-24T20:40:52.584Z" }, + { url = "https://files.pythonhosted.org/packages/65/fe/92a104d1d9731a97053193a3f3646a2ee286929fdb7f9c2d5077de782b33/multidict-7.2.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:f9e78d98a29e969a001e953eb09167a48bbc71249e804dae5db987ee7e6531c9", size = 492920, upload-time = "2026-10-24T20:40:15.165Z" }, + { url = "https://files.pythonhosted.org/packages/c6/6b/165323c76d383afbf60da76a4e67f4b78635b09a77c2b83d7033e72d5ee8/multidict-7.2.1-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:eb5c4a5b1281985271b6c29be53f2c1a9decf11e30a0e2733439c4d9d61b9ebb", size = 510473, upload-time = "2026-10-24T20:40:17.824Z" }, + { url = "https://files.pythonhosted.org/packages/ff/61/e25786f40ab8a862102c198ad0e39cbca704aeeac096edd9cffc85122f8c/multidict-7.2.1-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:2c4e6a97f79699f33e6dc13bddb5631781ee79a4a94c1822116d100e7d5c136c", size = 445954, upload-time = "2026-10-24T20:40:18.14Z" }, + { url = "https://files.pythonhosted.org/packages/a5/bb/deb193198dd1913e8feb54bc83dd13a0cf5425b1aaf7ac913e980537aca6/multidict-7.2.1-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:5324411117bdb67cfaeb3d1d28fb783710fcca3d88b855696af99044d7219e4b", size = 528252, upload-time = "2026-10-24T20:40:54.068Z" }, + { url = "https://files.pythonhosted.org/packages/7b/9f/ae4d6c442e11aea5ff631f36e4e8d5ff4d1f4c330d2c2721cb729fa5eed6/multidict-7.2.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:d615377a8e7bfc4f1983ede3f411c2ac2b0f7c3053f262d0437b7d8bcc4485e3", size = 508675, upload-time = "2026-10-24T20:40:17.249Z" }, + { url = "https://files.pythonhosted.org/packages/06/ca/bff250b81ada0df548da2b9c0abaf12b4fd864f40ee39e983cd9bada5799/multidict-7.2.1-cp312-cp312-win32.whl", hash = "sha256:30572b61c7932e4d3c2ad1e580de7db1f35b7a35d36db38f89397ce3f2e69096", size = 84510, upload-time = "2026-10-24T20:40:19.481Z" }, + { url = "https://files.pythonhosted.org/packages/68/d5/64108a33c21bde81454b5a400d16baa1378a7d01599de64b131c3e3e3114/multidict-7.2.1-cp312-cp312-win_amd64.whl", hash = "sha256:781ca5dfc2f1d58e47f52216a0c1c7e1ba91ce8aa235459e20de2d402af77fb3", size = 95372, upload-time = "2026-10-24T20:40:19.679Z" }, + { url = "https://files.pythonhosted.org/packages/e0/00/b746ff0f4f70589be9eca08d37a211c3257d602e0ba95224dd0ee0577801/multidict-7.2.1-cp312-cp312-win_arm64.whl", hash = "sha256:9306e0c5595f91874e685be0a9eb743d48ba069c888eea051bec3c67c08b5b8d", size = 92629, upload-time = "2026-10-24T20:40:55.897Z" }, + { url = "https://files.pythonhosted.org/packages/33/f7/453ab156d423def05ac3a4a268f52975378520bf919ded61c9a8bb432b7d/multidict-7.2.1-cp313-cp313-android_24_x86_64.whl", hash = "sha256:fba33e264cdd2ec43b762b9960d1648478eecfc1ce6e8159e7573510f0412c0a", size = 103189, upload-time = "2026-10-24T20:40:18.599Z" }, + { url = "https://files.pythonhosted.org/packages/dc/f1/db4171d67615081b007ceab10af476cf7d66a09291fe43c11f1608f08d4a/multidict-7.2.1-cp313-cp313-ios_13_0_arm64_iphoneos.whl", hash = "sha256:f2087ee23a18d1d618a135eedcafba7dfc40c6be4e8e52d7f29a1c8a2344cfcc", size = 101149, upload-time = "2026-10-24T20:40:20.693Z" }, + { url = "https://files.pythonhosted.org/packages/be/7f/adae49eae252c26f2b7a2fe89984533e0bdb0072f29023c1f2ad7588886e/multidict-7.2.1-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:f5812cfcf7daf3ace5fedf6e2ef8d4b342c92fb8ea3a87c1aed2b50453271093", size = 103294, upload-time = "2026-10-24T20:40:21.094Z" }, + { url = "https://files.pythonhosted.org/packages/48/45/9fac67be204fc5570593f4dfa2395c542bd1643ffd090c8566de0d1d7f8e/multidict-7.2.1-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:57ac987ec5d26d89bbc48c03e486f659e1367d425c465552ac2e4c4af8219def", size = 171995, upload-time = "2026-10-24T20:40:57.102Z" }, + { url = "https://files.pythonhosted.org/packages/91/5f/7912bfb95ab00ed6bd588884ca44adf29f7f56de871247a535135af5a2b4/multidict-7.2.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:714fe5f3eabd153b1b6911d0b5d31cfc2b808ae6b9e59a32fab17a4e6cdad5a6", size = 97470, upload-time = "2026-10-24T20:40:19.915Z" }, + { url = "https://files.pythonhosted.org/packages/06/18/29874e132d78ce182305e818a1553c4ddae238471ba55903a1ea38b5c4ee/multidict-7.2.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:4bebc9587cc29359e3b045518a7a09264fa882a7d165b0d143fdac8eeb7ea948", size = 103438, upload-time = "2026-10-24T20:40:21.892Z" }, + { url = "https://files.pythonhosted.org/packages/20/9c/0b181fac73aa9d0f24bc38ce24f56a9cb08c96109c3703d2f79ef15c2c2b/multidict-7.2.1-cp313-cp313-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:12bbab225ce7f69df75409ab8005b11b4e9309fae863821e019e81b32e53a2a8", size = 493852, upload-time = "2026-10-24T20:40:22.383Z" }, + { url = "https://files.pythonhosted.org/packages/4f/2e/d9ee8ccc91fcde4ad9a6e8275b1df67c0e079349fe33fd30530706dc2707/multidict-7.2.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:335f715f8c111654f29e4bf19086bdf0245579d2b4f4f59ca8dd9b3003b859c1", size = 506390, upload-time = "2026-10-24T20:40:58.494Z" }, + { url = "https://files.pythonhosted.org/packages/3c/f6/eca9192c0e598655258b2a3d14120894aecc338982670ca7ff4d4168b226/multidict-7.2.1-cp313-cp313-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:9df532dd12c59a7a4d381646fc1bf5ccb4bcdbd01c0887d07ec769fae965ea9a", size = 469470, upload-time = "2026-10-24T20:40:21.363Z" }, + { url = "https://files.pythonhosted.org/packages/cf/1b/a4cc6da2651966c725298812d965b9d70918544214a5638c670837034f24/multidict-7.2.1-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:9c9f285f788acf2448a57c9b93d31103ac69bd03f92907e2ffbb23c4e2b42eb6", size = 523167, upload-time = "2026-10-24T20:40:23.155Z" }, + { url = "https://files.pythonhosted.org/packages/20/64/f3df5b32600c6dfcc1a949f15c8de2b89e44053f5c78bea05c6240e10af8/multidict-7.2.1-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:21d86f2aa58aa428fb9909d6b8587b75eea827287e3515b8506dca86b55e2c7d", size = 547031, upload-time = "2026-10-24T20:40:23.769Z" }, + { url = "https://files.pythonhosted.org/packages/8f/85/15918b8f73aeb770c534f22b7dac256dc70b6fc7aa0571856c82b17bf3c5/multidict-7.2.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:cd69c99affd1b4debc1f9a53058ea6e3a9b34f2e733840bb45891666cd8ede0a", size = 516056, upload-time = "2026-10-24T20:40:59.951Z" }, + { url = "https://files.pythonhosted.org/packages/d6/eb/b74b3441b572218dd24068b67bf4f1f71934cfa5938f55c299425b1c41c0/multidict-7.2.1-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:fc45ff19520bc5321dcd9c6dd7df6f35ddd894eed35e5be65d1828a9c3f5e7fb", size = 449703, upload-time = "2026-10-24T20:40:22.96Z" }, + { url = "https://files.pythonhosted.org/packages/47/81/ac9bb12377260913c0384bdb60b2f9097b1ba580579a2f9697b9e21709f3/multidict-7.2.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:cba29f12cd717f1cbbe220edf005666f8df0453347217748331a0c2f7522eca4", size = 492340, upload-time = "2026-10-24T20:40:24.498Z" }, + { url = "https://files.pythonhosted.org/packages/b1/e9/bac55e20457d3e23879b65e8c46dca5ea90675eee73ca70e3fdc4984d53c/multidict-7.2.1-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:4f31ddf9c00e0e7db848b0236c717acbe8a51954d0d31b4d908c538ab3f0f5bc", size = 468205, upload-time = "2026-10-24T20:40:25.143Z" }, + { url = "https://files.pythonhosted.org/packages/ff/ce/1dc1e0f8bc28f41edee6fd0e2116f1d7b077e8fc04f50617e65f3938cbaa/multidict-7.2.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:7cb1a6bb70edcc06ea65cb9a35654f268ee39d9fc3a52240e6ba074db4d9c99e", size = 493634, upload-time = "2026-10-24T20:41:01.377Z" }, + { url = "https://files.pythonhosted.org/packages/70/e2/7a4e9f4e35d522715f8987a17d3a098582d0e879cfde621defa586330310/multidict-7.2.1-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:a2a322c8a6ca82a5a67ae6542e9c6a13ded9045cfd171dcccc5c213ac4fe0eab", size = 509128, upload-time = "2026-10-24T20:40:24.735Z" }, + { url = "https://files.pythonhosted.org/packages/60/cd/d142dc374de3585c57e2635659d45c3179cf47ded415794b2e7ead663373/multidict-7.2.1-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:678ac791b5820d9346eb13c8515fe0c9383659335e5cfc544bf6f54714ca1939", size = 444795, upload-time = "2026-10-24T20:40:25.846Z" }, + { url = "https://files.pythonhosted.org/packages/6d/41/7121157290d436282cf2405cda15d4448921231f7291679f5a3f47669bbe/multidict-7.2.1-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:0c454b677214fa604e9c4a38952c685dc88a62c96f5576a7ce550f213d1dc318", size = 526200, upload-time = "2026-10-24T20:40:26.763Z" }, + { url = "https://files.pythonhosted.org/packages/6f/fd/05e6e78a34023574db41c057676aa1c26925533fe0b60de9fb5ed5e1a101/multidict-7.2.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:3ca60708f0ca9d994f46790c5a5c774771e2f1dcb75b12c70a5582f915d0e721", size = 507752, upload-time = "2026-10-24T20:41:02.846Z" }, + { url = "https://files.pythonhosted.org/packages/41/50/3bccfa9f3003303fda37a1f7131ab90dcf36ef7fa9af6611151f4b2e316c/multidict-7.2.1-cp313-cp313-win32.whl", hash = "sha256:fa949c81e3865c10f981dea72fd8d418b59edd13a047a0aee89ae64790113d53", size = 84246, upload-time = "2026-10-24T20:40:26.077Z" }, + { url = "https://files.pythonhosted.org/packages/74/6b/3f90a565e6eb94266d197d91cca5833b34ab89768a24f7f07b29bc186e09/multidict-7.2.1-cp313-cp313-win_amd64.whl", hash = "sha256:ce0f884408938fbd72e764031d0e23a8f5e438a7bf73641089c7a6465cb84456", size = 95078, upload-time = "2026-10-24T20:40:27.34Z" }, + { url = "https://files.pythonhosted.org/packages/09/29/3acaf67a5d0f0ecce997f1f57cd14c8c634d05e1672df23b29d4f072262e/multidict-7.2.1-cp313-cp313-win_arm64.whl", hash = "sha256:554ee1d2e71fb5b4059c0c4ee35d8cbc8af2a3147036d65a454c53fea07ff4eb", size = 92390, upload-time = "2026-10-24T20:40:28.055Z" }, + { url = "https://files.pythonhosted.org/packages/de/0c/2eff3c4f36f45eddf11fb10b35069d9ebcef751b16483a585527061354ac/multidict-7.2.1-cp314-cp314-android_24_x86_64.whl", hash = "sha256:3d22ebb716ac79bf32c2a1d15250f017faef719114af4376e8dd814d6633cf0a", size = 102695, upload-time = "2026-10-24T20:41:04.31Z" }, + { url = "https://files.pythonhosted.org/packages/e2/46/4b8667914db791922e826a847f80324cb1f0acba9b05343fcb53c5a237f9/multidict-7.2.1-cp314-cp314-ios_13_0_arm64_iphoneos.whl", hash = "sha256:1d369ed297e79b417766327ece16bb7e89306c588df63c364a85d90d4aeac843", size = 101581, upload-time = "2026-10-24T20:40:27.297Z" }, + { url = "https://files.pythonhosted.org/packages/5a/40/80c50aa45b607086d43ff3d467c25450b85c7d9bb7e4bbcd521c3b030be9/multidict-7.2.1-cp314-cp314-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:a9cc121b5ee2c8b4bd4b6b526d5a26bb782f4d620463f73707691b2004b8c349", size = 103677, upload-time = "2026-10-24T20:40:28.633Z" }, + { url = "https://files.pythonhosted.org/packages/f3/e0/c822cf8d92f33f0d6fc0f733b6f5b287956133024765f31b7151b68f6198/multidict-7.2.1-cp314-cp314-macosx_10_15_universal2.whl", hash = "sha256:02009b402129a73e1f3da68f48eb999afbacd29f25aef0d5052b84ff5c2786a2", size = 172007, upload-time = "2026-10-24T20:40:29.243Z" }, + { url = "https://files.pythonhosted.org/packages/0b/d8/b36e8bbc49a59f38e6411bdf96e07c29462460d77e59527309d72469b1f8/multidict-7.2.1-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:cb7fc8820b206932ec6d8f8985aeba6edfd2932e13b6c4bf2434d6bcbbeef3e1", size = 97224, upload-time = "2026-10-24T20:41:05.627Z" }, + { url = "https://files.pythonhosted.org/packages/8e/3f/c014da364e2f9707945f921864a6b5c615e88a0ec0518c7999b3b2092405/multidict-7.2.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:cadd02ca804d6ebe799a7af19197d9730094fe2cc74b70eb4f374f4b8c1886c1", size = 103824, upload-time = "2026-10-24T20:40:28.61Z" }, + { url = "https://files.pythonhosted.org/packages/c9/73/bcd1fff09ba644499fcd864e6f86a596e51e90f5504c326354bdba3bb8a0/multidict-7.2.1-cp314-cp314-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:846b17193f1c373d6f05ada894fadf56bce2473067caea0aab51828849894b31", size = 486848, upload-time = "2026-10-24T20:40:29.976Z" }, + { url = "https://files.pythonhosted.org/packages/52/12/d6731ea19a185f76a1dc6b76f239fa3567732c8575188b47f7a715742c21/multidict-7.2.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6efdeed2723431999cf3bcbc84c72dbe0f65d16bb1f84e15a657f5b60ff18ca6", size = 500914, upload-time = "2026-10-24T20:40:30.626Z" }, + { url = "https://files.pythonhosted.org/packages/71/db/332a5b62d4c2c26950aede813a0da97e42cbc16b656ac936eb2c6e01f58f/multidict-7.2.1-cp314-cp314-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:f9c118e866164ce05498d9106a4bd01e745321403cd6f0b77a0b2587768f8c06", size = 462069, upload-time = "2026-10-24T20:41:06.892Z" }, + { url = "https://files.pythonhosted.org/packages/64/8d/c8c6826dc3e9b742bd21f3e84e1d8c46daffb584f45fd93429541e5e7f11/multidict-7.2.1-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:dc6f3dcb08c4b41e64f2d6cf272b5686d9144db585b2e138a8b1664376ab3921", size = 515356, upload-time = "2026-10-24T20:40:29.998Z" }, + { url = "https://files.pythonhosted.org/packages/92/c8/c13ffe0d352c4caaa17da0a74e9203c718606c62a1d62f98439feb1783d5/multidict-7.2.1-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:27cc258247b13008742f0e239933ad01dec5ed4e6dfc63849e30e04e1aa5bc82", size = 539793, upload-time = "2026-10-24T20:40:31.55Z" }, + { url = "https://files.pythonhosted.org/packages/3b/8f/bff861e3bd5a7cc13bd1f040d22aee8aa32b4f2755bba29b0c31a1d2ae25/multidict-7.2.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:822a7fcd33f6922b650e1b26594f09d53c5d011fe655fea7ded27b2728ce2a1b", size = 506944, upload-time = "2026-10-24T20:40:32.258Z" }, + { url = "https://files.pythonhosted.org/packages/a4/2f/f40fc4a7070798e31630ae0be583e0857fcab71a1bf80c37481ded49c553/multidict-7.2.1-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:0f30d6eaf3cb309b6c21096c6c2b4cf3800f195a78b1babae85f481ce851bdc2", size = 443550, upload-time = "2026-10-24T20:41:08.334Z" }, + { url = "https://files.pythonhosted.org/packages/ba/7e/068b48b20c1df58dddb7885f5e1befd6def91c7b6048f2644ccd81f57fa9/multidict-7.2.1-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:edffdb3950d3a8b769ddaec3a0962fb7b76b3c96f317f6b88500455a537dded2", size = 486514, upload-time = "2026-10-24T20:40:31.371Z" }, + { url = "https://files.pythonhosted.org/packages/fe/0d/a2f8b1fdd7cc2f497bb2fb0cc59dc7e2ced1fa4b0cd9b2912973e384ea77/multidict-7.2.1-cp314-cp314-musllinux_1_2_armv7l.whl", hash = "sha256:8c3ff4f5c376df7126695a52af61e6084b69c9e52dcb9f4713e71ce9819e1bfd", size = 459258, upload-time = "2026-10-24T20:40:32.999Z" }, + { url = "https://files.pythonhosted.org/packages/36/aa/74652a34732f16a951fce9ca118e659f1a9dbe102ee52d9bcea4a8001dad/multidict-7.2.1-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:d5738cd929f2af8651ebb284467acb58b1ec0f2f4d42489cd0597172bc82e15b", size = 487418, upload-time = "2026-10-24T20:40:33.649Z" }, + { url = "https://files.pythonhosted.org/packages/dd/91/ae90df6402911d310cee3f44a73914ea555d5219b1976a8f2842dc247eac/multidict-7.2.1-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:81a5f84a76401c4330e6db4e170dddd58860b30c4e8a44a181e5c2809c7f9c9d", size = 502308, upload-time = "2026-10-24T20:41:09.776Z" }, + { url = "https://files.pythonhosted.org/packages/3c/f3/5a1ab9f594e652bece00f1243bf565063790838250054ef9310999c856f7/multidict-7.2.1-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:efe695cc2081633b02fcb95bc1b13070f6647c9ad52d42a8beeb3c2a7ea062dc", size = 439169, upload-time = "2026-10-24T20:40:32.896Z" }, + { url = "https://files.pythonhosted.org/packages/38/a4/8c4fd4ecbea568de3b4605dc7323488f65a204475e1aac98db9d36fdbfd3/multidict-7.2.1-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:0c52fdd8cb8194fcb6969a417149aa1d09d6e48b69fb1b34ee1b1e4cb51ec183", size = 519617, upload-time = "2026-10-24T20:40:34.488Z" }, + { url = "https://files.pythonhosted.org/packages/1a/b5/4964b2d8f8b4ff03df7f24e8dc7d0de534fad0430e553ff0693aa2bcfb75/multidict-7.2.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:02d9c04d395a36eeebe89e45f2269614a4675b8e83fddcba15bba2be903971e5", size = 499402, upload-time = "2026-10-24T20:40:35.035Z" }, + { url = "https://files.pythonhosted.org/packages/ee/f2/c7d5c514e066fc6f9b9a2a9583f46a3d8178c49b7e91cadcc59241f22c12/multidict-7.2.1-cp314-cp314-win32.whl", hash = "sha256:b97bffa5772b7e853303de094829fcd3a9bd49fddd70534651ee4933691f6587", size = 83635, upload-time = "2026-10-24T20:41:11.337Z" }, + { url = "https://files.pythonhosted.org/packages/08/8f/2ec03cddf5f283f979813f8c5d38f5df798e21cb07a124dfc311ed28d8e9/multidict-7.2.1-cp314-cp314-win_amd64.whl", hash = "sha256:6e22756c6e2d4f57ead0d2e6be179d8a16d661bee424b81de0c6c0c1305ec39f", size = 94544, upload-time = "2026-10-24T20:40:34.202Z" }, + { url = "https://files.pythonhosted.org/packages/2e/75/3e9803944df2233cd43924c04ef057160a75c35e87f4fc083de7c855ab74/multidict-7.2.1-cp314-cp314-win_arm64.whl", hash = "sha256:b63acdf4df5a78a15223bbb510bb3e0f8234dfa807610ccb8796d0842db2c801", size = 92767, upload-time = "2026-10-24T20:40:35.787Z" }, + { url = "https://files.pythonhosted.org/packages/96/6d/e3a4b4de34cde67f98887ac0c134e2436e1eafdcef62e81f9f8b7ac8e189/multidict-7.2.1-cp314-cp314t-macosx_10_15_universal2.whl", hash = "sha256:15da10cf11fd8d8716720c95b93180e94c8317405d89d08524c579ef360128ac", size = 183485, upload-time = "2026-10-24T20:40:36.397Z" }, + { url = "https://files.pythonhosted.org/packages/e6/b7/c5aa68302159285e544c7f1b687a48d2b000217b9a90aff880052d6cb867/multidict-7.2.1-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:c753b820738cddc097892fee95e7cd716fbdfc9640414c5e9ce9463ad125321b", size = 103109, upload-time = "2026-10-24T20:41:12.496Z" }, + { url = "https://files.pythonhosted.org/packages/54/b5/7574cad64ee957cb65a32ac4f842663fbe948c1749f688a93eef0677644c/multidict-7.2.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:69befda4b1ef57027ea95dc6ed733568642f330fb3203a3e5c5ef107d41e0a1f", size = 109785, upload-time = "2026-10-24T20:40:35.496Z" }, + { url = "https://files.pythonhosted.org/packages/38/7b/ced76f7d87cce5ed15ae404213c7f9fdc594d0caaedbbacc6b8cdfac81e6/multidict-7.2.1-cp314-cp314t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:8648dd5dc4d5db32b5936dc5e85e9a4d79db1135513d40d1f54ca15503750324", size = 511246, upload-time = "2026-10-24T20:40:37.078Z" }, + { url = "https://files.pythonhosted.org/packages/51/91/b598741d494865ed002df52f37f9e92bf9ab5a0524098a3f7667c1bd6ac6/multidict-7.2.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:5efddcdbcb73f5485dca2b6624edc8ee063604b77bd3a3eb772826063965819f", size = 545199, upload-time = "2026-10-24T20:40:37.773Z" }, + { url = "https://files.pythonhosted.org/packages/e4/1d/2e3c15a07da380a7845e7d0969fde25cd6fca078a09bf30cf6deb06a3480/multidict-7.2.1-cp314-cp314t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:9c44bd978adddf39df5834c6a1efd7d075c84769a7a084168d035a2a276d9008", size = 489912, upload-time = "2026-10-24T20:41:13.782Z" }, + { url = "https://files.pythonhosted.org/packages/d6/5b/f6e2668e393430240da34a13503c190493dac8bef352ce7e26e831dc7949/multidict-7.2.1-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:cff7657e79224dea46f2f2e58eb99186656ca63ebe356212210c5c00e9beb814", size = 553445, upload-time = "2026-10-24T20:40:36.916Z" }, + { url = "https://files.pythonhosted.org/packages/05/ca/d7e0605545eebc8053167683fc6aa0d49114df2e75a2c474f2b65f8f083a/multidict-7.2.1-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:7fb3bc8d58e1b7c1d9fa1d995e30a4ce9dbe49f4c63c755a1ffdecdfbd026ccb", size = 573757, upload-time = "2026-10-24T20:40:38.554Z" }, + { url = "https://files.pythonhosted.org/packages/1b/de/9a74903ffdbe3712ba392166935c91785ccdff82dc4b6a15b28a4df52a14/multidict-7.2.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:66af55b07e4593790157e85f897f06983ded8a8692cb2fb048f3049c1d3fa172", size = 543116, upload-time = "2026-10-24T20:40:39.052Z" }, + { url = "https://files.pythonhosted.org/packages/8c/9d/8eb3ee4465610cd599b08b3320262a3448dcd03299565f4c725ee1504bbc/multidict-7.2.1-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:ed6c107642a9acaa7ede32dcd428a6c87e302c5d555ecd3ec132ffa8c6155b4b", size = 478536, upload-time = "2026-10-24T20:41:15.442Z" }, + { url = "https://files.pythonhosted.org/packages/49/fa/346308a741f2c06b23da186022fd72a75b9923f4fe7c88705605e20506d2/multidict-7.2.1-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:bc9decb36abd00ed5d123db9df70eb9a0da45d6376d86d64f4a94bfd5a1b83fe", size = 526429, upload-time = "2026-10-24T20:40:38.392Z" }, + { url = "https://files.pythonhosted.org/packages/eb/10/96986b2404bba1bdb54e364e682a2a9fc97a93c9f6598a2c35c065cbe28f/multidict-7.2.1-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:5a7df927c7999d1d3196176a8d4139d3a0e1765936f5de8c768097275b2d617a", size = 488886, upload-time = "2026-10-24T20:40:39.949Z" }, + { url = "https://files.pythonhosted.org/packages/8c/5b/59b11e1e2f93d39b34c554bfe3beb35777aa976c35af078f23eda41fa809/multidict-7.2.1-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:4eb2650aa240b62ab0c6d87238bee5d14aa4d411c0d69ad61be53e026e0785ba", size = 510875, upload-time = "2026-10-24T20:40:40.484Z" }, + { url = "https://files.pythonhosted.org/packages/83/af/79e0036cc9ecc160235f3bcbd337524cb44ebd266cfc77e7532d9bd06850/multidict-7.2.1-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:83fbd7cfaca614975efdbdcd9e2df45f3e987e819216468fb73e1db6f0365b98", size = 539190, upload-time = "2026-10-24T20:41:17.519Z" }, + { url = "https://files.pythonhosted.org/packages/a0/b5/342db062f9ae8816c1b940360c251dff21afeb88a9c4b1694c2b3348f2db/multidict-7.2.1-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:a878fef2797a7c082aa47559af68299372edebc7367bd5128dff2d36e6d820e1", size = 474879, upload-time = "2026-10-24T20:40:39.953Z" }, + { url = "https://files.pythonhosted.org/packages/8a/60/1420f7daae59b331f5506e5b32a79f60fa475e636f53bf4e6cacad5782ec/multidict-7.2.1-cp314-cp314t-musllinux_1_2_s390x.whl", hash = "sha256:f332b16911ffc668baec6aaf8f08a09e1af34a8ee87ccac26bd722589e264645", size = 549769, upload-time = "2026-10-24T20:40:41.241Z" }, + { url = "https://files.pythonhosted.org/packages/ce/af/c4b548057bee365137be7b1ed12cb6339b6911ad95d99a83d4b26e9bcb2a/multidict-7.2.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:81c6fc88ac9bf6920a0cdf22d3c383964167f12d35eb630463fc6d5ac89e460d", size = 535840, upload-time = "2026-10-24T20:40:41.927Z" }, + { url = "https://files.pythonhosted.org/packages/ba/df/70710e4bc50b29ced1ed69ec3a99124c56ac34747c6a64b05611f7b5856a/multidict-7.2.1-cp314-cp314t-win32.whl", hash = "sha256:0c7b4d8cc9e6ae7070b8129bdb840215552d4e2689ca765d37eb208a24919209", size = 90136, upload-time = "2026-10-24T20:41:18.854Z" }, + { url = "https://files.pythonhosted.org/packages/ac/cb/a330b1474608eef92e6a0a5861d61b8f2d3152d1a71b65dad8b56edea150/multidict-7.2.1-cp314-cp314t-win_amd64.whl", hash = "sha256:b5fb6b048931ea925b484f0c7c01b007981415a00a6c62ee74bbf8d229d39c08", size = 101163, upload-time = "2026-10-24T20:40:41.847Z" }, + { url = "https://files.pythonhosted.org/packages/66/fe/1563cd1336111755f79a60d06ffecd11dfbce5eb8c32ece9eae888d5fbef/multidict-7.2.1-cp314-cp314t-win_arm64.whl", hash = "sha256:e64b86d16158954825d12799271979c6944c1fd1d03575b2f22e869c3f7d00dc", size = 98630, upload-time = "2026-10-24T20:40:42.671Z" }, + { url = "https://files.pythonhosted.org/packages/03/fd/8048552a28d6ae6e1e11198b0605a4d98eee58e10527a35a9fbb3de5b6f6/multidict-7.2.1-cp315-cp315-android_24_x86_64.whl", hash = "sha256:f29885fef157a602d1816439e5da964c70ebcdbbcd4bb9d2d21b7e8bb5636604", size = 102703, upload-time = "2026-10-24T20:40:44.421Z" }, + { url = "https://files.pythonhosted.org/packages/f1/89/d16f1cb45c2c4d7dab10b199dad0c2907a7846326cbd141abb6c9dedc353/multidict-7.2.1-cp315-cp315-ios_13_0_arm64_iphoneos.whl", hash = "sha256:a92e3080d8889b0f7a80ea0c4a72181b4d4d5d3918a03136b4a459f51f5f59da", size = 101681, upload-time = "2026-10-24T20:41:20.058Z" }, + { url = "https://files.pythonhosted.org/packages/40/eb/2e14975652ca018dfed4bf14756f2aa9f71b74a0347aa52e8a4d0cac95a9/multidict-7.2.1-cp315-cp315-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:3ca4e2e9102d0788b94894a30a5e3561fd4818a0605d8748d8fe780f890aa069", size = 103843, upload-time = "2026-10-24T20:40:43.083Z" }, + { url = "https://files.pythonhosted.org/packages/46/76/9f80aa8013ac294dcbd9b51b0db0312d98f4db03dc92e56d6a404559332d/multidict-7.2.1-cp315-cp315-macosx_10_15_universal2.whl", hash = "sha256:a0f999155c22c8929cc492949c08c6fe7ec8079a5e1bfdeb34b9a3e4991959d0", size = 172121, upload-time = "2026-10-24T20:40:44.051Z" }, + { url = "https://files.pythonhosted.org/packages/82/96/ffc7c5ff41445b51dd71072b066f1189682c52fb32e46a58351f413ddf11/multidict-7.2.1-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:f15205c67d4c45250fcff5da077f0ae54102b5bc39e9ee8bab90d99e09a728c5", size = 97233, upload-time = "2026-10-24T20:40:46.192Z" }, + { url = "https://files.pythonhosted.org/packages/65/19/da52a85bde6db671d652b1d11113c507aa4021f2c8d431a5074108aa4d5e/multidict-7.2.1-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:f07f06db2e333b68dd52560b8b0b12b6f8bf6053cedebf9af4aecfecd2dc1b32", size = 103929, upload-time = "2026-10-24T20:41:21.262Z" }, + { url = "https://files.pythonhosted.org/packages/84/77/4c98e263f94cd5b27f89cdf3b5989bed698fe3a34a6812777620a8a4c518/multidict-7.2.1-cp315-cp315-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:d094951489bb7836342c005e790bd005e60b669aaf5c936b96dd5d68cbd2e23b", size = 490370, upload-time = "2026-10-24T20:40:44.571Z" }, + { url = "https://files.pythonhosted.org/packages/4f/e2/36a02b000bc0605061eebe4fbfe3ee9c39ebe644bbd053e1635d5a0f9286/multidict-7.2.1-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:d0381074dc21225951278d7e4a7a2241f7fb86a4d8b94154dfee1411f49cf851", size = 502507, upload-time = "2026-10-24T20:40:45.371Z" }, + { url = "https://files.pythonhosted.org/packages/42/ea/1fbceb93d48c65a731bc2264c34d9374d3c811657b3616c480a3ff32b152/multidict-7.2.1-cp315-cp315-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:2e279ad5a6e9347bc9e043fdbee180a0480c8fd52618c3258e983dd93d98ed49", size = 463742, upload-time = "2026-10-24T20:40:47.479Z" }, + { url = "https://files.pythonhosted.org/packages/a8/2c/e8e8e98bd831b74a4a011d007c6990cbebc834557825948a4c192855dd4d/multidict-7.2.1-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:e0f2b33a6ae233f4da38c77ea32f90aab2cb82ba819d7b6c4f1b68cd33d871b6", size = 515827, upload-time = "2026-10-24T20:41:22.557Z" }, + { url = "https://files.pythonhosted.org/packages/af/54/a777698e55878f569d3a9daa3658b6a5248608f99ca67fab94b5b94ceb95/multidict-7.2.1-cp315-cp315-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:57b5d0df4c60ab8b1159687610a1c3ae069ad2380d390a79dedff5c82318e714", size = 539980, upload-time = "2026-10-24T20:40:46.122Z" }, + { url = "https://files.pythonhosted.org/packages/63/a8/a00489f6ca40003a95c97e30b556eb136f510664fb9f605d8c1c9e38dd39/multidict-7.2.1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2592fb6c335d67f1912bf72788c02fd5dab305fc3c8c7eab078a5bec1aaa0f88", size = 508202, upload-time = "2026-10-24T20:40:47.003Z" }, + { url = "https://files.pythonhosted.org/packages/90/7a/67c29db7d0daec8548ba8412d98c1f45f6416171eaa208c5682764e2a227/multidict-7.2.1-cp315-cp315-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:d4af0d863e72f3ea48e85d3aa1d1b426fd81e9544fd7976fc6d6753584a25b03", size = 448626, upload-time = "2026-10-24T20:40:49.019Z" }, + { url = "https://files.pythonhosted.org/packages/ff/7b/986c45a79400c784c7eb2a2e848f77bdb5b97f32cb8a03fb4cda67b5ea28/multidict-7.2.1-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:8148c2aaaf4b85d7872f024c8bb0c9b9797cc76b10588e3594a69cb01057472a", size = 487794, upload-time = "2026-10-24T20:41:24.08Z" }, + { url = "https://files.pythonhosted.org/packages/c6/a1/d1707dbd709fbd774eac819aa15bf825ae6abf4c4ffaee9eb77e429ba11b/multidict-7.2.1-cp315-cp315-musllinux_1_2_armv7l.whl", hash = "sha256:7726c53b1d59eb57b009a9e8759d4f71049ebdacf30642a198a197f80cea451c", size = 459403, upload-time = "2026-10-24T20:40:47.645Z" }, + { url = "https://files.pythonhosted.org/packages/f6/c8/56e3b24559ab63efc76c261e5aa6813616b2094886e9bb9de688cd1a386a/multidict-7.2.1-cp315-cp315-musllinux_1_2_i686.whl", hash = "sha256:f62172cf387e92f4928b60e5936b02c06e3c8449ed7fb440978d6c9bcbfc85df", size = 489508, upload-time = "2026-10-24T20:40:48.541Z" }, + { url = "https://files.pythonhosted.org/packages/01/05/b1cbbdc23a7bcff56fb97d97e675892e9dd0bd941d8c6023c411ae6a1c26/multidict-7.2.1-cp315-cp315-musllinux_1_2_ppc64le.whl", hash = "sha256:03846be88267369908fcd9a91159358a3b142d740991c96e4f696d362fce516c", size = 502575, upload-time = "2026-10-24T20:40:50.968Z" }, + { url = "https://files.pythonhosted.org/packages/fe/f2/946fc151a8e9e17a71f4bd69d5893576addadc8e2528999dd3c1a742b48f/multidict-7.2.1-cp315-cp315-musllinux_1_2_riscv64.whl", hash = "sha256:785ef2f3e372dabc131f228a275f97eca92ad17cfab1ab138790e330d99abe3e", size = 444323, upload-time = "2026-10-24T20:41:25.534Z" }, + { url = "https://files.pythonhosted.org/packages/75/98/548bccbea2dcfe90acc130fa46124527b1460d60ba188d9b368309105a9f/multidict-7.2.1-cp315-cp315-musllinux_1_2_s390x.whl", hash = "sha256:2bac371da2c3554a99ba126f545e79ab8e8d9426a3e41df81d00ad725c1e2cbf", size = 520113, upload-time = "2026-10-24T20:40:49.455Z" }, + { url = "https://files.pythonhosted.org/packages/4a/98/25a588db57a7b4b786150aad4cb1f2aaad7aca13d20df60643461b58944e/multidict-7.2.1-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:2d4cfbbb1023f0f6795b5395c400752fb23a5a09ba756aa9003886bbc47b3e12", size = 500566, upload-time = "2026-10-24T20:40:49.974Z" }, + { url = "https://files.pythonhosted.org/packages/df/49/e319d4dcd4da99f356ca963b41f9c3c48a71d76afe606d8e8f0c90827317/multidict-7.2.1-cp315-cp315-win32.whl", hash = "sha256:584ebfa26c9dcf3e465637a5a9afa2647bebb3022b50b1ff384834ba8e0380d1", size = 83644, upload-time = "2026-10-24T20:40:52.389Z" }, + { url = "https://files.pythonhosted.org/packages/fd/3e/06a59c05402c2ff04eac97ef00783510b82b71128c67455a20b1b0eeecb4/multidict-7.2.1-cp315-cp315-win_amd64.whl", hash = "sha256:873d35366cc115be02a1c858f9b22a1a9f6182b99aab2171ee5276af02a153e3", size = 94542, upload-time = "2026-10-24T20:41:27.144Z" }, + { url = "https://files.pythonhosted.org/packages/d2/99/90e4c68ea5ca6ae89c682e3fa463d3fa7ebda5f6e2209a1b1f7b8ab1aa91/multidict-7.2.1-cp315-cp315-win_arm64.whl", hash = "sha256:f2cc27ec6a53b1d39bab44d2b9dd21cc31e796d01b5e18a76d569721282bb264", size = 92767, upload-time = "2026-10-24T20:40:50.934Z" }, + { url = "https://files.pythonhosted.org/packages/2a/39/66a05f6ce31217ee9ed9417c19433c7498e9468a15fae4cafd920284ef21/multidict-7.2.1-cp315-cp315t-macosx_10_15_universal2.whl", hash = "sha256:522f7d2351743804cdf5c5a304bc45f9d55e935dd87706fae2dbeafe0fed0b49", size = 183697, upload-time = "2026-10-24T20:40:51.79Z" }, + { url = "https://files.pythonhosted.org/packages/f9/88/185b62ccface5a6295934b24bae589f7817f79f54cd41b19267574bc1349/multidict-7.2.1-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:a3d9a59bcdf8531d46b56bcd512017533510c25e955c2c546efd0743bd840940", size = 103097, upload-time = "2026-10-24T20:40:53.594Z" }, + { url = "https://files.pythonhosted.org/packages/23/d6/bae59cc28b4bec2019e5a2fb0262a077982f68200dde08180f079a918a62/multidict-7.2.1-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:6966806cf917cbbeb9a8b5c581db52e19c9af0ef5fe009db54c1f5799a6e003f", size = 110045, upload-time = "2026-10-24T20:41:28.396Z" }, + { url = "https://files.pythonhosted.org/packages/36/a7/bee9b9f0ff28b751fd79d1c7630d6f88a9dead6218ef2f0e566f5d54ab0e/multidict-7.2.1-cp315-cp315t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:74d3e015c28b43b6c1a108eec324ea2efb185c359c459216cabd4cb98f7f02f6", size = 513704, upload-time = "2026-10-24T20:40:52.409Z" }, + { url = "https://files.pythonhosted.org/packages/4e/80/0c2781349f44d137fa138820bb871598116758e9e27042aad2d75835dc5c/multidict-7.2.1-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:2529873a3bf68c372532a9f8058bcf4199e78387e92cd6a01b73334bfe6a7e3f", size = 547454, upload-time = "2026-10-24T20:40:53.161Z" }, + { url = "https://files.pythonhosted.org/packages/16/60/8b97c48c728c980ab5d10abe12400d3a8633910a9cf99307f31100fe1366/multidict-7.2.1-cp315-cp315t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:223427392fdf993e198644ec40c404fd93f1cd2a61328d18842ecbf154d02c82", size = 490355, upload-time = "2026-10-24T20:40:55.976Z" }, + { url = "https://files.pythonhosted.org/packages/3d/e5/966b412dd21c58d13f378e60e15e08d13dae669b3a22ed31b1f582b0ec9d/multidict-7.2.1-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:90efd90a0f9b7ae3844a4fb3ae614321832d364ae19567b7cd312315fac4ec39", size = 553571, upload-time = "2026-10-24T20:41:29.67Z" }, + { url = "https://files.pythonhosted.org/packages/13/18/e0f099bdf895d1cc1dee64aecd4e761d4d537c4513875e765a6e5dda71b1/multidict-7.2.1-cp315-cp315t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:d10e49b940e70e2a4e91f44098007dda0bacb78c3f8e31ba7a37ee2ce52269e6", size = 572533, upload-time = "2026-10-24T20:40:54.421Z" }, + { url = "https://files.pythonhosted.org/packages/25/e7/150bfda9b5a12defbcd0c48385fcceb3efb8257bd9872c8c11cf79643eb0/multidict-7.2.1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ba5e8d9310a794b853fb0e327d46a827b5b015576341219a591f88ed9d799c27", size = 544014, upload-time = "2026-10-24T20:40:54.676Z" }, + { url = "https://files.pythonhosted.org/packages/31/98/083d4980f3c3eb15663a91ddba983f1317d96e373ae86ac90e93c34140b2/multidict-7.2.1-cp315-cp315t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:a7d120bdde5b213e67ed7dc80ea3adf4f014453fbc20195d619ba2ceb34084f3", size = 485204, upload-time = "2026-10-24T20:40:58.116Z" }, + { url = "https://files.pythonhosted.org/packages/06/2f/6990b941b9315f24575afa4ec4dada55c27fa3558ddc5962ca94322e93f4/multidict-7.2.1-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:27166b6ec73eac37696d66b2c6efbd44b6d04b597d655070959df54dc7c71c0b", size = 528125, upload-time = "2026-10-24T20:41:31.176Z" }, + { url = "https://files.pythonhosted.org/packages/d6/69/4efe79c2aa7f8cb42a826dfbffbec129358d81828f63158108eaf2e54603/multidict-7.2.1-cp315-cp315t-musllinux_1_2_armv7l.whl", hash = "sha256:13268013a3db11a214ccb6920f778d175b765f69a40509610b92e43602272718", size = 494332, upload-time = "2026-10-24T20:40:55.762Z" }, + { url = "https://files.pythonhosted.org/packages/d5/86/3704dd04ab0098e509a3dbed132269aca7897dd1d352638a333df5ebfc7c/multidict-7.2.1-cp315-cp315t-musllinux_1_2_i686.whl", hash = "sha256:65e4448dadc7c94a8643bb41361e45f3a73d46e36a008a9bc03e9b525f4d7c80", size = 511543, upload-time = "2026-10-24T20:40:56.457Z" }, + { url = "https://files.pythonhosted.org/packages/90/bb/2efa33d97e8b18533cb89b356a5782b61c28f66e21fb662c9853f71f96f4/multidict-7.2.1-cp315-cp315t-musllinux_1_2_ppc64le.whl", hash = "sha256:68b97b721d95b77d75e718d1b62a227fa4b3e647bd2a9fb39552d1a79ffb67c0", size = 538955, upload-time = "2026-10-24T20:40:59.701Z" }, + { url = "https://files.pythonhosted.org/packages/4f/aa/12510e431bbc652891297aeae4a5b19dc9532b477bbe1eb5642c933825e5/multidict-7.2.1-cp315-cp315t-musllinux_1_2_riscv64.whl", hash = "sha256:ec4ee5d2d624088775e61cada87bbe7629bfd936bfbd57f122a106970d8ab1ee", size = 481562, upload-time = "2026-10-24T20:41:32.578Z" }, + { url = "https://files.pythonhosted.org/packages/77/b0/3a9e0cc640a9f6031618f6b6415ba603040f68bce00ed36d659a2a8b6aba/multidict-7.2.1-cp315-cp315t-musllinux_1_2_s390x.whl", hash = "sha256:4b338b45dc26ca4bac702e1278754f78613d4d0081e14e94e44fe8e261bf1750", size = 548933, upload-time = "2026-10-24T20:40:57.407Z" }, + { url = "https://files.pythonhosted.org/packages/1d/c3/f4074a8e6c249cde81b5f29667161bdd4250f26174ac4bfbd45676f06b3a/multidict-7.2.1-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:9a53776adc1ba923c9e345fdea7b61553c44c17a9af5eba8d8def8c5dcac4dec", size = 537060, upload-time = "2026-10-24T20:40:57.916Z" }, + { url = "https://files.pythonhosted.org/packages/44/88/07382e85348d485db3f901ae7c0f3d33dd3562f6fe56d398631af0dad4c5/multidict-7.2.1-cp315-cp315t-win32.whl", hash = "sha256:fcfebcb537f419e415b6e2bfc77ddbd33abe3c036f0105410a25a14741df9c31", size = 90152, upload-time = "2026-10-24T20:41:01.076Z" }, + { url = "https://files.pythonhosted.org/packages/00/2f/45eb8700ee15716cc22f5b42592b4d5bc1ca65c880179c2c10e42fd6f0b4/multidict-7.2.1-cp315-cp315t-win_amd64.whl", hash = "sha256:25ebc4208d9098f77caeb16df895a0e56eb6c3b22870ac4e3ec43e0a9d6a33b6", size = 101193, upload-time = "2026-10-24T20:41:34.124Z" }, + { url = "https://files.pythonhosted.org/packages/7b/80/37d26f26d20b937344cfd68d9a1f57d8bc4f64adae416fc6828a7f8c8a10/multidict-7.2.1-cp315-cp315t-win_arm64.whl", hash = "sha256:4d61be3725016ef5db3543c95f1f062d7d150ba776582d959a982af88e75fa55", size = 98863, upload-time = "2026-10-24T20:40:59.146Z" }, + { url = "https://files.pythonhosted.org/packages/9d/96/1aaad0e5df33f1f5af21775c411349c0234a6edd581ea403bc81919a6eab/multidict-7.2.1-py3-none-any.whl", hash = "sha256:08ea94663d9e7c25d14d78222f7aee906c472d4837766bec62477c38f6e419dc", size = 28145, upload-time = "2026-10-24T20:40:59.159Z" }, +] + +[[package]] +name = "nacos-sdk-python" +version = "3.2.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "a2a-sdk" }, + { name = "aiofiles" }, + { name = "aiohttp" }, + { name = "alibabacloud-kms20160120" }, + { name = "alibabacloud-tea-openapi" }, + { name = "grpcio" }, + { name = "protobuf" }, + { name = "psutil" }, + { name = "pycryptodome" }, + { name = "pydantic" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/47/91/37bcae40b8f0be50d16223ca3a58028f93c078085aabcc48c79d003f8ae0/nacos_sdk_python-3.2.0.tar.gz", hash = "sha256:646fb1c243caf540f381f1e08d489160fc2a314df00c919db306512ea6265f56", size = 94558, upload-time = "2026-04-27T09:04:11.485Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/5f/cf/6c578843dd82e70ec3d48c57410ed36f00d32cfa8ee114dc8d3bce92055f/nacos_sdk_python-3.2.0-py3-none-any.whl", hash = "sha256:241ef203115eaabc97622dbbf773c3aa824b5886bc9f77033268a6d75b63d2a6", size = 120949, upload-time = "2026-04-27T09:04:09.914Z" }, +] + +[[package]] +name = "narwhals" +version = "2.29.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/c4/20/e2cce41bfa17909205b39c8a4aa3ec730d87f1c4e77453efd3f5aaf50b81/narwhals-2.29.0.tar.gz", hash = "sha256:eb19c877d9a705300bcc9414499a07b32a52db703369414e57e474ca5fc63c42", size = 773295, upload-time = "2026-11-17T15:30:43.03Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/9e/2b/20b4b463c3795dc390db8fa6ec2b5c3e0aea90a760f813305da4c33dd814/narwhals-2.29.0-py3-none-any.whl", hash = "sha256:1c69b3dc30240f6e848c5a673cafc86affa44184ecce721e25b7194663ad10dc", size = 501718, upload-time = "2026-11-17T15:30:41.263Z" }, +] + +[[package]] +name = "ngh2" +version = "0.5.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/70/ba/92404689daeb54bde05bf4751656366f40f7fe3cc269b49e5b301ea142f9/ngh2-0.5.0.tar.gz", hash = "sha256:0a51dff5ad77802fb5cc39123196efccd5c03457cecf1fcf0e15148a0720026f", size = 1361920, upload-time = "2026-11-02T08:33:40.571Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/69/2f/c08ed3eccab97f4ea3662bf0b2f2c4ef10c2cd2c8adcd964e183e99ffde8/ngh2-0.5.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:02396620b1c9589eeb684949f40322ef71acdb6af53a2c53475b43c532db77c4", size = 281889, upload-time = "2026-11-02T08:32:24.787Z" }, + { url = "https://files.pythonhosted.org/packages/87/92/9338a4f4c3a4daa63182e9cadf888391863bab5c64321e569d8edbbb1aa9/ngh2-0.5.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:3e8709e3644dc8b30e7c4d1d0c02e698efc142fe5da3b1c14fcee938552dc2ab", size = 268724, upload-time = "2026-11-02T08:32:26.017Z" }, + { url = "https://files.pythonhosted.org/packages/e0/9f/41de01e038796c71c7099b07fdaee558ac45a8848eb78f39ffd3d30c4995/ngh2-0.5.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ec8c7cad8115d4d13eff91bdd7b7a2fbb48f8e99e35687df9291fdf36741b202", size = 315553, upload-time = "2026-11-02T08:32:27.27Z" }, + { url = "https://files.pythonhosted.org/packages/8b/9a/03b86aa0bdf24773b9f48931d1c802537df9e9d593e486ee1aea3e3f57fa/ngh2-0.5.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8609568c0a04e184c1b86326f6394d2ab5ad47440c9be946c3f8135d32f20b99", size = 333617, upload-time = "2026-11-02T08:32:28.582Z" }, + { url = "https://files.pythonhosted.org/packages/22/0d/d8b333ada5ea91de515e04727be4e999c2dcedce870a97cecfb5b4e36fe1/ngh2-0.5.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:765217eca3ba11dcaa798bf89b44b389a6afadebef5c28ba03a4baf62d0a6a6a", size = 321037, upload-time = "2026-11-02T08:32:29.954Z" }, + { url = "https://files.pythonhosted.org/packages/8f/6d/c0ccc6a272b5104094b48f7ac589637531bbeffb8295ad4e13aaa68900fa/ngh2-0.5.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:3eb5d24cf8beb744a3f4e011e4d06bd68f91ebf82778c248179ceceaf9c75b5c", size = 336464, upload-time = "2026-11-02T08:32:31.262Z" }, + { url = "https://files.pythonhosted.org/packages/68/67/506f9b2f0131a989aca42b008e8800d99e4042ea6c111c0194d14209ad0d/ngh2-0.5.0-cp311-cp311-win_amd64.whl", hash = "sha256:8708b40977b774d70e3b8d04620192aabc178f9f1d95dbd634ecacdf8e879bf7", size = 260591, upload-time = "2026-11-02T08:32:32.989Z" }, + { url = "https://files.pythonhosted.org/packages/1f/50/70b8e4a3774ac283c1172cdb5f7c6eb4527182658e80b6b96a89f34f160b/ngh2-0.5.0-cp311-cp311-win_arm64.whl", hash = "sha256:5c7d3a6a1347008390bacb0552d6c53078f2b2c3576c7c51a6a34b28eca36870", size = 238129, upload-time = "2026-11-02T08:32:34.334Z" }, + { url = "https://files.pythonhosted.org/packages/f1/eb/74e40d19a95b1d4048a3939ae4bebc337e3c685ee8f02e3b8c7f777dbeb8/ngh2-0.5.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:be3e85b7db540f434174d8fbce229662556b8faefd625adfa9d594b2b9c6ac5d", size = 279779, upload-time = "2026-11-02T08:32:35.62Z" }, + { url = "https://files.pythonhosted.org/packages/48/7f/138d311247a2cb5fa7d74d835dc95e85c6f64d404b126ad7e018ba86d567/ngh2-0.5.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:431fa950f261b9132e54a874b23791a728eb54cdd732dd5749cd61cf1674835a", size = 265653, upload-time = "2026-11-02T08:32:36.955Z" }, + { url = "https://files.pythonhosted.org/packages/07/e8/6534ee6458623d963c46245c476955bdaa3b8526d623b8ae1cfd191a07ee/ngh2-0.5.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:5d249ae6ab0abedd496d398a4d7625f29086fba062329849736df4a80c0aad67", size = 298895, upload-time = "2026-11-02T08:32:38.342Z" }, + { url = "https://files.pythonhosted.org/packages/ec/43/09cab05a9a15fe98aed996bc474b7c9b8b76a9cbde8058f3f30122ead2d6/ngh2-0.5.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:323cb61612b00a16811043b541f953c6eb1ba8ddc4a61ee76a1e2fca9e3b70c9", size = 319737, upload-time = "2026-11-02T08:32:39.635Z" }, + { url = "https://files.pythonhosted.org/packages/86/e4/68d25386a6a1d6bea208573ce145291544c91670fffc747ba3c5984075d3/ngh2-0.5.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:fd036b52dcb681e86a470ba8cfa689773186bf3ed6b8d63cfb9bf258db4b97b8", size = 303720, upload-time = "2026-11-02T08:32:41.063Z" }, + { url = "https://files.pythonhosted.org/packages/75/77/eab39bbb5174317a8a7925aafceb13ae7ad28b5ee9b9b3df4488abb15b12/ngh2-0.5.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:12183a11dd080f3c073992e1c848efb92bdd6d340a13dc2dde13076327f1f03a", size = 322398, upload-time = "2026-11-02T08:32:42.369Z" }, + { url = "https://files.pythonhosted.org/packages/c0/19/5773a8488eb777653c09c833a350f25b52eaecaada490511c70459b25266/ngh2-0.5.0-cp312-cp312-win_amd64.whl", hash = "sha256:29406d113bf60b8d256cbe463d562f4e7fa8aba14b1bd56327530d9c0da3d6a0", size = 253300, upload-time = "2026-11-02T08:32:43.597Z" }, + { url = "https://files.pythonhosted.org/packages/7b/30/1dfffcfa4181c232e9fbc8fe7427883bf89718866336681178e6ec1e9ca7/ngh2-0.5.0-cp312-cp312-win_arm64.whl", hash = "sha256:3185765baa6ab79842df5286a3fdf669fb04655116a039c58171d75146788983", size = 230766, upload-time = "2026-11-02T08:32:44.834Z" }, + { url = "https://files.pythonhosted.org/packages/f6/81/5170b2240eb04d9b906a6dc0036e7df828d2ece0b87686cb6ed9471b7a5a/ngh2-0.5.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:9cc989e5882bf555886182563949a9c0bfb42c3e0f22a18bfa19a25510827571", size = 282546, upload-time = "2026-11-02T08:32:46.064Z" }, + { url = "https://files.pythonhosted.org/packages/86/65/036390f390b13fa61ee3c6fa2d6a13a29bbbb34f65aac0046980c1bc09ea/ngh2-0.5.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:fbcc7513c6c61639d4a08e5c66445604fc836ab39c0c5a452154d08db6298496", size = 267771, upload-time = "2026-11-02T08:32:47.301Z" }, + { url = "https://files.pythonhosted.org/packages/b1/62/bd3616e0068a19481720205426ccece6db7f241e1562af7bf69e431fd220/ngh2-0.5.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:a104bf349b0737a288e72031ec82ef013454337a1f50d5d4d63d4235996655bf", size = 299654, upload-time = "2026-11-02T08:32:48.726Z" }, + { url = "https://files.pythonhosted.org/packages/de/a5/dce08b1fc7d8a8a0b0e995dcc7ee4ae644768eb2e74eb7eccff61d3640b3/ngh2-0.5.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5ef03643c44c9f7dcbc6837146a380a23d83b58951539b935f4b7e7a4cc34717", size = 320265, upload-time = "2026-11-02T08:32:50.279Z" }, + { url = "https://files.pythonhosted.org/packages/1d/97/99be9e10c8e76785eee17bcf79bbbc3b961f4513eb8e2d134fc8a6ac2472/ngh2-0.5.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:0ccffd470a6d82ab968725f4fb9724c184092d4d0f9f1ad31898b226ec51deb5", size = 305262, upload-time = "2026-11-02T08:32:51.605Z" }, + { url = "https://files.pythonhosted.org/packages/cb/aa/d0942352d690c60d6b5b5f8bb5909bbf8b4aa903e74ee1698d9146e71275/ngh2-0.5.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:450e2f0cb6011e07aba877015638f20ade768243767f7e1563c163c80cecddf4", size = 323013, upload-time = "2026-11-02T08:32:53.082Z" }, + { url = "https://files.pythonhosted.org/packages/00/4c/76849c51c87cf10b2f8ea6f5513b29bcad0db10584b8342ff8264b8b77e0/ngh2-0.5.0-cp313-cp313-win_amd64.whl", hash = "sha256:495007ab0371cbabc4ce04fdd4db31b49b90aa4ebf7cb6b64e2c9c03313807b1", size = 253018, upload-time = "2026-11-02T08:32:54.698Z" }, + { url = "https://files.pythonhosted.org/packages/d8/98/6bebdacedc0b84e32fa4de358e929f3d4f7d7cab0554cf099a0409f12c6d/ngh2-0.5.0-cp313-cp313-win_arm64.whl", hash = "sha256:f8ed8ef638f504defb9ee9efadde2c37dc733c0aff705ba561a31385ca20a782", size = 229822, upload-time = "2026-11-02T08:32:56.077Z" }, + { url = "https://files.pythonhosted.org/packages/d2/ce/c0709a37295cc9bae378ca8aa452d3d6dba75fbac307aff248cd24eb76f0/ngh2-0.5.0-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:a7dd7a0f7afc012121f5ac3f50aa5d9f204c1f7ff60dd648db305f0151ce5a3d", size = 284116, upload-time = "2026-11-02T08:32:57.461Z" }, + { url = "https://files.pythonhosted.org/packages/03/42/4aebca08935b7e464461926c1b4cd6e0db3d26a0c7d83850bcd07bc23a92/ngh2-0.5.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:7510dc994f9867c8796aec9aaa97c0866c1a1abd1951afa8fcd6c2a9c043ff63", size = 269969, upload-time = "2026-11-02T08:32:58.908Z" }, + { url = "https://files.pythonhosted.org/packages/1c/06/5b692f3fe8181ab73582de6d825182ffb3c43b63ed8a4f8043a45c42f775/ngh2-0.5.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:8ae679e4b3575c60e3f8ecbedd45116a41b3cce795699c31c522fe59f27ce065", size = 303220, upload-time = "2026-11-02T08:33:00.379Z" }, + { url = "https://files.pythonhosted.org/packages/f9/3b/52ac31815270b45240328cb80fceae06037bdec3e9b38f6bd231e87373cb/ngh2-0.5.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:187eed561fb335e3881c99aaccbb973b93092ac925b8f93e88ab835c8b932453", size = 321689, upload-time = "2026-11-02T08:33:01.707Z" }, + { url = "https://files.pythonhosted.org/packages/5f/2d/9a377602bef4a5bc8297c00bd3e9887e6d6b5fe41eeb2db8a5b8dbf460e5/ngh2-0.5.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:d6b79a301876ad6b301a85c8e4a53787df1fa1afda7fc209231f777782060271", size = 308710, upload-time = "2026-11-02T08:33:03.059Z" }, + { url = "https://files.pythonhosted.org/packages/87/32/8e92eb4c876f18571b27145320b46705f8eb61ec0f1733ad26a81a203fc5/ngh2-0.5.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:6e8bd624552a2cc36d582c4695e4c1f5389c93d6f02f98d8f750f855ef7435e3", size = 324618, upload-time = "2026-11-02T08:33:04.331Z" }, + { url = "https://files.pythonhosted.org/packages/61/64/f3d0139aa61b9114986a7367b10abaf16bae54f94b78e53026348cd6042e/ngh2-0.5.0-cp314-cp314-win_amd64.whl", hash = "sha256:6ad8b5bfdf4f2e794fd009faa9546015d078578e706dad8e73f2d3dc9ba856ee", size = 260668, upload-time = "2026-11-02T08:33:05.566Z" }, + { url = "https://files.pythonhosted.org/packages/4d/81/e83fabc9b506762c387f530d47d859a8eb0fbb34eeaa67d6d8e2cbf8483a/ngh2-0.5.0-cp314-cp314-win_arm64.whl", hash = "sha256:5942ca4460a94aa2d3a6d4726c2ba738256dbe1ffd7afd8fcf87232b6423fc05", size = 239566, upload-time = "2026-11-02T08:33:06.935Z" }, + { url = "https://files.pythonhosted.org/packages/e3/eb/66546b8568c619f91a3136b310e59ccbf6ae67d9f2aea77ee67578529ddc/ngh2-0.5.0-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:8477ded42aede93cd96078715877c99152501eb7e12645750c2ba7ba295d5505", size = 296341, upload-time = "2026-11-02T08:33:08.5Z" }, + { url = "https://files.pythonhosted.org/packages/d9/3e/c04c0da25ae1a3a3edf97ab0292fc7206b9f3525cf0214686ab493ed0571/ngh2-0.5.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:a86c1820ebbfa826d2f4f2edccf716e087c7e3ca3a6ccaa981bcc058f6bbe636", size = 284130, upload-time = "2026-11-02T08:33:09.759Z" }, + { url = "https://files.pythonhosted.org/packages/5b/08/158f6356f5cacd0faf6755ddc5047820775b14fd4b808706339bea23c134/ngh2-0.5.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ac49a3f10d1c49ebaa0fa2f955d5875551cc36ed73ccadb67f331600b7fe4b30", size = 305103, upload-time = "2026-11-02T08:33:11.07Z" }, + { url = "https://files.pythonhosted.org/packages/a2/58/6d896561eef2a0960f9d7396ba36c1afa53d222f7d3e6da052bd7190ea08/ngh2-0.5.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e6b9b5952a7f3e2cef1077e12e0b26b7e41c0f1c9b5c6bbc73bf2983d5ceab83", size = 320122, upload-time = "2026-11-02T08:33:12.354Z" }, + { url = "https://files.pythonhosted.org/packages/df/c5/44e1b5e0e3e12c0f88da6d91668e2f5a8abc2711198804de97ee9dfa6b1a/ngh2-0.5.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:b7e57ece6c4eadd009ec80b5b0dc7ebe368ac21f23278805582f75130aeb8b84", size = 310922, upload-time = "2026-11-02T08:33:13.754Z" }, + { url = "https://files.pythonhosted.org/packages/0e/aa/47007bdb330e558b0f21391881c6bdf333d31eb7ab96cdfd6461f2813814/ngh2-0.5.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:96e15f43568984ef4b362d35b72989e0e3658366a752be447af315e30c88dfda", size = 323295, upload-time = "2026-11-02T08:33:15.021Z" }, + { url = "https://files.pythonhosted.org/packages/8e/99/71154a10398c91710001cefc474d6a7c92ffc86a845c233a117ac138a784/ngh2-0.5.0-cp314-cp314t-win_amd64.whl", hash = "sha256:08a642d7fece5ec3d6fbab38eba781603ff34c15c125565182d454a9f8da2a24", size = 279231, upload-time = "2026-11-02T08:33:16.368Z" }, + { url = "https://files.pythonhosted.org/packages/76/86/d5b8fcbe1441456da380b36bf49d3e11b35ba4830e76626e44fb9cf51ef4/ngh2-0.5.0-cp314-cp314t-win_arm64.whl", hash = "sha256:39b989a5cb332c400dfdde1dfbbf5bb4b2ab826d00c7c37c0bda14c41ab2281f", size = 253945, upload-time = "2026-11-02T08:33:17.654Z" }, + { url = "https://files.pythonhosted.org/packages/d3/f5/631739497d72100ca2a3bbd414ffba95fe405a2cd44e210bec496d1239ba/ngh2-0.5.0-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:571b0c798ebc19fea97d598292ccbb28e86f8f5dbfa3444a6aa2705ab6a0a25e", size = 283556, upload-time = "2026-11-02T08:33:19.075Z" }, + { url = "https://files.pythonhosted.org/packages/68/7a/5a2644f7eca888f83b42ebca49afd72dd2e67977e7cc8c19106f1c0505f8/ngh2-0.5.0-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:e637ab71d10a927208a7bb8560e4e72ea2c25b7406b3d9aedd09c54d86074480", size = 269276, upload-time = "2026-11-02T08:33:20.357Z" }, + { url = "https://files.pythonhosted.org/packages/9f/70/baf203ca722699e71714456177b4d975c178aba11ba42cb125464ddde885/ngh2-0.5.0-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:640eadec8d828e35ce2f018318ab01d840abe771718fc3feb9ddbd350fc4e957", size = 303245, upload-time = "2026-11-02T08:33:21.738Z" }, + { url = "https://files.pythonhosted.org/packages/05/7d/918c053b622112002240d00ad3555904fada1a13e7c611f9a766e01dc922/ngh2-0.5.0-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1fa014e3312fea8f762267809d390284c73f275eff563a82c74198da30989619", size = 321489, upload-time = "2026-11-02T08:33:23.202Z" }, + { url = "https://files.pythonhosted.org/packages/0b/dd/8dd2223032000c6d964ca583e8ac9fb21fa52f8938315bc91b57e22eeca6/ngh2-0.5.0-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:84a5ea8b164f62f9f3709ab8607511538a9e9c2ea9a768270dbd2bfe03b578c8", size = 308857, upload-time = "2026-11-02T08:33:24.569Z" }, + { url = "https://files.pythonhosted.org/packages/4b/15/e73d33b03477a65a063b509eee93d10f7df9451e0aa8743692780277c6aa/ngh2-0.5.0-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:4a34d4e6095b339783d5d53639889d1cd14acadf965ea4f28f26d9fd0bcf1628", size = 324612, upload-time = "2026-11-02T08:33:25.87Z" }, + { url = "https://files.pythonhosted.org/packages/43/7c/8d79f838d8eb4ed2d34a4e8f32842b3d91380a236f3583c7a80eb32c625e/ngh2-0.5.0-cp315-cp315-win_amd64.whl", hash = "sha256:64c3ad614fab4be4b3fa753e0a8a460810811fc70bf38de5a8ff04330c7960f6", size = 260126, upload-time = "2026-11-02T08:33:27.157Z" }, + { url = "https://files.pythonhosted.org/packages/d6/8a/85b9170bc7e0c775cb6cad502ee90ec5b1239789e5637a42e842aa648da6/ngh2-0.5.0-cp315-cp315-win_arm64.whl", hash = "sha256:5ea30cdc6956cfbe38a4025e5388dd116bacc53f5da1f430d016b0112db73a0b", size = 239492, upload-time = "2026-11-02T08:33:28.458Z" }, + { url = "https://files.pythonhosted.org/packages/fd/5b/b0a005002674cebcf0d3725127c0ef9ee59d25c2f74fa551956b9ede0b8e/ngh2-0.5.0-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:75e5295b5c977e80d74e953b4cceb7cc09577370f373516603854324eb22845c", size = 295043, upload-time = "2026-11-02T08:33:29.822Z" }, + { url = "https://files.pythonhosted.org/packages/04/e7/d596a0703b103dddce10a8741c700680c66b248b6c185fe3ac6778e3995b/ngh2-0.5.0-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:ca2a98614f106cb950f1d0efe52d55f516ad7840d1e285bfd11b39f9819fb910", size = 283507, upload-time = "2026-11-02T08:33:31.154Z" }, + { url = "https://files.pythonhosted.org/packages/98/e3/609fe13825f33bf29dc1d5107809d535d67b2a3812cd2a1bde2472541abc/ngh2-0.5.0-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:02a9d60ff37022499ed00e1158fed6b12c8b373d55cf1aa9ae2a15f758e71eae", size = 303726, upload-time = "2026-11-02T08:33:32.366Z" }, + { url = "https://files.pythonhosted.org/packages/ab/57/140c2228794c4d505b9e698186ca04cbbede36d130f23128438ffecf7578/ngh2-0.5.0-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2b44dcf542c7a5dcb3bea32f580fe99d4cfd047d74205271e8e1b0ee038b27e4", size = 320495, upload-time = "2026-11-02T08:33:33.674Z" }, + { url = "https://files.pythonhosted.org/packages/2d/20/bdf6566120d1bfc30b84423d3bf001735b974d9228b6e37f3689a1daf9f0/ngh2-0.5.0-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:efd663f6579dbeacd0c5a2bc3305c59d1d22132af09f528fab1a9974456d861f", size = 310358, upload-time = "2026-11-02T08:33:34.99Z" }, + { url = "https://files.pythonhosted.org/packages/7e/51/31053df685a49d5f2b1acc88f93c872f7ec821be2b7450ed1c3f031b257c/ngh2-0.5.0-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:1bfd128511bd0043a08dcb266508eb30cc2ecd8de6a90f7935268622216529fc", size = 323391, upload-time = "2026-11-02T08:33:36.349Z" }, + { url = "https://files.pythonhosted.org/packages/94/72/f516f5fff64c706a0257a403ba9b77b00e7858a9bc2a73b707c44fc615d6/ngh2-0.5.0-cp315-cp315t-win_amd64.whl", hash = "sha256:56852fc5b4005d813f30700d198f048523c4f26d8e4465ef9825b892d5dbd55c", size = 278053, upload-time = "2026-11-02T08:33:37.807Z" }, + { url = "https://files.pythonhosted.org/packages/63/77/d95a41f3870f7c2ae54a64ce5fd1e01857303526a15d9a578ccfd191df1e/ngh2-0.5.0-cp315-cp315t-win_arm64.whl", hash = "sha256:3147b3e4f54ca7fedc30affb23e1f0f6c45fd22e0a487480d4f6616b1dfbf4dd", size = 252271, upload-time = "2026-11-02T08:33:39.129Z" }, +] + +[[package]] +name = "nodeenv" +version = "1.12.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/e6/99/d27cfc9518f49e4cbc25c683ec7cf8704a9d31311341c291c0e78ddf791b/nodeenv-1.12.0.tar.gz", hash = "sha256:4ea7f88339310afebc3253f2c7a91b94bacf97d73a36a5c108962abdfaca501e", size = 131292, upload-time = "2026-10-31T19:03:18.847Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/2d/6a/8a9ac7d5e2f7cf53c459bfef90ebc17a2f8cd54b665af96799d4c534840e/nodeenv-1.12.0-py3-none-any.whl", hash = "sha256:80644d65c10cc2be12e3e4b54b3367ff288c7ad24ae75c2dcc65454fc7449d4d", size = 39442, upload-time = "2026-10-31T19:03:17.427Z" }, +] + +[[package]] +name = "opentelemetry-api" +version = "1.45.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/19/14/cf3a6b6448849656e1e5f4e2101f3988dc6789724050096aba1bc5ccf592/opentelemetry_api-1.45.2.tar.gz", hash = "sha256:d7b0008e21e5fd61cbe7a7f34ca3b6905a78ab677d9bc395e299359c75cda6b4", size = 73277, upload-time = "2026-10-29T17:29:37.888Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a9/2d/610db864d7513158cebb8f36cc88e67e73bd6c7aa1905ef18d89e1281c81/opentelemetry_api-1.45.2-py3-none-any.whl", hash = "sha256:2cbd737377e710ee740d261c94e93fa0f08e6d037c18f17513cc0a2d94479a34", size = 60335, upload-time = "2026-10-29T17:29:06.955Z" }, +] + +[[package]] +name = "packaging" +version = "26.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/7d/fa/3944b40b07da9ce895c0e6303a5ab7d53da063554f534556b134a54d6093/packaging-26.3.tar.gz", hash = "sha256:94edc256424af38762eb31306eed28beb9f0efc50a8837492c9d6fd6004aed79", size = 313412, upload-time = "2026-08-04T18:15:28.737Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/63/34/ba1c580383c9eada3711951fef0795c80b829a078d72188184bcab9dd527/packaging-26.3-py3-none-any.whl", hash = "sha256:d7193f7c8e4e93f444fde0262bf90af30e16fa0ad0ad44cb553c87339b23cd1c", size = 129956, upload-time = "2026-08-04T18:15:27.159Z" }, +] + +[[package]] +name = "platformdirs" +version = "4.14.5" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d7/9a/8475be631fb33ca1466915e70fd594c42a4e84b512db650eaa14f90fe75d/platformdirs-4.14.5.tar.gz", hash = "sha256:32e9921db7385aa8169bee4fe9501923e5715ba9fb7ea3b9c69b0d8e0639f7a1", size = 71464, upload-time = "2026-11-04T16:54:50.358Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7c/ae/ecbbbfd0e4343a6a521d49b3c8656fb4643dee2a4f6eaf941cf3280391a8/platformdirs-4.14.5-py3-none-any.whl", hash = "sha256:8e778c6fa421516f4d3369449f8df3b0e1b72c0e0005fe88e3ec772d0a14e750", size = 35402, upload-time = "2026-11-04T16:54:48.875Z" }, +] + +[[package]] +name = "pluggy" +version = "1.7.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/bf/db/7fc19e6f2dc92a966727031389fc2e08b558f0f25eb7403c1119ad4713cd/pluggy-1.7.0.tar.gz", hash = "sha256:d1eaa46ebb595891b860ab086b4d09c8588af65ebd4361b8e8f4bb8920b90ba8", size = 123304, upload-time = "2026-10-15T09:50:58.343Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/40/9e/2b38731e0fc536806f16490e1a12d7f0dc2a1235aa8cc07bcc75416a7daa/pluggy-1.7.0-py3-none-any.whl", hash = "sha256:7dd7b0d8832ba3cb632c306926ded123429211b83641b35dc5c41ad2d34f9bec", size = 27082, upload-time = "2026-10-15T09:50:56.808Z" }, +] + +[[package]] +name = "pre-commit" +version = "4.7.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "cfgv" }, + { name = "identify" }, + { name = "nodeenv" }, + { name = "pyyaml" }, + { name = "virtualenv" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/3a/c3/6965c2690ddce885ec75121572d065a5b94c5a5d8d3e657927ecda9fd715/pre_commit-4.7.0.tar.gz", hash = "sha256:1f3deee12b914c8fa184bd2b5953391c2e4f36763e403d4a23dc9983fa7c6e86", size = 198120, upload-time = "2026-10-12T20:45:40.32Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/eb/83/ce0a196e4f7b20b11ce3aa1fc72fb973f64b7628d51c1b8aebad37fb7f81/pre_commit-4.7.0-py2.py3-none-any.whl", hash = "sha256:2e229038ad3656081b70c27913157e4b636ef306f643f024a8a8e3f0f7b2f877", size = 226261, upload-time = "2026-10-12T20:45:38.858Z" }, +] + +[[package]] +name = "propcache" +version = "0.5.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/b3/9a/9fbf4e4ec0c2d7f1c32519fff782ef467859b8faa9fbc5331a96f6395d43/propcache-0.5.4.tar.gz", hash = "sha256:ff6b113f50bc066a698db5d944d2c6dc7507168dd3341e255a8892fd0715a558", size = 61545, upload-time = "2026-09-16T00:17:14.386Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/1e/40/14b21e505b7921617466576423f188a5c9caddfdaa1cf4b2b8a83d8fe216/propcache-0.5.4-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:897d1ddf6716e8f47200f7aad9a0efa6cc7586df66c6defa572f9eab379c078e", size = 86393, upload-time = "2026-09-16T00:14:06.9Z" }, + { url = "https://files.pythonhosted.org/packages/e7/4b/5a52e1a7b43563f7d408814194bb23cc8bf214eb6b86639b667a33a8d0d0/propcache-0.5.4-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:9cbfff4423eef4cc6cafc021469641a2b835f610b2647a6c5281903e21b8670d", size = 50431, upload-time = "2026-09-16T00:14:08.025Z" }, + { url = "https://files.pythonhosted.org/packages/05/cf/b5248180bf056cc76acc60c9c6e8c0ebbfdbd1c6cffd31fd14996927b7c8/propcache-0.5.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:3fc24f209c1b7f7f688b66b98293954f5504279760999b58920ee12dd8471c1d", size = 52116, upload-time = "2026-09-16T00:14:09.114Z" }, + { url = "https://files.pythonhosted.org/packages/86/a8/7c6cd6bfead1a11f2e411e688640e6d26574cb0bde7dcaa7423b0b65ed7a/propcache-0.5.4-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:62530ca89187827e4a4fe733f971abe81a7542eeea48ff61995f19b64d7199c8", size = 238729, upload-time = "2026-09-16T00:14:10.357Z" }, + { url = "https://files.pythonhosted.org/packages/5c/b4/442715b2e980df51be52d203549279e027728f24c80b00b5e525e31cd5ea/propcache-0.5.4-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:56fc3f7599528db40b1efa0889a620116e2704144495273d66066e8164e45838", size = 246121, upload-time = "2026-09-16T00:14:11.735Z" }, + { url = "https://files.pythonhosted.org/packages/bc/5d/df0684fc2b1732a01a7bec26d7897369022712422d25b09c37ce7dbc88a2/propcache-0.5.4-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:4f2d880ff60f45898f4acfa152aac8d04e3ee627d90ff4003491bf92239d5757", size = 251735, upload-time = "2026-09-16T00:14:13.053Z" }, + { url = "https://files.pythonhosted.org/packages/c7/06/519a5ebb48b6f94beb48396e55c905f12246a25c3a3608a7ec7bceabf50e/propcache-0.5.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:6e9368e87a3efc285e559131092c5db643eb8e56de4ee42064d5baec22ef2bb5", size = 235381, upload-time = "2026-09-16T00:14:14.398Z" }, + { url = "https://files.pythonhosted.org/packages/3c/07/1e0a9bb310830f2245edbd5cd3c6d24a783c053c4efd8e08e386e513c940/propcache-0.5.4-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:004e685b315646c410771836e72a44f143bbe624f29653a42687815069a303d5", size = 208973, upload-time = "2026-09-16T00:14:15.715Z" }, + { url = "https://files.pythonhosted.org/packages/62/5c/9324fab27d6088eecc47fe4332bf7aaf8c1ded93c36f558391e8a06d41a7/propcache-0.5.4-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:594eb4c6ec35e7179b058481f4e9f02521b56de16fa577c4b85c76fb1bf8a9f8", size = 233897, upload-time = "2026-09-16T00:14:17.25Z" }, + { url = "https://files.pythonhosted.org/packages/9c/a3/570d92fc952eae93b676f3a1568f4b89264102abd3c982ab6a9ebec58dcf/propcache-0.5.4-cp311-cp311-musllinux_1_2_armv7l.whl", hash = "sha256:2dba2f02d2d5c09ef8a0e6c1a42aeaa451f4be9898cb00b04fe98717da2eb23b", size = 223512, upload-time = "2026-09-16T00:14:18.87Z" }, + { url = "https://files.pythonhosted.org/packages/65/47/26810d889d89bba31db397e6a88f8984af775f5ed6bad0a29dce84324cff/propcache-0.5.4-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:c3ef2818d63bc86071e9d2989ae75a1bc32b8f7059cfd9f5abbbee70c32e2ed6", size = 239043, upload-time = "2026-09-16T00:14:20.366Z" }, + { url = "https://files.pythonhosted.org/packages/89/2d/f9c47691aa024c8299a3afacd78d22a01ab57eb627b481b6089708e71017/propcache-0.5.4-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:dd2ac8f5b643454c2cc6b6118b13da16e88f4a6434fc3ba61aca384029f04f36", size = 208218, upload-time = "2026-09-16T00:14:21.801Z" }, + { url = "https://files.pythonhosted.org/packages/74/6b/d510c0c378cabbf9d0ac7b663af6d00f2e9074073d93b20c85f24aa5c071/propcache-0.5.4-cp311-cp311-musllinux_1_2_s390x.whl", hash = "sha256:4054acf80d40456a0537f2913b349718649d8d6458a14ab7f48d0ce28c30869d", size = 240301, upload-time = "2026-09-16T00:14:23.121Z" }, + { url = "https://files.pythonhosted.org/packages/3d/80/c80f6adaaa1e51f0db2dce8c9b3714d94ec45e358a21f9a1910b10b40a80/propcache-0.5.4-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:40e94adb1e7d39ff28a8bd8d8b8fbd1df6b9f40976dbe379134f1ce058e532dd", size = 230785, upload-time = "2026-09-16T00:14:24.458Z" }, + { url = "https://files.pythonhosted.org/packages/d9/e2/c32a7df3f39caa7f11b2eb37ea5b6960a6946f2bc7c4b8ff97bbdf6d6b6e/propcache-0.5.4-cp311-cp311-win32.whl", hash = "sha256:9f86f7259efe2c951f43e57d471c9b41daa5bfc7db9f67189059cf1ae6d77fd9", size = 42747, upload-time = "2026-09-16T00:14:25.715Z" }, + { url = "https://files.pythonhosted.org/packages/0a/8a/3db6a3543d8101263b4c52978b6276a04ead2caff2c5ab880d934f47bd89/propcache-0.5.4-cp311-cp311-win_amd64.whl", hash = "sha256:e904d4d01f36bd6e197590be1533c44e06058771e0746dd073a8ebb3ef880858", size = 46268, upload-time = "2026-09-16T00:14:26.996Z" }, + { url = "https://files.pythonhosted.org/packages/41/07/5222e2665bbf6e45847492ecbf3b9f3e4975a0ae300e5fd465df7d48ce55/propcache-0.5.4-cp311-cp311-win_arm64.whl", hash = "sha256:d42a9a856a4a6e2f6c10f1318c07e7daa498d6593abe745c71dae4521a26ca39", size = 43547, upload-time = "2026-09-16T00:14:28.143Z" }, + { url = "https://files.pythonhosted.org/packages/71/cd/348d58f142aebc4873345c6b31087629182ca6e0f2b3caeaa528cf882eba/propcache-0.5.4-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:b28f41fa3b8c6900457f858ec5b03998f3a6d535fbc1bb2edec5961ea05ec429", size = 87285, upload-time = "2026-09-16T00:14:29.362Z" }, + { url = "https://files.pythonhosted.org/packages/df/f4/f3ffaee281b276da854ac1d7a6a506d26cbc62ea2e623756f1d0a4a1ba1a/propcache-0.5.4-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:dcbf346a318a5e30063f547630b02bb787ce2f45b6368d5da143660b6a3835d8", size = 50984, upload-time = "2026-09-16T00:14:30.473Z" }, + { url = "https://files.pythonhosted.org/packages/25/88/1d7df7201750b37765ef2b23bc1c526c028dadde80afa0f57a118fc01182/propcache-0.5.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:87a3caecf8095e48dc72f84bfa42e23a848cf410cc9cc13031fba4869b706a21", size = 52460, upload-time = "2026-09-16T00:14:31.692Z" }, + { url = "https://files.pythonhosted.org/packages/83/4f/48865bd02a16ee5236bc46166b2946f37b93e07b0eae355dac0be0b216ca/propcache-0.5.4-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:60a64cbccaa11b7760ce705a14ada17ba459e7ca9f23ba587eb013821032d7ef", size = 251768, upload-time = "2026-09-16T00:14:32.908Z" }, + { url = "https://files.pythonhosted.org/packages/b0/19/3742a5eed62317b03b4002ee865dc9fd720308bdd0da1f29a5786c630311/propcache-0.5.4-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:a74bfa37147cc08fb29df10bd9c16f40fa7f860cd3a6d2fff853323a94f6e17f", size = 257723, upload-time = "2026-09-16T00:14:34.267Z" }, + { url = "https://files.pythonhosted.org/packages/cb/d5/ee6350fb0be9122bb6c67082a876d34b90d980d100c106af4b81023e04f4/propcache-0.5.4-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:a4d7a54719b67338a305dca2ce6aafe366817df94ddfd4b5514374356f5ca546", size = 265597, upload-time = "2026-09-16T00:14:35.56Z" }, + { url = "https://files.pythonhosted.org/packages/85/9f/83a07b6ec0e043c050cfdd35fb0cf1b7897b91d554d6eea293740309afe7/propcache-0.5.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2814ecd8e818f487bee4b0f921bc4d1c176cc5fc71ac0f072d0fa67eda4ac14b", size = 250424, upload-time = "2026-09-16T00:14:36.894Z" }, + { url = "https://files.pythonhosted.org/packages/33/2c/a763a8251f50fba042af0fb1f02bfec4b31381e40aff760db2be7b2e1f84/propcache-0.5.4-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:6af4693716bfb03f1752ef1b30faa593db2c01d5272e9b8564a1549452a979ab", size = 216748, upload-time = "2026-09-16T00:14:38.369Z" }, + { url = "https://files.pythonhosted.org/packages/6a/e2/4d11bea8fd6a777149c6c20645f873952eab5de3a2497aa11648ec9ab6ab/propcache-0.5.4-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:4fbc1a15dc8cd1689508758d626b372b1f09d28d9577667feaf9e6bfcd8efcbc", size = 246533, upload-time = "2026-09-16T00:14:39.82Z" }, + { url = "https://files.pythonhosted.org/packages/9f/36/6683597de4907e70c717e3588c541202c66086a72ff3db58be49de66e72c/propcache-0.5.4-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:cdee8205a44d0be91bbac4c41b95d86641b72dfc7aef1279400e4fda3f26a937", size = 238173, upload-time = "2026-09-16T00:14:41.259Z" }, + { url = "https://files.pythonhosted.org/packages/85/84/cb08d79f1762daafeb2b030c470cd0c725c97b8ad67412457c6f35c53e9d/propcache-0.5.4-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:9a2a8a50a93dee0268a860a07fa3b4bd968f8ce4dbd794957da772f395368526", size = 251128, upload-time = "2026-09-16T00:14:42.652Z" }, + { url = "https://files.pythonhosted.org/packages/c2/0d/41b848036db6621370c1f2e5471a7da8149c730f8552a5257567721f4576/propcache-0.5.4-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:7ffafcbfc7b549ab940047e505c831eabac5e67de53e1bc174adbc5285c55944", size = 214821, upload-time = "2026-09-16T00:14:44.112Z" }, + { url = "https://files.pythonhosted.org/packages/f1/b7/adfae4bf9c63bccf12e2d9690a175c6579047a6eec3b5a6a5f51428c15e2/propcache-0.5.4-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:d1f5a500bfcbb2c0ab85e98a0dcd70f5899d34efe365a0187700369a79603031", size = 254793, upload-time = "2026-09-16T00:14:45.429Z" }, + { url = "https://files.pythonhosted.org/packages/51/6f/eeca9647245d5f92e87d53e5f14335bb42fce1a7e6842c8045b364eded8b/propcache-0.5.4-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:8a235f73d6e020855dc29dff012d920c02ee0feab8d73a24185a7569f4be1161", size = 247134, upload-time = "2026-09-16T00:14:46.976Z" }, + { url = "https://files.pythonhosted.org/packages/5d/a9/424e38838793d37160b4379c702f61c74c598fc6cd17204adbe3c554f7a8/propcache-0.5.4-cp312-cp312-win32.whl", hash = "sha256:b3083bfe87f95c756e610bd8025f26cbd1cd4aaa03a422f2d65efb7a97cd53d8", size = 43073, upload-time = "2026-09-16T00:14:48.338Z" }, + { url = "https://files.pythonhosted.org/packages/58/7b/6e8ef26f6d510a7916064fec68d55fcbfbdf7eb01e377480d66a122152d8/propcache-0.5.4-cp312-cp312-win_amd64.whl", hash = "sha256:98914de2c4d7f0f9f4a8c6ea4bf05841f4175796941e3ef7d47eb718f22311fb", size = 46190, upload-time = "2026-09-16T00:14:49.99Z" }, + { url = "https://files.pythonhosted.org/packages/08/b9/72028c5b56ced97f456de6aefa79435ca64d7f77af78ea8cf3c76fc5195f/propcache-0.5.4-cp312-cp312-win_arm64.whl", hash = "sha256:8876b39961e33d912afe3c1bee18ee564fdad0206f873cc15d522756b7f50737", size = 43075, upload-time = "2026-09-16T00:14:51.155Z" }, + { url = "https://files.pythonhosted.org/packages/78/4c/3b1365d58a667689e067e13d055fcd92bdf8d9a2fca3d9201b47ed5b3631/propcache-0.5.4-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:36c0d9db44b523ef93d03341b1c42d69ff01d673c053d1b1c6c3a363bcaa39ba", size = 85290, upload-time = "2026-09-16T00:14:52.342Z" }, + { url = "https://files.pythonhosted.org/packages/8f/61/5f9c29c3aa67c30238c4eadf95149b1d983a48f69b86b0cff927a7d6df13/propcache-0.5.4-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:e1d52a05dc417279f7e5c7618c5dfbbc29923aaf9bc0a5c1802ddcebf54c61a0", size = 50027, upload-time = "2026-09-16T00:14:53.67Z" }, + { url = "https://files.pythonhosted.org/packages/25/7d/c1ab1ef09e9d4d835be5d58c0a32a1e1de8397abaa4e502a9d4141328cad/propcache-0.5.4-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:44149f46500a0a41b95b4d99c2e586a77319539730607b9892974a092788b111", size = 51425, upload-time = "2026-09-16T00:14:54.826Z" }, + { url = "https://files.pythonhosted.org/packages/73/36/0093091ebb270fcd1bc1f6e095f93b2e0ed7f1011c28837dc2dbe5f96b99/propcache-0.5.4-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:dbab5f5ff6897c81f355d079010cdae85b02e5a0b518b5251523b8ad8ae9ac3c", size = 233595, upload-time = "2026-09-16T00:14:56.09Z" }, + { url = "https://files.pythonhosted.org/packages/ae/8f/0de9d4c8e05ce0be71b436919a216bd7fc5cc6e2691c0602295efb22b9ed/propcache-0.5.4-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:c3e98c55bde2bcf7db3c70d1aed7ae9aa8aebbf19a250c66645cde44cdb8b867", size = 240318, upload-time = "2026-09-16T00:14:57.674Z" }, + { url = "https://files.pythonhosted.org/packages/7d/71/2b35e91455209b85ee98f7859583e0814fab57d3af0f2381aaee34c37304/propcache-0.5.4-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:db3ae52ccc150dbc84704e9d642743897f3e1c54742ff34cacb661e52e3818a9", size = 246649, upload-time = "2026-09-16T00:14:59.352Z" }, + { url = "https://files.pythonhosted.org/packages/ed/74/08e6c1faf26ee2732023a3828787ba535557122774f4a386b1f715cbd8e0/propcache-0.5.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:f85915e00dcb1cd9f2f890ead064ed40a27df06f0db65be427b29482ae357572", size = 234316, upload-time = "2026-09-16T00:15:00.696Z" }, + { url = "https://files.pythonhosted.org/packages/5c/9a/08385733c9321c9bb78039d3ff31045e4fca962d9665023c4eb70f998819/propcache-0.5.4-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:c2ba30a89035b57b73e00475de948521602f543d79ce01db10b04b36c4c76fc8", size = 204666, upload-time = "2026-09-16T00:15:02.019Z" }, + { url = "https://files.pythonhosted.org/packages/1d/f4/e87bc7629af9a14a752b218764a78742d73c2c563ac58315da6841f0cbe4/propcache-0.5.4-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:ae58f361bd5dae942717c65d3413b478c70aea9c462599e7b9adad3731db3894", size = 225900, upload-time = "2026-09-16T00:15:03.394Z" }, + { url = "https://files.pythonhosted.org/packages/d9/6d/11014938d3fe9bea2ea2dcf930f26ed565bfb2f5be3c756362ea48c92636/propcache-0.5.4-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:96f7c5c15656040ddcbc51e56dc59b58aa25999d743c126abd425b9766ab43e9", size = 219988, upload-time = "2026-09-16T00:15:04.811Z" }, + { url = "https://files.pythonhosted.org/packages/dc/72/fbf17c589f92c0b3bbf6709a425661f8ef2ed0d46b38985a7d7b5a0f6b91/propcache-0.5.4-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:7cc528e760a8af06f2b13e9b9f362cd90c7c718ea61228a96dbd31ba16ed7f47", size = 233611, upload-time = "2026-09-16T00:15:06.498Z" }, + { url = "https://files.pythonhosted.org/packages/55/7e/dbd637572a279692e5518d117274a9331bf5faac59f191d30e82521a3ec7/propcache-0.5.4-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:425f8cc86ab5018b4b8d4a23bc8e74d964bd3d757c3702e301aa79be76c53f6c", size = 204333, upload-time = "2026-09-16T00:15:07.961Z" }, + { url = "https://files.pythonhosted.org/packages/ba/5a/f99c92068f1e0f5c886899ce0e4a619db376ca98c5279d93f95bd86906af/propcache-0.5.4-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:a5793c7698a53f56f4a1889a4737c7eeb1b7ad0842fa6b1abca22913ff79c8c1", size = 235177, upload-time = "2026-09-16T00:15:09.334Z" }, + { url = "https://files.pythonhosted.org/packages/ee/28/95456fabd2daf6be89049a13fbf03341756014d2959c83d12957d4c49694/propcache-0.5.4-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:c02c0e570c5c7e077b0181a9f3cdb7d4c3617d1cda6b5c95bd5d34022923d82c", size = 228982, upload-time = "2026-09-16T00:15:10.729Z" }, + { url = "https://files.pythonhosted.org/packages/b1/bb/df90f62c9cf7c93ea235f6f9405143bba802914607317266dd81fc8d737e/propcache-0.5.4-cp313-cp313-win32.whl", hash = "sha256:3e413d7a4a9b4866b7a761d6060d434b64d23cd35122eda3b026a0bbe8196b25", size = 42611, upload-time = "2026-09-16T00:15:12.111Z" }, + { url = "https://files.pythonhosted.org/packages/01/bc/e0a7b84af04ec02d73a48aa71f091e1e4a2107e3074b7ce12195b66901f4/propcache-0.5.4-cp313-cp313-win_amd64.whl", hash = "sha256:0c889f6fa84957bc7e8b4eab71fd16a0455068d5045e3aa40c733071d2b2fd77", size = 45342, upload-time = "2026-09-16T00:15:13.519Z" }, + { url = "https://files.pythonhosted.org/packages/9a/70/50b031cafe72a5c1878b903ee87303f71313345566bf3d6ec202e5ddc9ec/propcache-0.5.4-cp313-cp313-win_arm64.whl", hash = "sha256:69fc35c0779522da366c563e5faf203ffc1f8ff0021d5b1337fa4efa5be73177", size = 42408, upload-time = "2026-09-16T00:15:14.788Z" }, + { url = "https://files.pythonhosted.org/packages/33/c9/07e227b930c8ae513b8ef1aae3793499be097bffcdf7aee4fb8b33db4cd1/propcache-0.5.4-cp314-cp314-macosx_10_15_universal2.whl", hash = "sha256:e6720ba44ad7e72174314d0e1fb0172494cff5c73a3a8a2159c3d2402ff15565", size = 85933, upload-time = "2026-09-16T00:15:16.073Z" }, + { url = "https://files.pythonhosted.org/packages/e4/e1/6710bb44510c4e4a8e0f004bbaf3cecfd048141309c77bae56d4e5a6ebc1/propcache-0.5.4-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:4cfe0a92ae30151869e67a4b5f5e105e4e03ad30b3f38e5211b5bf77d0881993", size = 50179, upload-time = "2026-09-16T00:15:17.377Z" }, + { url = "https://files.pythonhosted.org/packages/e2/22/b533b493d7025456f44518b33e53e000021a20fe7c27b88cf3d341df7186/propcache-0.5.4-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:1d759d05634f1b038fb625a66662a8c85e5a8fec912da381b5149ddac107482b", size = 51942, upload-time = "2026-09-16T00:15:18.589Z" }, + { url = "https://files.pythonhosted.org/packages/f1/74/70ac8430e28f21e442c7bcb964eb46c4363f6881ade4aa0e978bfd8d503a/propcache-0.5.4-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:251c63dd46a0659bb875cb254dc4c1e79ee91a847c737cd62373295afc2235dc", size = 232647, upload-time = "2026-09-16T00:15:19.905Z" }, + { url = "https://files.pythonhosted.org/packages/72/95/f222f13b6fe623310be0eb61a673bf26df439ce27e563ca8e422d0818777/propcache-0.5.4-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:7a8d5ff04eb1f85698a78d20c62a14676e7b960dcafde09a388d60ad377d355d", size = 241541, upload-time = "2026-09-16T00:15:21.3Z" }, + { url = "https://files.pythonhosted.org/packages/a2/3e/763e370340db16115c5e63ad46e21ef0770a7f06928b3d3b62d8f8edfca4/propcache-0.5.4-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:7b9100a93b372418d8688f3f2a3e5b45c64d70ca4d6176e121aca1e3bfc1e32f", size = 245332, upload-time = "2026-09-16T00:15:22.802Z" }, + { url = "https://files.pythonhosted.org/packages/96/d3/e97cd6f5de2176bd90ed4076c7a9b5e09d0f0b9687d00a576507988bb62c/propcache-0.5.4-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:cc07876cfb079b6f6f36d21ce75784ad6c2c6b563eeac0ed26c2fa2669b85df9", size = 232757, upload-time = "2026-09-16T00:15:24.374Z" }, + { url = "https://files.pythonhosted.org/packages/f9/4c/6766e5f60bcda26d244333aa71d0a702c1c9b21b251d543c7af5953d1eee/propcache-0.5.4-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:0951315a6b3142ee2167404d707743f0157c110091342b1aa0accac5cf0e4acf", size = 204389, upload-time = "2026-09-16T00:15:25.667Z" }, + { url = "https://files.pythonhosted.org/packages/b8/5e/ec4bb09a70b26ea99d76a8292c3383b960b296de2b347ac9986678f1761c/propcache-0.5.4-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:bee7d3aed13d56f54e681df38c3a23031bc9e3863f687d9d598825c9146acd7d", size = 228217, upload-time = "2026-09-16T00:15:27.11Z" }, + { url = "https://files.pythonhosted.org/packages/e1/7d/b53922ba7d9e5bf797324e63aa05906ec240871899f779628df068743e2d/propcache-0.5.4-cp314-cp314-musllinux_1_2_armv7l.whl", hash = "sha256:4e985382be6d15da8d0c2710a6fa7b9070fc9ecdeefb7f580e88373984ec8be3", size = 216947, upload-time = "2026-09-16T00:15:28.532Z" }, + { url = "https://files.pythonhosted.org/packages/ff/39/b62eee45e5ea4de094a258cbb3b01c1e856ca51ddfd95b43135c5effd1eb/propcache-0.5.4-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:9e9ab13760aa8b6d0881ae7cb04fd891d8d490cd2554ea8e79bb278399169bcc", size = 233457, upload-time = "2026-09-16T00:15:29.977Z" }, + { url = "https://files.pythonhosted.org/packages/cc/a9/feec61ed296d993db9dd097e0f6723e3f576a647722367547495e4c5b05c/propcache-0.5.4-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:1b2f3bec4261a94019575481c726c29850f72e27907773c75b1de421e20e9f9d", size = 204131, upload-time = "2026-09-16T00:15:31.74Z" }, + { url = "https://files.pythonhosted.org/packages/92/4d/411ef380cddad28dc001f1c6d75ec72c76cd3817030f68ec1ccfba0ec6c1/propcache-0.5.4-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:720cf832eb2d0b0dfee129cb3335a26f6ce3cc45ee1187e8f0731758caa16792", size = 234820, upload-time = "2026-09-16T00:15:33.087Z" }, + { url = "https://files.pythonhosted.org/packages/15/37/c988229753629ef1cfd5198337a83e624780ea2b3787efe9e747c05aad2d/propcache-0.5.4-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:9fb0a5be8d9aa213150e8d8148a42aca4984b285bcad1e69587dc4298edd929b", size = 228350, upload-time = "2026-09-16T00:15:34.533Z" }, + { url = "https://files.pythonhosted.org/packages/12/49/5ef1c5cf98591da3c5b952b39e6a298084cc1ce353bc70f85e82397a5036/propcache-0.5.4-cp314-cp314-win32.whl", hash = "sha256:30cc1cebaf9aef49db06357a50398323ae04d70460c0491837d026ab7d6452ea", size = 43578, upload-time = "2026-09-16T00:15:35.957Z" }, + { url = "https://files.pythonhosted.org/packages/1e/9e/a0ac821a2229186af5e2e3c3635a78abb23cfddca57f38513ab5d70420f3/propcache-0.5.4-cp314-cp314-win_amd64.whl", hash = "sha256:0a095db8e15a6020db149ecbed6461939fe74f6acaa3ae8b702a1fe8c38cd983", size = 46304, upload-time = "2026-09-16T00:15:37.655Z" }, + { url = "https://files.pythonhosted.org/packages/a1/19/c8d0d36a9d16cba5dcee67d389c9333b988c8986a653a61c00a451817a46/propcache-0.5.4-cp314-cp314-win_arm64.whl", hash = "sha256:45488d1a5f9ab5bd90aaa1ca20f50fe1922b8ffad71a2009d2adf41355897aac", size = 43440, upload-time = "2026-09-16T00:15:39.091Z" }, + { url = "https://files.pythonhosted.org/packages/2c/e9/42f1da77cacfc184e6ec929557ef653b7961bbf6f1da460b9221273948b3/propcache-0.5.4-cp314-cp314t-macosx_10_15_universal2.whl", hash = "sha256:53eaa697c4d0422ff4cb714d00231b43352064d97b944033b30c1d57cc506ec0", size = 90672, upload-time = "2026-09-16T00:15:40.306Z" }, + { url = "https://files.pythonhosted.org/packages/cf/2f/4b79940908c6ab8c795097c102999d7bc1f7e0b8604dfd1c232f9d99d67a/propcache-0.5.4-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:886b59c4d28ca97dd23b025fdfc50a0356be934efbbbca89ad26230067f86fe5", size = 52586, upload-time = "2026-09-16T00:15:41.575Z" }, + { url = "https://files.pythonhosted.org/packages/eb/07/02196ae6320c110235bb343f90dbd34be41f8b8964a3ee30db84ec12579e/propcache-0.5.4-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:3fa15757fea1dfcd5b7745cad9f4638929605531bd4018ab2adff7955f1a403d", size = 54335, upload-time = "2026-09-16T00:15:43.027Z" }, + { url = "https://files.pythonhosted.org/packages/6f/44/f48b9a131985659924df5fa5093f68fe72c7ee375329802989ba3126efc6/propcache-0.5.4-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6f0093ac3e9daada202c2082439d414a625c57184727a46e112a3fb2a81cb788", size = 297567, upload-time = "2026-09-16T00:15:44.373Z" }, + { url = "https://files.pythonhosted.org/packages/04/a1/418d956d2735139f77fc35262179f1f52c23aa666de5a8ab3819c1ae7854/propcache-0.5.4-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:3cd3a7edb6b95b9b33998135ebfa18d709da82290fb8f27c858970b5a12c8b56", size = 297477, upload-time = "2026-09-16T00:15:46.048Z" }, + { url = "https://files.pythonhosted.org/packages/69/fd/ff811fdb6d3d3e67fd9bbfb75881675d34a42d0ef29a45d33e3e233dde07/propcache-0.5.4-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:c174bfd1c48a1b51a3078e95586dde718374bac79719ab3541ec9e74aec40574", size = 302669, upload-time = "2026-09-16T00:15:47.458Z" }, + { url = "https://files.pythonhosted.org/packages/fc/57/527910c455b5ec62f6871bef45d4f79fea16cb8c966ba0d4a07f0339ddc4/propcache-0.5.4-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:a219f0ac59817a9114dd2aa57c13180f993e819ba658c7ddab4b66ed1ee0d370", size = 287908, upload-time = "2026-09-16T00:15:48.99Z" }, + { url = "https://files.pythonhosted.org/packages/1d/86/f69ab82707534a0cb2057bdca04f9200a71214c7551800f9d34d6ac39e4f/propcache-0.5.4-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:17a7400cec0256f0a71ae71f9da398f9894c956ff6668a1c9d317b3367316320", size = 249804, upload-time = "2026-09-16T00:15:50.486Z" }, + { url = "https://files.pythonhosted.org/packages/27/19/60677af50d93be4256213de7cd487f056944c048b9c0b6f2e45b3a30f666/propcache-0.5.4-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:978f28401afbc76cdc3df9e1717b4229a06b626a1dcc75db4e1f2beb3884c3e9", size = 282344, upload-time = "2026-09-16T00:15:52.029Z" }, + { url = "https://files.pythonhosted.org/packages/7c/f7/a0057808a91fb3b6a5f3602b528f0cdcb3d53e0ff8315d73fabdfdf8fec4/propcache-0.5.4-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:4a1f4f5ffa55dce6307631f3cb2948e117e665966ea512e0d502b16c24f567e7", size = 270167, upload-time = "2026-09-16T00:15:53.466Z" }, + { url = "https://files.pythonhosted.org/packages/83/c8/f4a865490df0dc0c8531d4e59ac411cb6dc24bb255d2396a6f1c60a368f4/propcache-0.5.4-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:213bb68d9ced5cf2bf717b1071bf2b09b4b04c426256f9fe6d054c60318424c4", size = 286551, upload-time = "2026-09-16T00:15:54.995Z" }, + { url = "https://files.pythonhosted.org/packages/b0/67/b4faebde9da4e8173d0e5a30e8cd31335914af7ef350b988f27fec588cfd/propcache-0.5.4-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:286867fb156488c251a3721766e380ac4495e4fd6b51aaa1403d89ce7f4359d9", size = 249595, upload-time = "2026-09-16T00:15:56.505Z" }, + { url = "https://files.pythonhosted.org/packages/f6/40/52e1dd5636e9f5a27f6b5a4b4e2f33c322fd72afe956c397d82523ec4a80/propcache-0.5.4-cp314-cp314t-musllinux_1_2_s390x.whl", hash = "sha256:445ee3bfb46e85838387fb3c536a73cc0b994dc192b004e40e170adc54aa2a7e", size = 286700, upload-time = "2026-09-16T00:15:57.985Z" }, + { url = "https://files.pythonhosted.org/packages/d5/0e/30b2b324b93ff31a0bab539c102aae59e84e444031b2742150a7646aa1bb/propcache-0.5.4-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:48cb48c5346a97de792254af77715aa2529c2a1ebc5f586aa0aae44a02f1fe57", size = 280500, upload-time = "2026-09-16T00:15:59.487Z" }, + { url = "https://files.pythonhosted.org/packages/64/36/721bb59f682ff060d0c8df64274fca8cd0521b1a54506c2eedaef795b7f5/propcache-0.5.4-cp314-cp314t-win32.whl", hash = "sha256:03b229037d25b801e7af53fd52b9fc49d9439b036fca1e087e02780631adfa97", size = 46121, upload-time = "2026-09-16T00:16:01.349Z" }, + { url = "https://files.pythonhosted.org/packages/c1/86/0b1b80fa1ac3a0aac44e2922a6964fbe9cd52af5eab8fa933bf9e90b030c/propcache-0.5.4-cp314-cp314t-win_amd64.whl", hash = "sha256:8a1fc236528c457cd739c88abe823da851b7ab645d72792f88658114cc340c12", size = 49154, upload-time = "2026-09-16T00:16:02.901Z" }, + { url = "https://files.pythonhosted.org/packages/69/4f/9fe6f05a47cb550c823155052116f710064b6be5c6e8ec4e9faae7e18115/propcache-0.5.4-cp314-cp314t-win_arm64.whl", hash = "sha256:135036c5cfc93864affb0f9af9a27e5d7a71cb7bd745e7b6dbfc2d56cc30e827", size = 46005, upload-time = "2026-09-16T00:16:04.266Z" }, + { url = "https://files.pythonhosted.org/packages/58/25/895a11d1e4c5c2acc6d816e2bece34e02d9dc92f2182ae276cd819e9e804/propcache-0.5.4-cp315-cp315-macosx_10_15_universal2.whl", hash = "sha256:45bf2e730ab8905d0527fe05a86500f406e64305c34cc81ebe64b4617cab9760", size = 85634, upload-time = "2026-09-16T00:16:05.599Z" }, + { url = "https://files.pythonhosted.org/packages/58/41/c0acd69271de7a1cf439e77d5d60c18575fd09bad56e798b95fa23458ea4/propcache-0.5.4-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:31eb43ba2edc704ab2ec27815315dd8a19def0fb16215be4cfe8d32fe78ffd51", size = 50084, upload-time = "2026-09-16T00:16:07.384Z" }, + { url = "https://files.pythonhosted.org/packages/a5/1a/ad561f99f90884089e6403b76c220610809429ba868a81a2e7ce115d32e0/propcache-0.5.4-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:174507f82d3594622acb1dd2dafecf2d899d6d506335494e7107767bf05f3aae", size = 51692, upload-time = "2026-09-16T00:16:08.956Z" }, + { url = "https://files.pythonhosted.org/packages/e9/07/057bdd3a9609ffad59b06239cceee784b047f6c720247bfaa36d2103e138/propcache-0.5.4-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:50e337653721d20ead710da33bf44487fbe8a0db8782714b60306481e9f95b51", size = 232947, upload-time = "2026-09-16T00:16:10.466Z" }, + { url = "https://files.pythonhosted.org/packages/fa/dd/d36ad35986718530498a65e45e3713f9f0e6a580f192ef02d2ef7cae9b52/propcache-0.5.4-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:0d21d0d2c82bbfeb1677a9711f38df968f9837576102bb4add1bd449d28d88f1", size = 241250, upload-time = "2026-09-16T00:16:12.056Z" }, + { url = "https://files.pythonhosted.org/packages/fb/81/f1459415cdb6c10d46942779de39bb59a77b38e5a76bb1def9227962eb45/propcache-0.5.4-cp315-cp315-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:ccf4f7a79e26bb7efb06ecd50c177833b71df05cbc748701372325e6bcc17f6f", size = 245150, upload-time = "2026-09-16T00:16:13.596Z" }, + { url = "https://files.pythonhosted.org/packages/ce/4e/58b9b1460afc97a4c0b17ee89af701c4011d4d7f46470eba3aaff76a8069/propcache-0.5.4-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:23278f808cd81d5ada7184a76606b925fb3389c60e1077b2cd7da7b1fcf0553c", size = 232166, upload-time = "2026-09-16T00:16:15.126Z" }, + { url = "https://files.pythonhosted.org/packages/b9/c6/5a79e0eda3e7b6987d03d8c622ff6d52a42165a12e8418eb37694b9cc4b4/propcache-0.5.4-cp315-cp315-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:e738ab81179510ce79b2eac9a6ecf47feffd9e76d1c72e403005dddb6e36c06c", size = 206085, upload-time = "2026-09-16T00:16:16.713Z" }, + { url = "https://files.pythonhosted.org/packages/4e/72/940aed42c73f9da345ca2de0f6e835c726498159abca5f1ef14fb0a2af8a/propcache-0.5.4-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:a419ee85e654927baabda3929c03c0cc1112bf472ff0dfd6142f4e3a81ca4162", size = 228460, upload-time = "2026-09-16T00:16:18.352Z" }, + { url = "https://files.pythonhosted.org/packages/85/71/3f54e1535c8f323d91ba566044d7c2b39ff6f6a2f1d0bd9071779d07b9b3/propcache-0.5.4-cp315-cp315-musllinux_1_2_armv7l.whl", hash = "sha256:b61805357d966680acf68b3b6d49772631ed9df44ebece10ff1460e117a7da8a", size = 218350, upload-time = "2026-09-16T00:16:20.064Z" }, + { url = "https://files.pythonhosted.org/packages/a8/f4/025890cc389ac3ec485ecec607d4a7ca47e15bfa2a465746ab98af602536/propcache-0.5.4-cp315-cp315-musllinux_1_2_ppc64le.whl", hash = "sha256:58134228927cee6c047d626c08e60a81be604a20578a12ce752cc5c9a84d4826", size = 233156, upload-time = "2026-09-16T00:16:21.624Z" }, + { url = "https://files.pythonhosted.org/packages/04/29/b39cae08c87c140d3d274f0a2c058cb5588e836175c3309e260b230ab07d/propcache-0.5.4-cp315-cp315-musllinux_1_2_riscv64.whl", hash = "sha256:350b272b2279f4135a64fc0c304a5d08e28a137c9573442c606152446638a831", size = 206206, upload-time = "2026-09-16T00:16:23.204Z" }, + { url = "https://files.pythonhosted.org/packages/18/61/e16462ef18a87247dc9ebbd5c606f46d5ce67e708bd9cc734dd0d9222564/propcache-0.5.4-cp315-cp315-musllinux_1_2_s390x.whl", hash = "sha256:45bebbe252550fec975ba3b62bc6f931643cfd3b5464ef47619cf3fef154e01c", size = 234469, upload-time = "2026-09-16T00:16:24.841Z" }, + { url = "https://files.pythonhosted.org/packages/9f/84/b6a1490922427204fc47df920ed002eec709621de6b79b11592bf45c623a/propcache-0.5.4-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:ada748108a43d29b7c328ba7db3755327cd94f028bcc1a7ee3f0addcfacd9c38", size = 227311, upload-time = "2026-09-16T00:16:26.549Z" }, + { url = "https://files.pythonhosted.org/packages/ff/5c/5a59527582e9bcb694b2f08b9894134b65a0f5f79dbff174f054f5f74ed0/propcache-0.5.4-cp315-cp315-win32.whl", hash = "sha256:ee19113bce2f3acd46432050688b70f61acd6857d75abb9ec96341b7e9ced123", size = 43512, upload-time = "2026-09-16T00:16:28.313Z" }, + { url = "https://files.pythonhosted.org/packages/26/07/93cf699ed363681e754d7c3fad587fb09ef6b65618ee193332ad16a68d7b/propcache-0.5.4-cp315-cp315-win_amd64.whl", hash = "sha256:ceb3e879afac028f93d272c957814695dc5569e4904262dbee92f6c41bd5e4a3", size = 46264, upload-time = "2026-09-16T00:16:29.751Z" }, + { url = "https://files.pythonhosted.org/packages/65/10/fef04fbdcd44a4a163cb5ff5674599c6d6fdefd64a5a459438f9ad2ba042/propcache-0.5.4-cp315-cp315-win_arm64.whl", hash = "sha256:c83acbce9f2b5e3f5f5eda9e53d2001fed22fcdfef81274a9e02d8fd53b70a30", size = 43395, upload-time = "2026-09-16T00:16:31.5Z" }, + { url = "https://files.pythonhosted.org/packages/70/f6/7e2f4dab0b92ab46111bd48cee9ee1e5f519514c44e3779ede5358d7ada0/propcache-0.5.4-cp315-cp315t-macosx_10_15_universal2.whl", hash = "sha256:a5e8ef588c109725dc713ba69aadcac00a1ef90c2ce9c0a8c7075128f569f47f", size = 89825, upload-time = "2026-09-16T00:16:43.115Z" }, + { url = "https://files.pythonhosted.org/packages/9f/8b/dfeff925cb6ced97ede701d5c6a99998da963c6f2e06abbf879c9dac5b54/propcache-0.5.4-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:4d86476a935c88963d9b8e1a9a0d38188790e9622169bfbafa173046846709d3", size = 52159, upload-time = "2026-09-16T00:16:44.754Z" }, + { url = "https://files.pythonhosted.org/packages/24/6c/924c810be5b7cf218ef47e707cf06d34adb4e3f3a31e3c24c55c6d945a88/propcache-0.5.4-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:f5470694918830da62fac9e69133b53d23b736d7070e587b27a4a2be37e08e68", size = 53956, upload-time = "2026-09-16T00:16:46.762Z" }, + { url = "https://files.pythonhosted.org/packages/3f/b6/9ed0a5c939b58b6bed740a05b5d0f919f0b318d03284b4b6d81a0fe8a29a/propcache-0.5.4-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:10ef33a68a61ce317e095fd2e202a592ea92392b90944a78c993f0d9a73ab06c", size = 295235, upload-time = "2026-09-16T00:16:48.577Z" }, + { url = "https://files.pythonhosted.org/packages/5a/eb/5ce886e902a2e781dddf110993d5329458a9b1a8626b876c65e5e25bf413/propcache-0.5.4-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:5cacf3c9efd09df409dc33654dd077e1c245ba8fb747b0f0236ef41b7c49b589", size = 294463, upload-time = "2026-09-16T00:16:50.539Z" }, + { url = "https://files.pythonhosted.org/packages/f2/88/c98f49183ecd3e5b204a556f0ca47baa02c2206a500fe8c7ec1726297b0a/propcache-0.5.4-cp315-cp315t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:770e8209d018175fc0063936fa9583b6d27e88c5ad31543f3383d66080efdd62", size = 300081, upload-time = "2026-09-16T00:16:52.423Z" }, + { url = "https://files.pythonhosted.org/packages/27/0d/c5090f9e6f67cbc30a2b744c7bb0f8006dcba5ec1b0d82f866ae1cc7c5c4/propcache-0.5.4-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:03969626faf0783a592dfa17e28eac06018bd0b44dafae6943d53b92421a7f72", size = 285360, upload-time = "2026-09-16T00:16:54.141Z" }, + { url = "https://files.pythonhosted.org/packages/ac/9c/34a55396910583ed07926669ab309dde2213a2dec05a7e946bb90ad66908/propcache-0.5.4-cp315-cp315t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:ef3b928d9c984322b5c44e6964d8dbc653da87d2d8ee1647fa6da43072e650a9", size = 248014, upload-time = "2026-09-16T00:16:56.062Z" }, + { url = "https://files.pythonhosted.org/packages/cd/b5/c0a142b656093ca397039dd3fe166cbb87c945712b534546514a24cd2611/propcache-0.5.4-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:7177c43eddf10a0893c4fec52ebb408fdcd7f7d63962caace9180d8f81b14ece", size = 280662, upload-time = "2026-09-16T00:16:58.044Z" }, + { url = "https://files.pythonhosted.org/packages/54/28/fab2809c2e337fe26becea9648e84d5cef46075c91b826acb13e4f9dd04e/propcache-0.5.4-cp315-cp315t-musllinux_1_2_armv7l.whl", hash = "sha256:420162a77f94eb1cf5ef7893f500016dabd548e73de956785a1dd899cc73006a", size = 266149, upload-time = "2026-09-16T00:16:59.702Z" }, + { url = "https://files.pythonhosted.org/packages/3a/11/7ddf336288b2678a5f054f8da2e2bd1a719f5d4b7de714d9c6bd588a2313/propcache-0.5.4-cp315-cp315t-musllinux_1_2_ppc64le.whl", hash = "sha256:3eb2e820e8e2101407da93f17c57cbb7d225461955fc60105daaba14cd421ee2", size = 283097, upload-time = "2026-09-16T00:17:01.459Z" }, + { url = "https://files.pythonhosted.org/packages/1a/ae/351b1a5225f5473c411d9a612a229ae147cf0cf65c72ad838b87219ea8e8/propcache-0.5.4-cp315-cp315t-musllinux_1_2_riscv64.whl", hash = "sha256:13e52b6e0bde97dee98ab66552dbff2931649c96f1ac432eac299fe689ec373b", size = 248160, upload-time = "2026-09-16T00:17:03.298Z" }, + { url = "https://files.pythonhosted.org/packages/3f/d0/7f79f061e30d135bb615c9782c94a74652033d00b49254edbbf35a9165a8/propcache-0.5.4-cp315-cp315t-musllinux_1_2_s390x.whl", hash = "sha256:12682126712ddc19b70ff819debbd279e58adf1f0c8f8f8138c18ade2044b284", size = 283036, upload-time = "2026-09-16T00:17:05.238Z" }, + { url = "https://files.pythonhosted.org/packages/53/3c/016f1cad8bf4c428d748cf399b2bac603026fbfd6966e6a5579b5c5b6956/propcache-0.5.4-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:3af0c8642b2da4815d86e631232ac8286e17644fad907c19508aa8e7cb4ba8ad", size = 279350, upload-time = "2026-09-16T00:17:06.881Z" }, + { url = "https://files.pythonhosted.org/packages/ea/60/d8f72cb24b412487ed4c397f539117d3b74c3c33dd32020e91fe00a958a8/propcache-0.5.4-cp315-cp315t-win32.whl", hash = "sha256:1df8d8561b21465c5dd56110a01caf897e026d065b4b84e98a488209094272ec", size = 45874, upload-time = "2026-09-16T00:17:08.567Z" }, + { url = "https://files.pythonhosted.org/packages/d4/ef/8bae0a316d406644450522f2f3d44a4e19632f5f3bb60d1d0e6c53842616/propcache-0.5.4-cp315-cp315t-win_amd64.whl", hash = "sha256:02c0a34f16889cf800f10f0247a564d8ce6eeab6ffcd7c87198f769067eb8432", size = 48574, upload-time = "2026-09-16T00:17:10.077Z" }, + { url = "https://files.pythonhosted.org/packages/57/be/bcc053f66a97355683884b448198e79580fae8e8fa4d96b9bb01614e9913/propcache-0.5.4-cp315-cp315t-win_arm64.whl", hash = "sha256:dc4242ca653c9b30ab51c5f8193323e7bc0928f897ee9103201e59a43abcb72e", size = 45625, upload-time = "2026-09-16T00:17:11.377Z" }, + { url = "https://files.pythonhosted.org/packages/f5/cd/785c64ed382f3f04201870267b02783f63b4678c2acfddc177a3ebcc2727/propcache-0.5.4-py3-none-any.whl", hash = "sha256:62c60aec739ed00124573cce1178138fd690c7676352d67a37328c1cf51d7468", size = 16338, upload-time = "2026-09-16T00:17:13.106Z" }, +] + +[[package]] +name = "proto-plus" +version = "1.29.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "protobuf" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/46/70/783e33ffbb4466cc154a94f79b869b92a451e2bd45605054e68ff68b7af6/proto_plus-1.29.0.tar.gz", hash = "sha256:cfb4e62ad7e13dd18f346cabbda00cab39930d36a05791fd81ddb074d6ee884f", size = 58592, upload-time = "2026-09-29T19:26:15.963Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b1/05/a3ef5b1161498e7b5a2a60288a9cf41b9149e94555423a43ec536737ac1a/proto_plus-1.29.0-py3-none-any.whl", hash = "sha256:8acd070469a7aaf43f440b022ef9757c8cac1a9f866e933f59ae98669ddc6c8b", size = 50786, upload-time = "2026-09-29T19:25:50.409Z" }, +] + +[[package]] +name = "protobuf" +version = "7.36.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d9/89/5b8517baa72f84a67b8a307ba953c91057af618bf40bf676f3c03551f8f0/protobuf-7.36.2.tar.gz", hash = "sha256:497d0463ff3316681da6c0b9e8d06cb465d61abce00b613ab42226175644d1bb", size = 512737, upload-time = "2026-09-17T20:07:59.326Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/32/72/98342feb672507c8f3a69e34b4fa8961f608edba5c1a48a6f47156d92cb5/protobuf-7.36.2-cp310-abi3-macosx_10_9_universal2.whl", hash = "sha256:cbc70b17ee27e28894c7fee8bb04be1abead49e936bc70eb60052531eee2079e", size = 456039, upload-time = "2026-09-17T20:07:51.542Z" }, + { url = "https://files.pythonhosted.org/packages/b6/ea/91fdf7c2b8bbd49cde056f00a9df6773532987e1c00fe2830b895af95c7e/protobuf-7.36.2-cp310-abi3-manylinux2014_aarch64.whl", hash = "sha256:e11e1f0180583a2af89db6a2ecd9e8dc40aa6d2988ca175bfd0e6d12ea72d74e", size = 344219, upload-time = "2026-09-17T20:07:52.914Z" }, + { url = "https://files.pythonhosted.org/packages/17/ab/5fd5f8ece73fad885c5a09aa849b32d70472f954ba3a92d3bb5974ea953b/protobuf-7.36.2-cp310-abi3-manylinux2014_s390x.whl", hash = "sha256:f4fee11ec330d238b34a05c9b675f693c20415d1c5bd7d5320cc2f8a798eb9cf", size = 357223, upload-time = "2026-09-17T20:07:53.985Z" }, + { url = "https://files.pythonhosted.org/packages/db/f3/3996583dd2906297a637af12114deddf7658af6e683fedb83be061983fb5/protobuf-7.36.2-cp310-abi3-manylinux2014_x86_64.whl", hash = "sha256:89f23aa53c24553a2416fd4fd1ec06f74fa42b14b546d8883128813f775bbfd2", size = 343223, upload-time = "2026-09-17T20:07:54.931Z" }, + { url = "https://files.pythonhosted.org/packages/fc/1b/dcc64f358fcb51811b58ae40b3d28f820725f116d86487cc20bd4b130701/protobuf-7.36.2-cp310-abi3-win32.whl", hash = "sha256:912c1221170e16c08d1f086762f563dd61ff83c18b5fa6652952dfaded66f728", size = 442998, upload-time = "2026-09-17T20:07:55.826Z" }, + { url = "https://files.pythonhosted.org/packages/8a/55/b77bda4e5e5f5971fb51b07663694690e9afdb9402136c16a522bd621cad/protobuf-7.36.2-cp310-abi3-win_amd64.whl", hash = "sha256:a300819d441e078a5608c0d3c709796bb548136058fda017ae51d425b44fd353", size = 456514, upload-time = "2026-09-17T20:07:57.188Z" }, + { url = "https://files.pythonhosted.org/packages/e4/04/d52c7016b04b6c5108f26691f9d33ec82a9b65d041f1a9c771137693d618/protobuf-7.36.2-py3-none-any.whl", hash = "sha256:bdb3a345d48db958e6ce1f18e508beb0cc981d64f24088427549c866cd039f1e", size = 179806, upload-time = "2026-09-17T20:07:58.211Z" }, +] + +[[package]] +name = "psutil" +version = "7.2.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/aa/c6/d1ddf4abb55e93cebc4f2ed8b5d6dbad109ecb8d63748dd2b20ab5e57ebe/psutil-7.2.2.tar.gz", hash = "sha256:0746f5f8d406af344fd547f1c8daa5f5c33dbc293bb8d6a16d80b4bb88f59372", size = 493740, upload-time = "2026-01-28T18:14:54.428Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/51/08/510cbdb69c25a96f4ae523f733cdc963ae654904e8db864c07585ef99875/psutil-7.2.2-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:2edccc433cbfa046b980b0df0171cd25bcaeb3a68fe9022db0979e7aa74a826b", size = 130595, upload-time = "2026-01-28T18:14:57.293Z" }, + { url = "https://files.pythonhosted.org/packages/d6/f5/97baea3fe7a5a9af7436301f85490905379b1c6f2dd51fe3ecf24b4c5fbf/psutil-7.2.2-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:e78c8603dcd9a04c7364f1a3e670cea95d51ee865e4efb3556a3a63adef958ea", size = 131082, upload-time = "2026-01-28T18:14:59.732Z" }, + { url = "https://files.pythonhosted.org/packages/37/d6/246513fbf9fa174af531f28412297dd05241d97a75911ac8febefa1a53c6/psutil-7.2.2-cp313-cp313t-manylinux2010_x86_64.manylinux_2_12_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1a571f2330c966c62aeda00dd24620425d4b0cc86881c89861fbc04549e5dc63", size = 181476, upload-time = "2026-01-28T18:15:01.884Z" }, + { url = "https://files.pythonhosted.org/packages/b8/b5/9182c9af3836cca61696dabe4fd1304e17bc56cb62f17439e1154f225dd3/psutil-7.2.2-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:917e891983ca3c1887b4ef36447b1e0873e70c933afc831c6b6da078ba474312", size = 184062, upload-time = "2026-01-28T18:15:04.436Z" }, + { url = "https://files.pythonhosted.org/packages/16/ba/0756dca669f5a9300d0cbcbfae9a4c30e446dfc7440ffe43ded5724bfd93/psutil-7.2.2-cp313-cp313t-win_amd64.whl", hash = "sha256:ab486563df44c17f5173621c7b198955bd6b613fb87c71c161f827d3fb149a9b", size = 139893, upload-time = "2026-01-28T18:15:06.378Z" }, + { url = "https://files.pythonhosted.org/packages/1c/61/8fa0e26f33623b49949346de05ec1ddaad02ed8ba64af45f40a147dbfa97/psutil-7.2.2-cp313-cp313t-win_arm64.whl", hash = "sha256:ae0aefdd8796a7737eccea863f80f81e468a1e4cf14d926bd9b6f5f2d5f90ca9", size = 135589, upload-time = "2026-01-28T18:15:08.03Z" }, + { url = "https://files.pythonhosted.org/packages/81/69/ef179ab5ca24f32acc1dac0c247fd6a13b501fd5534dbae0e05a1c48b66d/psutil-7.2.2-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:eed63d3b4d62449571547b60578c5b2c4bcccc5387148db46e0c2313dad0ee00", size = 130664, upload-time = "2026-01-28T18:15:09.469Z" }, + { url = "https://files.pythonhosted.org/packages/7b/64/665248b557a236d3fa9efc378d60d95ef56dd0a490c2cd37dafc7660d4a9/psutil-7.2.2-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:7b6d09433a10592ce39b13d7be5a54fbac1d1228ed29abc880fb23df7cb694c9", size = 131087, upload-time = "2026-01-28T18:15:11.724Z" }, + { url = "https://files.pythonhosted.org/packages/d5/2e/e6782744700d6759ebce3043dcfa661fb61e2fb752b91cdeae9af12c2178/psutil-7.2.2-cp314-cp314t-manylinux2010_x86_64.manylinux_2_12_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1fa4ecf83bcdf6e6c8f4449aff98eefb5d0604bf88cb883d7da3d8d2d909546a", size = 182383, upload-time = "2026-01-28T18:15:13.445Z" }, + { url = "https://files.pythonhosted.org/packages/57/49/0a41cefd10cb7505cdc04dab3eacf24c0c2cb158a998b8c7b1d27ee2c1f5/psutil-7.2.2-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:e452c464a02e7dc7822a05d25db4cde564444a67e58539a00f929c51eddda0cf", size = 185210, upload-time = "2026-01-28T18:15:16.002Z" }, + { url = "https://files.pythonhosted.org/packages/dd/2c/ff9bfb544f283ba5f83ba725a3c5fec6d6b10b8f27ac1dc641c473dc390d/psutil-7.2.2-cp314-cp314t-win_amd64.whl", hash = "sha256:c7663d4e37f13e884d13994247449e9f8f574bc4655d509c3b95e9ec9e2b9dc1", size = 141228, upload-time = "2026-01-28T18:15:18.385Z" }, + { url = "https://files.pythonhosted.org/packages/f2/fc/f8d9c31db14fcec13748d373e668bc3bed94d9077dbc17fb0eebc073233c/psutil-7.2.2-cp314-cp314t-win_arm64.whl", hash = "sha256:11fe5a4f613759764e79c65cf11ebdf26e33d6dd34336f8a337aa2996d71c841", size = 136284, upload-time = "2026-01-28T18:15:19.912Z" }, + { url = "https://files.pythonhosted.org/packages/e7/36/5ee6e05c9bd427237b11b3937ad82bb8ad2752d72c6969314590dd0c2f6e/psutil-7.2.2-cp36-abi3-macosx_10_9_x86_64.whl", hash = "sha256:ed0cace939114f62738d808fdcecd4c869222507e266e574799e9c0faa17d486", size = 129090, upload-time = "2026-01-28T18:15:22.168Z" }, + { url = "https://files.pythonhosted.org/packages/80/c4/f5af4c1ca8c1eeb2e92ccca14ce8effdeec651d5ab6053c589b074eda6e1/psutil-7.2.2-cp36-abi3-macosx_11_0_arm64.whl", hash = "sha256:1a7b04c10f32cc88ab39cbf606e117fd74721c831c98a27dc04578deb0c16979", size = 129859, upload-time = "2026-01-28T18:15:23.795Z" }, + { url = "https://files.pythonhosted.org/packages/b5/70/5d8df3b09e25bce090399cf48e452d25c935ab72dad19406c77f4e828045/psutil-7.2.2-cp36-abi3-manylinux2010_x86_64.manylinux_2_12_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:076a2d2f923fd4821644f5ba89f059523da90dc9014e85f8e45a5774ca5bc6f9", size = 155560, upload-time = "2026-01-28T18:15:25.976Z" }, + { url = "https://files.pythonhosted.org/packages/63/65/37648c0c158dc222aba51c089eb3bdfa238e621674dc42d48706e639204f/psutil-7.2.2-cp36-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b0726cecd84f9474419d67252add4ac0cd9811b04d61123054b9fb6f57df6e9e", size = 156997, upload-time = "2026-01-28T18:15:27.794Z" }, + { url = "https://files.pythonhosted.org/packages/8e/13/125093eadae863ce03c6ffdbae9929430d116a246ef69866dad94da3bfbc/psutil-7.2.2-cp36-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:fd04ef36b4a6d599bbdb225dd1d3f51e00105f6d48a28f006da7f9822f2606d8", size = 148972, upload-time = "2026-01-28T18:15:29.342Z" }, + { url = "https://files.pythonhosted.org/packages/04/78/0acd37ca84ce3ddffaa92ef0f571e073faa6d8ff1f0559ab1272188ea2be/psutil-7.2.2-cp36-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:b58fabe35e80b264a4e3bb23e6b96f9e45a3df7fb7eed419ac0e5947c61e47cc", size = 148266, upload-time = "2026-01-28T18:15:31.597Z" }, + { url = "https://files.pythonhosted.org/packages/b4/90/e2159492b5426be0c1fef7acba807a03511f97c5f86b3caeda6ad92351a7/psutil-7.2.2-cp37-abi3-win_amd64.whl", hash = "sha256:eb7e81434c8d223ec4a219b5fc1c47d0417b12be7ea866e24fb5ad6e84b3d988", size = 137737, upload-time = "2026-01-28T18:15:33.849Z" }, + { url = "https://files.pythonhosted.org/packages/8c/c7/7bb2e321574b10df20cbde462a94e2b71d05f9bbda251ef27d104668306a/psutil-7.2.2-cp37-abi3-win_arm64.whl", hash = "sha256:8c233660f575a5a89e6d4cb65d9f938126312bca76d8fe087b947b3a1aaac9ee", size = 134617, upload-time = "2026-01-28T18:15:36.514Z" }, +] + +[[package]] +name = "pyasn1" +version = "0.6.5" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/88/7e/3c0da41061a2021cac7cd524fd57092adbe5b515e8bf9005702e366802e2/pyasn1-0.6.5.tar.gz", hash = "sha256:6b11616a6bcf3a40e635f082bb232fa57b5e0dd7f517bd7ddd69ec3794508a47", size = 155152, upload-time = "2026-10-27T06:32:49.125Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/19/1f/3eefd5c84c35cae44549ce1c7f7e58f7945b34f5a6bce07a135438522073/pyasn1-0.6.5-py3-none-any.whl", hash = "sha256:4017b0fce125096b8573b39c989fdb1a4b19cf761e683398184550fea0e66587", size = 84807, upload-time = "2026-10-27T06:32:48.045Z" }, +] + +[[package]] +name = "pyasn1-modules" +version = "0.4.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pyasn1" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/e9/e6/78ebbb10a8c8e4b61a59249394a4a594c1a7af95593dc933a349c8d00964/pyasn1_modules-0.4.2.tar.gz", hash = "sha256:677091de870a80aae844b1ca6134f54652fa2c8c5a52aa396440ac3106e941e6", size = 307892, upload-time = "2025-03-28T02:41:22.17Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/47/8d/d529b5d697919ba8c11ad626e835d4039be708a35b0d22de83a269a6682c/pyasn1_modules-0.4.2-py3-none-any.whl", hash = "sha256:29253a9207ce32b64c3ac6600edc75368f98473906e8fd1043bd6b5b1de2c14a", size = 181259, upload-time = "2025-03-28T02:41:19.028Z" }, +] + +[[package]] +name = "pycparser" +version = "3.12" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/cb/27/eeb9f307bf07060f3d9f9aa0fb8c15b01bdfded0a941e4b2719c7f94cacd/pycparser-3.12.tar.gz", hash = "sha256:f03387877eab82ce01bbdfd0ba7252ee55a90b1c708d5129e2ce915475cf1db6", size = 158785, upload-time = "2026-10-22T13:40:03.56Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b6/ae/315bbeee126a769cbde43cf4908acb4b40408d8bf8bbf334dd7368d8dadf/pycparser-3.12-py3-none-any.whl", hash = "sha256:a076f3f489b39b43ed13563a1dafe42447445bec2e294154ec5c57fcdda4c85e", size = 62600, upload-time = "2026-10-22T13:40:02.021Z" }, +] + +[[package]] +name = "pycryptodome" +version = "4.4.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/51/f2/ccbeb91d186b2323fc99986499d2da3caab2151b1c2fb2ef74f7488d8934/pycryptodome-4.4.0.tar.gz", hash = "sha256:eab7620c60c85f3fa251d026ec06e094f036d96187bebb9752e46fbcebabbb55", size = 1825611, upload-time = "2026-11-07T11:05:20.015Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ce/78/4bfdfa038f8c1a3b919bfd3445c79b1a9961b5373bdedd06d0e3c9057f17/pycryptodome-4.4.0-cp315-cp315t-macosx_10_15_universal2.whl", hash = "sha256:e05f6674230a0cb83a6f739af78eceec720e07659c782a080a56e087f69ef7ea", size = 1796557, upload-time = "2026-11-07T11:04:16.706Z" }, + { url = "https://files.pythonhosted.org/packages/a9/1b/03970e31dd6eabcf4ef49f3fbb4f378fb425168af9b6e248481cf50fe32b/pycryptodome-4.4.0-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:0783209214923f651fe875a47359bf454c23eea2da994376ce8785345fca52c3", size = 1550788, upload-time = "2026-11-07T11:04:19.795Z" }, + { url = "https://files.pythonhosted.org/packages/50/b4/80d77679233e5d793606bc9bd50acbc71a6200279cd03f57c3a8f929ddd0/pycryptodome-4.4.0-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:24bba57ddd268dfcbdeba8ac07b99c89a18243b2cd24a9a9e9b6278a554f9fb5", size = 2533691, upload-time = "2026-11-07T11:04:21.782Z" }, + { url = "https://files.pythonhosted.org/packages/90/b2/c882b63bd59ffbf3e555042a3638b3b15e7333c721383691f816d017053d/pycryptodome-4.4.0-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:7f8a06192031deafb54e311b44cb2f84e54ec61886d6869442bc443fa43edde3", size = 3053895, upload-time = "2026-11-07T11:04:24.209Z" }, + { url = "https://files.pythonhosted.org/packages/af/3f/d6ecd250856175f1603fe7b0f4f96205145dffe02d8eeef60856629344f6/pycryptodome-4.4.0-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:a85907762173d05a02e9e4591a50e0add0012175c36e0d7ecaecd0bf9bdf9ec2", size = 2563299, upload-time = "2026-11-07T11:04:26.66Z" }, + { url = "https://files.pythonhosted.org/packages/98/aa/37884e1d0f495554372a9d50d3fb2a618915c51a32babc385f2ba3c5b940/pycryptodome-4.4.0-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:42c6ff8f4ff3a6a45dcc035ffbfa699015549f7dfc7baf7511c1c8bcad466191", size = 3614130, upload-time = "2026-11-07T11:04:29.339Z" }, + { url = "https://files.pythonhosted.org/packages/b8/7c/3ce58410bc1312e20092d1308f0bd1f61e35412d00fc99cfe7c9ccfe0e0b/pycryptodome-4.4.0-cp315-cp315t-win32.whl", hash = "sha256:4422c0dd60b5ab228fbd11c1c1f4e4fb78130cbd0e65122e5ad0820b2ce9c940", size = 1333256, upload-time = "2026-11-07T11:04:31.402Z" }, + { url = "https://files.pythonhosted.org/packages/ae/5b/750455707ab342fd4e0c30a847c2f282c5a385b502c2e7545ad0a7ae8e0b/pycryptodome-4.4.0-cp315-cp315t-win_amd64.whl", hash = "sha256:24c2242884a985e45d6a2dcd9344dfe415856dd562ae53f65c8c1e9fc05aaf36", size = 1719003, upload-time = "2026-11-07T11:04:33.411Z" }, + { url = "https://files.pythonhosted.org/packages/29/66/8ea2c501563da4f4a832b6f168adb4bb67633828605fad60088891e29e49/pycryptodome-4.4.0-cp315-cp315t-win_arm64.whl", hash = "sha256:cd578ee99a6e4b8ba66064092372f2a88344bb42fc4e624ce71152ac25fd9c29", size = 1405144, upload-time = "2026-11-07T11:04:35.362Z" }, + { url = "https://files.pythonhosted.org/packages/cb/34/5165cc1660fccae5341c3f4d60c4fa1cc28b1a599e88145085a690d4a88b/pycryptodome-4.4.0-cp39-abi3-macosx_10_9_universal2.whl", hash = "sha256:99494a2ab8137a9a6967db30e21f54f6dfa70327d8e72863638dece6d6a16374", size = 1790964, upload-time = "2026-11-07T11:04:37.507Z" }, + { url = "https://files.pythonhosted.org/packages/9c/72/77f8fbdbc3827e11b458ec77728fd6102a7302c6f22e715fd7d7f8af0efc/pycryptodome-4.4.0-cp39-abi3-macosx_10_9_x86_64.whl", hash = "sha256:d6314c461a4bfcc341926daec45ef7c2b87668bcf9cd8bed81df906f4e8ed083", size = 1543809, upload-time = "2026-11-07T11:04:39.908Z" }, + { url = "https://files.pythonhosted.org/packages/58/a4/b7855e7f7c234a79543ce4b8367e49a1787fa8ece7ac1f92d47dbd69088c/pycryptodome-4.4.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:33e69ac53f745e5d1c8f06dc9b0d43a8236d2026f6de7a19e1a160aa307d933b", size = 2529505, upload-time = "2026-11-07T11:04:41.793Z" }, + { url = "https://files.pythonhosted.org/packages/0f/ea/347345577742b4521ba5c43ddd8ee353225802e89fe5fa7b1fb6caba2379/pycryptodome-4.4.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:32c1a3d98c93d92c2f2a45d6cc9c79fb8d7552aca1bd9a764209a3309bf6a7b1", size = 3041717, upload-time = "2026-11-07T11:04:43.859Z" }, + { url = "https://files.pythonhosted.org/packages/f1/98/588d439b4a28acbba456cee8cdb37527e4e1a09a1e08f2d78394328ef2e8/pycryptodome-4.4.0-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:b08782bf3133b08181cd720843ce05a73856c4d8fdf42eb3eef766e70bcf75c1", size = 2553311, upload-time = "2026-11-07T11:04:46.095Z" }, + { url = "https://files.pythonhosted.org/packages/30/10/8b7caf712e967f42226fb73bd43634d9ff8dac81d4cfe5e32b492f3ea9cf/pycryptodome-4.4.0-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:1f14824e99c1aedee8420fd10027ffa0c0fbf2913287c3cf002fd6e19eb5f934", size = 3605320, upload-time = "2026-11-07T11:04:48.852Z" }, + { url = "https://files.pythonhosted.org/packages/6c/9d/4a87fad295f76a459121ca41705d7ca5a6c53032f2ce6100d5b954fa15ba/pycryptodome-4.4.0-cp39-abi3-win32.whl", hash = "sha256:30ed79eceb765717609f96232a156fc6ea8ae1cb91d1b995d52af75220a2b148", size = 1320002, upload-time = "2026-11-07T11:04:50.739Z" }, + { url = "https://files.pythonhosted.org/packages/5b/28/1efce23b96b9549e40b7435b96f0ceec427b50abac4ff10c50ad0163408d/pycryptodome-4.4.0-cp39-abi3-win_amd64.whl", hash = "sha256:c5571df4f386ff4cdc0d5d0d040af9c0bdfc59ad587bf224063d873e07acbe61", size = 1689644, upload-time = "2026-11-07T11:04:52.972Z" }, + { url = "https://files.pythonhosted.org/packages/09/84/5df94591578dcaeb884fc39e2c2dc72646ade1e07c452671b06e37b344ec/pycryptodome-4.4.0-cp39-abi3-win_arm64.whl", hash = "sha256:56618bc56f3ddccfd30997c1b8edfcb3e2841f48af6fe963487255cd413e039e", size = 1377059, upload-time = "2026-11-07T11:04:54.807Z" }, + { url = "https://files.pythonhosted.org/packages/42/7d/7373c7d2e2a241761bfa0aaa5fa4092cc832a382a18b67ba0009c25c895f/pycryptodome-4.4.0-pp311-pypy311_pp80-macosx_10_15_x86_64.whl", hash = "sha256:8b666f5319e1f3014520ac7c56bc6c43084cf040606fa044cd47be40ecb4b6cb", size = 1499571, upload-time = "2026-11-07T11:05:04.447Z" }, + { url = "https://files.pythonhosted.org/packages/75/62/388e511275a30ff6a2465df3b5398131d25194ccccb7d91ef3aed19699a7/pycryptodome-4.4.0-pp311-pypy311_pp80-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1589c86a3daa78c006ce27b7d83b56f0127e09a7386348b016c02aa14c18f39d", size = 1325042, upload-time = "2026-11-07T11:05:06.07Z" }, + { url = "https://files.pythonhosted.org/packages/d8/15/9144a7a147ceb5a77d4c1fb59569f0cb9f051c0d7e86947a9407a7ce9185/pycryptodome-4.4.0-pp311-pypy311_pp80-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3a6a5ad829fbb7fda1145001f04b40fdc4a230c08b96c127d7c72771671c5a55", size = 1458092, upload-time = "2026-11-07T11:05:07.721Z" }, + { url = "https://files.pythonhosted.org/packages/72/44/09420d5bdae3d487d2b2a7ff109db70bc005fc6fb8d9d92f9d56a62bcd04/pycryptodome-4.4.0-pp311-pypy311_pp80-win_amd64.whl", hash = "sha256:6ac45473f76982b7d72c3f673b9ee0b31ff20885647ce3672d45bb206c958675", size = 1693238, upload-time = "2026-11-07T11:05:09.652Z" }, + { url = "https://files.pythonhosted.org/packages/26/f3/451e4e9bed44c2d66efe66a959e1ca8ec8e90fa717e17977f533814052bf/pycryptodome-4.4.0-pp312-pypy312_pp80-macosx_10_15_x86_64.whl", hash = "sha256:f367ff0d0fd70d42239cf27e495fa0cd5f86ea5b6dd04b0991b4acb9067e6a52", size = 1499557, upload-time = "2026-11-07T11:05:11.605Z" }, + { url = "https://files.pythonhosted.org/packages/48/91/ae2108585d9ab88e45934ff2dd54bfd818d44db6dba68c0195c890a3db47/pycryptodome-4.4.0-pp312-pypy312_pp80-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:d1acfd5447a4e3ba4ebf20a98e737b5d99b083b395829cbb60fa789bf9ce238d", size = 1325038, upload-time = "2026-11-07T11:05:14.064Z" }, + { url = "https://files.pythonhosted.org/packages/a2/44/7d8450968180ea6f454f19135e3039be862f52c7c58c547ce88ba52714e6/pycryptodome-4.4.0-pp312-pypy312_pp80-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:6992f441f52672d493ea8f52562a5c3582b52a028ecf8e2d8daf93be0c4a16e9", size = 1458093, upload-time = "2026-11-07T11:05:15.922Z" }, + { url = "https://files.pythonhosted.org/packages/e8/dd/688876067ce5fd6238cac501cb5df6bda5d2c014e0298967a023d9375a27/pycryptodome-4.4.0-pp312-pypy312_pp80-win_amd64.whl", hash = "sha256:d6e2c3a55ffa8abc77880a1ce2c319d72e328785e63c925d6a31f5a80a9a2975", size = 1693237, upload-time = "2026-11-07T11:05:17.854Z" }, +] + +[[package]] +name = "pydantic" +version = "2.14.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "annotated-types" }, + { name = "pydantic-core" }, + { name = "typing-extensions" }, + { name = "typing-inspection" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/b4/fc/1203d011145c98ddce3cd2f505bb54375ef8d43223053df6bfcf3c746f46/pydantic-2.14.3.tar.gz", hash = "sha256:1054f237f4d4733e5a30e1e2333bd33a2004ab9ab1510bd053a9a31bb48e232d", size = 925636, upload-time = "2026-11-05T09:17:04.686Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/72/b8/b864503789ef5c58597d2a7b4adbee62c26440ab1e682581fc6838df8947/pydantic-2.14.3-py3-none-any.whl", hash = "sha256:3f7b347782ab7e4cf4c798496ae3a82787d9f21ec12676a9c564355eeef8daa8", size = 494071, upload-time = "2026-11-05T09:17:02.426Z" }, +] + +[[package]] +name = "pydantic-core" +version = "2.50.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9c/0f/34f9ce4ba701dd0b815033ef94d99b56f66200e578ee6052aa3ac26f064e/pydantic_core-2.50.4.tar.gz", hash = "sha256:aead3b74b68396bf0feab5d57e050b730ded7df55853c1e048a87e00aaf033c6", size = 522249, upload-time = "2026-11-05T09:15:26.774Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/df/00/85e80811834d7cbd9bc228f9b5cdf8ec0edd69b55351ad720aac8c412d8c/pydantic_core-2.50.4-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:3e547ceec1da7382f01f9e13963023e53367a71802c88778b21b9645a077cbdf", size = 2170584, upload-time = "2026-11-05T09:11:41.139Z" }, + { url = "https://files.pythonhosted.org/packages/a3/f1/438de1fb99d717dcc6521922478dc16ef7b757302d4fc1f7faba3aaeac09/pydantic_core-2.50.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:c813ada7a651193acda85b6bc1cf12abd4b37cd25c7c6a75d7183512cc374969", size = 2128471, upload-time = "2026-11-05T09:11:42.65Z" }, + { url = "https://files.pythonhosted.org/packages/b7/74/f21ab568c6d3f315988b40e53f809c95b63fafc5403332963aa6dfc2c054/pydantic_core-2.50.4-cp311-cp311-manylinux1_i686.manylinux_2_5_i686.whl", hash = "sha256:57fa0a9490785139f1a4e4f43891830d55dfe4408845c0c9cb5eff4aeaf75f69", size = 2281509, upload-time = "2026-11-05T09:11:44.359Z" }, + { url = "https://files.pythonhosted.org/packages/a1/42/24ed3ea8e2fb6463c9ba5b8b1f089e69040905c7fd81dcfa6f52fcc692d5/pydantic_core-2.50.4-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:30d4dc35bc0eea52202a90b3820445ee0072c820241bfa710a623a078c9b267b", size = 2128064, upload-time = "2026-11-05T09:11:46.01Z" }, + { url = "https://files.pythonhosted.org/packages/d6/d1/44f541b2c18a46df6f18281a557acefeb5bbf0733a0b80b0a5e835e10ee4/pydantic_core-2.50.4-cp311-cp311-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:789f88dea57841cdebef392b5d6e90444d767117e9ff2e0d9172df5c9de6690c", size = 2214472, upload-time = "2026-11-05T09:11:47.503Z" }, + { url = "https://files.pythonhosted.org/packages/bd/1b/e9a9ad8733e8051abca9e4acce37ba3ddd13930fd3b8730f4c7816fa979a/pydantic_core-2.50.4-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:d690121e80ab16e623415351ab24713534d4e500b3cadff216409cb6826063d4", size = 2401153, upload-time = "2026-11-05T09:11:49.403Z" }, + { url = "https://files.pythonhosted.org/packages/79/84/d88e8e6aa42d4d677666d6625db9177ad6851be9e7564a25aeb0b0cbcaf2/pydantic_core-2.50.4-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:b42f64825f5d750228f08318a9bf4d723b7ecb4c472aedcb3013c3ec2dc1f949", size = 2453307, upload-time = "2026-11-05T09:11:51.118Z" }, + { url = "https://files.pythonhosted.org/packages/56/51/cbb7a1bc0196ff94d3478d265eed7449f811759988eb760d41f4edd0893b/pydantic_core-2.50.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:0574866e05f6adeecc520d87e87dd06210c0a51706341f6ef8421572f5a64444", size = 2253434, upload-time = "2026-11-05T09:11:52.997Z" }, + { url = "https://files.pythonhosted.org/packages/9e/04/206b4881d631033ae88f005da6e11bd610c850e1850217342c03053d253b/pydantic_core-2.50.4-cp311-cp311-manylinux_2_31_riscv64.whl", hash = "sha256:dcf2c7eaaa4cafe8e49b017e5bb49e76e084ab6f0cd712ee4019c812b5cf68b8", size = 2279365, upload-time = "2026-11-05T09:11:54.822Z" }, + { url = "https://files.pythonhosted.org/packages/a1/7c/d815b5a3f83069b283d3b6a2e61de6e14baac3b20c6cd3418e9e629551cf/pydantic_core-2.50.4-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:3b8ee2589a082739c522c1fe4be227412fcf108b903abb6672ae2f5570558882", size = 2319407, upload-time = "2026-11-05T09:11:56.46Z" }, + { url = "https://files.pythonhosted.org/packages/ee/00/c9a483276d1052d5142e1e01eccac97d939f83a3a3fd94c4766495a9b807/pydantic_core-2.50.4-cp311-cp311-musllinux_1_1_armv7l.whl", hash = "sha256:aec3c2d741a8e3ee993de7f95f37afb51e31b169c95dbd29da4cf6688f340914", size = 2489900, upload-time = "2026-11-05T09:11:58.102Z" }, + { url = "https://files.pythonhosted.org/packages/2d/b5/8cd8ee29a1d63ad47f95593384df92476cef6896c644f280db0748b8e76b/pydantic_core-2.50.4-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:8923fcd49f875e8a0448d7223d1fdf1a9973ae2d1f20d4158753ceb8909facd2", size = 2497732, upload-time = "2026-11-05T09:11:59.928Z" }, + { url = "https://files.pythonhosted.org/packages/60/31/050a48c0c373df16442ac07f3fa167414bb0e22f54a3e886f6d6cb7ad1d4/pydantic_core-2.50.4-cp311-cp311-win32.whl", hash = "sha256:fc04affef30be98c1f36f0c422a4061ef618fdc1dde79f5ad5458dd496fecffa", size = 2132347, upload-time = "2026-11-05T09:12:01.928Z" }, + { url = "https://files.pythonhosted.org/packages/c6/06/cebeeb7a8e87b42a3d8bc189d0d400e47df5d1736cb326764bae8a74c433/pydantic_core-2.50.4-cp311-cp311-win_amd64.whl", hash = "sha256:15bece43a02ad543c621c8305e67dedb5f27d378c5ba741e5a2c36523f8ef37f", size = 2255970, upload-time = "2026-11-05T09:12:03.888Z" }, + { url = "https://files.pythonhosted.org/packages/46/db/5b4bf14347da658c994483043fbabffedcab98929c41c261ec168c3c1f87/pydantic_core-2.50.4-cp311-cp311-win_arm64.whl", hash = "sha256:e498900bfbf7ddddd862f810440c09e9b81674739e8a11d619b40906dccd4a9a", size = 2196799, upload-time = "2026-11-05T09:12:05.389Z" }, + { url = "https://files.pythonhosted.org/packages/10/bf/d1f6b81709538f831ebe1c42f50fb89db3dfda06f9e9b1ea24e90fc69209/pydantic_core-2.50.4-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:32a991aebd165f227b7c7c60bb9d66c2c7de9c24308552da264c9938fde0f8d6", size = 2231444, upload-time = "2026-11-05T09:12:06.969Z" }, + { url = "https://files.pythonhosted.org/packages/c1/39/6618e541658d5a687a8d4962fc304350073a8f322bc4c62e8ed4c2d514d6/pydantic_core-2.50.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1e20cbde2b6deb33a51d08cd168454dd9044ec7d4474056f4d98d63f51578783", size = 2108048, upload-time = "2026-11-05T09:12:08.85Z" }, + { url = "https://files.pythonhosted.org/packages/d9/54/1c941fffa4e14bfc9ab0cd4977075f0e03201447856130d08a33cd45e47b/pydantic_core-2.50.4-cp312-cp312-manylinux1_i686.manylinux_2_5_i686.whl", hash = "sha256:8cceae48ae7f94990c2f4e36291e9ec9868735e8b0f19e4489a17b0422338466", size = 2256866, upload-time = "2026-11-05T09:12:10.495Z" }, + { url = "https://files.pythonhosted.org/packages/61/a0/8028ef3e014be522ce43060aeac82a5be2288215e660866f5e6260acc123/pydantic_core-2.50.4-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:16902a147b3da4840612164a5e67947104d63e978f7a57c395877a5e26690b9c", size = 2125682, upload-time = "2026-11-05T09:12:12.278Z" }, + { url = "https://files.pythonhosted.org/packages/c3/f2/b98bb73b1734ec4e42e786a766abc24f3c89620a0ddbaf8aa14e4b4c628c/pydantic_core-2.50.4-cp312-cp312-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:d6e3485a5e5c01fb5339c1ee3d4b9e21e2135a2a9d44caafb71acd994487ee7c", size = 2197108, upload-time = "2026-11-05T09:12:13.873Z" }, + { url = "https://files.pythonhosted.org/packages/f1/d1/7a7142786781400143e8806633fe5b65e2d407c311041fc9494490f05b18/pydantic_core-2.50.4-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:629eae995185540406e3635df5d5cf1d44f19ea240840b835d3f44541ff694d8", size = 2380521, upload-time = "2026-11-05T09:12:15.539Z" }, + { url = "https://files.pythonhosted.org/packages/b5/34/cf710ca48d4498b04a3ea605d45892675dc2b14a94a25121a8d03f56d3e9/pydantic_core-2.50.4-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:41b2cd8b29dbb5a4c9828a70f50d1abfc92011115c813213d3a91205c6f731b3", size = 2457436, upload-time = "2026-11-05T09:12:17.447Z" }, + { url = "https://files.pythonhosted.org/packages/91/23/e0c6e3cd09a0ac809953fea698c816b9f03bf0b35b6820c9553e4f5d85a8/pydantic_core-2.50.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c81d98e27d9d9261909dcccab1ba5d6ea1c98b0bb9470e368604614fd1d36ddd", size = 2261727, upload-time = "2026-11-05T09:12:19.097Z" }, + { url = "https://files.pythonhosted.org/packages/f9/00/292a0ed96d5d2d6edb49468ef481336e5b7e54f13435d73b7c912c891c23/pydantic_core-2.50.4-cp312-cp312-manylinux_2_31_riscv64.whl", hash = "sha256:ca83a32b2b41653d89f09a3d22b770bca96da72273bef8f7a68136bdd1e8b823", size = 2262071, upload-time = "2026-11-05T09:12:20.78Z" }, + { url = "https://files.pythonhosted.org/packages/f8/36/d4690faf8c082eacf7754e52ab6bebe1bc73b167272e28699c00480ee908/pydantic_core-2.50.4-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:817953730e4a73a09008b010c4a42396cefe799616a22df2ac21d3927b3080cf", size = 2298931, upload-time = "2026-11-05T09:12:22.614Z" }, + { url = "https://files.pythonhosted.org/packages/21/17/b180af6d17cf6c8e0d3d2661fc501a4a40959744ca4947d6ad0db81b1416/pydantic_core-2.50.4-cp312-cp312-musllinux_1_1_armv7l.whl", hash = "sha256:664e74848c2f5fc27db8505fe24e1ecd3ac669412913bf73d176916f86cc08e2", size = 2474285, upload-time = "2026-11-05T09:12:24.842Z" }, + { url = "https://files.pythonhosted.org/packages/6e/bb/7e44d4ac6e1292f1859384c688713045bdf5448e0635c49c003d2be3bb6c/pydantic_core-2.50.4-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:219114f8dcdcbe4720d82ef016b1287ce5a0a67d7c69ca61524eb72e82aac344", size = 2498172, upload-time = "2026-11-05T09:12:26.434Z" }, + { url = "https://files.pythonhosted.org/packages/d8/84/5101f35294579c4bef7dc32fd4f097d91eedac2e195894266bdabc1e6dfd/pydantic_core-2.50.4-cp312-cp312-win32.whl", hash = "sha256:67f7cc397e1d5556a801d1cba74de0d27d827eb242e6c036c0ca273c745414f1", size = 2119592, upload-time = "2026-11-05T09:12:27.971Z" }, + { url = "https://files.pythonhosted.org/packages/82/88/d438a8fcf3738e9ff2670f724047ca3893ec899bcd5cdfc077a2aab133c6/pydantic_core-2.50.4-cp312-cp312-win_amd64.whl", hash = "sha256:ea2f61b0bc12f3592288503961b764579dea0658852d96a0b3d823614d808821", size = 2264064, upload-time = "2026-11-05T09:12:29.538Z" }, + { url = "https://files.pythonhosted.org/packages/77/d4/4a0c73dc3ef9e50b122b8c3527afcded15a44838f1c9668d2d4b72cc09f0/pydantic_core-2.50.4-cp312-cp312-win_arm64.whl", hash = "sha256:32d6dda86383645ec428ea64dfc277036f5cbc60a72238eab28b91a3fdb9a113", size = 2167792, upload-time = "2026-11-05T09:12:31.103Z" }, + { url = "https://files.pythonhosted.org/packages/1b/21/39f8d97e7ea8e3083606ee9bb1d7f3ec70ded780bb6a872aad76c7eb08b2/pydantic_core-2.50.4-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:0f87ae9db5ba8d8de40dcb93982cf8dd544e6552a80d3345af51941cc2146b80", size = 2232841, upload-time = "2026-11-05T09:12:32.617Z" }, + { url = "https://files.pythonhosted.org/packages/90/a9/fc89a632331882c4cb91b949003418e6f5085ddcf2c9b875d499682bca91/pydantic_core-2.50.4-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:1239daaf063e62213ca1f34d96663900bd7510c42a786e843fd328af70e46445", size = 2108326, upload-time = "2026-11-05T09:12:34.419Z" }, + { url = "https://files.pythonhosted.org/packages/5d/6d/4f6d00e9e4ba2a7bfb206ae49cb32a3ea90c4d658e62f8775277d75e8291/pydantic_core-2.50.4-cp313-cp313-manylinux1_i686.manylinux_2_5_i686.whl", hash = "sha256:1afefe44ec042fbabfb4483ea258c04cf75ff4ff328d754f09b321fdaa232aca", size = 2256276, upload-time = "2026-11-05T09:12:36.212Z" }, + { url = "https://files.pythonhosted.org/packages/b3/b8/936cb0d85a4082e902c7397db0f05c4372eac08372c8bd2d0b43088fcf17/pydantic_core-2.50.4-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:a9ee990bf2cfbd81574c5d4f9f6c9d480a14b5b43d2c4f2ca13f4c6f48089394", size = 2125469, upload-time = "2026-11-05T09:12:37.913Z" }, + { url = "https://files.pythonhosted.org/packages/66/a1/f3b551ce233dcac73286b8b2ae45c23232a9f41c68663e2dcce4bb2dbcfa/pydantic_core-2.50.4-cp313-cp313-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:ab2822bcdcefb54d1e8ca29f5e3ec3afe160fb794bb3a3a73b09d11ed2671104", size = 2196397, upload-time = "2026-11-05T09:12:39.725Z" }, + { url = "https://files.pythonhosted.org/packages/3d/93/a8a6e7e20826567a73e6f52416667698aa3de704804d7a49d25272246af4/pydantic_core-2.50.4-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:0001d6920e3a5d92758cda460d6dc9f918a78ad6d5d092f1c8b5395e6b775356", size = 2380442, upload-time = "2026-11-05T09:12:41.196Z" }, + { url = "https://files.pythonhosted.org/packages/aa/ba/921d90c9d8ddfa653a35a92f2bbdcd650a9493f5c43f39cdfe4c56659cfa/pydantic_core-2.50.4-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:ad92d255a165cde5f9882ff69699eaf5495e0a1f32e97566bbbb80f11e46781f", size = 2457747, upload-time = "2026-11-05T09:12:42.723Z" }, + { url = "https://files.pythonhosted.org/packages/2b/c0/1c8f2c8f1b03d3fe2fdd7962df8f5a744fe48c90b4c49615e4eb77d04141/pydantic_core-2.50.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:fb2bb5b557080da398b866408117d98fe9731a12334afd0cdff221b458cdc5dc", size = 2260946, upload-time = "2026-11-05T09:12:44.185Z" }, + { url = "https://files.pythonhosted.org/packages/07/ab/5b78a78f0c0f11c8b54fac214ed49cbb4795c34881aa5e5a15715917936f/pydantic_core-2.50.4-cp313-cp313-manylinux_2_31_riscv64.whl", hash = "sha256:92f8f63df729061bb14558ed740e7a222f6e2aa6c2e6a5bcfb4e706676562049", size = 2261921, upload-time = "2026-11-05T09:12:45.706Z" }, + { url = "https://files.pythonhosted.org/packages/b3/e8/dd5d154cf3401f836d8754fdc1b82ecadd37944e4355d855e5b54c7d8ae5/pydantic_core-2.50.4-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:2a60ec2a57ac3ef3767e526e9bf706ec75aa3d79c4ea134d9d4fcf7c62a297a7", size = 2298475, upload-time = "2026-11-05T09:12:47.183Z" }, + { url = "https://files.pythonhosted.org/packages/b7/49/af059d9c4483cba168b17e5f84f1090a3e4547a02fc7698ebc231d48298a/pydantic_core-2.50.4-cp313-cp313-musllinux_1_1_armv7l.whl", hash = "sha256:a2f8716344bbbd10443391be0b1f2003b34949e3c4e6883005c2bc498ab6b64b", size = 2473226, upload-time = "2026-11-05T09:12:48.785Z" }, + { url = "https://files.pythonhosted.org/packages/71/ba/4e8cc3064e8bc2ea272cf80dfc57fa4e455f6835c1def21609a9b4f94135/pydantic_core-2.50.4-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:b300a30304c4c6aeab03ed06809819d9eceacdd58441d3c7dffe41edfd006091", size = 2498764, upload-time = "2026-11-05T09:12:50.316Z" }, + { url = "https://files.pythonhosted.org/packages/bf/96/0878499cfa88eb0b07762b488d3cc1b64cb156a4905db99a0d12096b2e17/pydantic_core-2.50.4-cp313-cp313-win32.whl", hash = "sha256:ef8a9ddb2e2a4eae4abb72dc0710eca6c2726779b0664bd10c3ce9fcfaed8c4e", size = 2119158, upload-time = "2026-11-05T09:12:51.834Z" }, + { url = "https://files.pythonhosted.org/packages/e7/e0/95b651213e79ffe0cbee855590bf5cfdf8e3a0d90a7fc73a080e63f7cc38/pydantic_core-2.50.4-cp313-cp313-win_amd64.whl", hash = "sha256:4c29b8f2d6417069bb1f257e6b9113f5d64dc2f554cc200ea90b4fe2c5cdb733", size = 2262887, upload-time = "2026-11-05T09:12:53.282Z" }, + { url = "https://files.pythonhosted.org/packages/08/d3/c3801dc75844a0b13d000bd575bf1b3b3a8aca9f63d19e1809f69c9c5121/pydantic_core-2.50.4-cp313-cp313-win_arm64.whl", hash = "sha256:a0c5210d038418a115e7cf8706bfa611bd14add2f5787274dba45aadca3155e0", size = 2167878, upload-time = "2026-11-05T09:12:54.677Z" }, + { url = "https://files.pythonhosted.org/packages/ee/ed/c9a4982ac3bbc78f27498d9efb85b3dabd739a1724db53c35cc4c018e1de/pydantic_core-2.50.4-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:5c074454dc6d4f6f4ba6561a56bf33a14db7651d882a5a5321ba3ae8868e082d", size = 2236841, upload-time = "2026-11-05T09:12:56.111Z" }, + { url = "https://files.pythonhosted.org/packages/56/32/92c174c17bfc5fc52d0c064e6a7969a727731e25829ede752fba8bacce0f/pydantic_core-2.50.4-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:a4bb174bd65f795c39ad6642d9d5bdc43351b306b7d0a654ab0d0abb38be245f", size = 2108348, upload-time = "2026-11-05T09:12:57.638Z" }, + { url = "https://files.pythonhosted.org/packages/cb/cb/9f637d424a04d3edce7dd527da941950cce05a74b025eef3d54427b86c8e/pydantic_core-2.50.4-cp314-cp314-manylinux1_i686.manylinux_2_5_i686.whl", hash = "sha256:0ec20aca2b067369913716847f7dfe5f4dddf16a46965b7a70bbad5defaaba86", size = 2261331, upload-time = "2026-11-05T09:12:59.154Z" }, + { url = "https://files.pythonhosted.org/packages/91/ff/1117a3cccabb67305bd98d992a84eaf275939a9a043b4f14126ed7252e4f/pydantic_core-2.50.4-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:70dbc9f83c41f37a4faa62dae5203853847223a891da446f48ef2efcfd5df806", size = 2128667, upload-time = "2026-11-05T09:13:00.614Z" }, + { url = "https://files.pythonhosted.org/packages/93/45/6de1b4a6e8c415cd547f90d1408a711e7975116423e3eb3046061c62d7c7/pydantic_core-2.50.4-cp314-cp314-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:3de6c2a4df2af0ac9ab4dc1488746fe8b1a90e27955d870d9edda3187d20092b", size = 2198183, upload-time = "2026-11-05T09:13:02.259Z" }, + { url = "https://files.pythonhosted.org/packages/d0/bd/c6e64c315d35cc0783a0ea033a3dca062bc368905d0217eab6f6f63007de/pydantic_core-2.50.4-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:3a48a5254d15a0ad050318bfc7a9566d4ec740118187e8f303e47a6840287eb7", size = 2386279, upload-time = "2026-11-05T09:13:03.988Z" }, + { url = "https://files.pythonhosted.org/packages/33/ab/0d56280c89d3841381e9c699c3fa80e3dd3288edf5e7fe4d149136835dca/pydantic_core-2.50.4-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:0af56dbf8822ba9f4efcbbfdc15478f8b6fb08f1609860cb50aa2cc8476b3c34", size = 2464343, upload-time = "2026-11-05T09:13:05.98Z" }, + { url = "https://files.pythonhosted.org/packages/56/9c/621ad8f88590a92a086b1168dce09369d9c5e079e2e635e6646d248af55b/pydantic_core-2.50.4-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:f1d62fb172db35c6478c9323da34ff37d1f3d37d7d44337a9d94ba8c583e5730", size = 2265388, upload-time = "2026-11-05T09:13:07.808Z" }, + { url = "https://files.pythonhosted.org/packages/f3/7b/cef68a667bf29b86e293a80a601d488a84c8f45508915ad6201fcfe1a798/pydantic_core-2.50.4-cp314-cp314-manylinux_2_31_riscv64.whl", hash = "sha256:5c1013647be741647895c102831dcf79c34209662dbb683df9efb864417ed7d5", size = 2267012, upload-time = "2026-11-05T09:13:09.273Z" }, + { url = "https://files.pythonhosted.org/packages/4b/9f/3ae4d163d8feda2b52de88b5cd96b1c40f79d11503003b061136d2ece6ab/pydantic_core-2.50.4-cp314-cp314-musllinux_1_1_aarch64.whl", hash = "sha256:aeb2e123cbf978a905e9f55155c1b8316fbbfa7cf64d04521fe174bab302d100", size = 2300478, upload-time = "2026-11-05T09:13:10.758Z" }, + { url = "https://files.pythonhosted.org/packages/e8/72/41881d31f6452430ed6792679c5391795910f0a27a6aebd424683e504ed6/pydantic_core-2.50.4-cp314-cp314-musllinux_1_1_armv7l.whl", hash = "sha256:523466eba8ee10f7480f3c2057563145978011c583130d2cc01fb1e7af808e25", size = 2474874, upload-time = "2026-11-05T09:13:12.188Z" }, + { url = "https://files.pythonhosted.org/packages/05/ef/099874dd6d5ca1e49987dea87eecc05610183249450b1fff883d87f1e8eb/pydantic_core-2.50.4-cp314-cp314-musllinux_1_1_x86_64.whl", hash = "sha256:c9e70012926e97069cdd09221861aff412aa94e4cac2e019055cdb79485b150c", size = 2502771, upload-time = "2026-11-05T09:13:13.981Z" }, + { url = "https://files.pythonhosted.org/packages/c6/07/a7d8615b8677bf69e24666bbce431299850c95a7b084649342582a1c3210/pydantic_core-2.50.4-cp314-cp314-pyemscripten_2026_0_wasm32.whl", hash = "sha256:e6da138a1ecc1341c8b788a5ee822670b03788e1f5decf7af9d461de6e508b8e", size = 1496509, upload-time = "2026-11-05T09:13:15.704Z" }, + { url = "https://files.pythonhosted.org/packages/ab/71/fdf2c25c3a4f89968263c1d896c933809ca8d2fb13443626648a17b2e296/pydantic_core-2.50.4-cp314-cp314-win32.whl", hash = "sha256:13b6dd62b5279f5b9d72f3bf918a35443ee8bd549241d9dc52d79a2c3b6d7016", size = 2122015, upload-time = "2026-11-05T09:13:17.09Z" }, + { url = "https://files.pythonhosted.org/packages/3a/9f/3554f0148b01ddaa5e678bf5fbce4679873534e5c0985cdf6c59c41dc9a9/pydantic_core-2.50.4-cp314-cp314-win_amd64.whl", hash = "sha256:b0cdb655fbd1562c2dfc9986f9103a106f7058cd0915afc6e656d4b1d73f3387", size = 2265109, upload-time = "2026-11-05T09:13:18.702Z" }, + { url = "https://files.pythonhosted.org/packages/ed/3c/196ef237d9ec5cca5ea9b773911dee1a387b9b1d4bfea05625b3e191a338/pydantic_core-2.50.4-cp314-cp314-win_arm64.whl", hash = "sha256:df1c174796cd63eb6b139f7daf783affe1f3ed659605850e843b24764c21bfc5", size = 2165745, upload-time = "2026-11-05T09:13:20.245Z" }, + { url = "https://files.pythonhosted.org/packages/36/12/0ee82a41a3995f0b531cf14e0b823dc2365ba4a22330670fccaa72753f12/pydantic_core-2.50.4-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:edbca8789fd10f0de534b660a6b4c71f1fd18039679c918dad392ab044bb37e4", size = 2223917, upload-time = "2026-11-05T09:13:21.623Z" }, + { url = "https://files.pythonhosted.org/packages/90/2c/592f8404abbcc65a70e6a802d1dc8f11412af44913e5146cf5c345370074/pydantic_core-2.50.4-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:33b21f69540a12c2053cd1d95766d8bd9667a3897f7c712a642de8aa37eb0865", size = 2087372, upload-time = "2026-11-05T09:13:23.16Z" }, + { url = "https://files.pythonhosted.org/packages/ea/1d/c7111757c84b5b8c19b1e39ceb5e131e6e48e14169ec6004e0f8f28f43f3/pydantic_core-2.50.4-cp314-cp314t-manylinux1_i686.manylinux_2_5_i686.whl", hash = "sha256:ffb616d8d55965839670301dc3bae3abacff560a7e137a89056058a8a9da4d96", size = 2275190, upload-time = "2026-11-05T09:13:24.634Z" }, + { url = "https://files.pythonhosted.org/packages/3d/ae/6c49cc9b8e66e61adee782d1763894bf64a357cddae82f725059b85bdc98/pydantic_core-2.50.4-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:6c5687b59b6ba0f663c4f2f15470f68507d6b45ccd3a19ee6d224f95cbee70d8", size = 2110343, upload-time = "2026-11-05T09:13:26.168Z" }, + { url = "https://files.pythonhosted.org/packages/ed/39/0ee5261d1daa9ad526371181c13696add0565251b2823f6e00a9a9af397d/pydantic_core-2.50.4-cp314-cp314t-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:c733087ecf7dde06b1d071679bfd5f3ba03266ba77814c1c7253bc48c9adedd9", size = 2207887, upload-time = "2026-11-05T09:13:27.681Z" }, + { url = "https://files.pythonhosted.org/packages/ac/b5/a0652c0e99590107e111088b6d059044380a787da9ffdd0b458ab4cd9453/pydantic_core-2.50.4-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:94733cb447c37b0ce6f71b39ca1288d5f966a084023a5617b4cc35a852586859", size = 2404171, upload-time = "2026-11-05T09:13:29.864Z" }, + { url = "https://files.pythonhosted.org/packages/a3/85/d49f0b8e09a0ffc40dcefb604f9e6020e0d61b51a5f64a504f382fa84c39/pydantic_core-2.50.4-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:b26f39a5be3cd91a2035818be3d0ffdf5282c3e1f5f53d3b80b7024021acee52", size = 2466049, upload-time = "2026-11-05T09:13:31.658Z" }, + { url = "https://files.pythonhosted.org/packages/e6/76/f2b04d7c53edfd8136053c812ea49914fbf4091196cb7baf9ea326fa2ff8/pydantic_core-2.50.4-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c856e439a9d54d514e81a7131229ba151cdf81df7c408e0f6c89340e5003dfe2", size = 2262062, upload-time = "2026-11-05T09:13:33.806Z" }, + { url = "https://files.pythonhosted.org/packages/24/60/016f14cea883adc33df90b8df220df934de49ded9640f45c8e92bb298494/pydantic_core-2.50.4-cp314-cp314t-manylinux_2_31_riscv64.whl", hash = "sha256:cbf0777d54672990b10cb8ca9b0523499e182d7e2ea39f86b138519a902aa601", size = 2263713, upload-time = "2026-11-05T09:13:35.337Z" }, + { url = "https://files.pythonhosted.org/packages/f1/3f/b05828e978512973e7e215bab69e65e70d223d6309a17bf48084a50692f4/pydantic_core-2.50.4-cp314-cp314t-musllinux_1_1_aarch64.whl", hash = "sha256:edc17549ab592e33cfcaf285f047bb75fcd98f608aa9309af1187fd736ce9641", size = 2305044, upload-time = "2026-11-05T09:13:37.043Z" }, + { url = "https://files.pythonhosted.org/packages/91/c1/fca6c5f623ac45ba284713c614b30173aa0794899a0a457f866fa6f5e886/pydantic_core-2.50.4-cp314-cp314t-musllinux_1_1_armv7l.whl", hash = "sha256:23a9ba564b2db709ff16eca990992ba95a19069972b34bff87c81d4b473cd755", size = 2483506, upload-time = "2026-11-05T09:13:40.524Z" }, + { url = "https://files.pythonhosted.org/packages/94/c2/ec41f68d1208e53e1a73ead940c050c4316bbb555ba42676a5e949fd529e/pydantic_core-2.50.4-cp314-cp314t-musllinux_1_1_x86_64.whl", hash = "sha256:41f4f8ae714e4fea1d635880f8a1af715ecf080eed4d13c5b04a0f3210f9c61a", size = 2512832, upload-time = "2026-11-05T09:13:43.361Z" }, + { url = "https://files.pythonhosted.org/packages/43/22/58583b86309f70cce854e0e77c412839a56ac6c682d6060f5794afeff315/pydantic_core-2.50.4-cp314-cp314t-win32.whl", hash = "sha256:601fce6cea9ddeaa85329e12e7f351def38d233075f42a3012b9c48071b02941", size = 2101977, upload-time = "2026-11-05T09:13:45.735Z" }, + { url = "https://files.pythonhosted.org/packages/6b/28/193bc0994f7fe15f2874c1dfe2f3bc7872aed8283ffda2cf05fb9a5a06b4/pydantic_core-2.50.4-cp314-cp314t-win_amd64.whl", hash = "sha256:22e874666bdbd96d6bf629d32cd8ab376fedf1fd62585b52a42b9fa9fa6c20b6", size = 2240461, upload-time = "2026-11-05T09:13:48.38Z" }, + { url = "https://files.pythonhosted.org/packages/00/ed/5615cfdd5620a4926440eb1a2b73db0dc895824ba565ccaa8d9eb3a8e974/pydantic_core-2.50.4-cp314-cp314t-win_arm64.whl", hash = "sha256:71395a43da5584bb70556f380387e15f845c0dcf76373c1afbfa0025737576ac", size = 2168505, upload-time = "2026-11-05T09:13:50.762Z" }, + { url = "https://files.pythonhosted.org/packages/6d/9f/e6673535165d965a11c1d5339f53995f90234019827eaecb41a57e6e463d/pydantic_core-2.50.4-cp315-cp315-macosx_10_12_x86_64.whl", hash = "sha256:7ac2769a7ddd661e07e26c12220adc31b17014c48234b2a5a88993b8d4109e09", size = 2241950, upload-time = "2026-11-05T09:13:53.055Z" }, + { url = "https://files.pythonhosted.org/packages/6f/02/65951efadbf7826e6a270843f97e3da2ef726de2b6d9cd7c5dfa4c48807e/pydantic_core-2.50.4-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:930ad463d3fb7a340d323bcc496ec32dae469ec9974c29ff569f19806b6b03b4", size = 2112412, upload-time = "2026-11-05T09:13:55.309Z" }, + { url = "https://files.pythonhosted.org/packages/c9/d3/4fb6e2e4a9e4951f1e05b198366ed5330e0874e83d52077e8b985350fe0e/pydantic_core-2.50.4-cp315-cp315-manylinux1_i686.manylinux_2_5_i686.whl", hash = "sha256:b867f9fd183d76977f810c626d539265183c25b2284762893a31e8d6cacc81c0", size = 2263220, upload-time = "2026-11-05T09:13:57.555Z" }, + { url = "https://files.pythonhosted.org/packages/63/83/42e70436c523357b49393b73f161f2741acf36003c8efd2f941d2be56bae/pydantic_core-2.50.4-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:49eb1241a969a5994db6880c18c012b6cbe2340343d8f529721571806583e500", size = 2134716, upload-time = "2026-11-05T09:13:59.413Z" }, + { url = "https://files.pythonhosted.org/packages/36/66/ed9b87f4751fd07e472c62cfe151f575abdf4c452fab943d35ba8efdc6c4/pydantic_core-2.50.4-cp315-cp315-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:477af785d1846e4e96bf56983b92ea7553aaeccdeb8acdaa55c7cee9eda0ae32", size = 2201901, upload-time = "2026-11-05T09:14:01.472Z" }, + { url = "https://files.pythonhosted.org/packages/2b/21/ff2e6ac7202b6d326e9f007c6082f6e6f3aaa063790ea2a355bdc985addc/pydantic_core-2.50.4-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:29358a8ca74e7d81158d14e2b10c904bd18773293ae3788716c0626fe0342347", size = 2389670, upload-time = "2026-11-05T09:14:03.431Z" }, + { url = "https://files.pythonhosted.org/packages/b9/34/e9348bc13d549641791a51843ed140fbb311d9066628e27477343412d5ad/pydantic_core-2.50.4-cp315-cp315-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:300753f71c73302e218124baf995f00058e085cd01869bd9610bcbd0bd4500c1", size = 2468951, upload-time = "2026-11-05T09:14:05.028Z" }, + { url = "https://files.pythonhosted.org/packages/ac/5e/145a02bf2b9f66981108caf6cc9e78917e31e4caca14d1e3ccd3ff2c7293/pydantic_core-2.50.4-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:26cb012c4b8ca9f847bd0ac15978bd3d0f55b050bfbe6c47355edfc7e945029b", size = 2272957, upload-time = "2026-11-05T09:14:06.587Z" }, + { url = "https://files.pythonhosted.org/packages/fd/38/b71c5b245e923f6cf144e948ed2a9d6b7fb97d8905784db8d860f5176b8b/pydantic_core-2.50.4-cp315-cp315-manylinux_2_31_riscv64.whl", hash = "sha256:9be1cfe715ecaa060ffd5d599ef410b94ef2697a0eed4cee562f788a2aa2175b", size = 2275028, upload-time = "2026-11-05T09:14:08.219Z" }, + { url = "https://files.pythonhosted.org/packages/ba/71/2504dacdc5cd3ea3ec5e68c9b6e097c979500bcff220b97046cc8ea3c1ad/pydantic_core-2.50.4-cp315-cp315-musllinux_1_1_aarch64.whl", hash = "sha256:c81e35862aced259177a537ce1a6264c3a97bae1ced184ca9dc10ea754563688", size = 2305447, upload-time = "2026-11-05T09:14:09.795Z" }, + { url = "https://files.pythonhosted.org/packages/2c/90/904233a6c148bcac9f30bb96a2761e5fb52682d0d6de31a40c74a3714ceb/pydantic_core-2.50.4-cp315-cp315-musllinux_1_1_armv7l.whl", hash = "sha256:b2f2d13239487cecaae98c9f4d5904ad0737643cdf8873c88ec6a78b12214f20", size = 2477852, upload-time = "2026-11-05T09:14:11.443Z" }, + { url = "https://files.pythonhosted.org/packages/72/33/1cbdcbf343ca23b507e967b21dddc4c8bf17a74c8b5cad59228c85ba4efc/pydantic_core-2.50.4-cp315-cp315-musllinux_1_1_x86_64.whl", hash = "sha256:e6b4b08d09054310a4dc389fa61ee22a7a5a292cb23ab8a985136ca8828bf924", size = 2506352, upload-time = "2026-11-05T09:14:13.165Z" }, + { url = "https://files.pythonhosted.org/packages/91/24/3ad9ea0876e6624c90967e5f1446e751b275cfdfaaf798a0d8e0b30025bc/pydantic_core-2.50.4-cp315-cp315-win32.whl", hash = "sha256:6619d49a89a15cd04334f76fec530c155923bfc60da74ff5d815a52629e1aa6c", size = 2127780, upload-time = "2026-11-05T09:14:17.52Z" }, + { url = "https://files.pythonhosted.org/packages/c0/3c/0582532b90a12492471977bdbca1317eca5144f6342ea581d2cee73ccd35/pydantic_core-2.50.4-cp315-cp315-win_amd64.whl", hash = "sha256:e5bd109d095aaae989a0463d5ef0fcc43e9ddd5de125e656d3c119a79e466380", size = 2270596, upload-time = "2026-11-05T09:14:20.955Z" }, + { url = "https://files.pythonhosted.org/packages/6c/50/967cfe4f7043a993c0c80cd3563c598b5281d2276aa775d0f6ff7f714271/pydantic_core-2.50.4-cp315-cp315-win_arm64.whl", hash = "sha256:6118e5a5550e36582e19bac1a403711a748f9f18251b054c326d3db02aaa7a18", size = 2170880, upload-time = "2026-11-05T09:14:24.822Z" }, + { url = "https://files.pythonhosted.org/packages/9e/71/3ec5bd8a82f792482f16d79fdbe8ce85aa71bf7147e556c5fc5f8546818d/pydantic_core-2.50.4-cp315-cp315t-macosx_10_12_x86_64.whl", hash = "sha256:d8201c9f9035520cdcc7dcad383b039ec8123969b87e01cf27c3dd883c02313b", size = 2233053, upload-time = "2026-11-05T09:14:27.942Z" }, + { url = "https://files.pythonhosted.org/packages/6e/2e/614dc37aedf8e9f811c1f2eedaf8eb09a7c196e2d137fe82bcc9d5662ca2/pydantic_core-2.50.4-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:1de7be9a66fc8536770481ab64a05aae5067c725f2b29a09543af00e6a417b97", size = 2090776, upload-time = "2026-11-05T09:14:30.281Z" }, + { url = "https://files.pythonhosted.org/packages/f9/14/aefc14e3e05013070ee959fc0b8703f6860a2776ed6e75b9c748f61aced0/pydantic_core-2.50.4-cp315-cp315t-manylinux1_i686.manylinux_2_5_i686.whl", hash = "sha256:789a6453e5ffd18a7ab6b8c3a0dd8403053829197ec258ecb90c604c21ffcc99", size = 2272481, upload-time = "2026-11-05T09:14:32.578Z" }, + { url = "https://files.pythonhosted.org/packages/13/c9/d56999aa7236dc9303091db2b1ef7303f0b022baf25ebf33cd200c0cb933/pydantic_core-2.50.4-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:6348ad12fa741bcc9c2f173e99fbf27cbc038826d8c31a4a7d836eca27878ba2", size = 2113069, upload-time = "2026-11-05T09:14:34.69Z" }, + { url = "https://files.pythonhosted.org/packages/b7/d5/a62da9e72f272f198f6118c5457332bbd4b9fdc4b77858448120569756de/pydantic_core-2.50.4-cp315-cp315t-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:d49127f137f871cde3c5650af33bbbdcee02679dae76e020902fa106f522b8ae", size = 2202754, upload-time = "2026-11-05T09:14:36.49Z" }, + { url = "https://files.pythonhosted.org/packages/37/4a/e7f21577f96e42ac3082cd014df398c1c913d482afac1c8ef17b9e039198/pydantic_core-2.50.4-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:2f5cc5bcb94063fbbdfd285a2b302da34af07491337c10bb35de1d5220fa1583", size = 2411472, upload-time = "2026-11-05T09:14:38.63Z" }, + { url = "https://files.pythonhosted.org/packages/38/ad/c57c5e13bbfd3404ec1af519764aadbc52ee01e39f9f9ae9d28317f982f2/pydantic_core-2.50.4-cp315-cp315t-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:b99bed995ed7c41515c11fe2beb86f8a6cc298e5537cae2f736de2f982f74ef0", size = 2475330, upload-time = "2026-11-05T09:14:40.519Z" }, + { url = "https://files.pythonhosted.org/packages/6e/63/65cf0e1f1fd8cfaafee3c005712b8020e063b0f3e3571493ea68db5ec44f/pydantic_core-2.50.4-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:faa4e96385c820ce9d7f7a623486e23d4134ae3c9ba2071e44e0ab5a5a5002c4", size = 2265718, upload-time = "2026-11-05T09:14:42.379Z" }, + { url = "https://files.pythonhosted.org/packages/72/5d/fd9fdec9b25e2ef1f788970a84f749f0e28f166573c87654fd5387d8e5ce/pydantic_core-2.50.4-cp315-cp315t-manylinux_2_31_riscv64.whl", hash = "sha256:d6a166978f22f10cb91413f70519861605219346decf65bc79008f9257c94afe", size = 2273454, upload-time = "2026-11-05T09:14:44.286Z" }, + { url = "https://files.pythonhosted.org/packages/34/8c/19705c6d5eb72ff8c25006df8a375da7466176a5968781789e5415384f65/pydantic_core-2.50.4-cp315-cp315t-musllinux_1_1_aarch64.whl", hash = "sha256:a70d5effebd81ebd8e15a8aabdc7980832367b2b00c36543bac378977004cc80", size = 2314862, upload-time = "2026-11-05T09:14:45.97Z" }, + { url = "https://files.pythonhosted.org/packages/b8/fb/acefa27031aba2646b0d3026c4a1602e526489d39395ab17bc47f03234e3/pydantic_core-2.50.4-cp315-cp315t-musllinux_1_1_armv7l.whl", hash = "sha256:f8fd23653a252cefabea11cd041efd7b80bdf403e43a36dea53f9cb0aaa21f0f", size = 2479073, upload-time = "2026-11-05T09:14:47.526Z" }, + { url = "https://files.pythonhosted.org/packages/ef/e1/db08fa1e5edf1779fa0612f8d09f9030bdc513f593687c883cb781b86caa/pydantic_core-2.50.4-cp315-cp315t-musllinux_1_1_x86_64.whl", hash = "sha256:7646353a5a7c553c04167aca628e2550b538f492765b03ccf34321a560acc43c", size = 2521328, upload-time = "2026-11-05T09:14:49.042Z" }, + { url = "https://files.pythonhosted.org/packages/0d/51/bf1ec5b96c076d8d514b08f3bcffb3397df7a0fcc729eb960838a8bbe27f/pydantic_core-2.50.4-cp315-cp315t-win32.whl", hash = "sha256:65376dbe1ab4dbc768ca2b72b7c13993562c035f5925fd3bc7ff9c8c585c515d", size = 2107629, upload-time = "2026-11-05T09:14:50.891Z" }, + { url = "https://files.pythonhosted.org/packages/18/32/43d5db1824ec2314f737ff8d9962ff59954a74616d8656a8cc78790e45f1/pydantic_core-2.50.4-cp315-cp315t-win_amd64.whl", hash = "sha256:f08ee8248aad2d054e5bc4c73554d4505464698f6d754f16198dbc5764e9821d", size = 2244906, upload-time = "2026-11-05T09:14:53.056Z" }, + { url = "https://files.pythonhosted.org/packages/3a/c0/38c505004969c4641c3a077a8e72e354f02d5c06d8f51d7a103699704772/pydantic_core-2.50.4-cp315-cp315t-win_arm64.whl", hash = "sha256:da779ae50b46f3f7d1e1b5f362fdc0ad376a49fd55f6f3122dc2b6149936cdf7", size = 2179018, upload-time = "2026-11-05T09:14:54.448Z" }, + { url = "https://files.pythonhosted.org/packages/9a/18/2f6a25e9104d5af713d16671711927601da1f0db74e785be67bd590385c9/pydantic_core-2.50.4-graalpy312-graalpy250_312_native-macosx_10_12_x86_64.whl", hash = "sha256:c04e9d920e2674f54651fd260a15c5d2843526c73d5242ee4311325ddc9573b3", size = 2212591, upload-time = "2026-11-05T09:14:56.262Z" }, + { url = "https://files.pythonhosted.org/packages/4c/1b/ba8b721af10a7659e7fbbef320ff8eb55462557a72607858af5a9bd22cb1/pydantic_core-2.50.4-graalpy312-graalpy250_312_native-macosx_11_0_arm64.whl", hash = "sha256:5bc1811ef2b4d4ba63e8e452f6e332b6374bd1d2cbbfdf66826c8cb1f71dd10d", size = 2048167, upload-time = "2026-11-05T09:14:57.681Z" }, + { url = "https://files.pythonhosted.org/packages/48/42/3f8638e7d90bdd9a7c7f3e5084723af59e7f43f15a292e242d35624073ce/pydantic_core-2.50.4-graalpy312-graalpy250_312_native-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:0b059a7968b1911be5a2d9a8234827ab0bef9d1e465d4b42da525894143550e8", size = 2119548, upload-time = "2026-11-05T09:14:59.317Z" }, + { url = "https://files.pythonhosted.org/packages/e0/8d/4bfbacaf191f7939893d165e18eb301731fa3366c59a6e57336c4f168fbd/pydantic_core-2.50.4-graalpy312-graalpy250_312_native-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:bee28aab5a580eec673f7b68dfa8dece3dd37bd207ef8d22fafe23a8e9837296", size = 2279952, upload-time = "2026-11-05T09:15:00.907Z" }, + { url = "https://files.pythonhosted.org/packages/9e/3a/d405a50e02ea81cd95e93fc97f43d351eeaa1707c28aa6fb58a9f1c1efa9/pydantic_core-2.50.4-graalpy313-graalpy253_313_native-macosx_11_0_arm64.whl", hash = "sha256:71e03d2ea1a221d020cfc5b6cc8bbbedef23a06704c70fcf4d0afb42965b22d1", size = 2049324, upload-time = "2026-11-05T09:15:02.379Z" }, + { url = "https://files.pythonhosted.org/packages/8f/3b/03e7992115e17cae4131ecd71aadb8fd5e4a04cc2aead72c3c27e9b453d1/pydantic_core-2.50.4-graalpy313-graalpy253_313_native-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:09450778e3ab58d3f565899fcfbf6c82926e31af29e28e799d1d50941316e0cb", size = 2119802, upload-time = "2026-11-05T09:15:03.901Z" }, + { url = "https://files.pythonhosted.org/packages/e3/d5/b76fc647e473377ca6e693c21549ee3a4a7677e4962c28ae4659337c5114/pydantic_core-2.50.4-graalpy313-graalpy253_313_native-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:4eb15be588407148ef5937dc8d9256a71f6b115e6cddadb7aa20b6ee384680dc", size = 2280639, upload-time = "2026-11-05T09:15:05.374Z" }, + { url = "https://files.pythonhosted.org/packages/d8/18/3ca5b3b8ce7a540305e6856d013e9c6b9c0fef93258fef6038db0beb233a/pydantic_core-2.50.4-pp311-pypy311_pp73-macosx_10_12_x86_64.whl", hash = "sha256:39f489ce31272073e6e146f6781690f9c1ee8c126836e6403361ef91154d89fe", size = 2166960, upload-time = "2026-11-05T09:15:06.902Z" }, + { url = "https://files.pythonhosted.org/packages/a3/60/65d725001bffcde0170f6d37ae8bccce715e5311122eb6127f698115957e/pydantic_core-2.50.4-pp311-pypy311_pp73-macosx_11_0_arm64.whl", hash = "sha256:5b26e5f1793b96cdc60242bf38da86ff24a27a708aa396214cac9b534bf571c7", size = 2085636, upload-time = "2026-11-05T09:15:08.395Z" }, + { url = "https://files.pythonhosted.org/packages/ac/12/934cf1d44a3fee3c47231d4690dddee19264150c3aa59a3ddf66fa43454d/pydantic_core-2.50.4-pp311-pypy311_pp73-manylinux1_i686.manylinux_2_5_i686.whl", hash = "sha256:7210398a1607ad607dc73196e575b3148b00a333cbb602ddbe1b60ba54554f43", size = 2284621, upload-time = "2026-11-05T09:15:09.82Z" }, + { url = "https://files.pythonhosted.org/packages/c4/91/52248eee98d76f8d9239166d24928f805292df16729109f4f189cdb59be4/pydantic_core-2.50.4-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:2f42584e5785385f681163a42506cab0d51295e17599a648396c52a7046c1372", size = 2277673, upload-time = "2026-11-05T09:15:11.236Z" }, + { url = "https://files.pythonhosted.org/packages/9f/89/900a7970ef19843aa79522a95b461e9c365b7fedd7ee80ef28a84dae9a41/pydantic_core-2.50.4-pp311-pypy311_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:2039e323acee9abfec1fb5f661776e8965fe5928f3b7f8431900a774cba5c317", size = 2297354, upload-time = "2026-11-05T09:15:12.798Z" }, + { url = "https://files.pythonhosted.org/packages/de/ec/053d829437f70070cdd7116a0257cc0da651103328ff1e9e82954c45efd6/pydantic_core-2.50.4-pp311-pypy311_pp73-musllinux_1_1_armv7l.whl", hash = "sha256:71ade6d2e445839350d589ff99bbddfde16f3f32db28da5c894a09f99c8b2a03", size = 2469913, upload-time = "2026-11-05T09:15:14.319Z" }, + { url = "https://files.pythonhosted.org/packages/80/af/207c821cb0813e16d630660e0073491e3ab07370efaa6fa0b8b10fffb7b6/pydantic_core-2.50.4-pp311-pypy311_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:d7d406709ae924cf0b08b8282ca2f0e1c90526911d93bc040557cbc83b74c55f", size = 2503746, upload-time = "2026-11-05T09:15:15.736Z" }, + { url = "https://files.pythonhosted.org/packages/e7/ca/8a053f24e22d8150349cabaecb2f35c89dcf07fbaadb5e48295184dd0e5b/pydantic_core-2.50.4-pp311-pypy311_pp73-win_amd64.whl", hash = "sha256:7472c39480ccc11dda69a196d1b7c7a6b48eb6594b77f05d945599d3e47f731c", size = 2333540, upload-time = "2026-11-05T09:15:17.883Z" }, + { url = "https://files.pythonhosted.org/packages/ac/9d/41b374c62cdb87f84081e2ef2963a115eacc6284a26dbc96bb83568e83ec/pydantic_core-2.50.4-pp311-pypy311_pp80-macosx_10_12_x86_64.whl", hash = "sha256:b67d38e8bb0ade7e6e84575e4bb153fab35b122458077273aeb08fdf12be9d2c", size = 2166962, upload-time = "2026-11-05T09:15:20.276Z" }, + { url = "https://files.pythonhosted.org/packages/9a/4f/51ef440ee346d4388a2c4a3ac4b271fcc7b1d3ff68be8da2ed2be4d488b0/pydantic_core-2.50.4-pp311-pypy311_pp80-macosx_11_0_arm64.whl", hash = "sha256:4eda7e3fdef382b7d4492745988a5baaf6953923a337f8b9dde5f76fa8afde20", size = 2085634, upload-time = "2026-11-05T09:15:21.953Z" }, + { url = "https://files.pythonhosted.org/packages/4b/5f/c9ed62b96beb9050db221d29e81856b6e28f277db601f8b0c3a08f8cf913/pydantic_core-2.50.4-pp311-pypy311_pp80-manylinux_2_28_x86_64.whl", hash = "sha256:474f7e598c7902165662a5d5160d3fce31037890a2975a9871ebf7c05862300b", size = 2277804, upload-time = "2026-11-05T09:15:23.836Z" }, + { url = "https://files.pythonhosted.org/packages/63/bd/b912a5e251ef10ed7be5e543a2bfbeebb0c79bf6302bee786f8dc3bf4341/pydantic_core-2.50.4-pp311-pypy311_pp80-win_amd64.whl", hash = "sha256:3e0b395648c6cb871bceb2906907f255dc876ec425f2d5b024e129985cea8519", size = 2333539, upload-time = "2026-11-05T09:15:25.354Z" }, +] + +[[package]] +name = "pygments" +version = "2.21.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/49/2e/ced460408999b33da6b31b0021b0f37d329e202d4169aeb164493778f25b/pygments-2.21.0.tar.gz", hash = "sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c", size = 5005329, upload-time = "2026-08-17T08:02:48.824Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/71/46/17f022dd3e953bf20a04a028a21ec746d942f8d2af30fa0f124fa0e6a684/pygments-2.21.0-py3-none-any.whl", hash = "sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9", size = 1250147, upload-time = "2026-08-17T08:02:44.912Z" }, +] + +[[package]] +name = "pytest" +version = "9.2.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, + { name = "iniconfig" }, + { name = "packaging" }, + { name = "pluggy" }, + { name = "pygments" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/79/42/bb4641652e58dedeac2ec51abc1f8cae4fee4ec63899a0999016229a0f2a/pytest-9.2.0.tar.gz", hash = "sha256:97c4f3b1f3c7414aa36465e09b8220f1d03627993bd51b1282e193753c80557b", size = 1797555, upload-time = "2026-10-27T21:30:20.728Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/51/39/1f5d8c8877a0fa327db959c19341d4be61660de1ab6b7391f9eb805bcd67/pytest-9.2.0-py3-none-any.whl", hash = "sha256:07acdcf88ec174f907dc01af70bf52d49b014bbab03faeeade31c96b18c2e588", size = 411776, upload-time = "2026-10-27T21:30:19.131Z" }, +] + +[[package]] +name = "python-discovery" +version = "1.9.5" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "filelock" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/68/55/70b46fae646bc6f5cb5e82569949d925cff1c7b5ce20ec4a11e0d977f8c6/python_discovery-1.9.5.tar.gz", hash = "sha256:86279f5d2728bc067de28b7ddc571be2eacc2ae0e7048f8629d2481a0f8848a2", size = 141121, upload-time = "2026-11-06T15:32:11.331Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ac/35/25bd092ca8a7e71192afdca67fbff4f797da74408e74ac3626e13b409ec0/python_discovery-1.9.5-py3-none-any.whl", hash = "sha256:a1fae8fca11e4bc61e38491c2aafff29e430b3c5e272d51ae52fb895bc4c0fac", size = 44377, upload-time = "2026-11-06T15:32:09.821Z" }, +] + +[[package]] +name = "pyyaml" +version = "6.0.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/05/8e/961c0007c59b8dd7729d542c61a4d537767a59645b82a0b521206e1e25c2/pyyaml-6.0.3.tar.gz", hash = "sha256:d76623373421df22fb4cf8817020cbb7ef15c725b9d5e45f17e189bfc384190f", size = 130960, upload-time = "2025-09-25T21:33:16.546Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/6d/16/a95b6757765b7b031c9374925bb718d55e0a9ba8a1b6a12d25962ea44347/pyyaml-6.0.3-cp311-cp311-macosx_10_13_x86_64.whl", hash = "sha256:44edc647873928551a01e7a563d7452ccdebee747728c1080d881d68af7b997e", size = 185826, upload-time = "2025-09-25T21:31:58.655Z" }, + { url = "https://files.pythonhosted.org/packages/16/19/13de8e4377ed53079ee996e1ab0a9c33ec2faf808a4647b7b4c0d46dd239/pyyaml-6.0.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:652cb6edd41e718550aad172851962662ff2681490a8a711af6a4d288dd96824", size = 175577, upload-time = "2025-09-25T21:32:00.088Z" }, + { url = "https://files.pythonhosted.org/packages/0c/62/d2eb46264d4b157dae1275b573017abec435397aa59cbcdab6fc978a8af4/pyyaml-6.0.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:10892704fc220243f5305762e276552a0395f7beb4dbf9b14ec8fd43b57f126c", size = 775556, upload-time = "2025-09-25T21:32:01.31Z" }, + { url = "https://files.pythonhosted.org/packages/10/cb/16c3f2cf3266edd25aaa00d6c4350381c8b012ed6f5276675b9eba8d9ff4/pyyaml-6.0.3-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:850774a7879607d3a6f50d36d04f00ee69e7fc816450e5f7e58d7f17f1ae5c00", size = 882114, upload-time = "2025-09-25T21:32:03.376Z" }, + { url = "https://files.pythonhosted.org/packages/71/60/917329f640924b18ff085ab889a11c763e0b573da888e8404ff486657602/pyyaml-6.0.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b8bb0864c5a28024fac8a632c443c87c5aa6f215c0b126c449ae1a150412f31d", size = 806638, upload-time = "2025-09-25T21:32:04.553Z" }, + { url = "https://files.pythonhosted.org/packages/dd/6f/529b0f316a9fd167281a6c3826b5583e6192dba792dd55e3203d3f8e655a/pyyaml-6.0.3-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:1d37d57ad971609cf3c53ba6a7e365e40660e3be0e5175fa9f2365a379d6095a", size = 767463, upload-time = "2025-09-25T21:32:06.152Z" }, + { url = "https://files.pythonhosted.org/packages/f2/6a/b627b4e0c1dd03718543519ffb2f1deea4a1e6d42fbab8021936a4d22589/pyyaml-6.0.3-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:37503bfbfc9d2c40b344d06b2199cf0e96e97957ab1c1b546fd4f87e53e5d3e4", size = 794986, upload-time = "2025-09-25T21:32:07.367Z" }, + { url = "https://files.pythonhosted.org/packages/45/91/47a6e1c42d9ee337c4839208f30d9f09caa9f720ec7582917b264defc875/pyyaml-6.0.3-cp311-cp311-win32.whl", hash = "sha256:8098f252adfa6c80ab48096053f512f2321f0b998f98150cea9bd23d83e1467b", size = 142543, upload-time = "2025-09-25T21:32:08.95Z" }, + { url = "https://files.pythonhosted.org/packages/da/e3/ea007450a105ae919a72393cb06f122f288ef60bba2dc64b26e2646fa315/pyyaml-6.0.3-cp311-cp311-win_amd64.whl", hash = "sha256:9f3bfb4965eb874431221a3ff3fdcddc7e74e3b07799e0e84ca4a0f867d449bf", size = 158763, upload-time = "2025-09-25T21:32:09.96Z" }, + { url = "https://files.pythonhosted.org/packages/d1/33/422b98d2195232ca1826284a76852ad5a86fe23e31b009c9886b2d0fb8b2/pyyaml-6.0.3-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:7f047e29dcae44602496db43be01ad42fc6f1cc0d8cd6c83d342306c32270196", size = 182063, upload-time = "2025-09-25T21:32:11.445Z" }, + { url = "https://files.pythonhosted.org/packages/89/a0/6cf41a19a1f2f3feab0e9c0b74134aa2ce6849093d5517a0c550fe37a648/pyyaml-6.0.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:fc09d0aa354569bc501d4e787133afc08552722d3ab34836a80547331bb5d4a0", size = 173973, upload-time = "2025-09-25T21:32:12.492Z" }, + { url = "https://files.pythonhosted.org/packages/ed/23/7a778b6bd0b9a8039df8b1b1d80e2e2ad78aa04171592c8a5c43a56a6af4/pyyaml-6.0.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9149cad251584d5fb4981be1ecde53a1ca46c891a79788c0df828d2f166bda28", size = 775116, upload-time = "2025-09-25T21:32:13.652Z" }, + { url = "https://files.pythonhosted.org/packages/65/30/d7353c338e12baef4ecc1b09e877c1970bd3382789c159b4f89d6a70dc09/pyyaml-6.0.3-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:5fdec68f91a0c6739b380c83b951e2c72ac0197ace422360e6d5a959d8d97b2c", size = 844011, upload-time = "2025-09-25T21:32:15.21Z" }, + { url = "https://files.pythonhosted.org/packages/8b/9d/b3589d3877982d4f2329302ef98a8026e7f4443c765c46cfecc8858c6b4b/pyyaml-6.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ba1cc08a7ccde2d2ec775841541641e4548226580ab850948cbfda66a1befcdc", size = 807870, upload-time = "2025-09-25T21:32:16.431Z" }, + { url = "https://files.pythonhosted.org/packages/05/c0/b3be26a015601b822b97d9149ff8cb5ead58c66f981e04fedf4e762f4bd4/pyyaml-6.0.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:8dc52c23056b9ddd46818a57b78404882310fb473d63f17b07d5c40421e47f8e", size = 761089, upload-time = "2025-09-25T21:32:17.56Z" }, + { url = "https://files.pythonhosted.org/packages/be/8e/98435a21d1d4b46590d5459a22d88128103f8da4c2d4cb8f14f2a96504e1/pyyaml-6.0.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:41715c910c881bc081f1e8872880d3c650acf13dfa8214bad49ed4cede7c34ea", size = 790181, upload-time = "2025-09-25T21:32:18.834Z" }, + { url = "https://files.pythonhosted.org/packages/74/93/7baea19427dcfbe1e5a372d81473250b379f04b1bd3c4c5ff825e2327202/pyyaml-6.0.3-cp312-cp312-win32.whl", hash = "sha256:96b533f0e99f6579b3d4d4995707cf36df9100d67e0c8303a0c55b27b5f99bc5", size = 137658, upload-time = "2025-09-25T21:32:20.209Z" }, + { url = "https://files.pythonhosted.org/packages/86/bf/899e81e4cce32febab4fb42bb97dcdf66bc135272882d1987881a4b519e9/pyyaml-6.0.3-cp312-cp312-win_amd64.whl", hash = "sha256:5fcd34e47f6e0b794d17de1b4ff496c00986e1c83f7ab2fb8fcfe9616ff7477b", size = 154003, upload-time = "2025-09-25T21:32:21.167Z" }, + { url = "https://files.pythonhosted.org/packages/1a/08/67bd04656199bbb51dbed1439b7f27601dfb576fb864099c7ef0c3e55531/pyyaml-6.0.3-cp312-cp312-win_arm64.whl", hash = "sha256:64386e5e707d03a7e172c0701abfb7e10f0fb753ee1d773128192742712a98fd", size = 140344, upload-time = "2025-09-25T21:32:22.617Z" }, + { url = "https://files.pythonhosted.org/packages/d1/11/0fd08f8192109f7169db964b5707a2f1e8b745d4e239b784a5a1dd80d1db/pyyaml-6.0.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:8da9669d359f02c0b91ccc01cac4a67f16afec0dac22c2ad09f46bee0697eba8", size = 181669, upload-time = "2025-09-25T21:32:23.673Z" }, + { url = "https://files.pythonhosted.org/packages/b1/16/95309993f1d3748cd644e02e38b75d50cbc0d9561d21f390a76242ce073f/pyyaml-6.0.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:2283a07e2c21a2aa78d9c4442724ec1eb15f5e42a723b99cb3d822d48f5f7ad1", size = 173252, upload-time = "2025-09-25T21:32:25.149Z" }, + { url = "https://files.pythonhosted.org/packages/50/31/b20f376d3f810b9b2371e72ef5adb33879b25edb7a6d072cb7ca0c486398/pyyaml-6.0.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ee2922902c45ae8ccada2c5b501ab86c36525b883eff4255313a253a3160861c", size = 767081, upload-time = "2025-09-25T21:32:26.575Z" }, + { url = "https://files.pythonhosted.org/packages/49/1e/a55ca81e949270d5d4432fbbd19dfea5321eda7c41a849d443dc92fd1ff7/pyyaml-6.0.3-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:a33284e20b78bd4a18c8c2282d549d10bc8408a2a7ff57653c0cf0b9be0afce5", size = 841159, upload-time = "2025-09-25T21:32:27.727Z" }, + { url = "https://files.pythonhosted.org/packages/74/27/e5b8f34d02d9995b80abcef563ea1f8b56d20134d8f4e5e81733b1feceb2/pyyaml-6.0.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0f29edc409a6392443abf94b9cf89ce99889a1dd5376d94316ae5145dfedd5d6", size = 801626, upload-time = "2025-09-25T21:32:28.878Z" }, + { url = "https://files.pythonhosted.org/packages/f9/11/ba845c23988798f40e52ba45f34849aa8a1f2d4af4b798588010792ebad6/pyyaml-6.0.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:f7057c9a337546edc7973c0d3ba84ddcdf0daa14533c2065749c9075001090e6", size = 753613, upload-time = "2025-09-25T21:32:30.178Z" }, + { url = "https://files.pythonhosted.org/packages/3d/e0/7966e1a7bfc0a45bf0a7fb6b98ea03fc9b8d84fa7f2229e9659680b69ee3/pyyaml-6.0.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:eda16858a3cab07b80edaf74336ece1f986ba330fdb8ee0d6c0d68fe82bc96be", size = 794115, upload-time = "2025-09-25T21:32:31.353Z" }, + { url = "https://files.pythonhosted.org/packages/de/94/980b50a6531b3019e45ddeada0626d45fa85cbe22300844a7983285bed3b/pyyaml-6.0.3-cp313-cp313-win32.whl", hash = "sha256:d0eae10f8159e8fdad514efdc92d74fd8d682c933a6dd088030f3834bc8e6b26", size = 137427, upload-time = "2025-09-25T21:32:32.58Z" }, + { url = "https://files.pythonhosted.org/packages/97/c9/39d5b874e8b28845e4ec2202b5da735d0199dbe5b8fb85f91398814a9a46/pyyaml-6.0.3-cp313-cp313-win_amd64.whl", hash = "sha256:79005a0d97d5ddabfeeea4cf676af11e647e41d81c9a7722a193022accdb6b7c", size = 154090, upload-time = "2025-09-25T21:32:33.659Z" }, + { url = "https://files.pythonhosted.org/packages/73/e8/2bdf3ca2090f68bb3d75b44da7bbc71843b19c9f2b9cb9b0f4ab7a5a4329/pyyaml-6.0.3-cp313-cp313-win_arm64.whl", hash = "sha256:5498cd1645aa724a7c71c8f378eb29ebe23da2fc0d7a08071d89469bf1d2defb", size = 140246, upload-time = "2025-09-25T21:32:34.663Z" }, + { url = "https://files.pythonhosted.org/packages/9d/8c/f4bd7f6465179953d3ac9bc44ac1a8a3e6122cf8ada906b4f96c60172d43/pyyaml-6.0.3-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:8d1fab6bb153a416f9aeb4b8763bc0f22a5586065f86f7664fc23339fc1c1fac", size = 181814, upload-time = "2025-09-25T21:32:35.712Z" }, + { url = "https://files.pythonhosted.org/packages/bd/9c/4d95bb87eb2063d20db7b60faa3840c1b18025517ae857371c4dd55a6b3a/pyyaml-6.0.3-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:34d5fcd24b8445fadc33f9cf348c1047101756fd760b4dacb5c3e99755703310", size = 173809, upload-time = "2025-09-25T21:32:36.789Z" }, + { url = "https://files.pythonhosted.org/packages/92/b5/47e807c2623074914e29dabd16cbbdd4bf5e9b2db9f8090fa64411fc5382/pyyaml-6.0.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:501a031947e3a9025ed4405a168e6ef5ae3126c59f90ce0cd6f2bfc477be31b7", size = 766454, upload-time = "2025-09-25T21:32:37.966Z" }, + { url = "https://files.pythonhosted.org/packages/02/9e/e5e9b168be58564121efb3de6859c452fccde0ab093d8438905899a3a483/pyyaml-6.0.3-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:b3bc83488de33889877a0f2543ade9f70c67d66d9ebb4ac959502e12de895788", size = 836355, upload-time = "2025-09-25T21:32:39.178Z" }, + { url = "https://files.pythonhosted.org/packages/88/f9/16491d7ed2a919954993e48aa941b200f38040928474c9e85ea9e64222c3/pyyaml-6.0.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c458b6d084f9b935061bc36216e8a69a7e293a2f1e68bf956dcd9e6cbcd143f5", size = 794175, upload-time = "2025-09-25T21:32:40.865Z" }, + { url = "https://files.pythonhosted.org/packages/dd/3f/5989debef34dc6397317802b527dbbafb2b4760878a53d4166579111411e/pyyaml-6.0.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:7c6610def4f163542a622a73fb39f534f8c101d690126992300bf3207eab9764", size = 755228, upload-time = "2025-09-25T21:32:42.084Z" }, + { url = "https://files.pythonhosted.org/packages/d7/ce/af88a49043cd2e265be63d083fc75b27b6ed062f5f9fd6cdc223ad62f03e/pyyaml-6.0.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:5190d403f121660ce8d1d2c1bb2ef1bd05b5f68533fc5c2ea899bd15f4399b35", size = 789194, upload-time = "2025-09-25T21:32:43.362Z" }, + { url = "https://files.pythonhosted.org/packages/23/20/bb6982b26a40bb43951265ba29d4c246ef0ff59c9fdcdf0ed04e0687de4d/pyyaml-6.0.3-cp314-cp314-win_amd64.whl", hash = "sha256:4a2e8cebe2ff6ab7d1050ecd59c25d4c8bd7e6f400f5f82b96557ac0abafd0ac", size = 156429, upload-time = "2025-09-25T21:32:57.844Z" }, + { url = "https://files.pythonhosted.org/packages/f4/f4/a4541072bb9422c8a883ab55255f918fa378ecf083f5b85e87fc2b4eda1b/pyyaml-6.0.3-cp314-cp314-win_arm64.whl", hash = "sha256:93dda82c9c22deb0a405ea4dc5f2d0cda384168e466364dec6255b293923b2f3", size = 143912, upload-time = "2025-09-25T21:32:59.247Z" }, + { url = "https://files.pythonhosted.org/packages/7c/f9/07dd09ae774e4616edf6cda684ee78f97777bdd15847253637a6f052a62f/pyyaml-6.0.3-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:02893d100e99e03eda1c8fd5c441d8c60103fd175728e23e431db1b589cf5ab3", size = 189108, upload-time = "2025-09-25T21:32:44.377Z" }, + { url = "https://files.pythonhosted.org/packages/4e/78/8d08c9fb7ce09ad8c38ad533c1191cf27f7ae1effe5bb9400a46d9437fcf/pyyaml-6.0.3-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:c1ff362665ae507275af2853520967820d9124984e0f7466736aea23d8611fba", size = 183641, upload-time = "2025-09-25T21:32:45.407Z" }, + { url = "https://files.pythonhosted.org/packages/7b/5b/3babb19104a46945cf816d047db2788bcaf8c94527a805610b0289a01c6b/pyyaml-6.0.3-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6adc77889b628398debc7b65c073bcb99c4a0237b248cacaf3fe8a557563ef6c", size = 831901, upload-time = "2025-09-25T21:32:48.83Z" }, + { url = "https://files.pythonhosted.org/packages/8b/cc/dff0684d8dc44da4d22a13f35f073d558c268780ce3c6ba1b87055bb0b87/pyyaml-6.0.3-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:a80cb027f6b349846a3bf6d73b5e95e782175e52f22108cfa17876aaeff93702", size = 861132, upload-time = "2025-09-25T21:32:50.149Z" }, + { url = "https://files.pythonhosted.org/packages/b1/5e/f77dc6b9036943e285ba76b49e118d9ea929885becb0a29ba8a7c75e29fe/pyyaml-6.0.3-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:00c4bdeba853cc34e7dd471f16b4114f4162dc03e6b7afcc2128711f0eca823c", size = 839261, upload-time = "2025-09-25T21:32:51.808Z" }, + { url = "https://files.pythonhosted.org/packages/ce/88/a9db1376aa2a228197c58b37302f284b5617f56a5d959fd1763fb1675ce6/pyyaml-6.0.3-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:66e1674c3ef6f541c35191caae2d429b967b99e02040f5ba928632d9a7f0f065", size = 805272, upload-time = "2025-09-25T21:32:52.941Z" }, + { url = "https://files.pythonhosted.org/packages/da/92/1446574745d74df0c92e6aa4a7b0b3130706a4142b2d1a5869f2eaa423c6/pyyaml-6.0.3-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:16249ee61e95f858e83976573de0f5b2893b3677ba71c9dd36b9cf8be9ac6d65", size = 829923, upload-time = "2025-09-25T21:32:54.537Z" }, + { url = "https://files.pythonhosted.org/packages/f0/7a/1c7270340330e575b92f397352af856a8c06f230aa3e76f86b39d01b416a/pyyaml-6.0.3-cp314-cp314t-win_amd64.whl", hash = "sha256:4ad1906908f2f5ae4e5a8ddfce73c320c2a1429ec52eafd27138b7f1cbe341c9", size = 174062, upload-time = "2025-09-25T21:32:55.767Z" }, + { url = "https://files.pythonhosted.org/packages/f1/12/de94a39c2ef588c7e6455cfbe7343d3b2dc9d6b6b2f40c4c6565744c873d/pyyaml-6.0.3-cp314-cp314t-win_arm64.whl", hash = "sha256:ebc55a14a21cb14062aa4162f906cd962b28e2e9ea38f9b4391244cd8de4ae0b", size = 149341, upload-time = "2025-09-25T21:32:56.828Z" }, +] + +[[package]] +name = "referencing" +version = "0.37.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "attrs" }, + { name = "rpds-py" }, + { name = "typing-extensions", marker = "python_full_version < '3.13'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/22/f5/df4e9027acead3ecc63e50fe1e36aca1523e1719559c499951bb4b53188f/referencing-0.37.0.tar.gz", hash = "sha256:44aefc3142c5b842538163acb373e24cce6632bd54bdb01b21ad5863489f50d8", size = 78036, upload-time = "2025-10-13T15:30:48.871Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/2c/58/ca301544e1fa93ed4f80d724bf5b194f6e4b945841c5bfd555878eea9fcb/referencing-0.37.0-py3-none-any.whl", hash = "sha256:381329a9f99628c9069361716891d34ad94af76e461dcb0335825aecc7692231", size = 26766, upload-time = "2025-10-13T15:30:47.625Z" }, +] + +[[package]] +name = "requests" +version = "2.34.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "certifi" }, + { name = "charset-normalizer" }, + { name = "idna" }, + { name = "urllib3" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/ac/c3/e2a2b89f2d3e2179abd6d00ebd70bff6273f37fb3e0cc209f48b39d00cbf/requests-2.34.2.tar.gz", hash = "sha256:f288924cae4e29463698d6d60bc6a4da69c89185ad1e0bcc4104f584e960b9ed", size = 142856, upload-time = "2026-05-14T19:25:27.735Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a0/f4/c67b0b3f1b9245e8d266f0f112c500d50e5b4e83cb6f3b71b6528104182a/requests-2.34.2-py3-none-any.whl", hash = "sha256:2a0d60c172f83ac6ab31e4554906c0f3b3588d37b5cb939b1c061f4907e278e0", size = 73075, upload-time = "2026-05-14T19:25:26.443Z" }, +] + +[[package]] +name = "rpds-py" +version = "2026.9.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/42/68/3bd46b8a5e01d3c2ebdf9c5e9497912e3fe0cde02bac21a7130ca866e403/rpds_py-2026.9.1.tar.gz", hash = "sha256:4793ef7f78268b124b73fa933440f01d258bbae01de9fa53e9080c9ab0425a12", size = 63948, upload-time = "2026-10-04T16:32:36.469Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f5/6d/ddb8dfcf41892ba9c672d27988592c038d30db61708230313831b6780a1b/rpds_py-2026.9.1-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:2711d29b653b3bce48a63d18b9c6b53274669e6d6c4094dddeb4d9a0e45128b2", size = 344947, upload-time = "2026-10-04T16:28:55.207Z" }, + { url = "https://files.pythonhosted.org/packages/9e/b2/632c3d034961149eff606e3e357547620a9ab37b849ae5815f67838753fd/rpds_py-2026.9.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:3231c4c0e521dafa5be0c9f114ee2c2ad46650836f2d72caa86801950c3e7044", size = 346770, upload-time = "2026-10-04T16:28:56.884Z" }, + { url = "https://files.pythonhosted.org/packages/6d/45/4df346410bb873d03ec60c3b891d1fceb8cabde1971d29844bbb625cc296/rpds_py-2026.9.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e01b3c878c8641913e688edd1b3f08658c6783d29cf6b826bd3c0d1ae7a1ffaa", size = 377795, upload-time = "2026-10-04T16:28:58.193Z" }, + { url = "https://files.pythonhosted.org/packages/ba/b8/a70f302207e4f29f873c01a986fcac5def49b9c8224328cef1ad7da6b7a9/rpds_py-2026.9.1-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:3e524c7874ac72884d28e16dd5b8d839fd09e0fe76b020d3fbca23212a7b8c52", size = 383137, upload-time = "2026-10-04T16:28:59.411Z" }, + { url = "https://files.pythonhosted.org/packages/13/e3/3aa28a48a01169d0e20728bf0e5ebbea3ae2774285b40853ae49b3ef332a/rpds_py-2026.9.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:761fdae6728ceb99ab182fad2f0cc1e262f610834dc891aea1d1a2a2e634776f", size = 496789, upload-time = "2026-10-04T16:29:01.011Z" }, + { url = "https://files.pythonhosted.org/packages/3e/a7/414e8d088602d66ad6f47c65bf07fe5090992a8574cdd4571c1a83b647ed/rpds_py-2026.9.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:6b723eb406dec5bc9ec516c73ab9c3239a3284e017f7eb89ee2b3258bd504fb7", size = 395929, upload-time = "2026-10-04T16:29:02.465Z" }, + { url = "https://files.pythonhosted.org/packages/2d/5c/aac3b960fd55d37b49f77c0eebbe043eaf36762ebd48e7b46951e59c1c05/rpds_py-2026.9.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:136a1c3fe4402b7008bc81cb62ee538481795b61a7e83df88dff3b3f02b726ff", size = 375426, upload-time = "2026-10-04T16:29:03.944Z" }, + { url = "https://files.pythonhosted.org/packages/d3/80/77987a41c40be7202a78d9aed4a650bfb05792237cfd3b9e22638d990fe5/rpds_py-2026.9.1-cp311-cp311-manylinux_2_31_riscv64.whl", hash = "sha256:839dde845559254f34885267c6878f60d61d5205180226d976fe488d45fa128e", size = 381497, upload-time = "2026-10-04T16:29:05.308Z" }, + { url = "https://files.pythonhosted.org/packages/b8/d0/640b02eb1ecd71a913c1178b6235287b31006266bca9a26862e80e497b54/rpds_py-2026.9.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:56cd8b3f77d7b6812f533b662186a1f28316931166ddc00fb893b1b0db7e9888", size = 405740, upload-time = "2026-10-04T16:29:06.578Z" }, + { url = "https://files.pythonhosted.org/packages/3e/8c/d034195d45d215625a23f2ae85dbbdb86a49a93a51272061c97c80b9d316/rpds_py-2026.9.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:074a4d198bc34d9a8ea425114fc3ded6d11ec01f6a314a8db67454a5152d8834", size = 555850, upload-time = "2026-10-04T16:29:08.115Z" }, + { url = "https://files.pythonhosted.org/packages/de/f8/532f1addfc86207bc3cf23749638bb0d457bce891595012ed8a08d0543b8/rpds_py-2026.9.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:6beb738155fe8ab8091afdfa5a3226b21c2b1593f1e50ebb90eb25b44dbc0391", size = 618661, upload-time = "2026-10-04T16:29:09.554Z" }, + { url = "https://files.pythonhosted.org/packages/50/5b/b0f2c9833a36a5b1f6ac5cb0e635fabacf713266f46ceefba2102da0bf51/rpds_py-2026.9.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:57492a550a1d88d29d003247e5f78dd8cf04a701fac0e4c8db8745a6d2504e0a", size = 583530, upload-time = "2026-10-04T16:29:11.072Z" }, + { url = "https://files.pythonhosted.org/packages/bf/20/464ed4b98d3c8c6a334f3b5e24d3886de04b05658a95fc40a37e0e6e4775/rpds_py-2026.9.1-cp311-cp311-win32.whl", hash = "sha256:d95a354e02393eada6d7351184671aced9d4cce109dabf927cb7aa99624352a1", size = 208125, upload-time = "2026-10-04T16:29:12.408Z" }, + { url = "https://files.pythonhosted.org/packages/df/c9/384a9b62f8cd89c8e3e609b8c9052c140e8c01d807261e0517c904b8bf29/rpds_py-2026.9.1-cp311-cp311-win_amd64.whl", hash = "sha256:ce4d4f52e2a4324396caddbd45a97d8d7be5f42edd25d2355282a9c34f9b2f7f", size = 226045, upload-time = "2026-10-04T16:29:13.751Z" }, + { url = "https://files.pythonhosted.org/packages/4f/3b/0a691f0dcb2301fa9c736346da2d0d4991778373283301c5c12b8f952f3d/rpds_py-2026.9.1-cp311-cp311-win_arm64.whl", hash = "sha256:fdcd198979b4ecffcc1beba366a7fbcf4eb41243691a82fe52ceb0b902f09c12", size = 222636, upload-time = "2026-10-04T16:29:14.989Z" }, + { url = "https://files.pythonhosted.org/packages/5d/34/a828586ea3329fbb50895b50e9cf98ca3d924a9f41a0b26d443bff1b3794/rpds_py-2026.9.1-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:50906f5aea24b5a865cbd0a589698288631d9f3a54c3a937c83aefa95a0d14af", size = 346822, upload-time = "2026-10-04T16:29:16.258Z" }, + { url = "https://files.pythonhosted.org/packages/90/81/ac6a0d064982251856ce009c9e1dd51a34110b3c055aa7d1aad18b4899a3/rpds_py-2026.9.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:e21c1429e205828ea886a2293a4a2c8e01f4c25d9893ca330e97a6cf73f52e7b", size = 341380, upload-time = "2026-10-04T16:29:17.706Z" }, + { url = "https://files.pythonhosted.org/packages/42/ff/bf7d54f362748fd6a49277b9d6531c394074110fedf50ad791ec59133fbb/rpds_py-2026.9.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2693b2728bbcc48d09a981a356954b0c47c53ff25b545856f28a889ea619f69a", size = 373053, upload-time = "2026-10-04T16:29:19.063Z" }, + { url = "https://files.pythonhosted.org/packages/60/de/74b0ccdbbd28687b9b5fdb34c1cabed88352182facaced9d6f5486b8b9ed/rpds_py-2026.9.1-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:8601470267d938bcb7f3ab1a336100af51a4fd5b6ed030ef52461bb3ef5e7e07", size = 377742, upload-time = "2026-10-04T16:29:20.543Z" }, + { url = "https://files.pythonhosted.org/packages/c2/6d/b979775a3057b2a5c26d75ecbff60a20a24ef081db6dd76836fca3f20247/rpds_py-2026.9.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3890a6aa36e6baa53d5258a2a25d3ef8b37ad165a6ab27a892d7c3e3a432cd69", size = 487289, upload-time = "2026-10-04T16:29:21.958Z" }, + { url = "https://files.pythonhosted.org/packages/1d/5d/7c34734ce3ece943d9d6ee0122a74a21bbc75b47acb5b7053c83f6efb1ed/rpds_py-2026.9.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:6b5b393eda5ea42cca1c1a6665f2a4882b4fd5d1777e41ce0545a107fb008c9d", size = 390710, upload-time = "2026-10-04T16:29:23.378Z" }, + { url = "https://files.pythonhosted.org/packages/1d/6d/b26eb1e75395925b3a142ed351cbed2ec8212f5c9d937aee3df32c701baa/rpds_py-2026.9.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:addeda51556dac7c1a2f14cda62db8b621cd12afba3091d03a96c72932387eab", size = 371261, upload-time = "2026-10-04T16:29:25.1Z" }, + { url = "https://files.pythonhosted.org/packages/7c/98/b2fdfe10301a9e27af21e634337fbba7baac0bc17fe44619a17c26bba2cb/rpds_py-2026.9.1-cp312-cp312-manylinux_2_31_riscv64.whl", hash = "sha256:d9edf30457d74eebfd76b045535e36f1cd89062566a128a0db2145ca042d787e", size = 376075, upload-time = "2026-10-04T16:29:26.748Z" }, + { url = "https://files.pythonhosted.org/packages/c5/b1/c4b8d954e49c3c69cf8063c0c9e0919c99f3d2cecc46311606a1cbe835dc/rpds_py-2026.9.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:815d26356930846a40c7bc1366e7b1b0320ab8a063e66c11298a208bed0fd237", size = 399358, upload-time = "2026-10-04T16:29:28.282Z" }, + { url = "https://files.pythonhosted.org/packages/b3/59/9559a7293c97dff0cbb293efffbd36644103883ecc27741af8ef90c84ca8/rpds_py-2026.9.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:3b5a6f40f0a1486b4b36c888123afc67acdbd9f33235927acf5ff295429a0ba3", size = 550267, upload-time = "2026-10-04T16:29:29.851Z" }, + { url = "https://files.pythonhosted.org/packages/6c/9d/6dc60e49511de4c8b00e74f9c1d43aed4d27f712cdb1ade92f2c199cbf64/rpds_py-2026.9.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:b5b8b0753718d258fd454283fbd57e14545d3b40583fa672e27cb4f987626bcc", size = 614018, upload-time = "2026-10-04T16:29:31.54Z" }, + { url = "https://files.pythonhosted.org/packages/fb/bc/92a4ecf27301b886232a413360f6b348a81d55ffef654f2ebda5970ebc3d/rpds_py-2026.9.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:46d80bc76b51a6c24f9944368c28d38b8bcbcea1da4f2f8d3ebc31a67e8c6ec6", size = 578509, upload-time = "2026-10-04T16:29:33.01Z" }, + { url = "https://files.pythonhosted.org/packages/08/53/efb97f2e6589b7ab8394385a73870e0b2ab2a195281c117b21fd6d7d4855/rpds_py-2026.9.1-cp312-cp312-win32.whl", hash = "sha256:befc2d6a953e563f8a7bfd87a42c22ebf8a3e980dcb7b6a4d17b70b0e914e8a3", size = 205401, upload-time = "2026-10-04T16:29:34.451Z" }, + { url = "https://files.pythonhosted.org/packages/1c/84/1700cc748d0eaa747486e4e82882d2575224e6e9a3148df583058850c629/rpds_py-2026.9.1-cp312-cp312-win_amd64.whl", hash = "sha256:5ce8943f79c2210f7abcc28e86367b03b28d95027fd01c46d2472373ae70c86f", size = 222923, upload-time = "2026-10-04T16:29:35.709Z" }, + { url = "https://files.pythonhosted.org/packages/c3/89/0302215373c2f8b4408b0fdfee955368cc378a98ff59508d47a7e0dc2dbf/rpds_py-2026.9.1-cp312-cp312-win_arm64.whl", hash = "sha256:501909f2e4a1e2dee528ef766fe3c469060ebc17e54a8383d404ba07a81a6f02", size = 218415, upload-time = "2026-10-04T16:29:37.263Z" }, + { url = "https://files.pythonhosted.org/packages/83/ea/ee88fd9e756ff93fb6b1182a47ec09504a242620e33ce1d20679efefe841/rpds_py-2026.9.1-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:a36b70596407634ca82d4b989a3729074a008537a0522e4c8046a67c729103e9", size = 346229, upload-time = "2026-10-04T16:29:38.82Z" }, + { url = "https://files.pythonhosted.org/packages/57/71/a097d6552f837500fc36e6b23d09cfb9890c3cc47531f9ca64e149799615/rpds_py-2026.9.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:eba5d173f7d5708b22a93815017a4611873ed54db9f268077c0dd1ed99cfc858", size = 340514, upload-time = "2026-10-04T16:29:40.405Z" }, + { url = "https://files.pythonhosted.org/packages/bd/b7/497e85768bf4e0d8ddbaa096a4cac31d1509251dee2728a8490aa367e0b5/rpds_py-2026.9.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:457866b85daf5034296666168b84a69e0b2e89dc4f1af102b46f6448a60b9063", size = 372611, upload-time = "2026-10-04T16:29:41.778Z" }, + { url = "https://files.pythonhosted.org/packages/52/4b/74ab4108916250b6e198e0d3af05bc6835eb046315f22f7a0ceb49667c5a/rpds_py-2026.9.1-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:a3a52a3ba86436ab3aef510fbe21512abc2ddd1993005dfe50514bd2284ef025", size = 377712, upload-time = "2026-10-04T16:29:43.242Z" }, + { url = "https://files.pythonhosted.org/packages/0c/8e/067e77d9d7b3cc793c9d909b7e97e7aadbbb1fb094093b6876902cc96d38/rpds_py-2026.9.1-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d7841166b7fa64c9c56404617ae4341448847482d45933b13135d26c130519e5", size = 488106, upload-time = "2026-10-04T16:29:44.692Z" }, + { url = "https://files.pythonhosted.org/packages/3c/b4/c5aae6c2dde269bf955f6b7d35065c655a57e47750d9668052ad67e74dda/rpds_py-2026.9.1-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:926bdd3e3b5998ddf70cc64bc8cf57209571f9044542913afb673799fec77dd0", size = 390795, upload-time = "2026-10-04T16:29:46.129Z" }, + { url = "https://files.pythonhosted.org/packages/a0/36/76fab39973ee11e7f9f357c55138197bb01c86f6502cb76487e3b4f42db0/rpds_py-2026.9.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7868b85224291c6cb6759f9b5adb9745f486d226f62b16a614dd5a2a5ab2b35b", size = 370794, upload-time = "2026-10-04T16:29:47.603Z" }, + { url = "https://files.pythonhosted.org/packages/3d/fe/cd2a80e6d7b871937a60e935c5d507aa390d143f4ff3636f640b9733d5df/rpds_py-2026.9.1-cp313-cp313-manylinux_2_31_riscv64.whl", hash = "sha256:3cd182d7291d29b92c521a0069d9c01ba6193628a9a105531d11b40a6d731a33", size = 375673, upload-time = "2026-10-04T16:29:49.223Z" }, + { url = "https://files.pythonhosted.org/packages/6c/18/7464a9953724e55a3b3206062fa0ffdeaa519584c6aabf65d3956d94f131/rpds_py-2026.9.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:e6ea1cda8d8c688278430e4268a42f5e5da3bdd74578dfadc0820c3f1766ce83", size = 398758, upload-time = "2026-10-04T16:29:50.601Z" }, + { url = "https://files.pythonhosted.org/packages/c0/86/1534b436700fd49ff411063b7c4d7e938adfabf90895b6cf1622d5a7d1f6/rpds_py-2026.9.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:5943980471829f6de242a20b109de3111ba6b77e3af0ffc587028ac854b05e6c", size = 550370, upload-time = "2026-10-04T16:29:52.002Z" }, + { url = "https://files.pythonhosted.org/packages/57/1c/e1fa82a8a01e3c5820f3ba98a8b2673f642128eb368fa88871b01dd2c909/rpds_py-2026.9.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:76d3af9732d2dab69f28179b40ba2d87e2f1d5824b4a694780aa787d685e8f36", size = 613106, upload-time = "2026-10-04T16:29:53.655Z" }, + { url = "https://files.pythonhosted.org/packages/29/55/b20b8c4c3dde8755bfcd5b08492a02d0cd2e26929aedf6199ca2a377d42a/rpds_py-2026.9.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:78326f4cb4427a56ba4996c0762b63be45f06b85f086526420d2b3a66e40f84d", size = 578235, upload-time = "2026-10-04T16:29:55.157Z" }, + { url = "https://files.pythonhosted.org/packages/55/42/df3f7bbc3f7ab37a8a9db8d6c2ff2c985422899f1f7926afbf7ec3c0b8b4/rpds_py-2026.9.1-cp313-cp313-win32.whl", hash = "sha256:172e47169583f46ce118cbec68e6795d0da0f4606b488b6434f8276bca0a058c", size = 205293, upload-time = "2026-10-04T16:29:56.669Z" }, + { url = "https://files.pythonhosted.org/packages/31/9c/ba5a9569d719bfdd6ce863df4133ac6a1658cf1b07cc3534c31db729fbbc/rpds_py-2026.9.1-cp313-cp313-win_amd64.whl", hash = "sha256:3e93b2cd69a9830be33e03945cd7cda940a0a8bfcfbff41d6144f0cb0d3d8bd9", size = 222409, upload-time = "2026-10-04T16:29:58.049Z" }, + { url = "https://files.pythonhosted.org/packages/35/72/f28ca566f6c23c35bbf7445f65eb0364577b25a026305995e24f78b83d94/rpds_py-2026.9.1-cp313-cp313-win_arm64.whl", hash = "sha256:d151e148117294133bf8af7eeace085e7e87432db15ab6adf640330298a47f6f", size = 217681, upload-time = "2026-10-04T16:29:59.449Z" }, + { url = "https://files.pythonhosted.org/packages/8a/f2/67b94be1532767803415c1c5a1fd88ea487643d74a673cec1ba140af77bb/rpds_py-2026.9.1-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:c9d1aca01f49170fdcf5c92761b1fafe97f554b721ca4570c5949fff778f0d4b", size = 347178, upload-time = "2026-10-04T16:30:00.865Z" }, + { url = "https://files.pythonhosted.org/packages/04/37/b751de2b59b0197a1d92a5dd491de88e8a5e928c2e6562581974f1e85263/rpds_py-2026.9.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:3f0e9ac28fc067d4d34b88ae43c48e9489455c97fee9633d851f7eeed5a05d35", size = 341878, upload-time = "2026-10-04T16:30:02.564Z" }, + { url = "https://files.pythonhosted.org/packages/72/e2/5873bc4643c250db9e05d48dc0c93763d4aa68bc3b81164cb1af3b45b284/rpds_py-2026.9.1-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:07deecbfce94c78473018bc7d10b337cc651d12df87a1eb2cb3e4024bc9c33d0", size = 373963, upload-time = "2026-10-04T16:30:04.026Z" }, + { url = "https://files.pythonhosted.org/packages/51/03/5acf7632158247f3f6386ff0af3a1ee48167d575037e8d0920594b76d92b/rpds_py-2026.9.1-cp314-cp314-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:821b2755db9194409254012f429c56643416fb96ef9be090be82ec8826b7f477", size = 377975, upload-time = "2026-10-04T16:30:05.555Z" }, + { url = "https://files.pythonhosted.org/packages/e6/00/63fda451b8bffa5808fc8bb311ee7c073b340974b09f273c7b2a145d3d62/rpds_py-2026.9.1-cp314-cp314-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3c91c210ae7645626c608400e3519b4a642f837cce09ca830db3beb2e9f274d4", size = 490347, upload-time = "2026-10-04T16:30:07.156Z" }, + { url = "https://files.pythonhosted.org/packages/a1/ae/c093ffd070ba0fb02f76c565d06fecc65ad6e4afdbae78f7031076d3cdac/rpds_py-2026.9.1-cp314-cp314-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:54ac2158a6f96cfbabff0b2eedaf94b90c5ec7ca8317fcadc61e1c2b2e0ff6ef", size = 392962, upload-time = "2026-10-04T16:30:08.77Z" }, + { url = "https://files.pythonhosted.org/packages/22/9d/d08a1128ab199b2f0cf25bfeb0639bd05119fff4b7c47bec24ef9a8ec23f/rpds_py-2026.9.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eac2f5dbafd585dfe31f86a23ebf0d3ba480a9d49ebc87947267b5608d4ea0cd", size = 371623, upload-time = "2026-10-04T16:30:10.501Z" }, + { url = "https://files.pythonhosted.org/packages/53/c7/4758ddcbb75609414bbccfcb11d612436f9b3ee821bd2f33f0f1604ee648/rpds_py-2026.9.1-cp314-cp314-manylinux_2_31_riscv64.whl", hash = "sha256:8aa5dda18d39b6143eb24809d158f9252c88f402749b6f1b62a506cc7d96cc35", size = 376997, upload-time = "2026-10-04T16:30:12.124Z" }, + { url = "https://files.pythonhosted.org/packages/87/e4/947bd7f608ff60faf46dc9d389c3dffd0e3d767d78a0be19978448ef0ce7/rpds_py-2026.9.1-cp314-cp314-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:5c90e7fa02e8f5de0d10c17595c568ada48c5302e749462c0ea1a4c362111a86", size = 400169, upload-time = "2026-10-04T16:30:13.804Z" }, + { url = "https://files.pythonhosted.org/packages/4b/35/fe93e020a0543b5670472c18d7e6af3197c08da571240ce1965c84f85c0f/rpds_py-2026.9.1-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:e6d198bad4e49dd6732fbd636e2fc5c082f45c8cad0b4acb756b00c82c76072e", size = 551615, upload-time = "2026-10-04T16:30:15.332Z" }, + { url = "https://files.pythonhosted.org/packages/0d/4f/5d2a0136bb03b2a56a39dc6ff92d58a6e3e53a2e17079238b86228882f16/rpds_py-2026.9.1-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:96beca19ec79de272e8668585380ff9092c47077c1d7a1e098e00bbd921f4785", size = 614655, upload-time = "2026-10-04T16:30:16.92Z" }, + { url = "https://files.pythonhosted.org/packages/09/1c/3f1025aaf70d9bf7272cc41f8b64ee76b48bf01726248138430e16f23b38/rpds_py-2026.9.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:a5cf77eb04f20b720be95265a3e00eb2a14814074255cc27069c551b2db53118", size = 579602, upload-time = "2026-10-04T16:30:18.555Z" }, + { url = "https://files.pythonhosted.org/packages/53/0d/5c72e6204f76610608706da32b6b7e11ef7e10317558a7bb15a122e008dc/rpds_py-2026.9.1-cp314-cp314-win32.whl", hash = "sha256:a03d57b86d2a51d0a66c92177e2be154ad015f357791d306e714569999cdb4cc", size = 206315, upload-time = "2026-10-04T16:30:20.05Z" }, + { url = "https://files.pythonhosted.org/packages/a4/0b/489d48abbcc7d70cf3fbf662d9d22abf1f4650761c0a9ae05260800800d3/rpds_py-2026.9.1-cp314-cp314-win_amd64.whl", hash = "sha256:837c6b305e26fe0f75b15c92cf3b2ba29e0ae19dc40b1c557b026cb426347d0c", size = 222852, upload-time = "2026-10-04T16:30:21.604Z" }, + { url = "https://files.pythonhosted.org/packages/91/16/bbb05a7e6a10cf79ba639be7f799d770ee15f64175cc61d081b218dd402a/rpds_py-2026.9.1-cp314-cp314-win_arm64.whl", hash = "sha256:fce4b85234a0cbad67bf8e6e1201ee815d172c9aebad75f25645bc4d834f8e31", size = 218709, upload-time = "2026-10-04T16:30:23.036Z" }, + { url = "https://files.pythonhosted.org/packages/22/ac/ac507a0a4ec478ca470440a09583db4be5259ba7670aeba0620822f1e57a/rpds_py-2026.9.1-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:3a72c11530d71abfb66c8d7696a2f86c43e63fca8b948f1a784ac490f4ec688e", size = 349596, upload-time = "2026-10-04T16:30:24.558Z" }, + { url = "https://files.pythonhosted.org/packages/e9/f2/817a46b658d5070f477f722c298ee9a24525b0e4017347964146ef5fdd0e/rpds_py-2026.9.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:068c37bba854ec2fe42f7365c640af11dd9895890ccbf2df5070d0c059bd7f96", size = 343114, upload-time = "2026-10-04T16:30:26.048Z" }, + { url = "https://files.pythonhosted.org/packages/6c/42/6ade976b13ac1b4cb3bf2eb603f1be2fe74df19a29988d4c2b386be59d6f/rpds_py-2026.9.1-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d7fca4eb6df565e2a928f1c7dad92d27db8f9df0f449e76423ed5d7e713ed445", size = 374197, upload-time = "2026-10-04T16:30:27.699Z" }, + { url = "https://files.pythonhosted.org/packages/d9/70/77cdf1d3f1a07faabe936016ae623aec7981f73108a8fe7a203ed2e21998/rpds_py-2026.9.1-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:c933c6678c6f116ff8af47a4c6db0868b8ace74af0343016c0ef00f00272ea69", size = 378025, upload-time = "2026-10-04T16:30:29.451Z" }, + { url = "https://files.pythonhosted.org/packages/3f/6b/18a44a3beaa9b7931acb04af7bd9539836477c630a794452d4826d6185d4/rpds_py-2026.9.1-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:028ad274ea951dac64491b5d1e65712a4aeabfdbdb9fccf797b57bd899b0c495", size = 491969, upload-time = "2026-10-04T16:30:30.995Z" }, + { url = "https://files.pythonhosted.org/packages/73/27/fb39cfd6bddaf741b024f813890374578ff8ac1f1adc473659c048b03b05/rpds_py-2026.9.1-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:740d0a99cf9de0b17a3943388e9294a59becf75e7c43421f387bd3c7a9901f7c", size = 393905, upload-time = "2026-10-04T16:30:32.628Z" }, + { url = "https://files.pythonhosted.org/packages/ed/71/0fa7bb77b57af0d710273964180d11b503f62b8a5c358eb2d8c3f62feff6/rpds_py-2026.9.1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0da298fb372dc192610a4b9ecbc68a0cd8b675bbbd1fc519d01b41cfd658333e", size = 374569, upload-time = "2026-10-04T16:30:34.257Z" }, + { url = "https://files.pythonhosted.org/packages/54/22/f41cfac269af3b449513ef1bc3d7f32fde52abbbd2d01c7e76b47743acd9/rpds_py-2026.9.1-cp314-cp314t-manylinux_2_31_riscv64.whl", hash = "sha256:eb61be926bb81567c1f48bdc8aa22b9855048dc2efd53871f9f7e6e9a5632346", size = 377482, upload-time = "2026-10-04T16:30:35.997Z" }, + { url = "https://files.pythonhosted.org/packages/b4/fc/312b49006e7f8f9ca5f96647577b8aa6f3df30519c46bd448f5c425af0b2/rpds_py-2026.9.1-cp314-cp314t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:42e75466f83cd43f6026c81eab74246efb2bdadafb307b85700632d06c68f299", size = 400040, upload-time = "2026-10-04T16:30:37.76Z" }, + { url = "https://files.pythonhosted.org/packages/cf/a6/18cca7a878dc7fa95165a83343fd4d7b65643fd22e54e47340a451121d5c/rpds_py-2026.9.1-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:617f59cde379b4f648a09797b7f683d04b90a46344cddab85639da5aff0f5531", size = 551849, upload-time = "2026-10-04T16:30:39.443Z" }, + { url = "https://files.pythonhosted.org/packages/e4/6d/1f5685e20f39604691bdc3c05aaa6b8bd2f954e9e996477adf2376768e33/rpds_py-2026.9.1-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:3edae8c5ddfdb6985d49ae9d150516e5076888879022f91a26c2de9276ce0bdb", size = 614842, upload-time = "2026-10-04T16:30:41.231Z" }, + { url = "https://files.pythonhosted.org/packages/c6/25/98652109fd9f7e10268dd4571aa52b81987001b806f37ef1a18260de714a/rpds_py-2026.9.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:0f045bb053c9057720d72c56dffe30dffdc05997b2897a827b9325f0ab6623fa", size = 582606, upload-time = "2026-10-04T16:30:43.345Z" }, + { url = "https://files.pythonhosted.org/packages/19/03/11ca09099bab5f53373a80a334c424ec917c13d050760a59499d2af5171e/rpds_py-2026.9.1-cp314-cp314t-win32.whl", hash = "sha256:bf35d0568abda97233239ce32896d3ad53fccc537832c104e30c94aa5fb93569", size = 203341, upload-time = "2026-10-04T16:30:44.954Z" }, + { url = "https://files.pythonhosted.org/packages/6f/8a/88909e3ffd9f47f5b58211473875d8c3c09079f0058c46fb72c55a702a26/rpds_py-2026.9.1-cp314-cp314t-win_amd64.whl", hash = "sha256:1e8d4d79d828299bf44a55db22a9388ab967b49d17132c88eab0f4360b48da8e", size = 222843, upload-time = "2026-10-04T16:30:46.486Z" }, + { url = "https://files.pythonhosted.org/packages/f6/b7/a662f367d4896dd0a10cef2fc91f10b7f08af1c10858e287e019563f338d/rpds_py-2026.9.1-cp315-cp315-macosx_10_12_x86_64.whl", hash = "sha256:1d77b649e6f7cdf12ca5c2a98dad0ad37f9ea9b6f960408a92f0cb12bb3d04d9", size = 347463, upload-time = "2026-10-04T16:30:48.203Z" }, + { url = "https://files.pythonhosted.org/packages/ae/3f/ad45d03df4f84ebae5439577ee81f3999d182711e82235c8037b6528890e/rpds_py-2026.9.1-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:00ba2d8c7dd4ee537978ddf4b3fbd712bef2d8751603f7f3146b3f4287768e25", size = 342051, upload-time = "2026-10-04T16:30:49.872Z" }, + { url = "https://files.pythonhosted.org/packages/7e/31/3dcd68c13d4bcc59c1f7eb33ac8e80698f06f3eb0d8a1e06419836071c20/rpds_py-2026.9.1-cp315-cp315-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ec450527cbf485e13c8d3602a54f428ab0432fdade0ede75efd74b735421c871", size = 374143, upload-time = "2026-10-04T16:30:51.508Z" }, + { url = "https://files.pythonhosted.org/packages/cf/0d/68c1f058a250fbd1380ebda9fc227cbf50117adf8ffe8161ef383ea79f68/rpds_py-2026.9.1-cp315-cp315-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:306ee1850d8105b5baf977e78d45fcadd12c1a54678d614c9baf217708446e91", size = 378604, upload-time = "2026-10-04T16:30:53.206Z" }, + { url = "https://files.pythonhosted.org/packages/d7/d6/2d4c59b85397cb4800594fadf692688ccf5ce556adc930e7a5bf21061a5e/rpds_py-2026.9.1-cp315-cp315-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ef6b65b03247c54692ad4fd9ee97cb772781927db72e3cb05e70b3db6d1ff14f", size = 490790, upload-time = "2026-10-04T16:30:54.925Z" }, + { url = "https://files.pythonhosted.org/packages/da/04/7e05dc3aebaf52f4e026766bd668fdd09a9d0e23f64a14686b36b3501892/rpds_py-2026.9.1-cp315-cp315-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:a575404ebc9cf2e91edd32eaf570ec1430eb900d4f56724ba7dd4bc1fc9c176d", size = 393146, upload-time = "2026-10-04T16:30:56.625Z" }, + { url = "https://files.pythonhosted.org/packages/57/ca/e2e9a0a46a74ed51a0498ba1fe10f4ea6b2d9a155f372a2f91e51f18cf10/rpds_py-2026.9.1-cp315-cp315-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2c16ab111bc27c646ba8aa005d0527754edc538ebb636f0b1bf8e244b48d1945", size = 372022, upload-time = "2026-10-04T16:30:58.295Z" }, + { url = "https://files.pythonhosted.org/packages/ba/cb/8f8774df5134e23424372838bcc5c7ed4127d723e1ff52f7bebd4dcb2563/rpds_py-2026.9.1-cp315-cp315-manylinux_2_31_riscv64.whl", hash = "sha256:7664419f27db41d4f1c43a78dccda7dd6e8ef2428df3ee01d0c2a07a6b071297", size = 377092, upload-time = "2026-10-04T16:30:59.984Z" }, + { url = "https://files.pythonhosted.org/packages/90/02/8d7095d73bf9114219be40230baa5df00611e0a82ed9517779ff9c19f82b/rpds_py-2026.9.1-cp315-cp315-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:4b26b03d9d2658ee2fa234f8f4f19f38a09773fe5261028025032e26d4d35af0", size = 400830, upload-time = "2026-10-04T16:31:01.721Z" }, + { url = "https://files.pythonhosted.org/packages/ec/02/8206856f8f363cd042a8315dc86b3912f5dcb6d3c66bbb24b69c2bfb0775/rpds_py-2026.9.1-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:be3e47e2d91aa3942ff9bf4077a505226005abfc39b6f7554a91c1b9393986b9", size = 551478, upload-time = "2026-10-04T16:31:03.472Z" }, + { url = "https://files.pythonhosted.org/packages/41/6b/36211f1bb1f0b0313f496d92f5905b74ea107f27cb16fa3355a82f04575e/rpds_py-2026.9.1-cp315-cp315-musllinux_1_2_i686.whl", hash = "sha256:6307a0da524939decb8ca4a3933b8ab62525794411d6984fca6726e732804af6", size = 615173, upload-time = "2026-10-04T16:31:05.281Z" }, + { url = "https://files.pythonhosted.org/packages/35/77/cda0c4a6f055446b692f0ed5692f73707cafd3dff82672ede31b1a9b59de/rpds_py-2026.9.1-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:159a7aab5c5e8b112c8830f54717ce56da1252ebdbb526f5be2df2309280b9e7", size = 579653, upload-time = "2026-10-04T16:31:07.065Z" }, + { url = "https://files.pythonhosted.org/packages/74/ec/d8385f446240aed643b9e92a5055cff3015cc04a13c61f73b2883c478ed5/rpds_py-2026.9.1-cp315-cp315-win32.whl", hash = "sha256:dbc2673f9223d420c91145599b3ba45a8a50c207d1976908e5fb5ddb0c9b9429", size = 206498, upload-time = "2026-10-04T16:31:08.989Z" }, + { url = "https://files.pythonhosted.org/packages/6d/a5/71b5cd00e0521e3b6b81828baea368c62b6b700ebdd9554cd7d41ddf12fa/rpds_py-2026.9.1-cp315-cp315-win_amd64.whl", hash = "sha256:75c38c50ab9aca840225d9a9a3810bf11d04bd5c1f186cabbb8aee56db3e9b15", size = 223121, upload-time = "2026-10-04T16:31:10.84Z" }, + { url = "https://files.pythonhosted.org/packages/33/58/dba857c3bc8221b31b62eb170a3080f4f191de79f047200389b7ed1b06a7/rpds_py-2026.9.1-cp315-cp315-win_arm64.whl", hash = "sha256:a431156bb41865fc14cd5d79bb9d7bbed83110b0159e34e62ae30951f96c0009", size = 218741, upload-time = "2026-10-04T16:31:12.592Z" }, + { url = "https://files.pythonhosted.org/packages/5b/d0/320ab28ccc1415eeb509d68682b0014fb74690cd49f1c2d29a232475af50/rpds_py-2026.9.1-cp315-cp315t-macosx_10_12_x86_64.whl", hash = "sha256:ef0d8c843e2827d6c120ab4687e9423fb1d893db1df27b7c1506615bcb9734a0", size = 349719, upload-time = "2026-10-04T16:31:14.48Z" }, + { url = "https://files.pythonhosted.org/packages/56/88/f5b12f1358f443c08b7ce3cc8391d82d335f4872580e2e097847fd36087a/rpds_py-2026.9.1-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:45bc6bccf78b20fd834237d18db64965d7ee68ba7f60440a26c7ab71e7b8d51a", size = 343267, upload-time = "2026-10-04T16:31:16.827Z" }, + { url = "https://files.pythonhosted.org/packages/f7/0c/c765b0059d532acb3b9c45d781ccc22f15a96dbe443d00903f643ba9df10/rpds_py-2026.9.1-cp315-cp315t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1d55198263bb51f557550c6ed2e6d1cb6a6fed6eb5c9120b741c5926bef8a45d", size = 374555, upload-time = "2026-10-04T16:31:18.931Z" }, + { url = "https://files.pythonhosted.org/packages/6b/8a/cafddfda77564a10cd21184640c3bffda6a2b8d20972fb5dedd5e0166328/rpds_py-2026.9.1-cp315-cp315t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:a8763f20692da7df39b0afdd1ba3042b004c50a45994f76c2d9a25641f7673db", size = 378346, upload-time = "2026-10-04T16:31:20.75Z" }, + { url = "https://files.pythonhosted.org/packages/b9/01/5e626016eff72c183bf6c96539240cace15d402468647a453ec08415b2fc/rpds_py-2026.9.1-cp315-cp315t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e43d4a1f673e8a1cbd8533e809e02b4bf9d4f2280269bb640436556312121250", size = 492373, upload-time = "2026-10-04T16:31:22.614Z" }, + { url = "https://files.pythonhosted.org/packages/3b/9c/15a2469e9389242f46896b3f0a01d68caea8a5a35c011fcb05ef333aae73/rpds_py-2026.9.1-cp315-cp315t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:ea394a937f17a54c51239348bdbe2e3518124c8d4a8951ba04a311d3095bd18f", size = 394371, upload-time = "2026-10-04T16:31:24.768Z" }, + { url = "https://files.pythonhosted.org/packages/63/f5/c100ff77e1e6366e947c75969c258fdfc4b7bc5bbfe7351e62ffbf2a1228/rpds_py-2026.9.1-cp315-cp315t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:cdeaa99ce822dca76cfb1b993e9120c5ea212f2eb66d48950ad63c349668a018", size = 375132, upload-time = "2026-10-04T16:31:26.588Z" }, + { url = "https://files.pythonhosted.org/packages/dd/f4/fe0269c9de253e99c81cabc12b8971a5feaa083debdaff1221e06264d9e3/rpds_py-2026.9.1-cp315-cp315t-manylinux_2_31_riscv64.whl", hash = "sha256:b4f062343e7ad3fa94f2c66e5ae667dee47ee74dd41a9057c4fbe163236a123d", size = 377642, upload-time = "2026-10-04T16:31:28.677Z" }, + { url = "https://files.pythonhosted.org/packages/05/65/b34a7b257baccff8f4a24a722933166d4941d5ebdc9c3f4bc4ffcd5ce4f4/rpds_py-2026.9.1-cp315-cp315t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:22ffd29a63d71fb1b81552c21f2c2b734949b7ac751a9be70675a939a900839b", size = 400855, upload-time = "2026-10-04T16:31:30.802Z" }, + { url = "https://files.pythonhosted.org/packages/98/32/844e54176b6071b90b38a564e6940bc6eb8f97b2890dc709c19db9dec0f4/rpds_py-2026.9.1-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:08dae4a4095150a7c4545a1fb40b98e1ab1744fbc2770d92c977b9dadaa49ab6", size = 552573, upload-time = "2026-10-04T16:31:32.709Z" }, + { url = "https://files.pythonhosted.org/packages/17/73/6041d20729dffbfdf155c02d65be58bc225a1c1fb548fd87c23ef306138f/rpds_py-2026.9.1-cp315-cp315t-musllinux_1_2_i686.whl", hash = "sha256:9a0460d43603d1fd9ef59c30278531e15d78581721ddb538fa560aa7817ea4ad", size = 615840, upload-time = "2026-10-04T16:31:34.565Z" }, + { url = "https://files.pythonhosted.org/packages/af/9e/418094adaee6b056ce199051b255448ed872829051e341b2294c80da0977/rpds_py-2026.9.1-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:1c2d1f6da5128eabf34e963d7163a818846075a52568250d006c4c953b40f903", size = 582764, upload-time = "2026-10-04T16:31:36.665Z" }, + { url = "https://files.pythonhosted.org/packages/3d/9b/1698ebf6b840ddfe8b472198abbed6ace35c6e398faeecd6c47dae742a4e/rpds_py-2026.9.1-cp315-cp315t-win32.whl", hash = "sha256:5c6ee90dee3e85e055ddfd502d611643d9b0fd94c818220bda84ec3dacd9b27b", size = 203795, upload-time = "2026-10-04T16:31:38.53Z" }, + { url = "https://files.pythonhosted.org/packages/8a/e2/91f70d804c61f8eac39a417e82aa1024f655ab9e8bdd7393b196242bc41b/rpds_py-2026.9.1-cp315-cp315t-win_amd64.whl", hash = "sha256:fe5ad0664ec772b02c45859041aa17655709cced7a31005817fbbbd988c25567", size = 223037, upload-time = "2026-10-04T16:31:40.468Z" }, + { url = "https://files.pythonhosted.org/packages/f3/ad/f0eba548e297987964ef8088403db875b333963bf8189f3f563b6936b20e/rpds_py-2026.9.1-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4c0d2cb595a420b34d5086db0add011e26e2c09d6a024afbac4228bf8f863a30", size = 384112, upload-time = "2026-10-04T16:31:42.643Z" }, + { url = "https://files.pythonhosted.org/packages/33/89/891fa4d81f1eae7fe262ecd0aba2c51de94a116c7f3ccfb034fa75f4c537/rpds_py-2026.9.1-pp311-pypy311_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:f3d6ed6a98cfd19155996605474982cc470d7601746a6439078f1a5a3fa8b050", size = 389662, upload-time = "2026-10-04T16:31:44.642Z" }, + { url = "https://files.pythonhosted.org/packages/4f/46/912cf623b2263f9c9c2d04e8508fc38dbe89983faeba5fb36ca4558ae550/rpds_py-2026.9.1-pp311-pypy311_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8171b44a054e5c67fd748ada04187f1250bf35b95f85e52ab64bcf3331a923bb", size = 504637, upload-time = "2026-10-04T16:31:46.667Z" }, + { url = "https://files.pythonhosted.org/packages/9b/5c/7f3cfa7c5f01765c9f47c8398210ed0c1eb686c0e99c223cb1c6776d3fb9/rpds_py-2026.9.1-pp311-pypy311_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:fda1d96e542c37b6c804547dbf489c129fe7c97183a76a5ec275909ba1a063df", size = 402607, upload-time = "2026-10-04T16:31:49.068Z" }, + { url = "https://files.pythonhosted.org/packages/f0/76/2e915d4115ee453c33e6af17bc1df7e22ddc52974e178eeeb92a78c09983/rpds_py-2026.9.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:270bdcdaac5d5b6f73c5e22e7e135c7f2a50e789f71d9e241d5be8d90026e19a", size = 382762, upload-time = "2026-10-04T16:31:51.24Z" }, + { url = "https://files.pythonhosted.org/packages/0d/e5/844382925d7b84a4074ad79fc2b9d05eb6231ea243b34f247e68e519b606/rpds_py-2026.9.1-pp311-pypy311_pp73-manylinux_2_31_riscv64.whl", hash = "sha256:84a6ecc0c940169190d2c23bd969debd48c94dbc855acd60188a68d71d421608", size = 389563, upload-time = "2026-10-04T16:31:53.549Z" }, + { url = "https://files.pythonhosted.org/packages/81/82/d6e3951602dc2e24790ef9d299aa24bf5e2493df5043f2c6da00480cc447/rpds_py-2026.9.1-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:ab4b2fda7c2b542f7f9d886cc6a838c5079d2b76f72e6081411faba11adde2c9", size = 416842, upload-time = "2026-10-04T16:31:55.76Z" }, + { url = "https://files.pythonhosted.org/packages/ea/1c/8d248e4ea671d525ab7daa0703ad81cc2175076fa0ccd7ef088facbd2b01/rpds_py-2026.9.1-pp311-pypy311_pp73-musllinux_1_2_aarch64.whl", hash = "sha256:44b32a7c4f0da3d28af31c259e38ddcff096f855e205ed0671d02fcf44f1ea1c", size = 562434, upload-time = "2026-10-04T16:31:57.874Z" }, + { url = "https://files.pythonhosted.org/packages/ad/38/e7ac0db898120d15dea25e3661b1242a40cb3b23d1f4db86c15a01fe0ba1/rpds_py-2026.9.1-pp311-pypy311_pp73-musllinux_1_2_i686.whl", hash = "sha256:a3dbc5ed9514908d5046107d7b1346bde71eea61de6e0e4919c19354f97e769f", size = 627909, upload-time = "2026-10-04T16:31:59.977Z" }, + { url = "https://files.pythonhosted.org/packages/03/c8/37e555514932cb1ee36c75349187aa882a98dee5d5654c761699ed8a0d27/rpds_py-2026.9.1-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl", hash = "sha256:6eae33003518fd4cb4f83a218d5371469dd3001aa3b87128c005b07762f7fe5e", size = 593658, upload-time = "2026-10-04T16:32:02.14Z" }, + { url = "https://files.pythonhosted.org/packages/12/5c/5f69a91add94a8a33acea68a2b034a464946a654ff7296af9d957ef0d6a5/rpds_py-2026.9.1-pp311-pypy311_pp80-macosx_10_12_x86_64.whl", hash = "sha256:0483515261947e4e8b8e1375bf7463e7eb6ccfb3d86e7b554d90cd5285f20f32", size = 351769, upload-time = "2026-10-04T16:32:04.675Z" }, + { url = "https://files.pythonhosted.org/packages/41/22/35ea8bf3b2682b90ab687c74e4828418ff12298a5b0b0a0c033f61c86a30/rpds_py-2026.9.1-pp311-pypy311_pp80-macosx_11_0_arm64.whl", hash = "sha256:4cfaf02209061880210819934de2f4f6aa83dc04dafe6770276acc240a56da31", size = 351719, upload-time = "2026-10-04T16:32:06.834Z" }, + { url = "https://files.pythonhosted.org/packages/a3/90/a9ba81408369d34c1aca73319c15adc91ed45c1d21e9e8ee4832ffb7fe0b/rpds_py-2026.9.1-pp312-pypy312_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6cdc537c8633d7fd92a82e2e0d2ab74320a3f63d5e59fb9cf08711e08fe151c4", size = 381109, upload-time = "2026-10-04T16:32:08.994Z" }, + { url = "https://files.pythonhosted.org/packages/b3/44/5192a0bed94cec86bd2a5e1cc5a1bb8f7eec3aec907eacd2deb13e87e326/rpds_py-2026.9.1-pp312-pypy312_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:10e208f2425d973938afcd56e28a7c4be32e27b6a60b5d381f49fb9d8acf9759", size = 388222, upload-time = "2026-10-04T16:32:11.321Z" }, + { url = "https://files.pythonhosted.org/packages/92/cd/5356549711448f18b52f7a11ffbe90f1228774996fbf3c6cd1b18d22abaf/rpds_py-2026.9.1-pp312-pypy312_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6c0dbbcc19735fe5f8b0a54c07659d154a9e69f47e15d0a6ab7299215daf62cb", size = 500384, upload-time = "2026-10-04T16:32:13.478Z" }, + { url = "https://files.pythonhosted.org/packages/7a/88/ddda9d28adfe33119c75b2e733d4ba7e326f41d7e1b1093951771768ca48/rpds_py-2026.9.1-pp312-pypy312_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:684fd492fff4fead00587544e059be2bbcb6f93454f21fa2a91b66fc7508be82", size = 401661, upload-time = "2026-10-04T16:32:15.653Z" }, + { url = "https://files.pythonhosted.org/packages/32/c3/bb59ba16a6b4a57995d15b8c04c00f28df3b938c4dcdde48fbe0f73edb0c/rpds_py-2026.9.1-pp312-pypy312_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d1028417bb44037eb3069c1009bd7b7277212876cda22fbe565b0bca9fab6d2c", size = 380748, upload-time = "2026-10-04T16:32:17.727Z" }, + { url = "https://files.pythonhosted.org/packages/f5/b8/0580faa1c5a32ddc160130dd7ae54d2d007272a89a40a6b5db3e50f9f585/rpds_py-2026.9.1-pp312-pypy312_pp73-manylinux_2_31_riscv64.whl", hash = "sha256:492e5e428cbe126221611f47e068f01660352feec4ad18bc0f5ea9b2ae88fb14", size = 385731, upload-time = "2026-10-04T16:32:19.855Z" }, + { url = "https://files.pythonhosted.org/packages/bf/70/f73564642bbe3322c7eeef2c2f258cf040b71c41a430b532e59d04a1b838/rpds_py-2026.9.1-pp312-pypy312_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:88b5268892fde430d5531f95bc560b6efbbd67c929662c586afd729a96e7461c", size = 412131, upload-time = "2026-10-04T16:32:22.285Z" }, + { url = "https://files.pythonhosted.org/packages/8c/5d/17fff2e1f8f68721a2afb5cb48f7e442c751bb6b4883157c5abaf618cd08/rpds_py-2026.9.1-pp312-pypy312_pp73-musllinux_1_2_aarch64.whl", hash = "sha256:01445c8d194aa032a08e944f16567672da1c62dbdbefd8b6d0693032e290cf68", size = 558193, upload-time = "2026-10-04T16:32:24.4Z" }, + { url = "https://files.pythonhosted.org/packages/2a/d0/869ab6fb08531f97aae4a780b4d61b4190d8aef48fe054ee28bcf7114466/rpds_py-2026.9.1-pp312-pypy312_pp73-musllinux_1_2_i686.whl", hash = "sha256:eef6a03b0b6d08d0835ccfa8ec8d1bc70525e3801387567137b50c557695e6da", size = 622448, upload-time = "2026-10-04T16:32:26.844Z" }, + { url = "https://files.pythonhosted.org/packages/ba/a5/9672e532fe02cd3b92c78cfd8743abca939d96853006c63835009a1ecb6f/rpds_py-2026.9.1-pp312-pypy312_pp73-musllinux_1_2_x86_64.whl", hash = "sha256:6b9bf3135b4ad5981df9a73d71a35272d650a2985ae9c2746357b24d59de2448", size = 591126, upload-time = "2026-10-04T16:32:29.274Z" }, + { url = "https://files.pythonhosted.org/packages/80/ef/3a9f8e4279c7920af561deed4cb7ebebed2794a8f608cf404d5eef14a105/rpds_py-2026.9.1-pp312-pypy312_pp80-macosx_10_12_x86_64.whl", hash = "sha256:56c6952a9b15047466d0c2347c446a761d4527f89976156341e68f0ce5cc08b0", size = 357108, upload-time = "2026-10-04T16:32:31.641Z" }, + { url = "https://files.pythonhosted.org/packages/b7/55/4b2fa381a583760aea5c92841e4e928a358e1c6511b129219e9c2826a226/rpds_py-2026.9.1-pp312-pypy312_pp80-macosx_11_0_arm64.whl", hash = "sha256:b242c27c8f836305a4a72df9cdd564386ac57b807bd252a063223331c9316b37", size = 346877, upload-time = "2026-10-04T16:32:34.061Z" }, +] + +[[package]] +name = "ruff" +version = "0.17.5" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/86/cc/7b71512eb8b49926efb887cc66c74dd993642943c29eba51a877f6b85692/ruff-0.17.5.tar.gz", hash = "sha256:625e57d80cd43352d12ea81690f3eac46cddc8c0f35026d137fb0f157f94592e", size = 5368382, upload-time = "2026-11-12T17:54:55.04Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d4/f2/61df414cb4338617290a9023ad09486e207fb9a6d09357a7be34f2e369a4/ruff-0.17.5-py3-none-linux_armv6l.whl", hash = "sha256:d511dd302982e46a285528942fa6557d57730edc4bdb9def95e86a2603d77396", size = 10231309, upload-time = "2026-11-12T17:54:09.314Z" }, + { url = "https://files.pythonhosted.org/packages/d1/72/8ed970f3361f7c8d3f8e1b3b1af27cf086bc4b3a6b62ec20e21a1aaaaff5/ruff-0.17.5-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:b72fbc232e328bdbb9cdddf4f1aedcd61bd1aa64d75fc012114b4add0bd7f26b", size = 10250018, upload-time = "2026-11-12T17:54:11.983Z" }, + { url = "https://files.pythonhosted.org/packages/dc/4b/8b10f6c9d0a18413301ae8dd2af9d180a81bb738b1b731d944a37404c523/ruff-0.17.5-py3-none-macosx_11_0_arm64.whl", hash = "sha256:6f0db748508f04a04e3fbebcc636a5c8b3bd76274f8ed28f497c44d75c2ea2d7", size = 9504737, upload-time = "2026-11-12T17:54:14.567Z" }, + { url = "https://files.pythonhosted.org/packages/b7/ea/1b3afa3943239dede7a0755ea139bdb51879f0f3f96f92894081d5c7d2e5/ruff-0.17.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6f6a7b138edf9cc402ca736a59d9525e6d766e5395760b72e7e146e6251ac963", size = 10168006, upload-time = "2026-11-12T17:54:17.195Z" }, + { url = "https://files.pythonhosted.org/packages/31/08/ee641daa45f83792f91274b65796cb011f1065f588911bfa3909ad9e31e7/ruff-0.17.5-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:e52622ecf3a0df9d03e796fe3eed4aa085adda65520db7e0619cbd2192a97342", size = 10043751, upload-time = "2026-11-12T17:54:19.815Z" }, + { url = "https://files.pythonhosted.org/packages/f8/cf/1c59fdb42d0b5671ad5b160636fab4005ee28db72cb06aef6e3f3c04f377/ruff-0.17.5-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:54c0f67d1be11b55d12c184a819fc229f5eee3ef45c16c4fcad41258e83b4882", size = 10690562, upload-time = "2026-11-12T17:54:22.789Z" }, + { url = "https://files.pythonhosted.org/packages/49/c5/578074716173fb0c1591e9648a9f85c469888d9530cb35b89b757dc1208b/ruff-0.17.5-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:dd0dfe7c6fe5a447fce467c58e69893be1d9a7e4378f5b9906432da33d94a97f", size = 11338465, upload-time = "2026-11-12T17:54:25.523Z" }, + { url = "https://files.pythonhosted.org/packages/aa/b9/d6428bcf5ed88f4dc1d6e3417ee350236ed36e7a35f9477b727c00e437bf/ruff-0.17.5-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:ec4ecf40fb4d6e1265b009dbe551727920926fc0f769070c452d6d84b422a74d", size = 10895501, upload-time = "2026-11-12T17:54:28.441Z" }, + { url = "https://files.pythonhosted.org/packages/f2/8a/1e29c0c3785ae7e5cd0d54ee8717a08867ef71545796340be4c653c57e24/ruff-0.17.5-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:40ca8afaac309b41a5b2e09e4e7beb1f824826b93c25697c4d74f573324fba4e", size = 10613231, upload-time = "2026-11-12T17:54:30.862Z" }, + { url = "https://files.pythonhosted.org/packages/32/b6/88944350c14bb90651014d678ad554e233ae2a79c14ad52101845f93d15b/ruff-0.17.5-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:8e85601bd6d9b6c3e3b95c0e0dccdbac1d23c6bcef006d187fbcddaf8225a5df", size = 10562789, upload-time = "2026-11-12T17:54:33.869Z" }, + { url = "https://files.pythonhosted.org/packages/6f/fd/2792e955b0bf54295cdcdddc4bb3f380c0790d7e60e789f528a9e6e48a31/ruff-0.17.5-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:f93d2b7d449ed9545304f6923699ca20d13c675b69f258481709a08ae61076db", size = 10069824, upload-time = "2026-11-12T17:54:36.663Z" }, + { url = "https://files.pythonhosted.org/packages/07/9c/d7cad341b4c19237948a6dd1fcea1c9c39c9d08b70f22f0e157d1236ebd6/ruff-0.17.5-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:0e5c125c5b31dc8efc948d41357496a4c4a312977565ccba740030efdff83580", size = 10038961, upload-time = "2026-11-12T17:54:39.452Z" }, + { url = "https://files.pythonhosted.org/packages/cc/a1/9cd0d4c371ddc70267d3bd557e718e2bdfb94c25e49d25605edfabb764bd/ruff-0.17.5-py3-none-musllinux_1_2_i686.whl", hash = "sha256:50dfc3c6b3ebd0a932f11dfd579bd42234b0b7137e68940eb6abdbfdb9d69697", size = 10385012, upload-time = "2026-11-12T17:54:41.808Z" }, + { url = "https://files.pythonhosted.org/packages/8f/a9/35f078ce98d4df318328ea5270382b5b65e680f7953b3db54f8e009c420c/ruff-0.17.5-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:86bd1f3b83c25f9b8055c6e796f0685b39d3127ce947322098c3108cf82fd586", size = 10793672, upload-time = "2026-11-12T17:54:44.342Z" }, + { url = "https://files.pythonhosted.org/packages/2c/a5/2e136dede2a88aaaf54498bbbdc81bc810f788ef6ef01efb97037d73cd1d/ruff-0.17.5-py3-none-win32.whl", hash = "sha256:e1546609b2ad73f1d6c5c076881b788672b7b3cc3283981182cbdbb6524ed88a", size = 9929908, upload-time = "2026-11-12T17:54:47.067Z" }, + { url = "https://files.pythonhosted.org/packages/ec/8c/e4db9ae1e0ee233c04df007ab6d0d42f799ae9abd95d352b6092ee7bc4bf/ruff-0.17.5-py3-none-win_amd64.whl", hash = "sha256:aa415d57c244299279901d776607fee3df7831c2a7435433fbfacde8632c6550", size = 10275454, upload-time = "2026-11-12T17:54:49.401Z" }, + { url = "https://files.pythonhosted.org/packages/e6/65/a1648bc1550e7683bf7bf1e2ce2485c9f8535cbca6cca9ec7b73cc12fb8e/ruff-0.17.5-py3-none-win_arm64.whl", hash = "sha256:64a6fd668a336df959c522991de33e9e3c8be463afc0c9ac8f029f9d19ef756e", size = 9849020, upload-time = "2026-11-12T17:54:52.055Z" }, +] + +[[package]] +name = "setuptools" +version = "84.2.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/70/b3/c19426f783614d625699a4b247faf628ea9ab1db228674491767b417f9e1/setuptools-84.2.1.tar.gz", hash = "sha256:3ff8b3b5492a0aa66960f4419365a86b84e013070d4313e4d4a6894f5d64d6bc", size = 1230289, upload-time = "2026-10-20T19:01:37.742Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ef/55/6dc6d6bb953bdfc52519a0059592c52b6e3b8ad51cf8256dffceb55b0610/setuptools-84.2.1-py3-none-any.whl", hash = "sha256:ca140b45d5325a9478f880e351484f62fef15f336462e449ca0c03c873d589c2", size = 876263, upload-time = "2026-10-20T19:01:35.678Z" }, +] + +[[package]] +name = "ty" +version = "0.0.104" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/a9/23/e7e960c518df4fe79c38154469f500ebc54631c1e8724a44c28ea052b7ef/ty-0.0.104.tar.gz", hash = "sha256:8aa1330e722a5a56336d8d1938d8897cb5dfc0841fffd8ed0627fdea177a9bdb", size = 8295902, upload-time = "2026-11-13T20:52:59.529Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/63/d0/b5371389f07c4da7cea80f306775001abfc1b1a11a13ac23338ad4b8e6d7/ty-0.0.104-py3-none-linux_armv6l.whl", hash = "sha256:c82f457daeaaa72147da117e9f17b9e9698ce2bf8ff9af956bce78fa18b58fa9", size = 14972660, upload-time = "2026-11-13T20:52:17.984Z" }, + { url = "https://files.pythonhosted.org/packages/db/61/2b8c8fa58bfd59ccb31b430e2798515fd9f6f7e19139f804a1bd4ecc18ff/ty-0.0.104-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:d83988dd0ace56c133417a976b798844c4c3f6b9e28b2856e5026432a6d907ee", size = 14555253, upload-time = "2026-11-13T20:52:20.658Z" }, + { url = "https://files.pythonhosted.org/packages/20/df/7b3865d367b83cce6411857f8769e05bd625034adc16d8dabf3f22ee58ad/ty-0.0.104-py3-none-macosx_11_0_arm64.whl", hash = "sha256:bab34539aedf4fb5dfcc9724874bce05fc79cb85cb783b1084e8615d4e6d6755", size = 13956073, upload-time = "2026-11-13T20:52:22.853Z" }, + { url = "https://files.pythonhosted.org/packages/f9/9e/195afd5f9472fe09655b22b14c70db9920332ff7c975359232e21947d9c6/ty-0.0.104-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6e2b7a31a117b45e88827b86746ef04760274c6813c9455a1d8fb456ac660476", size = 14844026, upload-time = "2026-11-13T20:52:24.995Z" }, + { url = "https://files.pythonhosted.org/packages/52/6f/8a544bedcbbcee26139d57a78b48cfa83c10c5af46e23fed062a60004101/ty-0.0.104-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:507e9ec0a638edd30f9962b3bf0f9e668324fee32bc727b0f1affdd205e9a9f0", size = 14717811, upload-time = "2026-11-13T20:52:29.027Z" }, + { url = "https://files.pythonhosted.org/packages/11/e4/dd373da855b1475f5f20e6708c4374edaa1e1179c10b16eef96fd5cae97d/ty-0.0.104-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:23775b9664f49a7c4294034a4343195475747c3f5a0e8275a6af2160197375c5", size = 15651255, upload-time = "2026-11-13T20:52:31.361Z" }, + { url = "https://files.pythonhosted.org/packages/55/7a/1b7060b71e1ae50c12f5dfe112968e2bc0503b6436200d7236aa9c82c751/ty-0.0.104-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:890c61fdbe8ba9dfe05de56c9db3dd86fb0f97545791a95435ba49bde4d5ac84", size = 16137148, upload-time = "2026-11-13T20:52:35.02Z" }, + { url = "https://files.pythonhosted.org/packages/8b/a1/02ca201bcd2add8a9287a209f461bf37bdc73c7ece48d066a3533ea7a46e/ty-0.0.104-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3afca137041c7299fdeab9beb001d309575464562b82fb36a3bc1a13a396df11", size = 16014926, upload-time = "2026-11-13T20:52:37.216Z" }, + { url = "https://files.pythonhosted.org/packages/c0/55/ac634ca578d3a3b39a293aab14c9c9334009c179c79564e59af7ea61ca12/ty-0.0.104-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:57b142b2e1a7396e0775df67469ec89f0e519d0a842787ffb8a2f5276f61c12e", size = 17568960, upload-time = "2026-11-13T20:52:39.513Z" }, + { url = "https://files.pythonhosted.org/packages/6e/ca/ee071674f7b7cb92d5ad9f432f64aecf656141389485577d765930fb8881/ty-0.0.104-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:620eb2a03e3de7c448ed5fb2fcab8fce21fd28ead2612d0c83b94aa6fe685af7", size = 15561031, upload-time = "2026-11-13T20:52:42.06Z" }, + { url = "https://files.pythonhosted.org/packages/4b/f8/1aa534b8d58d23aa90efac61082e80b26d1665a80e3b42d3850480e82c39/ty-0.0.104-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:082468bace6f213feef97fa19aec53228c09d2b551bf169ed01c120502a40fa7", size = 14387309, upload-time = "2026-11-13T20:52:44.343Z" }, + { url = "https://files.pythonhosted.org/packages/54/b6/e2a4bb6ff58afe23274a2d8b1957a7a16420279ef1320fd8e37f762a67f1/ty-0.0.104-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:7a77761dd89991170497f20fc5ab89add0bae7652dad750857d1e2c25598a7f3", size = 14712180, upload-time = "2026-11-13T20:52:46.434Z" }, + { url = "https://files.pythonhosted.org/packages/d3/94/922825e4878d29250a260d9f9970e3177eaebbb38c3572d80fd53859a81a/ty-0.0.104-py3-none-musllinux_1_2_i686.whl", hash = "sha256:9512c6a16525e417eebec8f97947ff8244589170cfbde58c4471424c749d17ae", size = 15037678, upload-time = "2026-11-13T20:52:48.556Z" }, + { url = "https://files.pythonhosted.org/packages/f5/1f/32908495b7f92c8d601179c4a08a168392f55c5e3d37b394fad243aefecc/ty-0.0.104-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:344ab49886b3495a0093bb35d61b1f1b49764b27360fa43ff6b6da3820bcc180", size = 15446992, upload-time = "2026-11-13T20:52:50.656Z" }, + { url = "https://files.pythonhosted.org/packages/15/25/70cba7688f9d9c15e72611ac52e5714cc373494997ea6b05510e39b673f6/ty-0.0.104-py3-none-win32.whl", hash = "sha256:6bc8194212b66cfc9bd0028acc4c740be468160b335937e5e00af945e312f565", size = 13899890, upload-time = "2026-11-13T20:52:52.825Z" }, + { url = "https://files.pythonhosted.org/packages/d8/ff/5fbb55f4afedc80e319d41927589c0c80325ed3e0e525f682684d3351c76/ty-0.0.104-py3-none-win_amd64.whl", hash = "sha256:ae5f746b4c800f202f8dae94957cc6dacbf3f4b19bd2b2d0df013043fb8af856", size = 14759284, upload-time = "2026-11-13T20:52:55.077Z" }, + { url = "https://files.pythonhosted.org/packages/54/5c/346c7c49876b15bd9d2e290aa15d4500c4887dbfa211dec7f5e43b105fd7/ty-0.0.104-py3-none-win_arm64.whl", hash = "sha256:57123ca77b218c7720e146659551a4ba0187e0a5bfa6c2fa13b5f6568b421c6b", size = 13964034, upload-time = "2026-11-13T20:52:57.432Z" }, +] + +[[package]] +name = "types-protobuf" +version = "7.35.1.20260906" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/e1/6c/e3e5b3e10bc328126a39637c138f9ebfd734bf14342b9f3540039b4ab995/types_protobuf-7.35.1.20260906.tar.gz", hash = "sha256:efd1a3862d4c967dad5512ef8d56b1530ac84f182c41735b94004756518c4998", size = 69895, upload-time = "2026-09-06T06:35:28.308Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/44/4e/f63e826c68f77ef875506d72f225918800346545ee99847bc28f3394f18d/types_protobuf-7.35.1.20260906-py3-none-any.whl", hash = "sha256:5155e48569e0dabff303fdf578db96cd31ea9a4a63b18018a4ceac6b0ae17462", size = 86419, upload-time = "2026-09-06T06:35:27.247Z" }, +] + +[[package]] +name = "typing-extensions" +version = "4.16.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f6/cc/6253133b5bb138fc3306cebfbda2c520f545d36b5be2c7255cc528bb45d6/typing_extensions-4.16.0.tar.gz", hash = "sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5", size = 113555, upload-time = "2026-07-02T08:40:05.92Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/49/d3/b8441a820a491ddfc024b0b0cf0393375b75ea13866d9c66727e54c2fc80/typing_extensions-4.16.0-py3-none-any.whl", hash = "sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8", size = 45571, upload-time = "2026-07-02T08:40:04.659Z" }, +] + +[[package]] +name = "typing-inspection" +version = "0.4.5" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/ff/50/0195198eb1d75bab716bb0a813abea4cc394bfa17a92a189f021a34859af/typing_inspection-0.4.5.tar.gz", hash = "sha256:7f16c411e7930dc79596d42ab44672a3fe5f60eb34b781a1647e7872363120c7", size = 81194, upload-time = "2026-11-04T14:13:23.774Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/de/0c/ea2544850a7c135e15033a5c7a8e7211136184b7ae63e2239d557c2b3019/typing_inspection-0.4.5-py3-none-any.whl", hash = "sha256:bc210535442b39e1bf2805e0c7a17dfd6a4ace760c84c7f7d16245d23a6b1c39", size = 14874, upload-time = "2026-11-04T14:13:22.616Z" }, +] + +[[package]] +name = "urllib3" +version = "2.8.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/e3/05/b17359e1cefb4f909b5e40b1b90a496d987258916dbbf88e842c729f510e/urllib3-2.8.0.tar.gz", hash = "sha256:63bf2ead4c879426ebf22ef2a781eeb4aa3b4ae798a0435506f8687fd5bb9b63", size = 458972, upload-time = "2026-09-15T19:29:36.253Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/92/9d/c4e665119135114480843e7ab388fa94d8480650450e6f8e26b70d323a4c/urllib3-2.8.0-py3-none-any.whl", hash = "sha256:0cf3cae568d36aa9576b28dfb35f11328f1cb974ca7647d9475ebb86c75ac6e3", size = 135717, upload-time = "2026-09-15T19:29:34.577Z" }, +] + +[[package]] +name = "uvloop" +version = "0.23.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/fa/42/02c739ce85fb2ee8d99212c61417da8140c6b87e9d97c430bea520d76044/uvloop-0.23.0.tar.gz", hash = "sha256:28d160f51ab4da3b187063652e643dea6831072add4adc1e6d62afbe73b6be27", size = 2559185, upload-time = "2026-10-01T03:17:04.4Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/2f/b1/948067eab45d5307f04b34e50eb7bd1f7352aee866fa5f0706b061ddacf0/uvloop-0.23.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:24c58ae4a83e93a04c504bcc678125e36a0bfc44af928ad69444880c60f187a5", size = 1415276, upload-time = "2026-10-01T03:15:32.634Z" }, + { url = "https://files.pythonhosted.org/packages/8a/6f/ee3ee84c5d27f2f0a47ae8b67a6adeacf9841b193c0e07412a1403586ce2/uvloop-0.23.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:0efdd55bddbd36bb2fcb842d64c0d5f6407c6958c68088cc25df8c09edc5b5fd", size = 779533, upload-time = "2026-10-01T03:15:34.062Z" }, + { url = "https://files.pythonhosted.org/packages/25/0d/b5f69dae3736d96a8753c6ecd32d676ecd212be7ba3252e9c379ad9cc05c/uvloop-0.23.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:8fcd721113260ffb5e38bf14a8725b17d431f34209f7d1c7005b667946e630b3", size = 3896377, upload-time = "2026-10-01T03:15:35.816Z" }, + { url = "https://files.pythonhosted.org/packages/16/fd/8cbf6124607863399008ae4b0d2bb50c22ed83526deec28dca08d635eb6d/uvloop-0.23.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ab17b3a8aa754be0de0e397f7b95f13b14e56f077a4c6ae295e3d4afd199b325", size = 3956355, upload-time = "2026-10-01T03:15:37.688Z" }, + { url = "https://files.pythonhosted.org/packages/a7/7a/b73007866e7198519067a1f1afc343b4973ae924d2b7afcea67c44320a98/uvloop-0.23.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:80cac5cb90ed7b9b72a217a1d6982b15b829cdbd0ee6bc19b93e3a9e47fb0ac9", size = 3755618, upload-time = "2026-10-01T03:15:39.27Z" }, + { url = "https://files.pythonhosted.org/packages/3c/28/e50816f1ce38b97b28d62bc4adf7c82c33b7c68fa902e41a39adc8a3d189/uvloop-0.23.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:93087a845cdfb35753e539354ac9551bdd2ff528c202a98df0ae46e852bcf021", size = 3863192, upload-time = "2026-10-01T03:15:40.882Z" }, + { url = "https://files.pythonhosted.org/packages/05/98/04e766a6de99e6f7f955ecb7829e8d5a557de3427cb85be2236de54dda0c/uvloop-0.23.0-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:93935ab27b6eaef4c3e5489aebc84284f0644592f7ab516df60ee1b27eaf5eb3", size = 1393055, upload-time = "2026-10-01T03:15:42.526Z" }, + { url = "https://files.pythonhosted.org/packages/33/8a/499e7b863a848ede009539bce39806b66205da5f8779354228e785601144/uvloop-0.23.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:4448e9124537620f9c25d004c227bb5104440b58955c19bbd312d910af919a63", size = 768909, upload-time = "2026-10-01T03:15:43.974Z" }, + { url = "https://files.pythonhosted.org/packages/3d/95/a880f8ce3b87ac5b307c354e8ee480be4658d24bf01f87921d57e3530b4a/uvloop-0.23.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f7548ede3ee908cfabc0d068106e303a9a2d811af959cdf6ab85676344cedcda", size = 4419106, upload-time = "2026-10-01T03:15:45.551Z" }, + { url = "https://files.pythonhosted.org/packages/51/27/c1d2f9fa977f8f42ea294604166df10e0027e6dc6cd17f85ede386c9bf36/uvloop-0.23.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:090865d8ce7a03986755a3ce711b7dd0d4b44eb14ab74368b717f3fad1180208", size = 4532597, upload-time = "2026-10-01T03:15:47.258Z" }, + { url = "https://files.pythonhosted.org/packages/42/dd/2cb6a2c8a30ca55c07a882dd4ae4ceae0fa7d8c15b25b3b7cb9a4b6cf4ca/uvloop-0.23.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:bd6f2f81c7b9da99d301c0b16b82044e76fe887086e42e1590ecf520b94dbdac", size = 4230048, upload-time = "2026-10-01T03:15:49.119Z" }, + { url = "https://files.pythonhosted.org/packages/f4/52/29989cbaa4022dc4ef35c1dd60a4ab989e4c2065f341ed483ae71d2bd950/uvloop-0.23.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:a6ac96da66c35bf789bdcde78a88dc7d56b7907d8379648c54adc1c61594575d", size = 4394152, upload-time = "2026-10-01T03:15:50.829Z" }, + { url = "https://files.pythonhosted.org/packages/5f/83/eb980d64e6dd5da46d4dc35755fa6afd6b5b47141437cf89615f1117c5a6/uvloop-0.23.0-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:2dcff2d69be43e6559e5dad2c5a7a2dbfb60e05a77311b6c4b7a4a8123d86c65", size = 1412726, upload-time = "2026-10-01T03:15:52.49Z" }, + { url = "https://files.pythonhosted.org/packages/04/c1/02a725e7698134c647904bdee6589e2be14a0e7fc9942c74f86e2b90d48b/uvloop-0.23.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:19c64108b507cd0bc140e400e3396bacebd9d504956aa7726272bf6de7d9aabb", size = 779071, upload-time = "2026-10-01T03:15:54.02Z" }, + { url = "https://files.pythonhosted.org/packages/0b/1d/cde53c79e8c01884ad1cdca8e407e086d523362cfe4139e2c2a8dde27304/uvloop-0.23.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1748321e3c59a14a75404b1ae8d5a8d81c4e201803ea0e14c1b6fd84421024b5", size = 4395323, upload-time = "2026-10-01T03:15:55.549Z" }, + { url = "https://files.pythonhosted.org/packages/98/54/b12915bebbf99d7ae0796211e7f5977b95f069830dca45dc1a346d84125d/uvloop-0.23.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e2cba180d6451822763eda8364f342435a873bcfb3849cbd82fdeca248ca65eb", size = 4480449, upload-time = "2026-10-01T03:15:57.362Z" }, + { url = "https://files.pythonhosted.org/packages/f7/8e/da6de68c31549a052a105fc76f5a9a204f6df22cb0909440aa4dbb06f9a2/uvloop-0.23.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:dc61e4f9e37b507069dc7e659ae28bca7adcb04c993c3508214315d12c63f848", size = 4219177, upload-time = "2026-10-01T03:15:59.351Z" }, + { url = "https://files.pythonhosted.org/packages/a1/c3/1b53c6a89dc9c9d5cb75eb9a0b891ad69b32e1421ad3aa01617a9cbdcc78/uvloop-0.23.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:7337b06a9f9ed9ea3049f04b76f65819db9b19bb832ee598e97b388eadf25e5f", size = 4346132, upload-time = "2026-10-01T03:16:01.064Z" }, + { url = "https://files.pythonhosted.org/packages/4e/a4/00e85345871c59c834a23c136c1771205856028ecc8ba940b3951178e59b/uvloop-0.23.0-cp314-cp314-macosx_10_15_universal2.whl", hash = "sha256:b90397a50ad6332ed3e459c648ac20d182cce24a557354363ad85fc9ea4a17cd", size = 1421363, upload-time = "2026-10-01T03:16:02.599Z" }, + { url = "https://files.pythonhosted.org/packages/d0/a9/e5f0f3cfde30af3ec32eba8ec07bccdba2b5116afbd1ecc53edfeb0a0790/uvloop-0.23.0-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:be53e1d5f83de43dc175c87612ecc128d444b38e5c56cb3f807f5a73d6887476", size = 785177, upload-time = "2026-10-01T03:16:04.018Z" }, + { url = "https://files.pythonhosted.org/packages/9e/79/9ddf78f8cd75a15c14a09a57f59c587b8cd9d82802c5c8368b9c3ebefa0b/uvloop-0.23.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6b3cbc4f96ddfa1fb88a78a69dd851369825b7816d9702eee8c4461505ba172e", size = 4381060, upload-time = "2026-10-01T03:16:05.642Z" }, + { url = "https://files.pythonhosted.org/packages/1e/20/57d63c44d32326878fcad5c63854afc9deb394ed95673c1b1a429178c79d/uvloop-0.23.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:31e0cf90bc8fd88784f6802cdba968a51fb1aec1cc3feec74d862b2d371d1330", size = 4418891, upload-time = "2026-10-01T03:16:07.326Z" }, + { url = "https://files.pythonhosted.org/packages/12/c5/0795abecda2cc3dfe41033f880a32a9ff103be4e6b177ac736833c153a0e/uvloop-0.23.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:fa8ed556fcc87a4091cf61587ef172fa104323dc89ecc085a618ba7ff8629a8f", size = 4214811, upload-time = "2026-10-01T03:16:09.13Z" }, + { url = "https://files.pythonhosted.org/packages/20/18/9010dacd5221eec1bd79a4a83ac68f3db6a42d7bb657f7b640c4838ca6b6/uvloop-0.23.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:f3fbfe82829d8e381426a289b87e59e585278728361db9ce975b88b51f64f410", size = 4294876, upload-time = "2026-10-01T03:16:10.875Z" }, + { url = "https://files.pythonhosted.org/packages/b1/08/f6384a03c771d00067cba4f542a69b2fc1a982e9fd78b357c2f788678d72/uvloop-0.23.0-cp314-cp314t-macosx_10_15_universal2.whl", hash = "sha256:7e35c9bc977760981693e1a7a51493b58ee5a501f9ebb1e547565ee40b6c6208", size = 1494811, upload-time = "2026-10-01T03:16:12.399Z" }, + { url = "https://files.pythonhosted.org/packages/ac/01/756a4fb24a449f313cf4a153eb0c6210b49cfe5539255ec9fb1e17d2c4ef/uvloop-0.23.0-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:5bb9be71d9ee39b4359b832f9569518ec9bc08704194034e79e4958e6bc4d46d", size = 819396, upload-time = "2026-10-01T03:16:14.094Z" }, + { url = "https://files.pythonhosted.org/packages/3e/45/e314b0c600b14f53dad3a3c2d7a922a249a88225fd727652b53e1854b9dd/uvloop-0.23.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1e84575f11873c109cf3962ad0bdf679094466184125f4cadcc41a73febff41f", size = 4734966, upload-time = "2026-10-01T03:16:15.815Z" }, + { url = "https://files.pythonhosted.org/packages/66/0d/8686a7f0b1b2d55ebd770ba21f8e0e4ffa0cde5ab738f43ffb8264499052/uvloop-0.23.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:bbbdb8fcd5e7062e546eec1ac78c28bb21ae7df54c18f8e4b06e15a18d661a49", size = 4584963, upload-time = "2026-10-01T03:16:18.198Z" }, + { url = "https://files.pythonhosted.org/packages/78/b2/034a2d47e435ac02357c42956246887167bdc0357bdd6ad31c5f6d94497b/uvloop-0.23.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:76345f51367fb1f23e08605c6efb18374f669be5b223658fbab6b17627950507", size = 4421388, upload-time = "2026-10-01T03:16:19.953Z" }, + { url = "https://files.pythonhosted.org/packages/f0/77/131f4b583e6b4b715c404a66b51c812d701db20f25c9018b188a2b00062c/uvloop-0.23.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:6c7ef4701a96553514b2688e342ef1bf2beae6cfd172d89a76c768292aabf405", size = 4402414, upload-time = "2026-10-01T03:16:21.716Z" }, + { url = "https://files.pythonhosted.org/packages/58/3d/ee11f4718ea1280595c67ed25c83d4c92115dc100bbdfd192d3ed9339168/uvloop-0.23.0-cp315-cp315-macosx_10_15_universal2.whl", hash = "sha256:f1341c6abcee1c31277cfe28d34e46196f2143ec3d755e6efe7452126e1f626d", size = 1418095, upload-time = "2026-10-01T03:16:23.241Z" }, + { url = "https://files.pythonhosted.org/packages/f8/0c/7ca516a0671418517d79a09d3ff2ccbb44af94c75711afa6e4cf58aa6f65/uvloop-0.23.0-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:e095f9e105af76593b4c183bb0bcbdae64bd913a59ec595732dc108b48730ab5", size = 784837, upload-time = "2026-10-01T03:16:24.666Z" }, + { url = "https://files.pythonhosted.org/packages/35/95/75d4e28e596d505b7ae11de517646b4ca3d369fb8537ba755410380da11a/uvloop-0.23.0-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f673d835bdb1a60229cc3609a113fd2c9ce3f4a3c75ad4eaed111180c00199d2", size = 4380276, upload-time = "2026-10-01T03:16:26.389Z" }, + { url = "https://files.pythonhosted.org/packages/10/99/68daf827ad62efaf4667d1f3fda127046d42161178396bdd93aab3684082/uvloop-0.23.0-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c3f23f403a273900d57de6ee5ca0614c650f7f58563065dad1a4744498960e53", size = 4451496, upload-time = "2026-10-01T03:16:28.364Z" }, + { url = "https://files.pythonhosted.org/packages/71/69/f67e696ee688f426a96f99099bae26fec14a1d0fa75dccdd6518ee267c0c/uvloop-0.23.0-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:cbe8d03d4efcccdb7fcedecbaa1e1fa02913eaf3a74cb933634a6bc6d2ea9e2a", size = 4212541, upload-time = "2026-10-01T03:16:30.014Z" }, + { url = "https://files.pythonhosted.org/packages/f1/6a/c8c436a9d7453297b4be70bdf6a9f9fc9400da45e0059ddf7b28ab63f4c7/uvloop-0.23.0-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:4f1798f56c6f4ba5ac11fa2869e5717926e4470d97a1dd42b4f59219d43b5027", size = 4319377, upload-time = "2026-10-01T03:16:31.705Z" }, + { url = "https://files.pythonhosted.org/packages/3b/2c/8fc15a03489299aab8a6212dfe0f137dc39836f915c87f7fd9d9ddd814de/uvloop-0.23.0-cp315-cp315t-macosx_10_15_universal2.whl", hash = "sha256:098a85e1393ef5202767b7e5fb41a32cd8bd81e6ee4af364c179801c4aa3f6d4", size = 1493428, upload-time = "2026-10-01T03:16:33.859Z" }, + { url = "https://files.pythonhosted.org/packages/b7/7c/05e4a210790229607f71460fcb2ed4a2c7bc72668d8a928ce577c22e38f8/uvloop-0.23.0-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:5a2bbad3a63007f7e9524d4903ba04fee252557c2acd86f9a3d4f91786695254", size = 818115, upload-time = "2026-10-01T03:16:35.45Z" }, + { url = "https://files.pythonhosted.org/packages/65/14/a40b11c6c024213803b13955664a15754c72f64c873a33d986b26ec9ff5b/uvloop-0.23.0-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:4a08875543bbd4519faf30497506c9cda8a48470467ffdf967c7313c7a5981a8", size = 4734149, upload-time = "2026-10-01T03:16:37.025Z" }, + { url = "https://files.pythonhosted.org/packages/9f/83/f421a077712c1e87603bfec62744c3cd3a2f4b47378025db3d740df9af0d/uvloop-0.23.0-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:12634f15e6625f78b3f2922f91404c4d7173487eba11746764153f556e9852dc", size = 4661763, upload-time = "2026-10-01T03:16:38.719Z" }, + { url = "https://files.pythonhosted.org/packages/f5/62/25dcaa6b7e7b48f82ce633854ce96597ab768f9650931f4f86c572de392c/uvloop-0.23.0-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:378188efbb1524f2219d05246a3e1e5907217848d2882144dff59585f1b81d55", size = 4421324, upload-time = "2026-10-01T03:16:40.488Z" }, + { url = "https://files.pythonhosted.org/packages/05/46/04628239b43dcef703af314202a3307d6060918e2d76aa86c5b1188f5551/uvloop-0.23.0-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:4b8e207c67d207a8608fec57e116511030af3495dc0109b8c333cf9cb412b16f", size = 4462501, upload-time = "2026-10-01T03:16:42.359Z" }, +] + +[[package]] +name = "virtualenv" +version = "21.15.6" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "distlib" }, + { name = "filelock" }, + { name = "packaging" }, + { name = "platformdirs" }, + { name = "python-discovery" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/b3/bd/e40ad2df6a9efc1f859ea23d63fd7371cff68252833f182ca9af819bb4d3/virtualenv-21.15.6.tar.gz", hash = "sha256:c8b65c7d206ca6ef18de9352c160b3f04f66fff9f6b0ec8fd31f14688eba52c4", size = 5641659, upload-time = "2026-11-06T18:17:32.46Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/0a/63/fd514dee3159f74a96ac01beb8f460b65e4ef0b972f63f4fe9f0cd2aa0e3/virtualenv-21.15.6-py3-none-any.whl", hash = "sha256:4b99ab9b95ff11043939bb4cad2fa0449175fa5a478372864f62160cb6c1a7ed", size = 5680963, upload-time = "2026-11-06T18:17:30.128Z" }, +] + +[[package]] +name = "vl-convert-python" +version = "1.9.0.post1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/93/89/36722344d1758ec2106f4e8eca980f173cfe8f8d0358c1b77cc5d2e035a4/vl_convert_python-1.9.0.post1.tar.gz", hash = "sha256:a5b06b3128037519001166f5341ec7831e19fbd7f3a5f78f73d557ac2d5859ef", size = 4663469, upload-time = "2026-01-21T00:09:55.61Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/9f/59/e5862245972ff467d38b0eb5ad28154685e23ecabb47e14f2b6962da7b56/vl_convert_python-1.9.0.post1-cp37-abi3-macosx_10_12_x86_64.whl", hash = "sha256:43e9515f65bbcd317d1ef328787fd7bf0344c2fde9292eb7a0e64d5d3d29fccb", size = 30512930, upload-time = "2026-01-21T00:09:43.198Z" }, + { url = "https://files.pythonhosted.org/packages/62/e6/e7d0b538c2f0daaf120901dc113bd5d5d1fa51a9532fa5ffd90234e8c69e/vl_convert_python-1.9.0.post1-cp37-abi3-macosx_11_0_arm64.whl", hash = "sha256:b0e7a3245f32addec7e7abeb1badf72b1513ed71ba1dba7aca853901217b3f4e", size = 29738742, upload-time = "2026-01-21T00:09:46.016Z" }, + { url = "https://files.pythonhosted.org/packages/b8/e2/5645a1bc174c53ff8cd305ed76a4a76ba36e155302db20b42b7e78daeef8/vl_convert_python-1.9.0.post1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e6ecfe4b7e2ea9e8c30fd6d6eaea3ef85475be1ad249407d9796dce4ecdb5b32", size = 33366278, upload-time = "2026-01-21T00:09:48.42Z" }, + { url = "https://files.pythonhosted.org/packages/a0/18/88e02899b72fa8273ffb32bde12b0e5776ee0fd9fb29559a49c48ec4c5fa/vl_convert_python-1.9.0.post1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3c1558fa0055e88c465bd3d71760cde9fa2c94a95f776a0ef9178252fd820b1f", size = 33520215, upload-time = "2026-01-21T00:09:50.992Z" }, + { url = "https://files.pythonhosted.org/packages/2f/db/6e8616587035bf0745d0f10b1791c7e945180ac5d6b28677d2f2b3ca693c/vl_convert_python-1.9.0.post1-cp37-abi3-win_amd64.whl", hash = "sha256:7e263269ac0d304640ca842b44dfe430ed863accd9edecff42e279bfc48ce940", size = 32051516, upload-time = "2026-01-21T00:09:53.47Z" }, +] + +[[package]] +name = "yarl" +version = "1.25.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "idna" }, + { name = "multidict" }, + { name = "propcache" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/75/16/e8be8e2fb175bbf41a0680381a319f1199fae256588241a2ac8677eafb49/yarl-1.25.1.tar.gz", hash = "sha256:03dd38de09bc213e9a8b29761eec33ee1d5318dac0e49d8af36e4d27830e23a7", size = 246245, upload-time = "2026-09-15T19:35:02.264Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/83/b3/2cea721d495ca57f8f414aa4867ee263f486b274e07463158cf52f02ba7f/yarl-1.25.1-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:9d693bf4bf534e9ba3ae2780cfd577f5135629f7b5ac653490859d0b77864865", size = 143794, upload-time = "2026-09-15T19:30:26.946Z" }, + { url = "https://files.pythonhosted.org/packages/55/e6/cd145cff8e5cf60b8b3c41fbecfa2a45028a8dec3fbc52bec03595ff3d3b/yarl-1.25.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:ab2054c5531af2a9ba7b69b8ec91e4f884420e83a8c5e579b013084cb57e5e5d", size = 103993, upload-time = "2026-09-15T19:30:28.661Z" }, + { url = "https://files.pythonhosted.org/packages/ce/7c/fbb40fe2d53747c40aa36a9e2bd2178a202f942bda0b670f3306d4aefbce/yarl-1.25.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:564fdc7085d2245ab84f88882fdb1d6ac0723124bff6ded35bfb1c00f812630d", size = 104010, upload-time = "2026-09-15T19:30:31.069Z" }, + { url = "https://files.pythonhosted.org/packages/f0/0b/5a516f70641092283f57cf3670bdb75e7327bcc0dcb5038697e4dfbfd569/yarl-1.25.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:acae6b45d1ace09b6ba3876da43b88366ef368f73b988c7f57e14231753d4420", size = 116444, upload-time = "2026-09-15T19:30:32.894Z" }, + { url = "https://files.pythonhosted.org/packages/b6/8a/d1a627f827b0a404ae0f5647cab0534959081cde13b0756a783469fb3b5e/yarl-1.25.1-cp311-cp311-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:1fb2a01ba8cd9c5d2c5dc1ec35e0fc951d04b4f037541d4ac090c993ce58b3d7", size = 107565, upload-time = "2026-09-15T19:30:35.188Z" }, + { url = "https://files.pythonhosted.org/packages/aa/cf/c8e0aaec886840a6c4480fe44eaec7cd4319f79a563b79321473be79c56f/yarl-1.25.1-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:e92b6bcc741b86d67606c40d3cb9c7cc8e6c737f81e31f4a94efc204456c92e3", size = 125006, upload-time = "2026-09-15T19:30:37.1Z" }, + { url = "https://files.pythonhosted.org/packages/50/26/0cce366d54a93cdc8342965dc7663385e4db161625cc1e8b18e786753d24/yarl-1.25.1-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:72c34ac7ad4314c19362d5ce27626dcc8429bd30bbf8c179f4234078851f9492", size = 128717, upload-time = "2026-09-15T19:30:38.904Z" }, + { url = "https://files.pythonhosted.org/packages/95/0c/a71501bbc1a674ff72c4d6c2b75f4d9a5af819f5244c3a7558080a8802c5/yarl-1.25.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d5add7b4ca7afeea91d52e4d4e4db3b1fe9885b71f07054560d8c4296b7441a2", size = 117728, upload-time = "2026-09-15T19:30:40.809Z" }, + { url = "https://files.pythonhosted.org/packages/e7/6f/c3267ca01defeed9ed9c4ff9b17bd54915432c405945233265b707475d1c/yarl-1.25.1-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:def538065f9e4d4cf1ae164bd59aba00dfa84f03923e0de4c3788f252d6bcd17", size = 116224, upload-time = "2026-09-15T19:30:42.818Z" }, + { url = "https://files.pythonhosted.org/packages/8f/69/fad57ee52d648431718ee0f1f68966a99c1352c3924688ffbdcc9d3fe51a/yarl-1.25.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:0a191bfdb30a79b98e5d175d75285f9fcb78bf0e46ba5efda042e1c72071a0de", size = 116299, upload-time = "2026-09-15T19:30:44.966Z" }, + { url = "https://files.pythonhosted.org/packages/2a/d4/6a8c1e29f33338687ca278cba0a8fbf6525a322c2c02a9a500ccbe041152/yarl-1.25.1-cp311-cp311-musllinux_1_2_armv7l.whl", hash = "sha256:71f42c5b9a948c113bbdebfa544598321431d064ff959d32e99b1feb61d68345", size = 108625, upload-time = "2026-09-15T19:30:46.874Z" }, + { url = "https://files.pythonhosted.org/packages/e8/d2/3a35ae791c9cb6522c106923ff25c3230d999091e5e65511bca23bbd9914/yarl-1.25.1-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:72849d892954be4d09e569b8b831ac39ce58417fedc767d4308a0fe542018a40", size = 124515, upload-time = "2026-09-15T19:30:49.082Z" }, + { url = "https://files.pythonhosted.org/packages/be/fd/2b022109a6b4af0f7dc371cf7500af380b0d4f034010243e1b0ce218dc93/yarl-1.25.1-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:efb01a106f971cb3752856bca2318bbdf7f01bd8823779c461586cbe5ffd5258", size = 115711, upload-time = "2026-09-15T19:30:51.208Z" }, + { url = "https://files.pythonhosted.org/packages/18/59/f7586271136c3ddb0126bbfe661844699369b76b555fe38c4efe86870b2e/yarl-1.25.1-cp311-cp311-musllinux_1_2_s390x.whl", hash = "sha256:a1daf47cd95a7c3a63456336bc5aaa8c86dd3a47d07ed3d0e76132ae4666a5a1", size = 122751, upload-time = "2026-09-15T19:30:53.535Z" }, + { url = "https://files.pythonhosted.org/packages/a0/0b/07f7a2d881f7e16c385b47fc1753382600847cad305dcc7fa0c25828acf8/yarl-1.25.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:9489e6abf47ba37f332075a91444c7cfedb03e6ce99fbb2f116bfe1ce810da3b", size = 117983, upload-time = "2026-09-15T19:30:55.277Z" }, + { url = "https://files.pythonhosted.org/packages/aa/9d/8cdceec66a9b940700cb45931741403f045b162afd79bcb93c41cadd0972/yarl-1.25.1-cp311-cp311-win_amd64.whl", hash = "sha256:d7306dee25b8a0e737363f347362b875094b4dc4e367311470656ae420fdbf8e", size = 102894, upload-time = "2026-09-15T19:30:57.606Z" }, + { url = "https://files.pythonhosted.org/packages/17/f1/7ec357db1d3ad2863542d71e8fe64a126bbec17b134cd7d30951196809a5/yarl-1.25.1-cp311-cp311-win_arm64.whl", hash = "sha256:abb1384477f5901d436b5d2e5465954de46ea6098f59163d243660b5c4461d35", size = 98609, upload-time = "2026-09-15T19:30:59.705Z" }, + { url = "https://files.pythonhosted.org/packages/75/b3/cd32ac66ae622b854c2df0ac52106dda220d361b65a64fde7d5b3684aa3f/yarl-1.25.1-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:94d7aa6debf92a1dd14cb5280b083a764169a13cfb23a452111160274ed989f4", size = 144798, upload-time = "2026-09-15T19:31:01.821Z" }, + { url = "https://files.pythonhosted.org/packages/61/fb/a2c52a8007c2051ba74662afb112ecf3d00346af4c25e33df9d80fd14fb8/yarl-1.25.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:83d4a37e4b95da4d8bda930d6d35b75b4cdadbacbb4980cae290ea3100b5d51d", size = 104583, upload-time = "2026-09-15T19:31:04.05Z" }, + { url = "https://files.pythonhosted.org/packages/be/dd/ee38aec8e09fdf957e50d4085453fbe202f56c6c3b4cf07b81cdb4f09ee9/yarl-1.25.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:e029648f9c951db30e98a7d7ec90835db88ec4b32820efe2a9bdc2287e032eb6", size = 104325, upload-time = "2026-09-15T19:31:06.338Z" }, + { url = "https://files.pythonhosted.org/packages/1e/b3/058dbfb1857b484c9cf9cc135659f50b85ce66e03c99e44dc2f7b6161f55/yarl-1.25.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:4d781294bb815ecb5ea57ff6bbf8038e0a31a95fdf3e1788f66e0dc100d64b58", size = 115358, upload-time = "2026-09-15T19:31:08.593Z" }, + { url = "https://files.pythonhosted.org/packages/db/39/29693446cf0cf6b15a0e2f75a5d40f93c56819b05b0622196f45e95b5cc0/yarl-1.25.1-cp312-cp312-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:e12c538e00e7c1b286a07061046b90e8124e6a9793efae2c70db6a4aad07faad", size = 107658, upload-time = "2026-09-15T19:31:10.802Z" }, + { url = "https://files.pythonhosted.org/packages/86/b3/3c4dd7e1af43b931fba95e0a722737f2ea94a6d199c802585282831d7abd/yarl-1.25.1-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:7e4de3ac4adbad3d0bc7c6f4360a7dbff5de2f15e3b723be3198074e17fd9c40", size = 122660, upload-time = "2026-09-15T19:31:12.84Z" }, + { url = "https://files.pythonhosted.org/packages/bd/b5/1b60dbc3cfc9c5712b15148c206748f2bc93953ffdbe25ea75b63dfc89c9/yarl-1.25.1-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:419f392a1da624877975709e3864dfe833af6cc7671b39318086d456e288380c", size = 126506, upload-time = "2026-09-15T19:31:15.088Z" }, + { url = "https://files.pythonhosted.org/packages/bc/7b/ca212cbe170ac8b96e45317ecbcf9c3c3ecf0cdec98d5b088a9c4088929b/yarl-1.25.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c6f117789d22dce188e5754e8bc65b7e6ebf8cb73963b9fa761f672a5883769d", size = 117050, upload-time = "2026-09-15T19:31:17.241Z" }, + { url = "https://files.pythonhosted.org/packages/cb/c3/72b4938cdbe619ad71ac156182faef4908846b84dc3ca4dbb4c4e6f84014/yarl-1.25.1-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:80e47012e730da131c9f059c80936783f9659aae22dc31c03c0595590d11ed54", size = 114174, upload-time = "2026-09-15T19:31:19.294Z" }, + { url = "https://files.pythonhosted.org/packages/e8/43/268717870f9ba0cc9701a95181587f6dc8c5f387aab4aeecc83158f38a79/yarl-1.25.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:e80f557716fd765439577131e526b8942ffc2c07bdbc5e39fa62f660ba1e963f", size = 114944, upload-time = "2026-09-15T19:31:21.414Z" }, + { url = "https://files.pythonhosted.org/packages/da/84/baa5bf504d51fe062c4bcaf62936da97fffb43285978d0b39984824231fd/yarl-1.25.1-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:f61964f235a43738bfac50da46fc4254943a7eea3051aeb0b6fc7c992c29fadc", size = 108263, upload-time = "2026-09-15T19:31:23.388Z" }, + { url = "https://files.pythonhosted.org/packages/a4/28/779a2ed9e0152a601a27039bed9aead3f0b79797a67e2c44bfa444622dd8/yarl-1.25.1-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:e546fe1d4a93ebc2910f0d768baff19faa09843ab3f2036a67ed6e69fae4419d", size = 122184, upload-time = "2026-09-15T19:31:25.343Z" }, + { url = "https://files.pythonhosted.org/packages/f8/1f/118e9e5b8f07694d63fd3222e801d7782270003f1a222aa798df3f8d5933/yarl-1.25.1-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:cce0727fd5ac04d372fa9bbfde9febc2bcf209aadfcf0468e45dec72719895d1", size = 114001, upload-time = "2026-09-15T19:31:27.465Z" }, + { url = "https://files.pythonhosted.org/packages/0f/ae/a4cf1cf372313734b17996d4007f9f73596e7a178b9485802e5494ecf484/yarl-1.25.1-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:af4ea5b37403ef4e30f3927eaed540db942bde01d8d3ff083527c0704d1c9c68", size = 120565, upload-time = "2026-09-15T19:31:29.47Z" }, + { url = "https://files.pythonhosted.org/packages/05/79/ad94f93ca731bc9e44d321833ab96b82a4f9f5f63cf773f81a4aeea5ecc1/yarl-1.25.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:68782fdb4027b8d1eee25ec35e9a6db05e863b899eb0310b3a33b6c3fef55707", size = 117060, upload-time = "2026-09-15T19:31:31.367Z" }, + { url = "https://files.pythonhosted.org/packages/bb/cc/51a7b4abf4ac593b8e7eb3794b28e5a35ae26eed8bc04787628d215af82f/yarl-1.25.1-cp312-cp312-win_amd64.whl", hash = "sha256:7d575b54cb3863ef9bc290ea4b009999d55dc237326131e4853cf33e888fee03", size = 102593, upload-time = "2026-09-15T19:31:33.329Z" }, + { url = "https://files.pythonhosted.org/packages/9d/21/0941a6b93a58b59a1ec75e5333bf06929b671309c43c0cd201c172d9c39f/yarl-1.25.1-cp312-cp312-win_arm64.whl", hash = "sha256:bc3ac7bf569f6b64dad04dd7808c7872dae8a97df657856eac05e9b7e3614a85", size = 97697, upload-time = "2026-09-15T19:31:35.855Z" }, + { url = "https://files.pythonhosted.org/packages/7b/ed/2f3129bbcc9a5c8ba12cc2b29d8060a3bab9c8043c456cfd4b5ca3188890/yarl-1.25.1-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:25868beca8b6765f8f7d0e11fe6dd7c66dd4b0793b9500286d20cc92352126a5", size = 143623, upload-time = "2026-09-15T19:31:37.966Z" }, + { url = "https://files.pythonhosted.org/packages/17/e1/f1bc3390fdca352826676b531d0712736f156919090206700421d46b2c37/yarl-1.25.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:10b2fd95332f0d716d5eee3c9fb2ce8eada19082de7fee83d32e37992fd75c26", size = 104011, upload-time = "2026-09-15T19:31:40.25Z" }, + { url = "https://files.pythonhosted.org/packages/a8/aa/50acc5c3e5da04172ae3c281c75405af4d2ca911e16120ab0563f4dffb66/yarl-1.25.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:0f12afda4eea8c8994a76d4df1875c765194f5fbe8a9d197929ea303caee29ec", size = 103677, upload-time = "2026-09-15T19:31:42.46Z" }, + { url = "https://files.pythonhosted.org/packages/30/d2/7d1e0ab9f8390e1fbcede5a6dbf70d23c96ad09b8c5567f3a514d1ddb0e2/yarl-1.25.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:14b79a30a93a3ce2e8832603fd0ab780ada281b0ba5110b519a634f2d7d7d1fc", size = 115392, upload-time = "2026-09-15T19:31:44.371Z" }, + { url = "https://files.pythonhosted.org/packages/71/e1/5ba1e3a2a22139213655e760919038e8ed7e2d4a99826d0bbddb3beb96e5/yarl-1.25.1-cp313-cp313-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:4bd6340d20ae2c7ca719b87b426e808e90743b676d05d4c26c4fb5ca71f41184", size = 107493, upload-time = "2026-09-15T19:31:46.273Z" }, + { url = "https://files.pythonhosted.org/packages/f5/53/780653d5e0f73831f467cf13548912e5eec97f21dc49fc8daf21da027df4/yarl-1.25.1-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:126a2533570c554719ca40a1288fdee1700b6bc82e7131aa69fa85252d92e651", size = 122537, upload-time = "2026-09-15T19:31:48.654Z" }, + { url = "https://files.pythonhosted.org/packages/03/92/d54fa70236c6036271c9c9c09fd978df5cbe3ef49ef6c46e9b833476d215/yarl-1.25.1-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:a3faadac7d812ddac258feb57b9846b60c1b437c4f4b9ad42595c6f6fe4390df", size = 126170, upload-time = "2026-09-15T19:31:50.872Z" }, + { url = "https://files.pythonhosted.org/packages/0e/b7/a82a49bf88340b837ef6972b508a1604ae377b9e6904b46b10cf5f1cf925/yarl-1.25.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:be80550d9bfe83d9b62398a37081a90434e6df2d978ec345c3d2820de6beddab", size = 117012, upload-time = "2026-09-15T19:31:53.189Z" }, + { url = "https://files.pythonhosted.org/packages/ef/78/5d684b411e3f3602464ee9b538db48205038f8605872985f61efb809ced0/yarl-1.25.1-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:e07595c7d6f4db270ceede356a1bd1c07a34f1c26f958d1ed0cd7b48e0d2bba3", size = 114950, upload-time = "2026-09-15T19:31:55.694Z" }, + { url = "https://files.pythonhosted.org/packages/2f/11/51d82b852c64f7fad0fc7a7ff3031517204887e874c722bbca839c0b23ac/yarl-1.25.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:eb96ed1ae6c7d072d60840c0434aef07a2df611812810807fbc54263a6053e9a", size = 115428, upload-time = "2026-09-15T19:31:57.966Z" }, + { url = "https://files.pythonhosted.org/packages/e4/49/9d1978049bf646b9ea918313926453c6901b71c92f097467777d47d36a88/yarl-1.25.1-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:3feb99222553a8cbedfa52c2f59dd84c3f50d5b582c728d522caf8d72769a54b", size = 108428, upload-time = "2026-09-15T19:32:00.048Z" }, + { url = "https://files.pythonhosted.org/packages/43/35/7b8f1ebb45d7ec3dda7d1909bf44f458de41ef91e2937f107733582a5166/yarl-1.25.1-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:a2ed0ba415ccdf08f14bf544cb78346d0f76086707ffee24921a2c84dbf1305a", size = 121961, upload-time = "2026-09-15T19:32:02.436Z" }, + { url = "https://files.pythonhosted.org/packages/63/d6/d8b689ab7ca26edeb85f6ff28812aac7a25376eefc1780e303a7bfbaceff/yarl-1.25.1-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:2b49375d22299b0a834c2bca72f39aaecc270d96fb24c30424899676f487b22a", size = 114961, upload-time = "2026-09-15T19:32:04.456Z" }, + { url = "https://files.pythonhosted.org/packages/cf/d5/1a1798ea4dc6b7ee3260010a27907ebc697c95dae99817d817ed446d24aa/yarl-1.25.1-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:ef74070ac553c59eb4f04258722066d6c6135b7baa03b2e9f2da65c096e96d98", size = 120036, upload-time = "2026-09-15T19:32:06.5Z" }, + { url = "https://files.pythonhosted.org/packages/91/8d/b1b35ed7903da6669b1d367cb2c09436acd4ff508029b4f39a0c0c2058fc/yarl-1.25.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:0a66db89ea473abeac4b70523cafd94db3772380e565f9d28af7a179b7af71fa", size = 117276, upload-time = "2026-09-15T19:32:09.401Z" }, + { url = "https://files.pythonhosted.org/packages/3a/8f/4db01cef62caff0d7a4593ed694fb8a41a27a11158cab80d290221f13e57/yarl-1.25.1-cp313-cp313-win_amd64.whl", hash = "sha256:1f51020b2eb8a003c84925638ec63c21a750a4bddd3a22ec8eac6a742dadf1b9", size = 101945, upload-time = "2026-09-15T19:32:11.545Z" }, + { url = "https://files.pythonhosted.org/packages/c0/5e/3ce00497c5c0babb74d4130c10c3828ccd215b4819d12020c42429f991ac/yarl-1.25.1-cp313-cp313-win_arm64.whl", hash = "sha256:b10dd0557ba422715b5206b3743192135a6022acca8baec51aa127d0a75db8fe", size = 97270, upload-time = "2026-09-15T19:32:14.127Z" }, + { url = "https://files.pythonhosted.org/packages/80/cf/54023edfab7aa773b860503db0c56e962ccab0922803ee97988c176ea090/yarl-1.25.1-cp314-cp314-macosx_10_15_universal2.whl", hash = "sha256:a9ca696eb02e5c02a8afd872ada510eba9b7fe6e68b9572c2e9a9b1941e31e2e", size = 143975, upload-time = "2026-09-15T19:32:16.416Z" }, + { url = "https://files.pythonhosted.org/packages/d7/a8/e6c1be0e6761d0f2d10bbf33a3e1e02b99dc83874d92945d7b461a72481e/yarl-1.25.1-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:a5877f2255aab518ebe528289037699201d5dc5f045f2396cb30aa02db22f57f", size = 104018, upload-time = "2026-09-15T19:32:18.364Z" }, + { url = "https://files.pythonhosted.org/packages/6e/bb/dda344765ffd3430afe1a1c66c866a57fae67786537d4f14607df6505ac1/yarl-1.25.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:7a5c3115595995779ee21f2567035793911c3802a43c74f3fbb0314929ec67ac", size = 104156, upload-time = "2026-09-15T19:32:20.459Z" }, + { url = "https://files.pythonhosted.org/packages/e5/5f/ed1538bcd06009fe990d6d283dd7667f639e62a81e35c6d8c6ef6c08fb3c/yarl-1.25.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:77e5099b99b37f3cf79c246998ca9f7313a78054cd1809ec46bc1afad47e1c4c", size = 116025, upload-time = "2026-09-15T19:32:22.766Z" }, + { url = "https://files.pythonhosted.org/packages/a2/af/2185daf56b99830d3356ecfada46faaa49945de6626e842b7728088d4980/yarl-1.25.1-cp314-cp314-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:6efaf45df6a849cef613a03a94c845647456662f85438c886bb67a9c027c8c2c", size = 106985, upload-time = "2026-09-15T19:32:24.749Z" }, + { url = "https://files.pythonhosted.org/packages/c1/65/bc1ae564fb4b04a30b6a8f250e787772581c57e4c3d5cf07ac3359de3103/yarl-1.25.1-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:d5f90e44653c4e0f78501ed9bb7d3fce835a8d62b7c6ed0cb16557534087e743", size = 123030, upload-time = "2026-09-15T19:32:27.084Z" }, + { url = "https://files.pythonhosted.org/packages/6a/3e/e2afcde10d74e53b3fa889960991efb3019beda2b1682a01de720a302056/yarl-1.25.1-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:632da579b2d879f6bad20f2cfa35ded1efe2f4f77f8abb26a6234a5b236acd2f", size = 126765, upload-time = "2026-09-15T19:32:29.332Z" }, + { url = "https://files.pythonhosted.org/packages/a2/be/415b00c0fe5a0615b062a456b26623d7ec91c2bee20faea1a14045aa0469/yarl-1.25.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:30eec96e8a91bd588ce897c9543f6d5d8d34b28fbcba28a4dedf20ebeae9fe57", size = 117199, upload-time = "2026-09-15T19:32:31.49Z" }, + { url = "https://files.pythonhosted.org/packages/97/27/3d8c63ddd3e8bcfd033748ab93876678ce59bacd66e4cb1ed851c9c5b37e/yarl-1.25.1-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:12b6bc4906e11f5e1a1cdcb12296e7afbd366c783cc8073403cd2fb74334e453", size = 115187, upload-time = "2026-09-15T19:32:34.137Z" }, + { url = "https://files.pythonhosted.org/packages/39/b7/7a81d0be1a502a26a0d4326c6f2ecb736c824f570ea1c6529f2b0b227b50/yarl-1.25.1-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:9d6ed3d17bccce4c05343e1ca8da13bc5c02c812a4e7282ddd05e8769322d3fc", size = 116085, upload-time = "2026-09-15T19:32:36.438Z" }, + { url = "https://files.pythonhosted.org/packages/f0/69/39fff459916aa0fab42215dc47b759586fd80f94aa56dfc4a7c15ba6e0dc/yarl-1.25.1-cp314-cp314-musllinux_1_2_armv7l.whl", hash = "sha256:f38a70074041d3b7e138e452799f5174198bae5bd5ab2000917badf403908c5f", size = 107996, upload-time = "2026-09-15T19:32:38.959Z" }, + { url = "https://files.pythonhosted.org/packages/c0/39/80b9a55a3335590451d9ecf3eb593a8c635351f4c905ef056d7e8a8fd9e7/yarl-1.25.1-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:4ca89e4e21854ed27ec753297dde84b16c9f8e53b14a4866fb44457d643c19f8", size = 122549, upload-time = "2026-09-15T19:32:41.151Z" }, + { url = "https://files.pythonhosted.org/packages/42/7d/a179c6757818bb59372a4adafd09f7f26a3b4a0f04c3ae404b544c0b0c82/yarl-1.25.1-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:1ab7618921a93767387a4b83776f751588f5b5ae9bb5bc96620e2e2e00bca868", size = 115107, upload-time = "2026-09-15T19:32:43.072Z" }, + { url = "https://files.pythonhosted.org/packages/32/2b/a773ac867e4ab53a98ed98e5cefe3bae31e6f550252ca9d1de266f1a40c5/yarl-1.25.1-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:0ae12ff2b805fa02c4dab838005caef735e39986322698c48588d3beacb65c62", size = 120666, upload-time = "2026-09-15T19:32:45.061Z" }, + { url = "https://files.pythonhosted.org/packages/bc/41/52be6505e85b0f76b4f85b01b5de7e06a0512201abc2c95e14e099549174/yarl-1.25.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:90c30ed53546da833c700115c0064c22120d1b1560f474699fd31f22dd668233", size = 117505, upload-time = "2026-09-15T19:32:47.177Z" }, + { url = "https://files.pythonhosted.org/packages/f5/01/349c0386caedbbe488d519f252df54efac8a1459282d466c474bdd84a620/yarl-1.25.1-cp314-cp314-win_amd64.whl", hash = "sha256:acfa7e22aa6c6e7a5996a41d275bfa01efa7ea56ab890590280e9063e2cf5c1b", size = 103446, upload-time = "2026-09-15T19:32:49.615Z" }, + { url = "https://files.pythonhosted.org/packages/5c/f0/8ec63180f77912f0dc4e5a42760cb8c08d20da1d5ace3578a01b84d1f3d8/yarl-1.25.1-cp314-cp314-win_arm64.whl", hash = "sha256:8e7d98cdbb6d71e726f7d525952867096053d1f290dd4e3c50d7d313a136f414", size = 99159, upload-time = "2026-09-15T19:32:51.686Z" }, + { url = "https://files.pythonhosted.org/packages/47/7d/92d2220d6886b70ab1ed8579533ac2af2dfac716d5d929001daff7986df9/yarl-1.25.1-cp314-cp314t-macosx_10_15_universal2.whl", hash = "sha256:d21f0fa80a02d05299207eeaafef345d812ace96d5306e4ef265e1d419a615fa", size = 150071, upload-time = "2026-09-15T19:32:53.911Z" }, + { url = "https://files.pythonhosted.org/packages/64/fc/b245e448124bcda9340df38e3553fa222b50260fca027a84095e9bd8642d/yarl-1.25.1-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:17c9877a89fb6e2bca6f9087eb24cd7fb434653946ef5075e470d23d49b52287", size = 106780, upload-time = "2026-09-15T19:32:56.443Z" }, + { url = "https://files.pythonhosted.org/packages/51/e2/9a6ce2e334ebf218a30335ae76fb1696459430d42f733b8cb0d7d65b84d3/yarl-1.25.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:29273edf1530e397bd07cb784db1fbe0d2590b77569f2e24679a9c0a2d763b94", size = 107361, upload-time = "2026-09-15T19:32:58.827Z" }, + { url = "https://files.pythonhosted.org/packages/ed/70/66e8c76b569b450d16e190f15071c916c3df70b0e33927e415ac497cf0c2/yarl-1.25.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b7abffdf37af1cec6a2ad69b827aa84320db5894791bc8ed932dc93fb274b7e9", size = 114396, upload-time = "2026-09-15T19:33:02.24Z" }, + { url = "https://files.pythonhosted.org/packages/73/23/0d82838a05c57fdc05bc8b66e8c92dcc0df15e27463a5f163142d521c682/yarl-1.25.1-cp314-cp314t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:2239a02249d9326655419e0168a28ca9008938eaab31dc29fc875c217927a6c0", size = 104882, upload-time = "2026-09-15T19:33:04.494Z" }, + { url = "https://files.pythonhosted.org/packages/86/d4/ea08615c4edaa6049a13a2f1128944d068d1893abda7d708d4d7ea01599a/yarl-1.25.1-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:664ec6a520b74a1df2810666eb67695fcb77fa663e6ea0a25aaf2e529cb24dfa", size = 119485, upload-time = "2026-09-15T19:33:06.583Z" }, + { url = "https://files.pythonhosted.org/packages/1a/82/0898bdce9b1ae403b308b9c733d0d24af4a3464270c2c081f457b16c3e0d/yarl-1.25.1-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:4f1c91f5a5980a937ff8e238e98e6897e1ad74a4b1e2c0d68c73b5ffbb3f5c0b", size = 122490, upload-time = "2026-09-15T19:33:08.653Z" }, + { url = "https://files.pythonhosted.org/packages/d1/38/97d79b81c342b78246cfedb74809e68841f3198d21653e10d3232bd9c622/yarl-1.25.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7c88edaec8c349ad4c5ad4c486a3defcc4b80ceb2f074436ffa0a87caf5e76a6", size = 115336, upload-time = "2026-09-15T19:33:11.056Z" }, + { url = "https://files.pythonhosted.org/packages/8e/9d/2577896554cd310dc470adb6da0b7dd0b435cb63e2565204a7ac240e504c/yarl-1.25.1-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:35dcbea443fafb3eece757ad4e514560ddeb6c34cfae1582c620d7b293d7feee", size = 111825, upload-time = "2026-09-15T19:33:13.204Z" }, + { url = "https://files.pythonhosted.org/packages/29/6b/7ac49d8ba84a5c4bd73415a4c949d22c749cb3762579b3d50e48019a78aa/yarl-1.25.1-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:882569ff613758cac762a457a5d72d6e211b28d4bcfea89d1d71ea942b02eac0", size = 114655, upload-time = "2026-09-15T19:33:15.553Z" }, + { url = "https://files.pythonhosted.org/packages/e5/18/e5942a16723f5b72f9b1297fd5a85a54f6300cd15c0dcb5005b90cd89156/yarl-1.25.1-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:d0f1489233a254bb3643d2f05de7d59019254d81daeca6b9162fe9edef57e0c7", size = 106395, upload-time = "2026-09-15T19:33:17.599Z" }, + { url = "https://files.pythonhosted.org/packages/7b/2d/549fa46240781513ebc47ae7eb418df428a163a2a3d644cc9cbb3ecb7846/yarl-1.25.1-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:f41753a76f4f63927d03a0d8ba8f5ce0f2083bec29a8cfaccc55371b1564b96b", size = 119277, upload-time = "2026-09-15T19:33:19.973Z" }, + { url = "https://files.pythonhosted.org/packages/76/16/4763f78dcdc0b3b9fb3842b04afe72b9320857c6a69300c62a0eab03d119/yarl-1.25.1-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:8fb0eb4955adf0579001581f2f71a126e8781ba61bcd120f127b0401163c6c2d", size = 112504, upload-time = "2026-09-15T19:33:22.464Z" }, + { url = "https://files.pythonhosted.org/packages/ae/b4/974e3edfe0d188393ce1cb9de400111c63fe61f4eb3b772a500d84c970d1/yarl-1.25.1-cp314-cp314t-musllinux_1_2_s390x.whl", hash = "sha256:a1e32763e641a1566507d90a8d3b19bfc3cc04a9d4e5ae3e32189874ed4b58a3", size = 116243, upload-time = "2026-09-15T19:33:24.788Z" }, + { url = "https://files.pythonhosted.org/packages/b0/aa/157b940428da80c104ca09666a740e51c94963df65d5b112e06b52e4d7a8/yarl-1.25.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:65b5b2066651b7432d389e9799d979c703bcc6ef44266bb8153ef54e91e4aab3", size = 115822, upload-time = "2026-09-15T19:33:26.886Z" }, + { url = "https://files.pythonhosted.org/packages/7e/af/19fbdce41412e1b96825544cc52cd7029d3724655d0988237972f078bd29/yarl-1.25.1-cp314-cp314t-win_amd64.whl", hash = "sha256:734f6e5400352ac4254456003d462866c684703570929cff7a7bde015d0cb371", size = 107386, upload-time = "2026-09-15T19:33:29.009Z" }, + { url = "https://files.pythonhosted.org/packages/2a/99/f6431c8968e89be608d74b28ae2d024521b2953f27dd44e0dece5e04f67a/yarl-1.25.1-cp314-cp314t-win_arm64.whl", hash = "sha256:287e99ff5aa4dc1c7630bfc683ded6f106d756c99dec432a2d7f197a784f51c6", size = 102094, upload-time = "2026-09-15T19:33:31.151Z" }, + { url = "https://files.pythonhosted.org/packages/c7/3b/4f51eab40c2eabea6c3d5b121dff4b8988dc35087732ffede12d2be8b8dd/yarl-1.25.1-cp315-cp315-macosx_10_15_universal2.whl", hash = "sha256:9b1bdaae98bc016825dd3c9d8ee1832f829b3341f9cc6ebd1a1b0a7fef7367cc", size = 143875, upload-time = "2026-09-15T19:33:33.52Z" }, + { url = "https://files.pythonhosted.org/packages/41/05/bbd58fc063f5f299a883f810760b265ca26c8167c91cb9a494d0fe2387e1/yarl-1.25.1-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:e7011b8fb8c4054bf0c12e5edc6cd83778b0028e99ce59b18586ed036f92cfdc", size = 104028, upload-time = "2026-09-15T19:33:36.22Z" }, + { url = "https://files.pythonhosted.org/packages/12/ee/2fba0aecb52e7020e189f684148783aa0b9cfa3b3bfb0b400646eef70ad4/yarl-1.25.1-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:f074e8d4aa0a5798920ddb6de3d08b228c614ff3724c3e8bd7577f4bafea867b", size = 104041, upload-time = "2026-09-15T19:33:38.86Z" }, + { url = "https://files.pythonhosted.org/packages/38/35/884beab53ed88c7247d1671972b5ef116f7351fe0c7e6de8c3558372cb16/yarl-1.25.1-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:7d42e7e3ca399555578b4d617e3a6ecf13371b3743a115995fa010c7bf341459", size = 116018, upload-time = "2026-09-15T19:33:44.265Z" }, + { url = "https://files.pythonhosted.org/packages/e2/cc/1a91b685afb55cc18608443ace95280e96e263a97565811732b6788d3269/yarl-1.25.1-cp315-cp315-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:aa4ed3dd308548f9e707d9caaf005d2d7f8c1e7868f858dfeb47fe76e16b391d", size = 107033, upload-time = "2026-09-15T19:33:46.45Z" }, + { url = "https://files.pythonhosted.org/packages/c5/c1/58b379fcb1d68d907b7fcf75200c44321896509b2a6a74abbb4b19d864d2/yarl-1.25.1-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:42a66563d8cc056ee32e6191e05097a7b2b3bc302e0bc3133daf8710eb18bd26", size = 123257, upload-time = "2026-09-15T19:33:48.631Z" }, + { url = "https://files.pythonhosted.org/packages/d7/2d/1fe96cf5c2aeab10095e48f38585cf5a8451fb7253234822398e52aa5336/yarl-1.25.1-cp315-cp315-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:98d370568f393215d605304cdb77b3d5539bd192c75b623c7304c42c8d6d8273", size = 126745, upload-time = "2026-09-15T19:33:50.999Z" }, + { url = "https://files.pythonhosted.org/packages/ad/60/8674394ce43f4dadae573a1d6f451716438e9eab7d7fe8d643c673a32d85/yarl-1.25.1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:23bf5b403c879a54964e0feac7285688e04bb220074878d737d331522da0a5bf", size = 117255, upload-time = "2026-09-15T19:33:53.456Z" }, + { url = "https://files.pythonhosted.org/packages/2f/72/0faa30e02605d56127d42bb987dcc97da3863b7bf70b9bfbf5f739c05e30/yarl-1.25.1-cp315-cp315-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:d45673badd08456d0340e9364eddafe1c53a9d2896424294de4d7dd71ad3ee57", size = 115166, upload-time = "2026-09-15T19:33:55.669Z" }, + { url = "https://files.pythonhosted.org/packages/8c/90/9a46eac564c437e128285c5c1d7bb385d268394e9209d84f6bf4a14471ef/yarl-1.25.1-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:0136d640dfa9b0523853e411430a99f8a91eca85774c6420285a33b755bc6de3", size = 116082, upload-time = "2026-09-15T19:33:57.78Z" }, + { url = "https://files.pythonhosted.org/packages/ad/38/4b1a686a3758878f93d2f1ea943f5a165f3555769cd16e761cfd0efdca17/yarl-1.25.1-cp315-cp315-musllinux_1_2_armv7l.whl", hash = "sha256:59ba3a6e1aa8cfe5adf4bd270fd965db21955401b7ca6f1696010c55ed4daec2", size = 108048, upload-time = "2026-09-15T19:34:00.25Z" }, + { url = "https://files.pythonhosted.org/packages/da/14/f348eb967f31a58348612a2b93bd8a2ab664548e2b5e879cac7f592f7201/yarl-1.25.1-cp315-cp315-musllinux_1_2_ppc64le.whl", hash = "sha256:87796fedc3ba97ec14fab55acb48584276e6c1e4c1e89c422bda62c838e754a9", size = 122775, upload-time = "2026-09-15T19:34:02.455Z" }, + { url = "https://files.pythonhosted.org/packages/ab/e9/4f7b79700f88cb9e8bb66f8b54f9bce1844c013a2c39fdc47112e9334c95/yarl-1.25.1-cp315-cp315-musllinux_1_2_riscv64.whl", hash = "sha256:bd0912757081f89b107d6c00b2ff8a194401b0b87eadcf4481de2b865a8fd44f", size = 115096, upload-time = "2026-09-15T19:34:05.283Z" }, + { url = "https://files.pythonhosted.org/packages/cf/37/f9cb020331997d3eb887bd28d5410ecfd3d80bf163c23d7cec490d78dade/yarl-1.25.1-cp315-cp315-musllinux_1_2_s390x.whl", hash = "sha256:b51c159a9794633f5e0db7ecec7b2b6e3734eca1f5d17dc989ff3552a43ff78b", size = 120655, upload-time = "2026-09-15T19:34:07.382Z" }, + { url = "https://files.pythonhosted.org/packages/12/83/52fceb22891a41f168db7ec22fd1d81e06b6a0b8d9f70921bd3e785defd0/yarl-1.25.1-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:319e070a01db9920fb63761843f96a104c8e2b9427266731810dc1e22595b17c", size = 117488, upload-time = "2026-09-15T19:34:09.988Z" }, + { url = "https://files.pythonhosted.org/packages/f5/5c/ce6c4ff1247fcbe4b33d462c23a097106d909b173fde7042bc52290466e2/yarl-1.25.1-cp315-cp315-win_amd64.whl", hash = "sha256:a2059a2d891bd156bc5184e7ab7a56e78a84dfcfdeac8c501b552533ad1c36ee", size = 103434, upload-time = "2026-09-15T19:34:12.56Z" }, + { url = "https://files.pythonhosted.org/packages/3c/a1/766a906b0704fb26d52b19dc22bed48a8ba0544203b70dcf44da350e8194/yarl-1.25.1-cp315-cp315-win_arm64.whl", hash = "sha256:a78b50b4f7918a3de71105d5c0b93bbc57bb8339a4d03a9dfd449f9068e76f3d", size = 99155, upload-time = "2026-09-15T19:34:15.132Z" }, + { url = "https://files.pythonhosted.org/packages/bd/d3/a1d09b32cb6ab14f66b44939f5b4255b8b9e747aef3974af1d5d80ccc2fd/yarl-1.25.1-cp315-cp315t-macosx_10_15_universal2.whl", hash = "sha256:b5402a340723fa7da00b5cff987ddab61276be6d11251ea71ae02bcac54890d8", size = 149284, upload-time = "2026-09-15T19:34:17.452Z" }, + { url = "https://files.pythonhosted.org/packages/7f/3b/fe554d879692650bca70bfbc0df124e82e4d2bb7456f698c7756f1279a96/yarl-1.25.1-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:eda19ea5ee88742f47a2340816e6f2d40b53bed3ab5b69794769f36af9f35bb4", size = 106399, upload-time = "2026-09-15T19:34:21.474Z" }, + { url = "https://files.pythonhosted.org/packages/e1/4b/e7af56177ac8d40094c82d7728224c0b8472157d50d362e5fb3b014b2bc8/yarl-1.25.1-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:75baa6cf9b6d1c52f3e111a130e202fd8cf0a5b3a066c3f73d615e885092e4ec", size = 106968, upload-time = "2026-09-15T19:34:23.619Z" }, + { url = "https://files.pythonhosted.org/packages/da/4f/2df41fd738d46f23ef829ae8b4468d94bb6070038fc6dfab6165ed44fea8/yarl-1.25.1-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:dbcef5a9119ef653653132cccaf999b30a0af6f33bb0a4ba80bec30056868487", size = 114717, upload-time = "2026-09-15T19:34:25.879Z" }, + { url = "https://files.pythonhosted.org/packages/69/ea/002b66df53bbd1aed1c23358ff99c9bdc744fe3f4d2740e1b2fdd7192885/yarl-1.25.1-cp315-cp315t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:7efc9f082dfed77c316edffa9deb52888e1bc6789171887cc1f68e06d65465c8", size = 105198, upload-time = "2026-09-15T19:34:28.204Z" }, + { url = "https://files.pythonhosted.org/packages/b1/7c/95c8bc0c8f97d71e59c94525ad60d76f5c57d3f2820f08137ca8b9f0542a/yarl-1.25.1-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:fe01645169a2112aa1d4ebc3e4c5f029c5c8f97adfc32e5d37c993b39a994d75", size = 120271, upload-time = "2026-09-15T19:34:30.5Z" }, + { url = "https://files.pythonhosted.org/packages/5d/7a/6fe9da56ec77927baa669fd86c39c567ce6205bab53d581082c6744c8ae7/yarl-1.25.1-cp315-cp315t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:d1c557dfd5e3db046053a0bdc72261ade790ebe8e2c7a41b36b0ca1f14cb95f3", size = 123572, upload-time = "2026-09-15T19:34:32.73Z" }, + { url = "https://files.pythonhosted.org/packages/8b/83/35f222d17fa70a14c7c74fdf112ccf5515e0c2a87082b1f9b99f7693bf57/yarl-1.25.1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8ce4d6ccafb33d39bd78444612d14938ead674c25702ded2ee9c54a47735d225", size = 115228, upload-time = "2026-09-15T19:34:35.344Z" }, + { url = "https://files.pythonhosted.org/packages/da/6f/fbaaf619423578a7d898d0f226ae47bc1906c293865c416d83c17b828b0e/yarl-1.25.1-cp315-cp315t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:80a063f8297fc796296f00f100be520f209b23dc98f93ce8eba6ee7122598209", size = 111618, upload-time = "2026-09-15T19:34:37.656Z" }, + { url = "https://files.pythonhosted.org/packages/ba/78/7383278f1b3cf8e0496bd95b3281a7b09b89217b6b428db24c6b99b3deca/yarl-1.25.1-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:7cb414a73e21a7ab58254926073f2930cb22f5b4314ea4260a687e2b3fd4dce3", size = 114839, upload-time = "2026-09-15T19:34:40.099Z" }, + { url = "https://files.pythonhosted.org/packages/62/49/5506e5b6d29aab91bd845cc9016d88c3d3f81b81bc242b8100bdd5737825/yarl-1.25.1-cp315-cp315t-musllinux_1_2_armv7l.whl", hash = "sha256:85a18376073f8a39aa07be34f9fc77e2869aa72c55c441efdd2cf79a0407504d", size = 106212, upload-time = "2026-09-15T19:34:42.768Z" }, + { url = "https://files.pythonhosted.org/packages/46/8a/19877c193b7c5929f4b07118c18bbe390f3fadd0f59dd98c0cd12b31fa5c/yarl-1.25.1-cp315-cp315t-musllinux_1_2_ppc64le.whl", hash = "sha256:77716e245c90f058466a05e6a465bb8600f767a8f4b18b4d40f3aff958e5f73c", size = 119985, upload-time = "2026-09-15T19:34:44.976Z" }, + { url = "https://files.pythonhosted.org/packages/4e/6c/0a46fbbf9ecbcbd0cc20d2193394254b9e19817f22c814aab60f99847400/yarl-1.25.1-cp315-cp315t-musllinux_1_2_riscv64.whl", hash = "sha256:1e80dcf1446e1b080b1932b0d103c464a04112f5bc31f0f983ad418172063cde", size = 112081, upload-time = "2026-09-15T19:34:47.45Z" }, + { url = "https://files.pythonhosted.org/packages/ef/30/93f5d471230c74ccd06255d0842739f86551f937f9e63a5e947853c6244a/yarl-1.25.1-cp315-cp315t-musllinux_1_2_s390x.whl", hash = "sha256:bdc8d8b8c22e9e43ac68316b5e6cf083dec537f4ec213cb4aa967b583bc3fa64", size = 116995, upload-time = "2026-09-15T19:34:49.972Z" }, + { url = "https://files.pythonhosted.org/packages/2b/80/c386593035ee3f9c6c6af0847b5578f2830c674794a9d7701b744a3ebd42/yarl-1.25.1-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:dfbf531053a0935f2e871bcd4753f90313688772ff8c017f5ea402e315a78c1f", size = 115570, upload-time = "2026-09-15T19:34:52.628Z" }, + { url = "https://files.pythonhosted.org/packages/38/02/eef443559563ef8f2e10469387b8b1e97cb5efee95b288a56da60801f7ee/yarl-1.25.1-cp315-cp315t-win_amd64.whl", hash = "sha256:b13b88747769537f3d32e89e3a735da10c0a9e35d7322928c701b5f93d3afffd", size = 106811, upload-time = "2026-09-15T19:34:54.935Z" }, + { url = "https://files.pythonhosted.org/packages/88/91/41e284ca2cf5211e05dae031d126a3668aea88fa759df56e7e35c6ad25ba/yarl-1.25.1-cp315-cp315t-win_arm64.whl", hash = "sha256:783dd1467083f4d3f7722ad6a313f24c173e7571372738fcb7a6e6d1ba48df25", size = 101804, upload-time = "2026-09-15T19:34:57.231Z" }, + { url = "https://files.pythonhosted.org/packages/54/22/318c7980066769c6bcd9221ed2248294f5698811da099013098c670565ed/yarl-1.25.1-py3-none-any.whl", hash = "sha256:681c758b0490f9e96b78e5fa8e8dc6e648e9185bb6eaebe73183c33ea0c445f3", size = 63617, upload-time = "2026-09-15T19:34:59.616Z" }, +]