Struct wasmcloud_control_interface::Client
source · pub struct Client<T: Clone + Debug> {
pub lattice_prefix: String,
/* private fields */
}
Expand description
Lattice control interface client
Fields§
§lattice_prefix: String
Implementations§
source§impl<T: KvStore + Clone + Debug + Send + Sync> Client<T>
impl<T: KvStore + Clone + Debug + Send + Sync> Client<T>
sourcepub fn lattice_metadata_client(&self) -> &T
pub fn lattice_metadata_client(&self) -> &T
Returns a handle to the underlying metadata client for use in advanced scenarios and queries
sourcepub async fn get_hosts(&self) -> Result<Vec<Host>, Box<dyn Error + Send + Sync>>
pub async fn get_hosts(&self) -> Result<Vec<Host>, Box<dyn Error + Send + Sync>>
Queries the lattice for all responsive hosts, waiting for the full period specified by timeout.
sourcepub async fn get_host_inventory(
&self,
host_id: &str
) -> Result<HostInventory, Box<dyn Error + Send + Sync>>
pub async fn get_host_inventory( &self, host_id: &str ) -> Result<HostInventory, Box<dyn Error + Send + Sync>>
Retrieves the contents of a running host
sourcepub async fn get_claims(
&self
) -> Result<Vec<HashMap<String, String>>, Box<dyn Error + Send + Sync>>
pub async fn get_claims( &self ) -> Result<Vec<HashMap<String, String>>, Box<dyn Error + Send + Sync>>
Retrieves the full set of all cached claims in the lattice.
sourcepub async fn perform_actor_auction(
&self,
actor_ref: &str,
constraints: HashMap<String, String>
) -> Result<Vec<ActorAuctionAck>, Box<dyn Error + Send + Sync>>
pub async fn perform_actor_auction( &self, actor_ref: &str, constraints: HashMap<String, String> ) -> Result<Vec<ActorAuctionAck>, Box<dyn Error + Send + Sync>>
Performs an actor auction within the lattice, publishing a set of constraints and the metadata for the actor in question. This will always wait for the full period specified by duration, and then return the set of gathered results. It is then up to the client to choose from among the “auction winners” to issue the appropriate command to start an actor. Clients cannot assume that auctions will always return at least one result.
sourcepub async fn perform_provider_auction(
&self,
provider_ref: &str,
link_name: &str,
constraints: HashMap<String, String>
) -> Result<Vec<ProviderAuctionAck>, Box<dyn Error + Send + Sync>>
pub async fn perform_provider_auction( &self, provider_ref: &str, link_name: &str, constraints: HashMap<String, String> ) -> Result<Vec<ProviderAuctionAck>, Box<dyn Error + Send + Sync>>
Performs a provider auction within the lattice, publishing a set of constraints and the metadata for the provider in question. This will always wait for the full period specified by duration, and then return the set of gathered results. It is then up to the client to choose from among the “auction winners” and issue the appropriate command to start a provider. Clients cannot assume that auctions will always return at least one result.
sourcepub async fn start_actor(
&self,
host_id: &str,
actor_ref: &str,
count: u16,
annotations: Option<HashMap<String, String>>
) -> Result<CtlOperationAck, Box<dyn Error + Send + Sync>>
pub async fn start_actor( &self, host_id: &str, actor_ref: &str, count: u16, annotations: Option<HashMap<String, String>> ) -> Result<CtlOperationAck, Box<dyn Error + Send + Sync>>
Sends a request to the given host to start a given actor by its OCI reference. This returns an acknowledgement of receipt of the command, not a confirmation that the actor started. An acknowledgement will either indicate some form of validation failure, or, if no failure occurs, the receipt of the command. To avoid blocking consumers, wasmCloud hosts will acknowledge the start actor command prior to fetching the actor’s OCI bytes. If a client needs deterministic results as to whether the actor completed its startup process, the client will have to monitor the appropriate event in the control event stream
sourcepub async fn scale_actor(
&self,
host_id: &str,
actor_ref: &str,
actor_id: &str,
count: u16,
annotations: Option<HashMap<String, String>>
) -> Result<CtlOperationAck, Box<dyn Error + Send + Sync>>
pub async fn scale_actor( &self, host_id: &str, actor_ref: &str, actor_id: &str, count: u16, annotations: Option<HashMap<String, String>> ) -> Result<CtlOperationAck, Box<dyn Error + Send + Sync>>
Sends a request to the given host to scale a given actor. This returns an acknowledgement of receipt of the command, not a confirmation that the actor scaled. An acknowledgement will either indicate some form of validation failure, or, if no failure occurs, the receipt of the command. To avoid blocking consumers, wasmCloud hosts will acknowledge the scale actor command prior to fetching the actor’s OCI bytes. If a client needs deterministic results as to whether the actor completed its startup process, the client will have to monitor the appropriate event in the control event stream
sourcepub async fn put_registries(
&self,
registries: RegistryCredentialMap
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn put_registries( &self, registries: RegistryCredentialMap ) -> Result<(), Box<dyn Error + Send + Sync>>
Publishes a registry credential map to the control interface of the lattice. All hosts will be listening and all will overwrite their registry credential map with the new information. It is highly recommended you use TLS connections with NATS and isolate the control interface credentials when using this function in production as the data contains secrets
sourcepub async fn advertise_link(
&self,
actor_id: &str,
provider_id: &str,
contract_id: &str,
link_name: &str,
values: HashMap<String, String>
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn advertise_link( &self, actor_id: &str, provider_id: &str, contract_id: &str, link_name: &str, values: HashMap<String, String> ) -> Result<(), Box<dyn Error + Send + Sync>>
Puts a link into the lattice metadata keyvalue bucket. Returns an error if it was unable to put the link
sourcepub async fn remove_link(
&self,
actor_id: &str,
contract_id: &str,
link_name: &str
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn remove_link( &self, actor_id: &str, contract_id: &str, link_name: &str ) -> Result<(), Box<dyn Error + Send + Sync>>
Removes a link from the lattice metadata keyvalue bucket. Returns an error if it was unable to delete. This is an idempotent operation.
sourcepub async fn query_links(
&self
) -> Result<Vec<LinkDefinition>, Box<dyn Error + Send + Sync>>
pub async fn query_links( &self ) -> Result<Vec<LinkDefinition>, Box<dyn Error + Send + Sync>>
Retrieves the list of link definitions stored in the lattice metadata key-value bucket. If the client was created with caching, this will return the cached list of links. Otherwise, it will query the bucket for the list of links.
sourcepub async fn update_actor(
&self,
host_id: &str,
existing_actor_id: &str,
new_actor_ref: &str,
annotations: Option<HashMap<String, String>>
) -> Result<CtlOperationAck, Box<dyn Error + Send + Sync>>
pub async fn update_actor( &self, host_id: &str, existing_actor_id: &str, new_actor_ref: &str, annotations: Option<HashMap<String, String>> ) -> Result<CtlOperationAck, Box<dyn Error + Send + Sync>>
Issue a command to a host instructing that it replace an existing actor (indicated by its public key) with a new actor indicated by an OCI image reference. The host will acknowledge this request as soon as it verifies that the target actor is running. This acknowledgement occurs before the new bytes are downloaded. Live-updating an actor can take a long time and control clients cannot block waiting for a reply that could come several seconds later. If you need to verify that the actor has been updated, you will want to set up a listener for the appropriate PublishedEvent which will be published on the control events channel in JSON
sourcepub async fn start_provider(
&self,
host_id: &str,
provider_ref: &str,
link_name: Option<String>,
annotations: Option<HashMap<String, String>>,
provider_configuration: Option<String>
) -> Result<CtlOperationAck, Box<dyn Error + Send + Sync>>
pub async fn start_provider( &self, host_id: &str, provider_ref: &str, link_name: Option<String>, annotations: Option<HashMap<String, String>>, provider_configuration: Option<String> ) -> Result<CtlOperationAck, Box<dyn Error + Send + Sync>>
Issues a command to a host to start a provider with a given OCI reference using the specified link name (or “default” if none is specified). The target wasmCloud host will acknowledge the receipt of this command before downloading the provider’s bytes from the OCI registry, indicating either a validation failure or success. If a client needs deterministic guarantees that the provider has completed its startup process, such a client needs to monitor the control event stream for the appropriate event. If a host ID is not supplied (empty string), then this function will return an early acknowledgement, go find a host, and then submit the start request to a target host.
sourcepub async fn stop_provider(
&self,
host_id: &str,
provider_ref: &str,
link_name: &str,
contract_id: &str,
annotations: Option<HashMap<String, String>>
) -> Result<CtlOperationAck, Box<dyn Error + Send + Sync>>
pub async fn stop_provider( &self, host_id: &str, provider_ref: &str, link_name: &str, contract_id: &str, annotations: Option<HashMap<String, String>> ) -> Result<CtlOperationAck, Box<dyn Error + Send + Sync>>
Issues a command to a host to stop a provider for the given OCI reference, link name, and contract ID. The target wasmCloud host will acknowledge the receipt of this command, and will not supply a discrete confirmation that a provider has terminated. For that kind of information, the client must also monitor the control event stream
sourcepub async fn stop_actor(
&self,
host_id: &str,
actor_ref: &str,
count: u16,
annotations: Option<HashMap<String, String>>
) -> Result<CtlOperationAck, Box<dyn Error + Send + Sync>>
pub async fn stop_actor( &self, host_id: &str, actor_ref: &str, count: u16, annotations: Option<HashMap<String, String>> ) -> Result<CtlOperationAck, Box<dyn Error + Send + Sync>>
Issues a command to a host to stop an actor for the given OCI reference. The target wasmCloud host will acknowledge the receipt of this command, and will not supply a discrete confirmation that the actor has terminated. For that kind of information, the client must also monitor the control event stream
sourcepub async fn stop_host(
&self,
host_id: &str,
timeout_ms: Option<u64>
) -> Result<CtlOperationAck, Box<dyn Error + Send + Sync>>
pub async fn stop_host( &self, host_id: &str, timeout_ms: Option<u64> ) -> Result<CtlOperationAck, Box<dyn Error + Send + Sync>>
Issues a command to a specific host to perform a graceful termination. The target host will acknowledge receipt of the command before it attempts a shutdown. To deterministically verify that the host is down, a client should monitor for the “host stopped” event or passively detect the host down by way of a lack of heartbeat receipts
sourcepub async fn events_receiver(
&self
) -> Result<Receiver<Event>, Box<dyn Error + Send + Sync>>
pub async fn events_receiver( &self ) -> Result<Receiver<Event>, Box<dyn Error + Send + Sync>>
Returns the receiver end of a channel that subscribes to the lattice control event stream.
Any Event
s that are published after this channel is created
will be added to the receiver channel’s buffer, which can be observed or handled if needed.
See the example for how you could use this receiver to handle events.
Example
use wasmcloud_control_interface::{Client, ClientBuilder};
async {
let nc = async_nats::connect("127.0.0.1:4222").await.unwrap();
let client = ClientBuilder::new(nc)
.rpc_timeout(std::time::Duration::from_millis(1000))
.auction_timeout(std::time::Duration::from_millis(1000))
.build().await.unwrap();
let mut receiver = client.events_receiver().await.unwrap();
tokio::spawn( async move {
while let Some(evt) = receiver.recv().await {
println!("Event received: {:?}", evt);
}
});
// perform other operations on client
client.get_host_inventory("NAEXHW...").await.unwrap();
};
Once you’re finished with the event receiver, be sure to call drop
with the receiver
as an argument. This closes the channel and will prevent the sender from endlessly
sending messages into the channel buffer.
Example
use wasmcloud_control_interface::{Client, ClientBuilder};
async {
let nc = async_nats::connect("0.0.0.0:4222").await.unwrap();
let client = ClientBuilder::new(nc)
.rpc_timeout(std::time::Duration::from_millis(1000))
.auction_timeout(std::time::Duration::from_millis(1000))
.build().await.unwrap();
let mut receiver = client.events_receiver().await.unwrap();
// read the docs for flume receiver. You can use it in either sync or async code
// The receiver can be cloned() as needed.
// If you drop the receiver. The subscriber will exit
// If the nats connection ic closed, the loop below will exit.
while let Some(evt) = receiver.recv().await {
println!("Event received: {:?}", evt);
}
};