Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Commit 781360e

Browse files
committed
Remove package_manager in favor of IOSService interface
1 parent 5372d72 commit 781360e

8 files changed

Lines changed: 48 additions & 130 deletions

File tree

include/cloysterhpc/models/os.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#define CLOYSTERHPC_OS_H_
88

99
#include <cloysterhpc/const.h>
10-
#include <cloysterhpc/services/package_manager.h>
1110
#include <fmt/format.h>
1211
#include <gsl/gsl-lite.hpp>
1312
#include <memory>
@@ -72,8 +71,6 @@ class OS {
7271
unsigned m_majorVersion {};
7372
unsigned m_minorVersion {};
7473

75-
std::shared_ptr<package_manager> m_packageManager;
76-
7774
void setMajorVersion(unsigned int majorVersion);
7875

7976
void setMinorVersion(unsigned int minorVersion);
@@ -86,9 +83,6 @@ class OS {
8683
*/
8784
static std::string getValueFromKey(const std::string& line);
8885

89-
std::shared_ptr<package_manager> factoryPackageManager(
90-
OS::Platform platform);
91-
9286
public:
9387
OS();
9488

@@ -117,9 +111,6 @@ class OS {
117111

118112
[[nodiscard]] unsigned int getMajorVersion() const;
119113
[[nodiscard]] unsigned int getMinorVersion() const;
120-
121-
gsl::not_null<package_manager*> packageManager() const;
122-
123114
[[nodiscard]] PackageType getPackageType() const;
124115

125116
/**

include/cloysterhpc/services/dnf.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

include/cloysterhpc/services/osservice.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define CLOYSTER_OSSERVICE_H_
33

44
#include <string>
5+
#include <vector>
56

67
#include <cloysterhpc/models/os.h>
78

@@ -24,7 +25,7 @@ using cloyster::models::OS;
2425
* recipes used by the installer. Also this interface is for getting runtime
2526
* information from the operating system, for in-memory state use
2627
* cloyster::models::OS class instead.
27-
*
28+
*
2829
* @see See main.cpp for intialization and osservice.cpp for more info.
2930
*/
3031
class IOSService {
@@ -39,6 +40,17 @@ class IOSService {
3940
[[nodiscard]] virtual std::string getKernelInstalled() const = 0;
4041
[[nodiscard]] virtual std::string getKernelRunning() const = 0;
4142

43+
// These methods are const because the implementation is expected to be stateless
44+
// The implementation is expect to be stateless to avoid double source of true,
45+
// the internal state vs the OS runtime state
46+
virtual bool install(std::string_view package) const = 0;
47+
virtual bool remove(std::string_view package) const = 0;
48+
virtual bool update(std::string_view package) const = 0;
49+
virtual bool update() const = 0;
50+
virtual void check() const = 0;
51+
virtual void clean() const = 0;
52+
virtual std::vector<std::string> repolist() const = 0;
53+
4254
static std::unique_ptr<IOSService> factory(const OS& osinfo);
4355
};
4456

include/cloysterhpc/services/package_manager.h

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/models/os.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#include <cloysterhpc/cloyster.h>
77
#include <cloysterhpc/functions.h>
88
#include <cloysterhpc/models/os.h>
9-
#include <cloysterhpc/services/dnf.h>
10-
#include <cloysterhpc/services/package_manager.h>
119
#include <magic_enum/magic_enum.hpp>
1210
#include <stdexcept>
1311
#include <variant>
@@ -85,8 +83,6 @@ OS::OS()
8583
fmt::format("Error while reading file: {}", filename));
8684
}
8785
}
88-
89-
factoryPackageManager(getPlatform());
9086
}
9187

9288
OS::Arch OS::getArch() const { return std::get<OS::Arch>(m_arch); }
@@ -262,26 +258,6 @@ std::string OS::getValueFromKey(const std::string& line)
262258
return value;
263259
}
264260

265-
std::shared_ptr<package_manager> OS::factoryPackageManager(
266-
OS::Platform platform)
267-
{
268-
auto platformName = cloyster::utils::enums::toString(platform);
269-
for (const auto& supportedPlatform : cloyster::utils::enums::toStrings<Platform>()) {
270-
if (platformName == supportedPlatform) {
271-
m_packageManager = std::make_shared<dnf>();
272-
return m_packageManager;
273-
}
274-
}
275-
276-
throw std::runtime_error(fmt::format(
277-
"Unsupported OS platform: {}", cloyster::utils::enums::toString(platform)));
278-
}
279-
280-
gsl::not_null<package_manager*> OS::packageManager() const
281-
{
282-
return m_packageManager.get();
283-
}
284-
285261
void OS::printData() const
286262
{
287263
#ifndef NDEBUG

src/services/dnf.cpp

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/services/osservice.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,38 @@ class ELOSService final : public IOSService {
2020
{
2121
return Singleton<IRunner>::get()->checkOutput("uname -r")[0];
2222
}
23+
24+
bool install(std::string_view package) const override
25+
{
26+
return (
27+
cloyster::runCommand(fmt::format("dnf -y install {}", package)) != 0);
28+
}
29+
30+
bool remove(std::string_view package) const override
31+
{
32+
return (
33+
cloyster::runCommand(fmt::format("dnf -y remove {}", package)) != 0);
34+
}
35+
36+
bool update(std::string_view package) const override
37+
{
38+
return (
39+
cloyster::runCommand(fmt::format("dnf -y update {}", package)) != 0);
40+
}
41+
42+
bool update() const override
43+
{
44+
return (cloyster::runCommand("dnf -y update") != 0);
45+
}
46+
47+
void check() const override { cloyster::runCommand("dnf check"); }
48+
49+
void clean() const override { cloyster::runCommand("dnf clean all"); }
50+
51+
[[nodiscard]] std::vector<std::string> repolist() const override
52+
{
53+
return Singleton<IRunner>::get()->checkOutput("dnf repolist");
54+
}
2355
};
2456

2557
std::unique_ptr<IOSService> IOSService::factory(const OS& osinfo)

src/services/xcat.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ XCAT::Image XCAT::getImage() const
8787

8888
void XCAT::installPackages()
8989
{
90-
auto packageManager = cluster()->getHeadnode().getOS().packageManager();
91-
packageManager->install("initscripts");
92-
packageManager->install("xCAT");
90+
auto osservice = cloyster::Singleton<IOSService>::get();
91+
osservice->install("initscripts");
92+
osservice->install("xCAT");
9393
}
9494

9595
void XCAT::patchInstall()

0 commit comments

Comments
 (0)