Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
wilyle committed Jan 9, 2024
1 parent 9bdcfa1 commit a7a146f
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 57 deletions.
2 changes: 1 addition & 1 deletion common/src/http_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ macro_rules! server_error {
($body:expr) => {
freyja_common::response!(INTERNAL_SERVER_ERROR, $body)
};
}
}
7 changes: 5 additions & 2 deletions common/src/provider_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use std::{fmt::Debug, sync::Arc};
use async_trait::async_trait;
use strum_macros::Display;

use crate::{entity::{Entity, EntityEndpoint}, signal_store::SignalStore};
use crate::{
entity::{Entity, EntityEndpoint},
signal_store::SignalStore,
};

/// Represents a signal value
pub struct SignalValue {
Expand Down Expand Up @@ -37,7 +40,7 @@ pub trait ProviderProxy {
/// - `signal_store`: the shared signal store
fn create_new(
provider_uri: &str,
signals: Arc<SignalStore>
signals: Arc<SignalStore>,
) -> Result<Self, ProviderProxyError>
where
Self: Sized;
Expand Down
2 changes: 1 addition & 1 deletion mocks/mock_digital_twin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use tokio::sync::{mpsc, mpsc::UnboundedSender};
use crate::config::{Config, EntityConfig};
use freyja_build_common::config_file_stem;
use freyja_common::digital_twin_adapter::FindByIdResponse;
use freyja_common::{config_utils, out_dir, not_found, ok, server_error};
use freyja_common::{config_utils, not_found, ok, out_dir, server_error};
use http_mock_provider_proxy::http_mock_provider_proxy::{EntityValueRequest, EntityValueResponse};
use mock_digital_twin::{ENTITY_GET_VALUE_PATH, ENTITY_PATH, ENTITY_SUBSCRIBE_PATH};

Expand Down
9 changes: 6 additions & 3 deletions mocks/mock_mapping_service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ use log::{info, LevelFilter};

use config::Config;
use freyja_build_common::config_file_stem;
use freyja_common::{mapping_client::{
CheckForWorkResponse, GetMappingResponse, SendInventoryRequest, SendInventoryResponse,
}, ok};
use freyja_common::{
cmd_utils::{get_log_level, parse_args},
config_utils, out_dir,
};
use freyja_common::{
mapping_client::{
CheckForWorkResponse, GetMappingResponse, SendInventoryRequest, SendInventoryResponse,
},
ok,
};

struct MappingState {
count: u8,
Expand Down
3 changes: 2 additions & 1 deletion provider_proxies/grpc/v1/src/grpc_client_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ impl DigitalTwinConsumer for GRPCClientImpl {

let value = message_utils::parse_value(value);

self.signals.set_value(entity_id.clone(), value)
self.signals
.set_value(entity_id.clone(), value)
.map(|_| Response::new(PublishResponse {}))
.ok_or(Status::not_found(format!("Entity {entity_id} not found")))
}
Expand Down
5 changes: 1 addition & 4 deletions provider_proxies/grpc/v1/src/grpc_provider_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ impl ProviderProxy for GRPCProviderProxy {
/// # Arguments
/// - `provider_uri`: the provider uri for accessing an entity's information
/// - `signals`: The shared signal store
fn create_new(
provider_uri: &str,
signals: Arc<SignalStore>,
) -> Result<Self, ProviderProxyError>
fn create_new(provider_uri: &str, signals: Arc<SignalStore>) -> Result<Self, ProviderProxyError>
where
Self: Sized,
{
Expand Down
3 changes: 2 additions & 1 deletion provider_proxies/grpc/v1/src/grpc_provider_proxy_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use std::sync::Arc;

use freyja_common::{
entity::{Entity, EntityEndpoint},
provider_proxy::{ProviderProxy, ProviderProxyError, ProviderProxyFactory}, signal_store::SignalStore,
provider_proxy::{ProviderProxy, ProviderProxyError, ProviderProxyFactory},
signal_store::SignalStore,
};

use crate::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

use std::{collections::HashMap, net::SocketAddr, str::FromStr, sync::{Arc, Mutex}};
use std::{
collections::HashMap,
net::SocketAddr,
str::FromStr,
sync::{Arc, Mutex},
};

use async_trait::async_trait;
use axum::{
Expand All @@ -20,11 +25,11 @@ use freyja_build_common::config_file_stem;
use freyja_common::{
config_utils,
entity::EntityEndpoint,
out_dir,
not_found, ok, out_dir,
provider_proxy::{
EntityRegistration, ProviderProxy, ProviderProxyError, ProviderProxyErrorKind,
},
signal_store::SignalStore, ok, not_found
signal_store::SignalStore,
};

const CALLBACK_FOR_VALUES_PATH: &str = "/value";
Expand Down Expand Up @@ -114,10 +119,7 @@ impl ProviderProxy for HttpMockProviderProxy {
/// # Arguments
/// - `provider_uri`: the provider uri for accessing an entity's information
/// - `signal_values_queue`: shared queue for all proxies to push new signal values of entities
fn create_new(
provider_uri: &str,
signals: Arc<SignalStore>,
) -> Result<Self, ProviderProxyError>
fn create_new(provider_uri: &str, signals: Arc<SignalStore>) -> Result<Self, ProviderProxyError>
where
Self: Sized,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ impl InMemoryMockProviderProxy {
let value = entity_config.values.get_nth(n).to_string();
let entity_id = String::from(entity_id);

signals.set_value(entity_id, value).map(|_| ()).ok_or(ProviderProxyErrorKind::EntityNotFound.into())
signals
.set_value(entity_id, value)
.map(|_| ())
.ok_or(ProviderProxyErrorKind::EntityNotFound.into())
}
}

Expand Down Expand Up @@ -139,7 +142,8 @@ impl ProviderProxy for InMemoryMockProviderProxy {
{
let data = data.lock().await;
for entity_id in entities_with_subscribe {
if Self::generate_signal_value(&entity_id, signals.clone(), &data).is_err() {
if Self::generate_signal_value(&entity_id, signals.clone(), &data).is_err()
{
warn!("Attempt to set value for non-existent entity {entity_id}");
}
}
Expand Down Expand Up @@ -277,20 +281,23 @@ mod in_memory_mock_digital_twin_adapter_tests {
};

let signals = Arc::new(SignalStore::new());
signals.add([
SignalPatch {
id: STATIC_ID.to_owned(),
..Default::default()
},
SignalPatch {
id: INCREASING_ID.to_owned(),
..Default::default()
},
SignalPatch {
id: DECREASING_ID.to_owned(),
..Default::default()
},
].into_iter());
signals.add(
[
SignalPatch {
id: STATIC_ID.to_owned(),
..Default::default()
},
SignalPatch {
id: INCREASING_ID.to_owned(),
..Default::default()
},
SignalPatch {
id: DECREASING_ID.to_owned(),
..Default::default()
},
]
.into_iter(),
);
let in_memory_mock_provider_proxy =
InMemoryMockProviderProxy::from_config(config, signals.clone()).unwrap();

Expand All @@ -300,11 +307,8 @@ mod in_memory_mock_digital_twin_adapter_tests {
// entity that has the stepwise functionality configured.
let data = in_memory_mock_provider_proxy.data.lock().await;
for i in 0..END_OF_SENSOR_VALUE_CONFIG_ITERATION {
let result = InMemoryMockProviderProxy::generate_signal_value(
STATIC_ID,
signals.clone(),
&data,
);
let result =
InMemoryMockProviderProxy::generate_signal_value(STATIC_ID, signals.clone(), &data);
assert!(result.is_ok());

validate_signal(signals.clone(), STATIC_ID, 42.0);
Expand All @@ -330,13 +334,10 @@ mod in_memory_mock_digital_twin_adapter_tests {

// Validating each entity that has the stepwise functionality configured is at its end value
for _ in 0..END_OF_SENSOR_VALUE_CONFIG_ITERATION {
let result = InMemoryMockProviderProxy::generate_signal_value(
STATIC_ID,
signals.clone(),
&data,
);
let result =
InMemoryMockProviderProxy::generate_signal_value(STATIC_ID, signals.clone(), &data);
assert!(result.is_ok());

validate_signal(signals.clone(), STATIC_ID, 42.0);

let result = InMemoryMockProviderProxy::generate_signal_value(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use std::sync::Arc;

use freyja_common::{
entity::{Entity, EntityEndpoint},
provider_proxy::{ProviderProxy, ProviderProxyError, ProviderProxyFactory}, signal_store::SignalStore,
provider_proxy::{ProviderProxy, ProviderProxyError, ProviderProxyFactory},
signal_store::SignalStore,
};

use crate::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use std::sync::Arc;

use freyja_common::{
entity::{Entity, EntityEndpoint},
provider_proxy::{ProviderProxy, ProviderProxyError, ProviderProxyFactory}, signal_store::SignalStore,
provider_proxy::{ProviderProxy, ProviderProxyError, ProviderProxyFactory},
signal_store::SignalStore,
};

use crate::{
Expand Down
8 changes: 2 additions & 6 deletions provider_proxies/mqtt/src/mqtt_provider_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use freyja_build_common::config_file_stem;
use freyja_common::{
config_utils,
entity::EntityEndpoint,
message_utils,
out_dir,
message_utils, out_dir,
provider_proxy::{
EntityRegistration, ProviderProxy, ProviderProxyError, ProviderProxyErrorKind,
},
Expand Down Expand Up @@ -49,10 +48,7 @@ impl ProviderProxy for MqttProviderProxy {
/// # Arguments
/// - `provider_uri`: the provider uri for accessing an entity's information
/// - `signals`: The shared signal store
fn create_new(
provider_uri: &str,
signals: Arc<SignalStore>,
) -> Result<Self, ProviderProxyError>
fn create_new(provider_uri: &str, signals: Arc<SignalStore>) -> Result<Self, ProviderProxyError>
where
Self: Sized,
{
Expand Down
3 changes: 2 additions & 1 deletion provider_proxies/mqtt/src/mqtt_provider_proxy_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use std::sync::Arc;

use freyja_common::{
entity::{Entity, EntityEndpoint},
provider_proxy::{ProviderProxy, ProviderProxyError, ProviderProxyFactory}, signal_store::SignalStore,
provider_proxy::{ProviderProxy, ProviderProxyError, ProviderProxyFactory},
signal_store::SignalStore,
};

use crate::{mqtt_provider_proxy::MqttProviderProxy, MQTT_PROTOCOL, SUBSCRIBE_OPERATION};
Expand Down
3 changes: 2 additions & 1 deletion provider_proxy_selector/src/provider_proxy_selector_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use freyja_common::{
provider_proxy::{EntityRegistration, ProviderProxy, ProviderProxyFactory},
provider_proxy_selector::{
ProviderProxySelector, ProviderProxySelectorError, ProviderProxySelectorErrorKind,
}, signal_store::SignalStore,
},
signal_store::SignalStore,
};

use crate::PROXY_SELECTOR_LOOPBACK_MAX;
Expand Down

0 comments on commit a7a146f

Please sign in to comment.