Skip to content

Commit

Permalink
Merge pull request #15 from drogue-iot/add-progress-update
Browse files Browse the repository at this point in the history
Add update progress to firmware stores
  • Loading branch information
Ulf Lilleengen authored Sep 30, 2022
2 parents 52a53a0 + 71b4033 commit b8fc0f3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 10 deletions.
10 changes: 10 additions & 0 deletions server/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ impl FirmwareStore for FileClient {
Ok(((), Some(f.try_into()?)))
}

async fn update_progress(
&mut self,
_: &Self::Params,
_: &Self::Context,
_: u32,
_: u32,
) -> Result<(), anyhow::Error> {
Ok(())
}

async fn mark_synced(
&mut self,
_: &Self::Params,
Expand Down
44 changes: 34 additions & 10 deletions server/src/hawkbit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl HawkbitClient {
&self,
controller: &str,
deployment: &Deployment,
success: bool,
status: serde_json::Value,
) -> Result<(), anyhow::Error> {
let client = reqwest::Client::new();
let url = format!(
Expand All @@ -99,14 +99,7 @@ impl HawkbitClient {
let feedback = json! {
{
"id": deployment.id,
"status": {
"result": {
"finished": if success { "success" } else { "failed" },
},
"execution": "closed",
"details": ["Update was successfully installed."],
}

"status": status,
}
};

Expand Down Expand Up @@ -221,14 +214,45 @@ impl FirmwareStore for HawkbitClient {
}
}

async fn update_progress(
&mut self,
params: &Self::Params,
context: &Self::Context,
offset: u32,
size: u32,
) -> Result<(), anyhow::Error> {
if let PollResult::Deployment(d) = context {
let status = json!({
"result": {
"progress": {
"of": size,
"cnt": offset,
},
"finished": "none",
},
"execution": "proceeding",
"details": ["Updating..."],
});
self.provide_feedback(params, d, status).await?;
}
Ok(())
}

async fn mark_synced(
&mut self,
params: &Self::Params,
context: &Self::Context,
success: bool,
) -> Result<(), anyhow::Error> {
if let PollResult::Deployment(d) = context {
self.provide_feedback(params, d, success).await?;
let status = json!({
"result": {
"finished": if success { "success" } else { "failed" },
},
"execution": "closed",
"details": ["Update was successfully installed."],
});
self.provide_feedback(params, d, status).await?;
}
Ok(())
}
Expand Down
10 changes: 10 additions & 0 deletions server/src/oci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ impl FirmwareStore for OciClient {
Ok(((), m))
}

async fn update_progress(
&mut self,
_: &Self::Params,
_: &Self::Context,
_: u32,
_: u32,
) -> Result<(), anyhow::Error> {
Ok(())
}

type Context = ();
async fn fetch_firmware(
&mut self,
Expand Down
12 changes: 12 additions & 0 deletions server/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ impl Updater {
);
}

let _ = store
.update_progress(params, &ctx, offset as u32, metadata.size)
.await;

if offset < metadata.size as usize {
let firmware = store.fetch_firmware(params, &ctx, &metadata).await?;

Expand Down Expand Up @@ -235,6 +239,14 @@ pub trait FirmwareStore {
None
}

async fn update_progress(
&mut self,
params: &Self::Params,
context: &Self::Context,
offset: u32,
size: u32,
) -> Result<(), anyhow::Error>;

async fn mark_synced(
&mut self,
params: &Self::Params,
Expand Down

0 comments on commit b8fc0f3

Please sign in to comment.