Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MetadataService with GetHealth and GetVersion #267

Merged
merged 12 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `GetClients` to `SrsService`, which retrieves a list of units that are connected to SRS and the frequencies they are connected to.
- Added `SrsConnectEvent` and `SrsDisconnectEvent` events
- Added `GetDrawArgumentValue` API for units, which returns the value for drawing. (useful for "hook down", "doors open" checks)
- Added `AdministrationService` with `GetHealth` and `GetVersion` for quick checks on health (even when DCS mission is unresponsive) and version.

### Fixed
- Fixed `MarkAddEvent`, `MarkChangeEvent` and `MarkRemoveEvent` position
Expand Down
26 changes: 26 additions & 0 deletions protos/dcs/administration/v0/administration.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";
package dcs.administration.v0;
option csharp_namespace = "RurouniJones.Dcs.Grpc.V0.Administration";
option go_package = "github.com/DCS-gRPC/go-bindings/dcs/v0/administration";

//A service to get administrative data like health and version
service AdministrationService {

rpc GetHealth(GetHealthRequest) returns (GetHealthResponse) {}

rpc GetVersion(GetVersionRequest) returns (GetVersionResponse) {}
}

message GetHealthRequest {
}

message GetHealthResponse {
bool alive = 1;
}

message GetVersionRequest {
}

message GetVersionResponse {
string version = 1;
}
1 change: 1 addition & 0 deletions protos/dcs/dcs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";

package dcs;

import "dcs/administration/v0/administration.proto";
import "dcs/atmosphere/v0/atmosphere.proto";
import "dcs/coalition/v0/coalition.proto";
import "dcs/common/v0/common.proto";
Expand Down
1 change: 1 addition & 0 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub use self::srs::Srs;
use crate::shutdown::ShutdownHandle;
use crate::stats::Stats;

mod administration;
mod atmosphere;
mod coalition;
mod controller;
Expand Down
30 changes: 30 additions & 0 deletions src/rpc/administration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use stubs::administration::v0::administration_service_server::AdministrationService;
use stubs::*;
use tonic::async_trait;
use tonic::{Request, Response, Status};

use super::MissionRpc;

#[async_trait]
impl AdministrationService for MissionRpc {
async fn get_health(
&self,
_request: Request<administration::v0::GetHealthRequest>,
) -> Result<Response<administration::v0::GetHealthResponse>, Status> {
let alive: bool = true;
return Ok(Response::new(administration::v0::GetHealthResponse {
alive,
}));
}

async fn get_version(
&self,
_request: Request<administration::v0::GetVersionRequest>,
) -> Result<Response<administration::v0::GetVersionResponse>, Status> {
const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION");
let version = VERSION.unwrap_or("unknown").to_string();
return Ok(Response::new(administration::v0::GetVersionResponse {
version,
}));
}
}
4 changes: 3 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::time::Duration;

use dcs_module_ipc::IPC;
use futures_util::FutureExt;
use stubs::administration::v0::administration_service_server::AdministrationServiceServer;
use stubs::atmosphere::v0::atmosphere_service_server::AtmosphereServiceServer;
use stubs::coalition::v0::coalition_service_server::CoalitionServiceServer;
use stubs::controller::v0::controller_service_server::ControllerServiceServer;
Expand Down Expand Up @@ -205,7 +206,7 @@ async fn try_run(
srs_transmit,
} = state;

let mut mission_rpc =
let mut mission_rpc: MissionRpc =
MissionRpc::new(ipc_mission.clone(), stats.clone(), shutdown_signal.clone());
let mut hook_rpc = HookRpc::new(ipc_hook, stats, shutdown_signal.clone());

Expand Down Expand Up @@ -243,6 +244,7 @@ async fn try_run(
});

transport::Server::builder()
.add_service(AdministrationServiceServer::new(mission_rpc.clone()))
.add_service(AtmosphereServiceServer::new(mission_rpc.clone()))
.add_service(CoalitionServiceServer::new(mission_rpc.clone()))
.add_service(ControllerServiceServer::new(mission_rpc.clone()))
Expand Down
3 changes: 3 additions & 0 deletions stubs/src/administration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod v0 {
tonic::include_proto!("dcs.administration.v0");
}
1 change: 1 addition & 0 deletions stubs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![allow(clippy::derive_partial_eq_without_eq)]
#![allow(clippy::large_enum_variant)]

pub mod administration;
pub mod atmosphere;
pub mod coalition;
pub mod common;
Expand Down
Loading