Skip to content

Commit

Permalink
chore: bump to yang3 0.6 and adapt the code accordingly
Browse files Browse the repository at this point in the history
yang3 0.6 introduces a lifetime parameter for the `DataTree` struct,
which refers to the associated YANG context. In Holo, we use the
global variable `YANG_CTX` to store the YANG context, so we can use
`DataTree<'static>`.

Signed-off-by: Renato Westphal <[email protected]>
  • Loading branch information
rwestphal committed Aug 2, 2024
1 parent 305184f commit 08dcc23
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ tonic = { version = "0.11", features = ["tls"] }
tonic-build = "0.11"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
yang3 = { version = "0.5", features = ["bundled"] }
yang3 = { version = "0.6", features = ["bundled"] }

[workspace.lints.rust]
rust_2018_idioms = { level = "warn", priority = -1 }
Expand Down
16 changes: 8 additions & 8 deletions holo-daemon/src/northbound/client/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ pub mod client {

#[derive(Debug)]
pub struct GetResponse {
pub dtree: DataTree,
pub dtree: DataTree<'static>,
}

#[derive(Debug)]
pub struct ValidateRequest {
pub config: DataTree,
pub config: DataTree<'static>,
pub responder: Responder<Result<ValidateResponse>>,
}

Expand All @@ -71,13 +71,13 @@ pub mod client {

#[derive(Debug)]
pub struct ExecuteRequest {
pub data: DataTree,
pub data: DataTree<'static>,
pub responder: Responder<Result<ExecuteResponse>>,
}

#[derive(Debug)]
pub struct ExecuteResponse {
pub data: DataTree,
pub data: DataTree<'static>,
}

#[derive(Debug)]
Expand All @@ -98,7 +98,7 @@ pub mod client {

#[derive(Debug)]
pub struct GetTransactionResponse {
pub dtree: DataTree,
pub dtree: DataTree<'static>,
}

// ===== impl Request =====
Expand Down Expand Up @@ -126,7 +126,7 @@ pub enum DataType {

#[derive(Debug)]
pub enum CommitConfiguration {
Merge(DataTree),
Replace(DataTree),
Change(DataDiff),
Merge(DataTree<'static>),
Replace(DataTree<'static>),
Change(DataDiff<'static>),
}
6 changes: 3 additions & 3 deletions holo-daemon/src/northbound/client/gnmi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl proto::GNmi for GNmiService {
impl GNmiService {
fn gen_update_ietf_json(
&self,
dtree: DataTree,
dtree: DataTree<'static>,
_models: &[proto::ModelData],
) -> Vec<proto::Update> {
dtree
Expand Down Expand Up @@ -343,7 +343,7 @@ impl GNmiService {

fn gen_update_proto(
&self,
dtree: DataTree,
dtree: DataTree<'static>,
_models: &[proto::ModelData],
) -> Vec<proto::Update> {
dtree
Expand Down Expand Up @@ -398,7 +398,7 @@ impl GNmiService {
.collect()
}

async fn get_running(&self) -> Result<DataTree, Status> {
async fn get_running(&self) -> Result<DataTree<'static>, Status> {
// Create oneshot channel to receive response back from the northbound.
let (responder_tx, responder_rx) = oneshot::channel();

Expand Down
12 changes: 8 additions & 4 deletions holo-daemon/src/northbound/client/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ fn get_timestamp() -> i64 {
}

fn data_tree_init(
dtree: &DataTree,
dtree: &DataTree<'static>,
encoding: proto::Encoding,
printer_flags: DataPrinterFlags,
) -> Result<proto::DataTree, Status> {
Expand Down Expand Up @@ -444,7 +444,9 @@ fn data_tree_init(
})
}

fn data_tree_get(data_tree: &proto::DataTree) -> Result<DataTree, Status> {
fn data_tree_get(
data_tree: &proto::DataTree,
) -> Result<DataTree<'static>, Status> {
let yang_ctx = YANG_CTX.get().unwrap();
let encoding = proto::Encoding::try_from(data_tree.encoding)
.map_err(|_| Status::invalid_argument("Invalid data encoding"))?;
Expand Down Expand Up @@ -474,7 +476,9 @@ fn data_tree_get(data_tree: &proto::DataTree) -> Result<DataTree, Status> {
.map_err(|error| Status::invalid_argument(error.to_string()))
}

fn data_diff_get(data_tree: &proto::DataTree) -> Result<DataDiff, Status> {
fn data_diff_get(
data_tree: &proto::DataTree,
) -> Result<DataDiff<'static>, Status> {
let yang_ctx = YANG_CTX.get().unwrap();
let encoding = proto::Encoding::try_from(data_tree.encoding)
.map_err(|_| Status::invalid_argument("Invalid data encoding"))?;
Expand Down Expand Up @@ -505,7 +509,7 @@ fn data_diff_get(data_tree: &proto::DataTree) -> Result<DataDiff, Status> {
.map_err(|error| Status::invalid_argument(error.to_string()))
}

fn rpc_get(data_tree: &proto::DataTree) -> Result<DataTree, Status> {
fn rpc_get(data_tree: &proto::DataTree) -> Result<DataTree<'static>, Status> {
let yang_ctx = YANG_CTX.get().unwrap();
let encoding = proto::Encoding::try_from(data_tree.encoding)
.map_err(|_| Status::invalid_argument("Invalid data encoding"))?;
Expand Down
30 changes: 18 additions & 12 deletions holo-daemon/src/northbound/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::northbound::{db, yang, Error, Result};

pub struct Northbound {
// YANG-modeled running configuration.
running_config: Arc<DataTree>,
running_config: Arc<DataTree<'static>>,

// Non-volatile storage.
db: Database,
Expand Down Expand Up @@ -72,7 +72,7 @@ pub struct Transaction {

// Configuration that was committed.
#[serde(with = "holo_yang::serde::data_tree")]
pub configuration: DataTree,
pub configuration: DataTree<'static>,
}

#[derive(Debug)]
Expand All @@ -87,7 +87,7 @@ pub struct ConfirmedCommit {

#[derive(Debug)]
pub struct Rollback {
configuration: DataTree,
configuration: DataTree<'static>,
#[allow(dead_code)]
timeout: TimeoutTask,
}
Expand Down Expand Up @@ -225,7 +225,7 @@ impl Northbound {
// Processes a `Validate` message received from an external client.
async fn process_client_validate(
&mut self,
candidate: DataTree,
candidate: DataTree<'static>,
) -> Result<capi::client::ValidateResponse> {
let candidate = Arc::new(candidate);

Expand Down Expand Up @@ -275,7 +275,7 @@ impl Northbound {
// Processes an `Execute` message received from an external client.
async fn process_client_execute(
&mut self,
data: DataTree,
data: DataTree<'static>,
) -> Result<capi::client::ExecuteResponse> {
let data = self.execute(data).await?;
Ok(capi::client::ExecuteResponse { data })
Expand Down Expand Up @@ -330,7 +330,7 @@ impl Northbound {
// fails to be validated, or if one or more resources fail to be allocated.
async fn create_transaction(
&mut self,
candidate: DataTree,
candidate: DataTree<'static>,
comment: String,
confirmed_timeout: u32,
) -> Result<u32> {
Expand Down Expand Up @@ -434,7 +434,7 @@ impl Northbound {
// Request all data providers to validate the candidate configuration.
async fn validate_notify(
&mut self,
candidate: &Arc<DataTree>,
candidate: &Arc<DataTree<'static>>,
) -> std::result::Result<(), northbound::error::Error> {
let mut handles = Vec::new();

Expand Down Expand Up @@ -470,7 +470,7 @@ impl Northbound {
async fn commit_phase_notify(
&mut self,
phase: CommitPhase,
candidate: &Arc<DataTree>,
candidate: &Arc<DataTree<'static>>,
changes: &[ConfigChange],
) -> std::result::Result<(), northbound::error::Error> {
// Spawn one task per data provider.
Expand Down Expand Up @@ -514,7 +514,10 @@ impl Northbound {
}

// Gets a full or partial copy of the running configuration.
fn get_configuration(&self, path: Option<&str>) -> Result<DataTree> {
fn get_configuration(
&self,
path: Option<&str>,
) -> Result<DataTree<'static>> {
match path {
Some(path) => {
let yang_ctx = YANG_CTX.get().unwrap();
Expand All @@ -538,7 +541,7 @@ impl Northbound {

// Gets dynamically generated operational data for the provided path. The
// request might span multiple data providers.
async fn get_state(&self, path: Option<&str>) -> Result<DataTree> {
async fn get_state(&self, path: Option<&str>) -> Result<DataTree<'static>> {
let yang_ctx = YANG_CTX.get().unwrap();
let mut dtree = DataTree::new(yang_ctx);

Expand All @@ -563,7 +566,10 @@ impl Northbound {
}

// Invoke a YANG RPC or Action.
async fn execute(&self, data: DataTree) -> Result<DataTree> {
async fn execute(
&self,
data: DataTree<'static>,
) -> Result<DataTree<'static>> {
let yang_ctx = YANG_CTX.get().unwrap();
let mut dtree = DataTree::new(yang_ctx);

Expand Down Expand Up @@ -591,7 +597,7 @@ impl Northbound {
// ===== impl ConfirmedCommit =====

impl ConfirmedCommit {
fn start(&mut self, configuration: DataTree, timeout: u32) {
fn start(&mut self, configuration: DataTree<'static>, timeout: u32) {
debug!(%timeout, "starting confirmed commit timeout");

let timeout = self.timeout_task(timeout);
Expand Down
2 changes: 1 addition & 1 deletion holo-northbound/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl<'a> StructBuilder<'a> {
// into_data_node() function implementation.
writeln!(
output,
"{}fn into_data_node(self: Box<Self>, dnode: &mut DataNodeRef<'_>) {{",
"{}fn into_data_node(self: Box<Self>, dnode: &mut DataNodeRef<'_, '_>) {{",
indent2
)
.unwrap();
Expand Down
14 changes: 7 additions & 7 deletions holo-northbound/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub mod daemon {
#[derive(Debug, Deserialize, Serialize)]
pub struct ValidateRequest {
#[serde(with = "holo_yang::serde::data_tree::arc")]
pub config: Arc<DataTree>,
pub config: Arc<DataTree<'static>>,
#[serde(skip)]
pub responder: Option<Responder<Result<ValidateResponse, Error>>>,
}
Expand All @@ -59,9 +59,9 @@ pub mod daemon {
pub struct CommitRequest {
pub phase: CommitPhase,
#[serde(with = "holo_yang::serde::data_tree::arc")]
pub old_config: Arc<DataTree>,
pub old_config: Arc<DataTree<'static>>,
#[serde(with = "holo_yang::serde::data_tree::arc")]
pub new_config: Arc<DataTree>,
pub new_config: Arc<DataTree<'static>>,
pub changes: ConfigChanges,
#[serde(skip)]
pub responder: Option<Responder<Result<CommitResponse, Error>>>,
Expand All @@ -79,20 +79,20 @@ pub mod daemon {

#[derive(Debug)]
pub struct GetResponse {
pub data: DataTree,
pub data: DataTree<'static>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct RpcRequest {
#[serde(with = "holo_yang::serde::data_tree")]
pub data: DataTree,
pub data: DataTree<'static>,
#[serde(skip)]
pub responder: Option<Responder<Result<RpcResponse, Error>>>,
}

#[derive(Debug)]
pub struct RpcResponse {
pub data: DataTree,
pub data: DataTree<'static>,
}
}

Expand All @@ -102,6 +102,6 @@ pub mod provider {

#[derive(Debug)]
pub struct Notification {
pub data: DataTree,
pub data: DataTree<'static>,
}
}
Loading

0 comments on commit 08dcc23

Please sign in to comment.