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

Implement subscribe_id and id i32 to EntryUpdate #6

Open
wants to merge 1 commit into
base: rel-0.5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
57 changes: 57 additions & 0 deletions databroker/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub use crate::types::{ChangeType, DataType, DataValue, EntryType, ValueFailure}
use tokio::sync::{broadcast, mpsc, RwLock};
use tokio_stream::wrappers::ReceiverStream;
use tokio_stream::Stream;
use tonic::{Code, Status};

use std::collections::{HashMap, HashSet};
use std::convert::TryFrom;
Expand All @@ -43,6 +44,36 @@ pub enum UpdateError {
PermissionExpired,
}

impl UpdateError {
pub fn to_status_with_code(&self, id: &i32) -> Status {
match self {
UpdateError::NotFound => {
Status::new(Code::NotFound, format!("Signal not found (id: {})", id))
}
UpdateError::WrongType => Status::new(
Code::InvalidArgument,
format!("Wrong type provided (id: {})", id),
),
UpdateError::OutOfBounds => Status::new(
Code::OutOfRange,
format!("Index out of bounds (id: {})", id),
),
UpdateError::UnsupportedType => Status::new(
Code::Unimplemented,
format!("Unsupported type (id: {})", id),
),
UpdateError::PermissionDenied => Status::new(
Code::PermissionDenied,
format!("Permission denied (id: {})", id),
),
UpdateError::PermissionExpired => Status::new(
Code::Unauthenticated,
format!("Permission expired (id: {})", id),
),
}
}
}

#[derive(Debug, Clone)]
pub enum ReadError {
NotFound,
Expand Down Expand Up @@ -165,6 +196,8 @@ pub struct NotificationError {}

#[derive(Debug, Clone, Default)]
pub struct EntryUpdate {
pub id: Option<i32>,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion EntryUpdate should have one of ìd or path other one could be get by some functions. Does not make sense to save both.


pub path: Option<String>,

pub datapoint: Option<Datapoint>,
Expand Down Expand Up @@ -1762,6 +1795,7 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: time1,
Expand Down Expand Up @@ -1794,6 +1828,7 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: time1,
Expand All @@ -1816,6 +1851,7 @@ mod tests {
.update_entries([(
id2,
EntryUpdate {
id: Some(id2),
path: None,
datapoint: None,
actuator_target: Some(Some(Datapoint {
Expand Down Expand Up @@ -1888,6 +1924,7 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand All @@ -1914,6 +1951,7 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: None,
actuator_target: None,
Expand All @@ -1936,6 +1974,7 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: None,
actuator_target: None,
Expand All @@ -1955,6 +1994,7 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: time1,
Expand Down Expand Up @@ -2026,6 +2066,7 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand Down Expand Up @@ -2128,6 +2169,7 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand Down Expand Up @@ -2211,6 +2253,7 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand Down Expand Up @@ -2270,6 +2313,7 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand Down Expand Up @@ -2368,6 +2412,7 @@ mod tests {
(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand All @@ -2385,6 +2430,7 @@ mod tests {
(
id2,
EntryUpdate {
id: Some(id2),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand Down Expand Up @@ -2448,6 +2494,7 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -2513,6 +2560,7 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -2593,6 +2641,7 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -2649,6 +2698,7 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -2704,6 +2754,7 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -2756,6 +2807,7 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -2785,6 +2837,7 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -2842,6 +2895,7 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -2871,6 +2925,7 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -2931,6 +2986,7 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -3018,6 +3074,7 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand Down
1 change: 1 addition & 0 deletions databroker/src/grpc/kuksa_val_v1/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ impl broker::EntryUpdate {
None
};
Self {
id: None,
path: None,
datapoint,
actuator_target,
Expand Down
Loading
Loading