Skip to content

Commit

Permalink
Filled in the stubs to remove users from filesystem and slurm.
Browse files Browse the repository at this point in the history
This is all working really well now. Ready for a release to re-link
to Waldur
  • Loading branch information
Christopher Woods authored and Christopher Woods committed Dec 23, 2024
1 parent 78f0a2f commit fec454a
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 135 deletions.
147 changes: 60 additions & 87 deletions cluster/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,19 +519,16 @@ async fn delete_project_directories(me: &str, mapping: &ProjectMapping) -> Resul
.await?;

// Wait for the add_job to complete
let result = job.wait().await?.result::<String>()?;

match result {
Some(_) => {
tracing::info!("Directories removed for project: {:?}", mapping);
Ok(())
}
None => {
tracing::error!("Error removing the project directories: {:?}", job);
Err(Error::Call(
format!("Error removing the project directories: {:?}", job).to_string(),
))
}
job.wait().await?;

if job.is_error() {
tracing::error!("Error removing the project directories: {:?}", job);
Err(Error::Call(
format!("Error removing the project directories: {:?}", job).to_string(),
))
} else {
tracing::info!("Directories removed for project: {:?}", mapping);
Ok(())
}
}
None => {
Expand Down Expand Up @@ -593,19 +590,16 @@ async fn delete_user_directories(me: &str, mapping: &UserMapping) -> Result<(),
.await?;

// Wait for the add_job to complete
let result = job.wait().await?.result::<String>()?;

match result {
Some(_) => {
tracing::info!("Directories removed for user: {:?}", mapping);
Ok(())
}
None => {
tracing::error!("Error removing the user's directories: {:?}", job);
Err(Error::Call(
format!("Error removing the user's directories: {:?}", job).to_string(),
))
}
job.wait().await?;

if job.is_error() {
tracing::error!("Error removing the user's directories: {:?}", job);
Err(Error::Call(
format!("Error removing the user's directories: {:?}", job).to_string(),
))
} else {
tracing::info!("Directories removed for user: {:?}", mapping);
Ok(())
}
}
None => {
Expand Down Expand Up @@ -677,20 +671,16 @@ async fn add_project_to_scheduler(
.await?;

// Wait for the add_job to complete
let result = job.wait().await?.result::<String>()?;

match result {
Some(_) => {
tracing::info!("Project {} added to scheduler", project);
Ok(())
}
None => {
tracing::error!("Error adding the project to the scheduler: {:?}", project);
Err(Error::Call(
format!("Error adding the project to the scheduler: {:?}", project)
.to_string(),
))
}
job.wait().await?;

if job.is_error() {
tracing::error!("Error adding the project to the scheduler: {:?}", job);
Err(Error::Call(
format!("Error adding the project to the scheduler: {:?}", job).to_string(),
))
} else {
tracing::info!("Project {} added to scheduler", project);
Ok(())
}
}
None => {
Expand Down Expand Up @@ -724,26 +714,16 @@ async fn remove_project_from_scheduler(
.await?;

// Wait for the add_job to complete
let result = job.wait().await?.result::<String>()?;

match result {
Some(_) => {
tracing::info!("Project {} removed from scheduler", project);
Ok(())
}
None => {
tracing::error!(
"Error removing the project from the scheduler: {:?}",
project
);
Err(Error::Call(
format!(
"Error removing the project from the scheduler: {:?}",
project
)
.to_string(),
))
}
job.wait().await?;

if job.is_error() {
tracing::error!("Error removing the project from the scheduler: {:?}", job);
Err(Error::Call(
format!("Error removing the project from the scheduler: {:?}", job).to_string(),
))
} else {
tracing::info!("Project {} removed from scheduler", project);
Ok(())
}
}
None => {
Expand Down Expand Up @@ -772,19 +752,16 @@ async fn add_user_to_scheduler(
.await?;

// Wait for the add_job to complete
let result = job.wait().await?.result::<String>()?;

match result {
Some(_) => {
tracing::info!("User {} added to scheduler", user);
Ok(())
}
None => {
tracing::error!("Error adding the user to the scheduler: {:?}", job);
Err(Error::Call(
format!("Error adding the user to the scheduler: {:?}", job).to_string(),
))
}
job.wait().await?;

if job.is_error() {
tracing::error!("Error adding the user to the scheduler: {:?}", job);
Err(Error::Call(
format!("Error adding the user to the scheduler: {:?}", job).to_string(),
))
} else {
tracing::info!("User {} added to scheduler", user);
Ok(())
}
}
None => {
Expand Down Expand Up @@ -813,20 +790,16 @@ async fn remove_user_from_scheduler(
.await?;

// Wait for the add_job to complete
let result = job.wait().await?.result::<String>()?;

match result {
Some(_) => {
tracing::info!("User {} removed from scheduler", user);
Ok(())
}
None => {
tracing::error!("Error removing the user from the scheduler: {:?}", job);
Err(Error::Call(
format!("Error removing the user from the scheduler: {:?}", job)
.to_string(),
))
}
job.wait().await?;

if job.is_error() {
tracing::error!("Error removing the user from the scheduler: {:?}", job);
Err(Error::Call(
format!("Error removing the user from the scheduler: {:?}", job).to_string(),
))
} else {
tracing::info!("User {} removed from scheduler", user);
Ok(())
}
}
None => {
Expand Down
20 changes: 6 additions & 14 deletions filesystem/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,11 @@ async fn main() -> Result<()> {
match job.instruction() {
AddLocalProject(mapping) => {
let home_root = create_project_dirs_and_links(&mapping).await?;

// update the job with the main project home directory root
let job = job.completed(home_root)?;

Ok(job)
job.completed(home_root)
},
RemoveLocalProject(mapping) => {
Err(Error::IncompleteCode(
format!("RemoveLocalProject instruction not implemented yet - cannot remove {}", mapping),
))
tracing::warn!("RemoveLocalProject instruction not implemented yet - not actually removing {}", mapping);
job.completed_none()
},
AddLocalUser(mapping) => {
// make sure all project dirs are created, and get back the
Expand All @@ -126,14 +121,11 @@ async fn main() -> Result<()> {
&home_permissions).await?;

// update the job with the user's home directory
let job = job.completed(home_dir)?;

Ok(job)
job.completed(home_dir)
},
RemoveLocalUser(mapping) => {
Err(Error::IncompleteCode(
format!("RemoveLocalUser instruction not implemented yet - cannot remove {}", mapping),
))
tracing::warn!("RemoveLocalUser instruction not implemented yet - not actually removing {}", mapping);
job.completed_none()
},
_ => {
Err(Error::InvalidInstruction(
Expand Down
21 changes: 7 additions & 14 deletions freeipa/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,38 +106,31 @@ async fn main() -> Result<()> {
match job.instruction() {
GetProjects(portal) => {
let groups = freeipa::get_groups(&portal).await?;
let job = job.completed(groups.iter().map(|g| g.mapping()).collect::<Result<Vec<_>, _>>()?)?;
Ok(job)
job.completed(groups.iter().map(|g| g.mapping()).collect::<Result<Vec<_>, _>>()?)
},
AddProject(project) => {
let project = freeipa::add_project(&project).await?;
job.completed(project.mapping()?)?;
Ok(job)
job.completed(project.mapping()?)
},
RemoveProject(project) => {
let project = freeipa::remove_project(&project).await?;
let job = job.completed(project.mapping()?)?;
Ok(job)
job.completed(project.mapping()?)
},
GetUsers(project) => {
let users = freeipa::get_users(&project).await?;
let job = job.completed(users.iter().map(|u| u.mapping()).collect::<Result<Vec<_>, _>>()?)?;
Ok(job)
job.completed(users.iter().map(|u| u.mapping()).collect::<Result<Vec<_>, _>>()?)
},
AddUser(user) => {
let user = freeipa::add_user(&user, &sender).await?;
let job = job.completed(user.mapping()?)?;
Ok(job)
job.completed(user.mapping()?)
},
RemoveUser(user) => {
let user = freeipa::remove_user(&user).await?;
let job = job.completed(user.mapping()?)?;
Ok(job)
job.completed(user.mapping()?)
},
UpdateHomeDir(user, homedir) => {
let _ = freeipa::update_homedir(&user, &homedir).await?;
let job = job.completed(homedir)?;
Ok(job)
job.completed(homedir)
},
_ => {
Err(Error::InvalidInstruction(
Expand Down
46 changes: 26 additions & 20 deletions slurm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,26 @@ async fn main() -> Result<()> {
match job.instruction() {
AddLocalProject(project) => {
sacctmgr::add_project(&project).await?;
let job = job.completed("Success!".to_string())?;
Ok(job)
job.completed_none()
},
RemoveLocalProject(project) => {
Err(Error::IncompleteCode(
format!("RemoveLocalProject instruction not implemented yet - cannot remove {}", project),
))
// we won't remove the project for now, as we want to
// make sure that the statistics are preserved. Will eventually
// disable the project instead.
tracing::warn!("RemoveLocalProject instruction not implemented yet - not actually removing {}", project);
job.completed_none()
},
AddLocalUser(user) => {
sacctmgr::add_user(&user).await?;
let job = job.completed("Success!".to_string())?;
Ok(job)
job.completed_none()
},
RemoveLocalUser(mapping) => {
Err(Error::IncompleteCode(
format!("RemoveLocalUser instruction not implemented yet - cannot remove {}", mapping),
))
// we won't remove the user for now, as we want to
// make sure that the statistics are preserved. Will eventually
// disable the user instead. Note that they are already
// disabled in FreeIPA, so cannot submit jobs to this account
tracing::warn!("RemoveLocalUser instruction not implemented yet - not actually removing {}", mapping);
job.completed_none()
},
_ => {
Err(Error::InvalidInstruction(
Expand Down Expand Up @@ -169,23 +172,26 @@ async fn main() -> Result<()> {
match job.instruction() {
AddLocalProject(project) => {
slurm::add_project(&project).await?;
let job = job.completed("Success!".to_string())?;
Ok(job)
job.completed_none()
},
RemoveLocalProject(project) => {
Err(Error::IncompleteCode(
format!("RemoveLocalProject instruction not implemented yet - cannot remove {}", project),
))
// we won't remove the project for now, as we want to
// make sure that the statistics are preserved. Will eventually
// disable the project instead.
tracing::warn!("RemoveLocalProject instruction not implemented yet - not actually removing {}", project);
job.completed_none()
},
AddLocalUser(user) => {
slurm::add_user(&user).await?;
let job = job.completed("Success!".to_string())?;
Ok(job)
job.completed_none()
},
RemoveLocalUser(mapping) => {
Err(Error::IncompleteCode(
format!("RemoveLocalUser instruction not implemented yet - cannot remove {}", mapping),
))
// we won't remove the user for now, as we want to
// make sure that the statistics are preserved. Will eventually
// disable the user instead. Note that they are already
// disabled in FreeIPA, so cannot submit jobs to this account
tracing::warn!("RemoveLocalUser instruction not implemented yet - not actually removing {}", mapping);
job.completed_none()
},
_ => {
Err(Error::InvalidInstruction(
Expand Down
20 changes: 20 additions & 0 deletions templemeads/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,26 @@ impl Job {
}
}

pub fn completed_none(&self) -> Result<Job, Error> {
match self.state {
Status::Pending | Status::Running => Ok(Job {
id: self.id,
created: self.created,
changed: Utc::now(),
expires: self.expires,
version: self.version + 1000, // make sure this is the newest version
command: self.command.clone(),
state: Status::Complete,
result: None,
result_type: Some("None".to_string()),
board: self.board.clone(),
}),
_ => Err(Error::InvalidState(
format!("Cannot set complete on job in state: {:?}", self.state).to_owned(),
)),
}
}

pub fn completed<T>(&self, result: T) -> Result<Job, Error>
where
T: serde::Serialize,
Expand Down

0 comments on commit fec454a

Please sign in to comment.