diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-12-11 14:36:00 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-12-12 14:37:18 +0100 |
commit | f77232b3f0bf9a53127d138a54a8a263b1a29f39 (patch) | |
tree | f4ac24169e7a386c239913fc017ea76f9ed321f1 /src/buildtool/serve_api/remote/target_client.cpp | |
parent | 3fdfd22e7f02effbf28ad99b00e4916ae6f4b4ad (diff) | |
download | justbuild-f77232b3f0bf9a53127d138a54a8a263b1a29f39.tar.gz |
serve target: Update client-side to add execution configuration fields to request
Diffstat (limited to 'src/buildtool/serve_api/remote/target_client.cpp')
-rw-r--r-- | src/buildtool/serve_api/remote/target_client.cpp | 43 |
1 files changed, 33 insertions, 10 deletions
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<ObjectType::File>( - 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); |