From 7a96b66ea113bf7f3f219e9cbba2d3c49f084fa1 Mon Sep 17 00:00:00 2001 From: Daniel Hilst Date: Wed, 12 Feb 2025 19:36:59 -0300 Subject: [PATCH] Refactoring the repo manager code --- include/cloysterhpc/services/repos.h | 2 +- include/cloysterhpc/services/shell.h | 10 +++--- src/main.cpp | 2 +- src/services/repos.cpp | 4 +-- src/services/shell.cpp | 46 ++++++++++++++++++---------- 5 files changed, 37 insertions(+), 27 deletions(-) diff --git a/include/cloysterhpc/services/repos.h b/include/cloysterhpc/services/repos.h index e792ca1..4c81390 100644 --- a/include/cloysterhpc/services/repos.h +++ b/include/cloysterhpc/services/repos.h @@ -29,7 +29,7 @@ class RepoManager { void loadFiles(const std::filesystem::path& basedir = "/etc/yum.repos.d"); void commitStatus(); void enable(const std::string& repo); - void enableMultiple(std::vector repos); + void enable(const std::vector& repos); void disable(const std::string& repo); [[nodiscard]] const std::vector& listRepos() const; [[nodiscard]] std::vector getxCATOSImageRepos() const; diff --git a/include/cloysterhpc/services/shell.h b/include/cloysterhpc/services/shell.h index a972cee..c301e9e 100644 --- a/include/cloysterhpc/services/shell.h +++ b/include/cloysterhpc/services/shell.h @@ -21,11 +21,10 @@ using cloyster::models::Cluster; * This class provides functionalities for configuring various system settings, * installing required packages, and setting up cluster-specific services. */ -class Shell : public Execution { +class Shell final : public Execution { private: - const std::unique_ptr& m_cluster; + const std::unique_ptr m_cluster; -private: /** * @brief Configures SELinux mode. * @@ -142,6 +141,7 @@ class Shell : public Execution { */ void configureQueueSystem(); + /** * @brief Configures the InfiniBand settings. * @@ -172,8 +172,6 @@ class Shell : public Execution { static void disableSELinux(); public: - // FIXME: Guideline: Don’t use a const unique_ptr& as a parameter; - // use widget* instead. /** * @brief Constructs a Shell object. * @@ -181,7 +179,7 @@ class Shell : public Execution { * * @param cluster A reference to a unique pointer managing a Cluster object. */ - explicit Shell(const std::unique_ptr& cluster); + explicit Shell(const std::unique_ptr cluster); /** * @brief Installs and configures the system. * diff --git a/src/main.cpp b/src/main.cpp index e6b9728..9603631 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -176,7 +176,7 @@ int main(int argc, const char** argv) } std::unique_ptr executionEngine - = std::make_unique(model); + = std::make_unique(std::move(model)); executionEngine->install(); diff --git a/src/services/repos.cpp b/src/services/repos.cpp index ccf960a..66e42c8 100644 --- a/src/services/repos.cpp +++ b/src/services/repos.cpp @@ -178,9 +178,9 @@ void RepoManager::setEnableState(const std::string& id, bool value) void RepoManager::enable(const std::string& id) { setEnableState(id, true); } -void RepoManager::enableMultiple(std::vector ids) +void RepoManager::enable(const std::vector& ids) { - std::ranges::for_each(ids, [&](const auto& id) { this->enable(id); }); + std::ranges::for_each(ids, [&](const auto& id) { enable(id); }); } void RepoManager::disable(const std::string& id) { setEnableState(id, false); } diff --git a/src/services/shell.cpp b/src/services/shell.cpp index b46c8f8..bab7ee4 100644 --- a/src/services/shell.cpp +++ b/src/services/shell.cpp @@ -24,13 +24,14 @@ #include #include +#include using cloyster::runCommand; namespace cloyster::services { -Shell::Shell(const std::unique_ptr& cluster) - : m_cluster(cluster) +Shell::Shell(std::unique_ptr cluster) + : m_cluster(std::move(cluster)) { // Initialize directory tree cloyster::createDirectory(installPath); @@ -385,6 +386,31 @@ void Shell::installDevelopmentComponents() runCommand("dnf -y install lmod-defaults-gnu12-openmpi4-ohpc"); } +namespace { +auto getToEnableRepoNames() +{ + return std::vector({ "-beegfs", "-elrepo", "-epel", "-openhpc", + "-openhpc-updates", "-rpmfusion-free-updates" }) + | std::views::transform([](const std::string& repo) { + return fmt::format("{}{}", cloyster::productName, repo); + }) + | std::ranges::to>(); +} + +} + +void Shell::configureRepositories() +{ + auto repos = cloyster::getRepoManager(m_cluster->getHeadnode().getOS()); + // 1. Install files into /etc, these files are the templates + // at include/cloysterhpc/repos/el*/*.repo + repos->loadFiles(); + // 2. Enable the repositories + repos->enable(getToEnableRepoNames()); + // 3. Commit data to disk + repos->commitStatus(); +} + /* This method is the entrypoint of shell based cluster install * The first session of the method will configure and install services on the * headnode. The last part will do provisioner related settings and image @@ -411,21 +437,7 @@ void Shell::install() installRequiredPackages(); - // TODO: This is the repos entrypoint. It should be replaced. - auto repos = cloyster::getRepoManager(m_cluster->getHeadnode().getOS()); - repos->loadFiles(); - - const auto toEnable = std::vector(); - // @TODO Fix this - // std::vector({ "-beegfs", "-elrepo", "-epel", "-openhpc", "-openhpc-updates", "-rpmfusion-free-updates" }) - // | std::views::transform([&](const std::string& pkg) { - // return cloyster::productName + pkg; - // }) - // | std::ranges::to>(); - - repos->enableMultiple(toEnable); - repos->commitStatus(); - // End of Repos entrypoint + configureRepositories(); runSystemUpdate();