/build/source/nativelink-service/src/push_server.rs
Line | Count | Source |
1 | | // Copyright 2025 The NativeLink Authors. All rights reserved. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | use core::convert::Into; |
16 | | |
17 | | use nativelink_config::cas_server::PushConfig; |
18 | | use nativelink_error::{Error, ResultExt}; |
19 | | use nativelink_proto::build::bazel::remote::asset::v1::push_server::{Push, PushServer as Server}; |
20 | | use nativelink_proto::build::bazel::remote::asset::v1::{ |
21 | | PushBlobRequest, PushBlobResponse, PushDirectoryRequest, PushDirectoryResponse, |
22 | | }; |
23 | | use nativelink_store::store_manager::StoreManager; |
24 | | use nativelink_util::digest_hasher::make_ctx_for_hash_func; |
25 | | use opentelemetry::context::FutureExt; |
26 | | use tonic::{Request, Response, Status}; |
27 | | use tracing::{Instrument, Level, error_span, instrument}; |
28 | | |
29 | | #[derive(Debug, Clone, Copy)] |
30 | | pub struct PushServer {} |
31 | | |
32 | | impl PushServer { |
33 | 0 | pub const fn new(_config: &PushConfig, _store_manager: &StoreManager) -> Result<Self, Error> { |
34 | 0 | Ok(Self {}) |
35 | 0 | } |
36 | | |
37 | 0 | pub fn into_service(self) -> Server<Self> { |
38 | 0 | Server::new(self) |
39 | 0 | } |
40 | | |
41 | 1 | async fn inner_push_blob( |
42 | 1 | &self, |
43 | 1 | _request: PushBlobRequest, |
44 | 1 | ) -> Result<Response<PushBlobResponse>, Error> { |
45 | 1 | Ok(Response::new(PushBlobResponse {})) |
46 | 1 | } |
47 | | } |
48 | | |
49 | | #[tonic::async_trait] |
50 | | impl Push for PushServer { |
51 | | #[allow(clippy::blocks_in_conditions)] |
52 | | #[instrument( |
53 | | err, |
54 | | ret(level = Level::INFO), |
55 | | level = Level::ERROR, |
56 | | skip_all, |
57 | | fields(request = ?grpc_request.get_ref()) |
58 | | )] |
59 | | async fn push_blob( |
60 | | &self, |
61 | | grpc_request: Request<PushBlobRequest>, |
62 | 2 | ) -> Result<Response<PushBlobResponse>, Status> { |
63 | 1 | let request = grpc_request.into_inner(); |
64 | 1 | let digest_function = request.digest_function; |
65 | 1 | self.inner_push_blob(request) |
66 | 1 | .instrument(error_span!("push_push_blob")) |
67 | 1 | .with_context( |
68 | 1 | make_ctx_for_hash_func(digest_function).err_tip(|| "In PushServer::push_blob")?0 , |
69 | | ) |
70 | 1 | .await |
71 | 1 | .err_tip(|| "Failed on push_blob() command") |
72 | 1 | .map_err(Into::into) |
73 | 2 | } |
74 | | |
75 | | #[allow(clippy::blocks_in_conditions)] |
76 | | #[instrument( |
77 | | err, |
78 | | ret(level = Level::INFO), |
79 | | level = Level::ERROR, |
80 | | skip_all, |
81 | | fields(request = ?_grpc_request.get_ref()) |
82 | | )] |
83 | | async fn push_directory( |
84 | | &self, |
85 | | _grpc_request: Request<PushDirectoryRequest>, |
86 | 0 | ) -> Result<Response<PushDirectoryResponse>, Status> { |
87 | 0 | todo!() |
88 | 0 | } |
89 | | } |