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

Implement stop and paure/resume in client #22

Merged
merged 2 commits into from
Oct 23, 2024
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
30 changes: 24 additions & 6 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,32 @@ impl AdminClient {
let _response = self.connect_to().await?.start_application(request).await?;
Ok(())
}
pub async fn stop(&self, _app: String) -> anyhow::Result<()> {
todo!();
pub async fn stop(&self, app_name: String) -> anyhow::Result<()> {
let request = pb::admin::ApplicationRequest {
app_name,
vm_name: None,
args: Vec::new(),
};
let _response = self.connect_to().await?.stop_application(request).await?;
Ok(())
}
pub async fn pause(&self, _app: String) -> anyhow::Result<()> {
todo!();
pub async fn pause(&self, app_name: String) -> anyhow::Result<()> {
let request = pb::admin::ApplicationRequest {
app_name,
vm_name: None,
args: Vec::new(),
};
let _response = self.connect_to().await?.pause_application(request).await?;
Ok(())
}
pub async fn resume(&self, _app: String) -> anyhow::Result<()> {
todo!();
pub async fn resume(&self, app_name: String) -> anyhow::Result<()> {
let request = pb::admin::ApplicationRequest {
app_name,
vm_name: None,
args: Vec::new(),
};
let _response = self.connect_to().await?.resume_application(request).await?;
Ok(())
}
pub async fn reboot(&self) -> anyhow::Result<()> {
let request = pb::admin::Empty {};
Expand Down
5 changes: 5 additions & 0 deletions nixos/tests/admin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ in
print(hostvm.succeed("${cli} --addr ${nodes.adminvm.config.givc.admin.addr} --port ${nodes.adminvm.config.givc.admin.port} --cacert ${nodes.hostvm.givc.host.tls.caCertPath} --cert ${nodes.hostvm.givc.host.tls.certPath} --key ${nodes.hostvm.givc.host.tls.keyPath} ${if tls then "" else "--notls"} --name ${nodes.adminvm.config.givc.admin.name} start --vm chromium-vm foot"))
wait_for_window("ghaf@appvm")

with subtest("stop application"):
mbssrc marked this conversation as resolved.
Show resolved Hide resolved
appvm.succeed("pgrep foot")
print(hostvm.succeed("${cli} --addr ${nodes.adminvm.config.givc.admin.addr} --port ${nodes.adminvm.config.givc.admin.port} --cacert ${nodes.hostvm.givc.host.tls.caCertPath} --cert ${nodes.hostvm.givc.host.tls.certPath} --key ${nodes.hostvm.givc.host.tls.keyPath} ${if tls then "" else "--notls"} --name ${nodes.adminvm.config.givc.admin.name} stop foot@1.service"))
appvm.fail("pgrep foot")

with subtest("clear exit and restart"):
print(hostvm.succeed("${cli} --addr ${nodes.adminvm.config.givc.admin.addr} --port ${nodes.adminvm.config.givc.admin.port} --cacert ${nodes.hostvm.givc.host.tls.caCertPath} --cert ${nodes.hostvm.givc.host.tls.certPath} --key ${nodes.hostvm.givc.host.tls.keyPath} ${if tls then "" else "--notls"} --name ${nodes.adminvm.config.givc.admin.name} start --vm chromium-vm clearexit"))
time.sleep(20) # Give few seconds to application to spin up, exit, then start it again
Expand Down
31 changes: 12 additions & 19 deletions src/admin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,17 @@ impl AdminServiceImpl {
self.endpoint(&host_mgr).context("Resolving host agent")
}

pub fn endpoint(&self, reentry: &RegistryEntry) -> anyhow::Result<EndpointConfig> {
let transport = reentry.agent()?.to_owned();
pub fn endpoint(&self, entry: &RegistryEntry) -> anyhow::Result<EndpointConfig> {
let transport = match &entry.placement {
Placement::Managed(parent) => {
let parent = self.registry.by_name(&parent)?;
parent
.agent()
.with_context(|| "When get_remote_status()")?
.to_owned() // Fail, if parent also `Managed`
}
Placement::Endpoint(endpoint) => endpoint.clone(), // FIXME: avoid clone!
};
let tls_name = transport.tls_name.clone();
Ok(EndpointConfig {
transport,
Expand Down Expand Up @@ -136,23 +145,7 @@ impl AdminServiceImpl {
&self,
entry: &RegistryEntry,
) -> anyhow::Result<crate::types::UnitStatus> {
let transport = match &entry.placement {
Placement::Managed(parent) => {
let parent = self.registry.by_name(parent)?;
parent.agent()?.to_owned() // Fail, if parent also `Managed`
}
Placement::Endpoint(endpoint) => endpoint.clone(), // FIXME: avoid clone!
};
let tls_name = transport.tls_name.clone();
info!("Get remote status for {tls_name}!");
let endpoint = EndpointConfig {
transport: transport.to_owned(),
tls: self.tls_config.clone().map(|mut tls| {
tls.tls_name = Some(tls_name);
tls
}),
};

let endpoint = self.endpoint(entry)?;
let client = SystemDClient::new(endpoint);
client.get_remote_status(entry.name.clone()).await
}
Expand Down