diff options
Diffstat (limited to 'src/buildtool/serve_api/remote')
-rw-r--r-- | src/buildtool/serve_api/remote/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/serve_api/remote/serve_api.hpp | 12 | ||||
-rw-r--r-- | src/buildtool/serve_api/remote/target_client.cpp | 18 | ||||
-rw-r--r-- | src/buildtool/serve_api/remote/target_client.hpp | 10 |
4 files changed, 22 insertions, 19 deletions
diff --git a/src/buildtool/serve_api/remote/TARGETS b/src/buildtool/serve_api/remote/TARGETS index 6443e699..efb923f0 100644 --- a/src/buildtool/serve_api/remote/TARGETS +++ b/src/buildtool/serve_api/remote/TARGETS @@ -36,6 +36,7 @@ , ["src/buildtool/common/remote", "port"] , ["src/buildtool/common/remote", "remote_common"] , ["src/buildtool/file_system/symlinks_map", "pragma_special"] + , ["src/buildtool/execution_api/common", "api_bundle"] , "source_tree_client" , "target_client" , "configuration_client" diff --git a/src/buildtool/serve_api/remote/serve_api.hpp b/src/buildtool/serve_api/remote/serve_api.hpp index 89e287a4..9175857b 100644 --- a/src/buildtool/serve_api/remote/serve_api.hpp +++ b/src/buildtool/serve_api/remote/serve_api.hpp @@ -29,6 +29,7 @@ class ServeApi final {}; #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/remote/port.hpp" #include "src/buildtool/common/remote/remote_common.hpp" +#include "src/buildtool/execution_api/common/api_bundle.hpp" #include "src/buildtool/file_system/symlinks_map/pragma_special.hpp" #include "src/buildtool/serve_api/remote/config.hpp" #include "src/buildtool/serve_api/remote/configuration_client.hpp" @@ -37,8 +38,9 @@ class ServeApi final {}; class ServeApi final { public: - explicit ServeApi(ServerAddress const& address) noexcept - : stc_{address}, tc_{address}, cc_{address} {} + explicit ServeApi(ServerAddress const& address, + gsl::not_null<ApiBundle const*> const& apis) noexcept + : stc_{address}, tc_{address, apis}, cc_{address} {} ~ServeApi() noexcept = default; ServeApi(ServeApi const&) = delete; @@ -47,10 +49,12 @@ class ServeApi final { auto operator=(ServeApi&&) -> ServeApi& = delete; [[nodiscard]] static auto Create( - RemoteServeConfig const& serve_config) noexcept + RemoteServeConfig const& serve_config, + gsl::not_null<ApiBundle const*> const& apis) noexcept -> std::optional<ServeApi> { if (serve_config.remote_address) { - return std::make_optional<ServeApi>(*serve_config.remote_address); + return std::make_optional<ServeApi>(*serve_config.remote_address, + apis); } return std::nullopt; } diff --git a/src/buildtool/serve_api/remote/target_client.cpp b/src/buildtool/serve_api/remote/target_client.cpp index 917f1133..d0e6796e 100644 --- a/src/buildtool/serve_api/remote/target_client.cpp +++ b/src/buildtool/serve_api/remote/target_client.cpp @@ -25,7 +25,9 @@ #include "src/buildtool/common/remote/client_common.hpp" #include "src/buildtool/logging/log_level.hpp" -TargetClient::TargetClient(ServerAddress const& address) noexcept { +TargetClient::TargetClient(ServerAddress const& address, + gsl::not_null<ApiBundle const*> const& apis) noexcept + : apis_{*apis} { stub_ = justbuild::just_serve::Target::NewStub( CreateChannelWithCredentials(address.host, address.port)); } @@ -34,17 +36,17 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key, const std::string& repo_key) const noexcept -> std::optional<serve_target_result_t> { // make sure the blob containing the key is in the remote cas - if (!local_api_->RetrieveToCas({key.Id()}, &*remote_api_)) { + if (!apis_.local->RetrieveToCas({key.Id()}, &*apis_.remote)) { return serve_target_result_t{ std::in_place_index<1>, fmt::format("Failed to retrieve to remote cas ObjectInfo {}", key.Id().ToString())}; } // make sure the repository configuration blob is in the remote cas - if (!local_api_->RetrieveToCas( + if (!apis_.local->RetrieveToCas( {Artifact::ObjectInfo{.digest = ArtifactDigest{repo_key, 0, false}, .type = ObjectType::File}}, - &*remote_api_)) { + &*apis_.remote)) { return serve_target_result_t{ std::in_place_index<1>, fmt::format("Failed to retrieve to remote cas blob {}", repo_key)}; @@ -90,7 +92,7 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key, } auto const& dispatch_info = Artifact::ObjectInfo{ .digest = ArtifactDigest{*dispatch_dgst}, .type = ObjectType::File}; - if (!local_api_->RetrieveToCas({dispatch_info}, &*remote_api_)) { + if (!apis_.local->RetrieveToCas({dispatch_info}, &*apis_.remote)) { return serve_target_result_t{ std::in_place_index<1>, fmt::format("Failed to upload blob {} to remote cas", @@ -122,8 +124,8 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key, ArtifactDigest{response.target_value()}; auto const& obj_info = Artifact::ObjectInfo{ .digest = target_value_dgst, .type = ObjectType::File}; - if (!local_api_->IsAvailable(target_value_dgst)) { - if (!remote_api_->RetrieveToCas({obj_info}, &*local_api_)) { + if (!apis_.local->IsAvailable(target_value_dgst)) { + if (!apis_.remote->RetrieveToCas({obj_info}, &*apis_.local)) { return serve_target_result_t{ std::in_place_index<1>, fmt::format( @@ -132,7 +134,7 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key, } } auto const& target_value_str = - local_api_->RetrieveToMemory(obj_info); + apis_.local->RetrieveToMemory(obj_info); if (!target_value_str) { return serve_target_result_t{ std::in_place_index<1>, diff --git a/src/buildtool/serve_api/remote/target_client.hpp b/src/buildtool/serve_api/remote/target_client.hpp index bc3aa382..35bb2d29 100644 --- a/src/buildtool/serve_api/remote/target_client.hpp +++ b/src/buildtool/serve_api/remote/target_client.hpp @@ -52,7 +52,8 @@ using serve_target_result_t = /// src/buildtool/serve_api/serve_service/just_serve.proto class TargetClient { public: - explicit TargetClient(ServerAddress const& address) noexcept; + explicit TargetClient(ServerAddress const& address, + gsl::not_null<ApiBundle const*> const& apis) noexcept; /// \brief Retrieve the pair of TargetCacheEntry and ObjectInfo associated /// to the given key. @@ -86,14 +87,9 @@ class TargetClient { const noexcept -> std::optional<ArtifactDigest>; private: + ApiBundle const& apis_; std::unique_ptr<justbuild::just_serve::Target::Stub> stub_; Logger logger_{"RemoteTargetClient"}; - gsl::not_null<IExecutionApi::Ptr> const remote_api_{ - CreateExecutionApi(RemoteExecutionConfig::RemoteAddress(), - std::nullopt, - "remote-execution")}; - gsl::not_null<IExecutionApi::Ptr> const local_api_{ - CreateExecutionApi(std::nullopt)}; }; #endif // INCLUDED_SRC_BUILDTOOL_SERVE_API_TARGET_CLIENT_HPP |