Skip to content

Commit

Permalink
chore(deps): update for control-interface v2.0.0
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Adossi <vadossi@cosmonic.com>
  • Loading branch information
vados-cosmonic committed Sep 26, 2024
1 parent fbf06f6 commit c78b259
Show file tree
Hide file tree
Showing 15 changed files with 480 additions and 412 deletions.
591 changes: 333 additions & 258 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ wadm-types = { workspace = true }

[workspace.dependencies]
anyhow = "1"
async-nats = "0.33"
async-nats = "0.36"
async-trait = "0.1"
base64 = "0.22.1"
bytes = "1"
Expand Down Expand Up @@ -86,7 +86,7 @@ uuid = "1"
wadm = { version = "0.15.0", path = "./crates/wadm" }
wadm-client = { version = "0.4.0", path = "./crates/wadm-client" }
wadm-types = { version = "0.4.0", path = "./crates/wadm-types" }
wasmcloud-control-interface = "1.0.0"
wasmcloud-control-interface = { version = "2.0.0", path = "/home/mrman/code/work/cosmonic/forks/wasmCloud/crates/control-interface" }
wasmcloud-secrets-types = "0.2.0"
wit-bindgen-wrpc = { version = "0.3.7", default-features = false }

Expand Down
8 changes: 4 additions & 4 deletions crates/wadm/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
};

use serde::{Deserialize, Serialize};
use wasmcloud_control_interface::InterfaceLinkDefinition;
use wasmcloud_control_interface::Link;

use crate::{
events::{ComponentScaleFailed, ComponentScaled, Event, ProviderStartFailed, ProviderStarted},
Expand Down Expand Up @@ -235,9 +235,9 @@ pub struct PutLink {
pub model_name: String,
}

impl From<PutLink> for InterfaceLinkDefinition {
fn from(value: PutLink) -> InterfaceLinkDefinition {
InterfaceLinkDefinition {
impl From<PutLink> for Link {
fn from(value: PutLink) -> Link {
Link {
source_id: value.source_id,
target: value.target,
name: value.name,
Expand Down
6 changes: 2 additions & 4 deletions crates/wadm/src/events/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use std::{
use cloudevents::{AttributesReader, Data, Event as CloudEvent, EventBuilder, EventBuilderV10};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use wasmcloud_control_interface::{
ComponentDescription, InterfaceLinkDefinition, ProviderDescription,
};
use wasmcloud_control_interface::{ComponentDescription, Link, ProviderDescription};

use wadm_types::Manifest;

Expand Down Expand Up @@ -424,7 +422,7 @@ event_impl!(
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct LinkdefSet {
#[serde(flatten)]
pub linkdef: InterfaceLinkDefinition,
pub linkdef: Link,
}

event_impl!(LinkdefSet, "com.wasmcloud.lattice.linkdef_set");
Expand Down
4 changes: 2 additions & 2 deletions crates/wadm/src/scaler/daemonscaler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ mod test {
use anyhow::Result;
use chrono::Utc;
use wadm_types::{api::StatusType, Spread, SpreadScalerProperty};
use wasmcloud_control_interface::{HostInventory, InterfaceLinkDefinition};
use wasmcloud_control_interface::{HostInventory, Link};

use crate::{
commands::Command,
Expand Down Expand Up @@ -957,7 +957,7 @@ mod test {
.is_empty());
assert!(blobby_daemonscaler
.handle_event(&Event::LinkdefSet(LinkdefSet {
linkdef: InterfaceLinkDefinition::default()
linkdef: Link::default()
}))
.await?
.is_empty());
Expand Down
21 changes: 12 additions & 9 deletions crates/wadm/src/scaler/spreadscaler/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,15 @@ where
(
true,
// TODO(#88): reverse compare too
// Ensure all named configs are the same
linkdef.source_config.iter().all(|config_name| {
self.config.source_config.iter().any(|c| c == config_name)
}) || linkdef.target_config.iter().all(|config_name| {
self.config.target_config.iter().any(|c| c == config_name)
}),
// Ensure all supplied configs (both source and target) are the same
linkdef
.source_config
.iter()
.eq(self.config.source_config.iter())
&& linkdef
.target_config
.iter()
.eq(self.config.target_config.iter()),
)
})
.unwrap_or((false, false));
Expand Down Expand Up @@ -275,7 +278,7 @@ mod test {
vec,
};

use wasmcloud_control_interface::InterfaceLinkDefinition;
use wasmcloud_control_interface::Link;

use chrono::Utc;

Expand Down Expand Up @@ -427,7 +430,7 @@ mod test {
let provider_ref = "provider_ref".to_string();
let provider_id = "provider".to_string();

let linkdef = InterfaceLinkDefinition {
let linkdef = Link {
source_id: component_id.to_string(),
target: provider_id.to_string(),
wit_namespace: "namespace".to_string(),
Expand Down Expand Up @@ -580,7 +583,7 @@ mod test {

let commands = link_scaler
.handle_event(&Event::LinkdefSet(LinkdefSet {
linkdef: InterfaceLinkDefinition {
linkdef: Link {
// NOTE: contract, link, and provider id matches but the component is different
source_id: "nm0001772".to_string(),
target: "VASDASD".to_string(),
Expand Down
4 changes: 2 additions & 2 deletions crates/wadm/src/scaler/spreadscaler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ mod test {
use anyhow::Result;
use chrono::Utc;
use wadm_types::{Spread, SpreadScalerProperty};
use wasmcloud_control_interface::InterfaceLinkDefinition;
use wasmcloud_control_interface::Link;

use crate::{
commands::Command,
Expand Down Expand Up @@ -1499,7 +1499,7 @@ mod test {
.is_empty());
assert!(blobby_spreadscaler
.handle_event(&Event::LinkdefSet(LinkdefSet {
linkdef: InterfaceLinkDefinition::default()
linkdef: Link::default()
}))
.await?
.is_empty());
Expand Down
6 changes: 3 additions & 3 deletions crates/wadm/src/storage/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;

use tokio::sync::RwLock;
use tracing::debug;
use wasmcloud_control_interface::InterfaceLinkDefinition;
use wasmcloud_control_interface::Link;
use wasmcloud_secrets_types::SecretConfig;

use crate::storage::{Component, Host, Provider, ReadStore, StateKind};
Expand All @@ -28,7 +28,7 @@ pub struct SnapshotStore<S, L> {
lattice_source: L,
lattice_id: String,
stored_state: Arc<RwLock<InMemoryData>>,
links: Arc<RwLock<Vec<InterfaceLinkDefinition>>>,
links: Arc<RwLock<Vec<Link>>>,
}

impl<S, L> Clone for SnapshotStore<S, L>
Expand Down Expand Up @@ -165,7 +165,7 @@ where
S: Send + Sync,
L: Send + Sync,
{
async fn get_links(&self) -> anyhow::Result<Vec<InterfaceLinkDefinition>> {
async fn get_links(&self) -> anyhow::Result<Vec<Link>> {
Ok(self.links.read().await.clone())
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/wadm/src/storage/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ impl From<HostHeartbeat> for Host {
.into_iter()
.map(|component| {
(
component.id, // SAFETY: Unlikely to not fit into a usize, but fallback just in case
component.max_instances.try_into().unwrap_or(usize::MAX),
component.id().into(), // SAFETY: Unlikely to not fit into a usize, but fallback just in case
component.max_instances().try_into().unwrap_or(usize::MAX),
)
})
.collect();
Expand Down Expand Up @@ -326,9 +326,9 @@ impl From<&HostHeartbeat> for Host {
.iter()
.map(|component| {
(
component.id.to_owned(),
component.id().to_owned(),
// SAFETY: Unlikely to not fit into a usize, but fallback just in case
component.max_instances.try_into().unwrap_or(usize::MAX),
component.max_instances().try_into().unwrap_or(usize::MAX),
)
})
.collect();
Expand Down
6 changes: 3 additions & 3 deletions crates/wadm/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{collections::HashMap, sync::Arc};

use serde::{de::DeserializeOwned, Serialize};
use tokio::sync::RwLock;
use wasmcloud_control_interface::{HostInventory, InterfaceLinkDefinition};
use wasmcloud_control_interface::{HostInventory, Link};
use wasmcloud_secrets_types::SecretConfig;

use crate::publisher::Publisher;
Expand Down Expand Up @@ -111,7 +111,7 @@ impl crate::storage::Store for TestStore {
pub struct TestLatticeSource {
pub claims: HashMap<String, Claims>,
pub inventory: Arc<RwLock<HashMap<String, HostInventory>>>,
pub links: Vec<InterfaceLinkDefinition>,
pub links: Vec<Link>,
pub config: HashMap<String, HashMap<String, String>>,
}

Expand All @@ -131,7 +131,7 @@ impl InventorySource for TestLatticeSource {

#[async_trait::async_trait]
impl LinkSource for TestLatticeSource {
async fn get_links(&self) -> anyhow::Result<Vec<InterfaceLinkDefinition>> {
async fn get_links(&self) -> anyhow::Result<Vec<Link>> {
Ok(self.links.clone())
}
}
Expand Down
6 changes: 4 additions & 2 deletions crates/wadm/src/workers/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ impl Worker for CommandWorker {
.map_err(|e| anyhow::anyhow!("{e:?}"));

match res {
Ok(ack) if !ack.success => {
Ok(ack) if !ack.succeeded() => {
message.nack().await;
Err(WorkError::Other(anyhow::anyhow!("{}", ack.message).into()))
Err(WorkError::Other(
anyhow::anyhow!("{}", ack.message()).into(),
))
}
Ok(_) => message.ack().await.map_err(WorkError::from),
Err(e) => {
Expand Down
41 changes: 22 additions & 19 deletions crates/wadm/src/workers/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,46 +495,49 @@ where
.into_iter()
.map(|component_description| {
let instance = HashSet::from_iter([WadmComponentInfo {
count: component_description.max_instances as usize,
count: component_description.max_instances() as usize,
annotations: component_description
.annotations
.map(|a| a.into_iter().collect())
.annotations()
.map(|a| a.clone())
.unwrap_or_default(),
}]);
if let Some(component) = components.get(&component_description.id) {
if let Some(component) = components.get(component_description.id()) {
// Construct modified Component with new instances included
let mut new_instances = component.instances.clone();
new_instances.insert(host_id.to_owned(), instance);
let component = Component {
instances: new_instances,
reference: component_description.image_ref,
name: component_description.name.unwrap_or(component.name.clone()),
reference: component_description.image_ref().into(),
name: component_description
.name()
.unwrap_or(&component.name)
.into(),
..component.clone()
};

(component_description.id, component)
} else if let Some(claim) = claims.get(&component_description.id) {
(component_description.id().to_string(), component)
} else if let Some(claim) = claims.get(component_description.id()) {
(
component_description.id.clone(),
component_description.id().to_string(),
Component {
id: component_description.id,
id: component_description.id().into(),
name: claim.name.to_owned(),
issuer: claim.issuer.to_owned(),
instances: HashMap::from_iter([(host_id.to_owned(), instance)]),
reference: component_description.image_ref,
reference: component_description.image_ref().into(),
},
)
} else {
debug!("Claims not found for component on host, component is unsigned");

(
component_description.id.clone(),
component_description.id().to_string(),
Component {
id: component_description.id,
id: component_description.id().into(),
name: "".to_owned(),
issuer: "".to_owned(),
instances: HashMap::from_iter([(host_id.to_owned(), instance)]),
reference: component_description.image_ref,
reference: component_description.image_ref().into(),
},
)
}
Expand All @@ -558,12 +561,12 @@ where
.iter()
.filter_map(|component_description| {
if components
.get(&component_description.id)
.get(component_description.id())
// NOTE(brooksmtownsend): This code maps the component to a boolean indicating if it's up-to-date with the heartbeat or not.
// If the component matches what the heartbeat says, we return None, otherwise we return Some(component_description).
.map(|component| {
// If the stored reference isn't what we receive on the heartbeat, update
component_description.image_ref == component.reference
component_description.image_ref() == component.reference
&& component
.instances
.get(&host.host_id)
Expand All @@ -575,14 +578,14 @@ where
// Update if annotations or counts are different
let annotations: BTreeMap<String, String> =
component_description
.annotations
.clone()
.annotations()
.cloned()
.map(|a| a.into_iter().collect())
.unwrap_or_default();
store_instances.get(&annotations).map_or(
false,
|store_instance| {
component_description.max_instances as usize
component_description.max_instances() as usize
== store_instance.count
},
)
Expand Down
Loading

0 comments on commit c78b259

Please sign in to comment.