summaryrefslogtreecommitdiff
path: root/src/buildtool/serve_api/serve_service/target.hpp
diff options
context:
space:
mode:
authorAlberto Sartori <alberto.sartori@huawei.com>2023-11-13 16:03:56 +0100
committerAlberto Sartori <alberto.sartori@huawei.com>2023-11-15 20:19:18 +0100
commit9cc638844836b67ba09504985dd7ad85846046ab (patch)
treebd9baa464c8a1047e24a942152dd3ddab1fc2936 /src/buildtool/serve_api/serve_service/target.hpp
parent67df0b309e6c84d6a5c6239706333848bd02c518 (diff)
downloadjustbuild-9cc638844836b67ba09504985dd7ad85846046ab.tar.gz
just-serve: initial server-side implementation of "Target" and "Configuration" services.
The RPC ServeTarget has not implemented the orchestration of remote build yet. If the TargetCacheKey is not found in the target cache, the response contains status == grpc::StatusCode::UNIMPLEMENTED. Co-authored-by: Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com>
Diffstat (limited to 'src/buildtool/serve_api/serve_service/target.hpp')
-rw-r--r--src/buildtool/serve_api/serve_service/target.hpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/buildtool/serve_api/serve_service/target.hpp b/src/buildtool/serve_api/serve_service/target.hpp
new file mode 100644
index 00000000..0f3f4ae2
--- /dev/null
+++ b/src/buildtool/serve_api/serve_service/target.hpp
@@ -0,0 +1,91 @@
+// 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_BUILD_SERVE_API_SERVE_SERVICE_TARGET_HPP
+#define INCLUDED_SRC_BUILD_SERVE_API_SERVE_SERVICE_TARGET_HPP
+
+#include <filesystem>
+#include <memory>
+#include <optional>
+
+#include "justbuild/just_serve/just_serve.grpc.pb.h"
+#include "src/buildtool/common/remote/remote_common.hpp"
+#include "src/buildtool/execution_api/common/create_execution_api.hpp"
+#include "src/buildtool/execution_api/remote/config.hpp"
+#include "src/buildtool/logging/logger.hpp"
+
+#include <gsl/gsl>
+
+class TargetService final : public justbuild::just_serve::Target::Service {
+ public:
+ // Given a target-level caching key, returns the computed value. In doing
+ // so, it can build on the associated end-point passing the
+ // RemoteExecutionProperties contained in the ServeTargetRequest.
+ //
+ // If the status has a code different from `OK`, the response MUST not be
+ // used.
+ //
+ // Errors:
+ // * `FAILED_PRECONDITION`: Failed to find required information in the CAS
+ // or the target cache key is malformed.
+ // * `UNAVAILABLE`: Could not communicate with the remote execution
+ // endpoint.
+ // * `INTERNAL`: Internally, something is very broken.
+ auto ServeTarget(
+ ::grpc::ServerContext* /*context*/,
+ const ::justbuild::just_serve::ServeTargetRequest* /*request*/,
+ ::justbuild::just_serve::ServeTargetResponse* /*response*/)
+ -> ::grpc::Status override;
+
+ // Given the target-level root tree and the name of an export target,
+ // returns the list of flexible variables from that target's description.
+ //
+ // If the status has a code different from `OK`, the response MUST not be
+ // used.
+ //
+ // Errors:
+ // * `FAILED_PRECONDITION`: An error occurred in retrieving the
+ // configuration of the requested target, such as missing entries
+ // (target-root, target file, target name), unparsable target file, or
+ // requested target not being of "type" : "export".
+ // * `INTERNAL`: Internally, something is very broken.
+ auto ServeTargetVariables(
+ ::grpc::ServerContext* /*context*/,
+ const ::justbuild::just_serve::ServeTargetVariablesRequest* request,
+ ::justbuild::just_serve::ServeTargetVariablesResponse* response)
+ -> ::grpc::Status override;
+
+ private:
+ std::shared_ptr<Logger> logger_{std::make_shared<Logger>("target-service")};
+
+ // remote execution endpoint used for remote building
+ gsl::not_null<IExecutionApi::Ptr> const remote_api_{
+ CreateExecutionApi(RemoteExecutionConfig::RemoteAddress(),
+ "serve-remote-execution")};
+ // used for storing and retrieving target-level cache entries
+ gsl::not_null<IExecutionApi::Ptr> const local_api_{
+ CreateExecutionApi(std::nullopt)};
+
+ /// \brief Get the blob content at given path inside a Git tree.
+ /// \returns If tree found, pair of "no-internal-errors" flag and content of
+ /// blob at the path specified if blob exists, nullopt otherwise.
+ [[nodiscard]] static auto GetBlobContent(
+ std::filesystem::path const& repo_path,
+ std::string const& tree_id,
+ std::string const& rel_path,
+ std::shared_ptr<Logger> const& logger)
+ -> std::optional<std::pair<bool, std::optional<std::string>>>;
+};
+
+#endif // INCLUDED_SRC_BUILD_SERVE_API_SERVE_SERVICE_TARGET_HPP