Skip to content

Commit

Permalink
Bazel remote execution server mock
Browse files Browse the repository at this point in the history
  • Loading branch information
allada committed Dec 25, 2020
1 parent 5c65005 commit 862a923
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 15 deletions.
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ rust_binary(
"//proto",
"//third_party:tonic",
"//third_party:tokio",
"//third_party:futures_core",
],
)
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ clap = "2.33.3"
prost-build = "0.6.1"
tonic-build = "0.3.1"
rustfmt-nightly = "1.4.21"
futures-core = "0.3.8"

[package.metadata.raze.crates.prost-build.'*']
gen_buildrs = true
Expand Down
56 changes: 41 additions & 15 deletions helloworld_main.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,62 @@
// Copyright 2020 Nathan (Blaise) Bruer. All rights reserved.

use std::pin::Pin;

use futures_core::Stream;
use tonic::{transport::Server, Request, Response, Status};

use proto::helloworld::{HelloReply, HelloRequest};
use proto::helloworld::greeter_server::{Greeter, GreeterServer};
use proto::build::bazel::remote::execution::v2 as bre_v2;

use bre_v2::{
content_addressable_storage_server::ContentAddressableStorage,
content_addressable_storage_server::ContentAddressableStorageServer, BatchReadBlobsRequest,
BatchReadBlobsResponse, BatchUpdateBlobsRequest, BatchUpdateBlobsResponse,
FindMissingBlobsRequest, FindMissingBlobsResponse, GetTreeRequest, GetTreeResponse,
};

#[derive(Debug, Default)]
pub struct MyGreeter {}
pub struct CasServer {}

#[tonic::async_trait]
impl Greeter for MyGreeter {
async fn say_hello(
impl ContentAddressableStorage for CasServer {
async fn find_missing_blobs(
&self,
request: Request<HelloRequest>,
) -> Result<Response<HelloReply>, Status> {
println!("Got a request: {:?}", request);
_request: Request<FindMissingBlobsRequest>,
) -> Result<Response<FindMissingBlobsResponse>, Status> {
Err(Status::unimplemented("Not yet implemented"))
}

let reply = HelloReply {
message: format!("Hello {}!", request.into_inner().name).into(),
};
async fn batch_update_blobs(
&self,
_request: Request<BatchUpdateBlobsRequest>,
) -> Result<Response<BatchUpdateBlobsResponse>, Status> {
Err(Status::unimplemented("Not yet implemented"))
}

Ok(Response::new(reply))
async fn batch_read_blobs(
&self,
_request: Request<BatchReadBlobsRequest>,
) -> Result<Response<BatchReadBlobsResponse>, Status> {
Err(Status::unimplemented("Not yet implemented"))
}

type GetTreeStream =
Pin<Box<dyn Stream<Item = Result<GetTreeResponse, Status>> + Send + Sync + 'static>>;
async fn get_tree(
&self,
_request: Request<GetTreeRequest>,
) -> Result<Response<Self::GetTreeStream>, Status> {
Err(Status::unimplemented("Not yet implemented"))
}
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "[::1]:50051".parse()?;
let greeter = MyGreeter::default();
let addr = "0.0.0.0:50051".parse()?;
let cas = CasServer::default();

Server::builder()
.add_service(GreeterServer::new(greeter))
.add_service(ContentAddressableStorageServer::new(cas))
.serve(addr)
.await?;

Expand Down
9 changes: 9 additions & 0 deletions third_party/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ alias(
],
)

alias(
name = "futures_core",
actual = "@raze__futures_core__0_3_8//:futures_core",
tags = [
"cargo-raze",
"manual",
],
)

alias(
name = "prost",
actual = "@raze__prost__0_6_1//:prost",
Expand Down

0 comments on commit 862a923

Please sign in to comment.