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

Move config_update file download from tedge-mapper-c8y to tedge-agent #2511

Merged
merged 2 commits into from
Dec 15, 2023
Merged
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
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.

Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ define_tedge_config! {
#[doku(as = "PathBuf")]
key_path: Utf8PathBuf,

/// Path to a file containing the PEM encoded CA certificates that are
/// Path to a directory containing the PEM encoded CA certificates that are
/// trusted when checking incoming client certificates for the File Transfer Service
#[tedge_config(example = "/etc/ssl/certs")]
#[doku(as = "PathBuf")]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/c8y_api/src/http_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub enum C8yEndPointError {
}

/// Define a C8y endpoint
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct C8yEndPoint {
c8y_host: String,
pub device_id: String,
Expand Down
1 change: 1 addition & 0 deletions crates/core/tedge_agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ reqwest = { workspace = true }
rustls = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sha256 = { workspace = true }
tedge_actors = { workspace = true }
tedge_api = { workspace = true }
tedge_config = { workspace = true }
Expand Down
50 changes: 33 additions & 17 deletions crates/core/tedge_agent/src/agent.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::file_transfer_server::actor::FileTransferServerBuilder;
use crate::file_transfer_server::actor::FileTransferServerConfig;
use crate::operation_file_cache::FileCacheActorBuilder;
use crate::restart_manager::builder::RestartManagerBuilder;
use crate::restart_manager::config::RestartManagerConfig;
use crate::software_manager::builder::SoftwareManagerBuilder;
Expand Down Expand Up @@ -75,6 +76,7 @@ pub(crate) struct AgentConfig {
pub mqtt_topic_root: Arc<str>,
pub service_type: String,
pub identity: Option<Identity>,
pub fts_url: Arc<str>,
pub is_sudo_enabled: bool,
pub capabilities: Capabilities,
}
Expand Down Expand Up @@ -145,6 +147,11 @@ impl AgentConfig {
config_snapshot: tedge_config.agent.enable.config_snapshot,
log_upload: tedge_config.agent.enable.log_upload,
};
let fts_url = format!(
"{}:{}",
tedge_config.http.client.host, tedge_config.http.client.port
)
.into();

Ok(Self {
mqtt_config,
Expand All @@ -162,6 +169,7 @@ impl AgentConfig {
mqtt_device_topic_id,
service_type: tedge_config.service.ty.clone(),
identity,
fts_url,
is_sudo_enabled,
capabilities,
})
Expand Down Expand Up @@ -295,7 +303,7 @@ impl Agent {
let log_manager_config = LogManagerConfig::from_options(LogManagerOptions {
config_dir: self.config.config_dir.clone().into(),
tmp_dir: self.config.config_dir.into(),
mqtt_schema,
mqtt_schema: mqtt_schema.clone(),
mqtt_device_topic_id: self.config.mqtt_device_topic_id.clone(),
})?;
Some(
Expand All @@ -311,6 +319,30 @@ impl Agent {
None
};

// TODO: replace with a call to entity store when we stop assuming default MQTT schema
let is_main_device =
self.config.mqtt_device_topic_id == EntityTopicId::default_main_device();
if is_main_device {
info!("Running as a main device, starting tedge_to_te_converter and File Transfer Service");

runtime.spawn(tedge_to_te_converter).await?;

let file_transfer_server_builder =
FileTransferServerBuilder::try_bind(self.config.http_config).await?;
runtime.spawn(file_transfer_server_builder).await?;

let operation_file_cache_builder = FileCacheActorBuilder::new(
mqtt_schema,
self.config.fts_url.clone(),
self.config.data_dir,
&mut downloader_actor_builder,
&mut mqtt_actor_builder,
);
runtime.spawn(operation_file_cache_builder).await?;
} else {
info!("Running as a child device, tedge_to_te_converter and File Transfer Service disabled");
}

// Spawn all
runtime.spawn(signal_actor_builder).await?;
runtime.spawn(mqtt_actor_builder).await?;
Expand All @@ -329,22 +361,6 @@ impl Agent {
runtime.spawn(converter_actor_builder).await?;
runtime.spawn(health_actor).await?;

// TODO: replace with a call to entity store when we stop assuming default MQTT schema
let is_main_device =
self.config.mqtt_device_topic_id == EntityTopicId::default_main_device();
if is_main_device {
info!(
"Running as a main device, starting tedge_to_te_converter and file transfer actors"
);

let file_transfer_server_builder =
FileTransferServerBuilder::try_bind(self.config.http_config).await?;
runtime.spawn(tedge_to_te_converter).await?;
runtime.spawn(file_transfer_server_builder).await?;
} else {
info!("Running as a child device, tedge_to_te_converter and file transfer actors disabled");
}

runtime.run_to_completion().await?;

Ok(())
Expand Down
1 change: 1 addition & 0 deletions crates/core/tedge_agent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use tracing::log::warn;

mod agent;
mod file_transfer_server;
mod operation_file_cache;
mod restart_manager;
mod software_manager;
mod state_repository;
Expand Down
Loading