diff options
Diffstat (limited to 'src')
3 files changed, 103 insertions, 0 deletions
diff --git a/src/buildtool/serve_api/remote/TARGETS b/src/buildtool/serve_api/remote/TARGETS index a56adf60..eeaf5b69 100644 --- a/src/buildtool/serve_api/remote/TARGETS +++ b/src/buildtool/serve_api/remote/TARGETS @@ -5,4 +5,17 @@ , "deps": [["src/buildtool/execution_api/remote", "config"]] , "stage": ["src", "buildtool", "serve_api", "remote"] } +, "serve_target_level_cache_client": + { "type": ["@", "rules", "CC", "library"] + , "name": ["serve_target_level_cache_client"] + , "hdrs": ["serve_target_level_cache_client.hpp"] + , "srcs": ["serve_target_level_cache_client.cpp"] + , "deps": + [ ["src/buildtool/common/remote", "port"] + , ["src/buildtool/logging", "logging"] + ] + , "proto": [["src/buildtool/serve_api/serve_service", "just_serve_proto"]] + , "stage": ["src", "buildtool", "serve_api", "remote"] + , "private-deps": [["src/buildtool/common/remote", "client_common"]] + } } diff --git a/src/buildtool/serve_api/remote/serve_target_level_cache_client.cpp b/src/buildtool/serve_api/remote/serve_target_level_cache_client.cpp new file mode 100644 index 00000000..e09b3d03 --- /dev/null +++ b/src/buildtool/serve_api/remote/serve_target_level_cache_client.cpp @@ -0,0 +1,46 @@ +// Copyright 2023 Huawei Cloud Computing Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/buildtool/serve_api/remote/serve_target_level_cache_client.hpp" + +#include "src/buildtool/common/remote/client_common.hpp" + +ServeTargetLevelCacheClient::ServeTargetLevelCacheClient( + std::string const& server, + Port port) noexcept { + stub_ = justbuild::just_serve::TargetLevelCache::NewStub( + CreateChannelWithCredentials(server, port)); +} + +auto ServeTargetLevelCacheClient::ServeCommitTree(std::string const& commit_id, + std::string const& subdir) + -> std::optional<std::string> { + justbuild::just_serve::ServeCommitTreeRequest request{}; + request.set_commit(commit_id); + request.set_subdir(subdir); + + grpc::ClientContext context; + justbuild::just_serve::ServeCommitTreeResponse response; + grpc::Status status = stub_->ServeCommitTree(&context, request, &response); + + if (not status.ok()) { + LogStatus(&logger_, LogLevel::Debug, status); + return std::nullopt; + } + if (response.status().code() != grpc::StatusCode::OK) { + LogStatus(&logger_, LogLevel::Debug, response.status()); + return std::nullopt; + } + return response.tree(); +} diff --git a/src/buildtool/serve_api/remote/serve_target_level_cache_client.hpp b/src/buildtool/serve_api/remote/serve_target_level_cache_client.hpp new file mode 100644 index 00000000..fa89c24b --- /dev/null +++ b/src/buildtool/serve_api/remote/serve_target_level_cache_client.hpp @@ -0,0 +1,44 @@ +// Copyright 2023 Huawei Cloud Computing Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef INCLUDED_SRC_BUILDTOOL_SERVE_API_REMOTE_SERVE_TLC_CLIENT_HPP +#define INCLUDED_SRC_BUILDTOOL_SERVE_API_REMOTE_SERVE_TLC_CLIENT_HPP + +#include <memory> +#include <string> + +#include "justbuild/just_serve/just_serve.grpc.pb.h" +#include "src/buildtool/common/remote/port.hpp" +#include "src/buildtool/logging/logger.hpp" + +/// Implements client side for service defined in: +/// src/buildtool/serve_api/serve_service/just_serve.proto +class ServeTargetLevelCacheClient { + public: + ServeTargetLevelCacheClient(std::string const& server, Port port) noexcept; + + /// \brief Retrieve the Git tree of a given commit, if known by the remote. + /// \param[in] commit_id Hash of the Git commit to look up. + /// \param[in] subdir Relative path of the tree inside commit. + /// \returns The hash of the tree if commit found, nullopt otherwise. + [[nodiscard]] auto ServeCommitTree(std::string const& commit_id, + std::string const& subdir) + -> std::optional<std::string>; + + private: + std::unique_ptr<justbuild::just_serve::TargetLevelCache::Stub> stub_; + Logger logger_{"RemoteTLCClient"}; +}; + +#endif // INCLUDED_SRC_BUILDTOOL_SERVE_API_REMOTE_SERVE_TLC_CLIENT_HPP |