From f77232b3f0bf9a53127d138a54a8a263b1a29f39 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Mon, 11 Dec 2023 14:36:00 +0100 Subject: serve target: Update client-side to add execution configuration fields to request --- src/buildtool/serve_api/remote/target_client.cpp | 43 ++++++++++++++++++------ 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'src/buildtool/serve_api/remote/target_client.cpp') diff --git a/src/buildtool/serve_api/remote/target_client.cpp b/src/buildtool/serve_api/remote/target_client.cpp index 7166a604..7819efb6 100644 --- a/src/buildtool/serve_api/remote/target_client.cpp +++ b/src/buildtool/serve_api/remote/target_client.cpp @@ -46,25 +46,48 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key, return std::nullopt; } + // add target cache key to request bazel_re::Digest key_dgst{key.Id().digest}; justbuild::just_serve::ServeTargetRequest request{}; *(request.mutable_target_cache_key_id()) = std::move(key_dgst); - auto execution_backend_dgst = ArtifactDigest::Create( - StorageConfig::ExecutionBackendDescription()); - auto const& execution_info = - Artifact::ObjectInfo{.digest = ArtifactDigest{execution_backend_dgst}, - .type = ObjectType::File}; - if (!local_api_->RetrieveToCas({execution_info}, &*remote_api_)) { + // add execution properties to request + for (auto const& [k, v] : RemoteExecutionConfig::PlatformProperties()) { + auto* prop = request.add_execution_properties(); + prop->set_name(k); + prop->set_value(v); + } + + // add dispatch information to request, while ensuring blob is uploaded to + // remote cas + auto dispatch_list = nlohmann::json::array(); + for (auto const& [props, endpoint] : + RemoteExecutionConfig::DispatchList()) { + auto entry = nlohmann::json::array(); + entry.push_back(nlohmann::json(props)); + entry.push_back(endpoint.ToJson()); + dispatch_list.push_back(entry); + } + + auto dispatch_dgst = + Storage::Instance().CAS().StoreBlob(dispatch_list.dump(2)); + if (not dispatch_dgst) { + logger_.Emit(LogLevel::Error, + "failed to store blob {} to local cas", + dispatch_list.dump(2)); + return std::nullopt; + } + auto const& dispatch_info = Artifact::ObjectInfo{ + .digest = ArtifactDigest{*dispatch_dgst}, .type = ObjectType::File}; + if (!local_api_->RetrieveToCas({dispatch_info}, &*remote_api_)) { logger_.Emit(LogLevel::Error, "failed to upload blob {} to remote cas", - execution_info.ToString()); + dispatch_info.ToString()); return std::nullopt; } + *(request.mutable_dispatch_info()) = std::move(*dispatch_dgst); - *(request.mutable_execution_backend_description_id()) = - std::move(execution_backend_dgst); - + // call rpc grpc::ClientContext context; justbuild::just_serve::ServeTargetResponse response; auto const& status = stub_->ServeTarget(&context, request, &response); -- cgit v1.2.3