diff options
Diffstat (limited to 'src/buildtool/serve_api/serve_service/target.cpp')
-rw-r--r-- | src/buildtool/serve_api/serve_service/target.cpp | 48 |
1 files changed, 12 insertions, 36 deletions
diff --git a/src/buildtool/serve_api/serve_service/target.cpp b/src/buildtool/serve_api/serve_service/target.cpp index 6cae3d8b..1e69af63 100644 --- a/src/buildtool/serve_api/serve_service/target.cpp +++ b/src/buildtool/serve_api/serve_service/target.cpp @@ -40,6 +40,7 @@ #include "src/buildtool/progress_reporting/progress.hpp" #include "src/buildtool/progress_reporting/progress_reporter.hpp" #include "src/buildtool/serve_api/serve_service/target_utils.hpp" +#include "src/buildtool/storage/backend_description.hpp" #include "src/buildtool/storage/garbage_collector.hpp" #include "src/buildtool/storage/target_cache_key.hpp" #include "src/utils/cpp/verify_hash.hpp" @@ -138,7 +139,7 @@ auto TargetService::ServeTarget( // start filling in the backend description auto const address = RemoteExecutionConfig::RemoteAddress(); - // read in the execution properties and add it to the description; + // 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. @@ -146,11 +147,7 @@ auto TargetService::ServeTarget( for (auto const& p : request->execution_properties()) { platform_properties[p.name()] = p.value(); } - auto description = nlohmann::json{ - {"remote_address", address ? address->ToJson() : nlohmann::json{}}, - {"platform_properties", platform_properties}}; - - // read in the dispatch list and add it to the description, if not empty + // 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}; @@ -165,40 +162,19 @@ auto TargetService::ServeTarget( // keep dispatch list, as it needs to be passed to the executor (via the // graph_traverser) auto dispatch_list = *res; - // parse dispatch list to json and add to description - auto dispatch_json = nlohmann::json::array(); - try { - for (auto const& [props, endpoint] : dispatch_list) { - auto entry = nlohmann::json::array(); - entry.push_back(nlohmann::json(props)); - entry.push_back(endpoint.ToJson()); - dispatch_json.push_back(entry); - } - } catch (std::exception const& ex) { - logger_->Emit(LogLevel::Info, - "Parsing dispatch list to JSON failed with:\n{}", - ex.what()); - } - if (not dispatch_json.empty()) { - description["endpoint dispatch list"] = std::move(dispatch_json); - } - // add backend description to CAS; - // we match the sharding strategy from regular just builds, i.e., allowing - // fields with invalid UTF-8 characters to be considered for the serialized - // JSON description, but using the UTF-8 replacement character to solve any - // decoding errors. - std::string description_str; - try { - description_str = description.dump( - 2, ' ', false, nlohmann::json::error_handler_t::replace); - } catch (std::exception const& ex) { - // normally shouldn't happen - std::string err{"Failed to dump backend JSON description to string"}; + // get backend description + auto description = + DescribeBackend(address, platform_properties, dispatch_list); + if (not description) { + auto err = fmt::format("Failed to create backend description:\n{}", + description.error()); logger_->Emit(LogLevel::Error, err); return ::grpc::Status{::grpc::StatusCode::INTERNAL, err}; } - auto execution_backend_dgst = storage_.CAS().StoreBlob(description_str); + + // add backend description to CAS + auto execution_backend_dgst = storage_.CAS().StoreBlob(*description); if (not execution_backend_dgst) { std::string err{ "Failed to store execution backend description in local CAS"}; |