diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/serve_api/serve_service/TARGETS | 3 | ||||
-rw-r--r-- | src/buildtool/serve_api/serve_service/target.cpp | 71 | ||||
-rw-r--r-- | src/buildtool/serve_api/serve_service/target.hpp | 9 |
3 files changed, 50 insertions, 33 deletions
diff --git a/src/buildtool/serve_api/serve_service/TARGETS b/src/buildtool/serve_api/serve_service/TARGETS index 18d04bc2..4374dafd 100644 --- a/src/buildtool/serve_api/serve_service/TARGETS +++ b/src/buildtool/serve_api/serve_service/TARGETS @@ -89,6 +89,7 @@ , ["src/buildtool/execution_api/common", "api_bundle"] , ["src/buildtool/execution_api/common", "common"] , ["src/buildtool/execution_api/local", "context"] + , ["src/buildtool/execution_api/remote", "config"] , ["src/buildtool/serve_api/remote", "config"] , ["src/utils/cpp", "expected"] ] @@ -105,8 +106,6 @@ , ["src/buildtool/build_engine/target_map", "result_map"] , ["src/buildtool/common/remote", "remote_common"] , ["src/buildtool/common/remote", "retry_config"] - , ["src/buildtool/execution_api/local", "context"] - , ["src/buildtool/execution_api/remote", "config"] , ["src/buildtool/file_system", "file_system_manager"] , ["src/buildtool/graph_traverser", "graph_traverser"] , ["src/buildtool/logging", "log_level"] diff --git a/src/buildtool/serve_api/serve_service/target.cpp b/src/buildtool/serve_api/serve_service/target.cpp index 6ab95b8a..001b9387 100644 --- a/src/buildtool/serve_api/serve_service/target.cpp +++ b/src/buildtool/serve_api/serve_service/target.cpp @@ -28,7 +28,6 @@ #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/common/statistics.hpp" -#include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/graph_traverser/graph_traverser.hpp" @@ -119,6 +118,35 @@ auto TargetService::HandleFailureLog( return ::grpc::Status::OK; } +auto TargetService::CreateRemoteExecutionConfig( + const ::justbuild::just_serve::ServeTargetRequest* request) noexcept + -> expected<RemoteExecutionConfig, ::grpc::Status> { + // read in the execution properties + auto platform_properties = ExecutionProperties{}; + for (auto const& p : request->execution_properties()) { + platform_properties[p.name()] = p.value(); + } + // read in the dispatch list + if (auto msg = IsAHash(request->dispatch_info().hash()); msg) { + logger_->Emit(LogLevel::Error, "{}", *msg); + return unexpected{ + ::grpc::Status{::grpc::StatusCode::INVALID_ARGUMENT, *msg}}; + } + auto const& dispatch_info_digest = ArtifactDigest{request->dispatch_info()}; + auto res = GetDispatchList(dispatch_info_digest); + if (not res) { + auto err = move(res).error(); + logger_->Emit(LogLevel::Error, "{}", err.error_message()); + return unexpected{std::move(err)}; + } + // the remote and cache addresses are kept from the stored ApiBundle + return RemoteExecutionConfig{ + .remote_address = apis_.remote_config.remote_address, + .dispatch = *std::move(res), + .cache_address = apis_.remote_config.cache_address, + .platform_properties = std::move(platform_properties)}; +} + auto TargetService::ServeTarget( ::grpc::ServerContext* /*context*/, const ::justbuild::just_serve::ServeTargetRequest* request, @@ -146,35 +174,16 @@ auto TargetService::ServeTarget( return ::grpc::Status{::grpc::StatusCode::INTERNAL, msg}; } - // start filling in the backend description - auto const address = apis_.remote_config.remote_address; - // read in the execution properties. - // Important: we will need to pass these platform properties also to the - // executor (via the graph_traverser) in order for the build to be properly - // dispatched to the correct remote-execution endpoint. - auto platform_properties = ExecutionProperties{}; - for (auto const& p : request->execution_properties()) { - platform_properties[p.name()] = p.value(); - } - // Read in the dispatch list - if (auto msg = IsAHash(request->dispatch_info().hash()); msg) { - logger_->Emit(LogLevel::Error, "{}", *msg); - return ::grpc::Status{::grpc::StatusCode::INVALID_ARGUMENT, *msg}; - } - auto const& dispatch_info_digest = ArtifactDigest{request->dispatch_info()}; - auto res = GetDispatchList(dispatch_info_digest); - if (not res) { - auto err = move(res).error(); - logger_->Emit(LogLevel::Error, "{}", err.error_message()); - return err; + // set up the remote execution config instance for the orchestrated build + auto remote_config = CreateRemoteExecutionConfig(request); + if (not remote_config) { + return std::move(remote_config).error(); } - // keep dispatch list, as it needs to be passed to the executor (via the - // graph_traverser) - auto dispatch_list = *res; // get backend description - auto description = - DescribeBackend(address, platform_properties, dispatch_list); + auto description = DescribeBackend(remote_config->remote_address, + remote_config->platform_properties, + remote_config->dispatch); if (not description) { auto err = fmt::format("Failed to create backend description:\n{}", description.error()); @@ -194,7 +203,7 @@ auto TargetService::ServeTarget( // get a target cache instance with the correct computed shard auto shard = - address + remote_config->remote_address ? std::make_optional(ArtifactDigest(*execution_backend_dgst).hash()) : std::nullopt; auto const& tc = local_context_.storage->TargetCache().WithShard(shard); @@ -490,12 +499,12 @@ auto TargetService::ServeTarget( &repository_config, &apis_.auth, &apis_.retry_config, - &apis_.remote_config}; + &(*remote_config)}; GraphTraverser const traverser{ std::move(traverser_args), &repository_config, - std::move(platform_properties), - std::move(dispatch_list), + remote_config->platform_properties, + remote_config->dispatch, &stats, &progress, &local_apis, diff --git a/src/buildtool/serve_api/serve_service/target.hpp b/src/buildtool/serve_api/serve_service/target.hpp index 88e5a205..89076f05 100644 --- a/src/buildtool/serve_api/serve_service/target.hpp +++ b/src/buildtool/serve_api/serve_service/target.hpp @@ -31,6 +31,7 @@ #include "src/buildtool/execution_api/common/api_bundle.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/execution_api/local/context.hpp" +#include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/logging/logger.hpp" #include "src/buildtool/serve_api/remote/config.hpp" #include "src/buildtool/serve_api/remote/serve_api.hpp" @@ -149,6 +150,14 @@ class TargetService final : public justbuild::just_serve::Target::Service { std::string const& failure_scope, ::justbuild::just_serve::ServeTargetResponse* response) noexcept -> ::grpc::Status; + + /// \brief Create the execution configuration needed to shard the target + /// cache and dispatch the build to the remote endpoint. + /// \returns A set up RemoteExecutionConfig or an unexpected error as + /// grpc::Status. + [[nodiscard]] auto CreateRemoteExecutionConfig( + const ::justbuild::just_serve::ServeTargetRequest* request) noexcept + -> expected<RemoteExecutionConfig, ::grpc::Status>; }; #endif // INCLUDED_SRC_BUILD_SERVE_API_SERVE_SERVICE_TARGET_HPP |