Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Add ha_resource_move action #2391

Merged
merged 2 commits into from
Nov 17, 2020
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 iml-agent/src/action_plugins/action_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub fn create_registry() -> action_plugins::Actions {
.add_plugin("remove_fstab_entry", lustre::client::remove_fstab_entry)
.add_plugin("ha_resource_start", high_availability::start_resource)
.add_plugin("ha_resource_stop", high_availability::stop_resource)
.add_plugin("ha_resource_move", high_availability::move_resource)
.add_plugin(
"ha_resource_create",
high_availability::create_single_resource,
Expand Down
38 changes: 36 additions & 2 deletions iml-agent/src/action_plugins/high_availability/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub use crate::high_availability::{crm_attribute, pcs};

const NO_EXTRA: Vec<String> = vec![];

const WAIT_SEC: u64 = 300;
const WAIT_DELAY: u64 = 2;

fn create(elem: &Element) -> ResourceAgentInfo {
ResourceAgentInfo {
agent: {
Expand Down Expand Up @@ -76,8 +79,8 @@ fn create(elem: &Element) -> ResourceAgentInfo {
}

async fn wait_resource(resource: &str, running: bool) -> Result<(), ImlAgentError> {
let sec_to_wait = 300;
let sec_delay = 2;
let sec_to_wait = WAIT_SEC;
let sec_delay = WAIT_DELAY;
let delay_duration = Duration::new(sec_delay, 0);
for _ in 0..(sec_to_wait / sec_delay) {
let output = crm_mon_cmd().checked_output().await?;
Expand Down Expand Up @@ -619,6 +622,37 @@ pub async fn stop_resource(resource: String) -> Result<(), ImlAgentError> {
Ok(())
}

pub async fn move_resource((resource, dest_host): (String, String)) -> Result<(), ImlAgentError> {
let delay_duration = Duration::new(WAIT_DELAY, 0);

crm_resource(&["--resource", &resource, "--move", "--node", &dest_host]).await?;

let mut counter = 0;
let rc = loop {
let output = crm_mon_cmd().checked_output().await?;
let cluster = read_crm_output(&output.stdout)?;

let res = cluster.resources.into_iter().find(|r| r.id == resource);
if let Some(r) = res {
if r.active_node_name.unwrap_or_else(|| "".into()) == dest_host {
break Ok(());
}
}
if counter >= WAIT_SEC {
break Err(ImlAgentError::from(RequiredError(format!(
"Waiting for resource {} to move to {} failed after {} sec",
resource, dest_host, WAIT_SEC,
))));
}
counter += WAIT_DELAY;
delay_for(delay_duration).await;
};

crm_resource(&["--resource", &resource, "--un-move", "--node", &dest_host]).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--un-move should be called --allow-move or something more representative


rc
}

#[cfg(test)]
mod tests {
use super::{process_resource, PacemakerOperations, ResourceAgentInfo, ResourceAgentType};
Expand Down