Skip to content

Commit

Permalink
Add name spaces and move files to their places
Browse files Browse the repository at this point in the history
I'm favoring to move stuff to models/ or services/
folders/namespaces. There is a lot of moves to do
yet but this already outlines some structure
  • Loading branch information
Daniel Hilst committed Feb 12, 2025
1 parent 086f661 commit 27629b4
Show file tree
Hide file tree
Showing 68 changed files with 644 additions and 413 deletions.
4 changes: 2 additions & 2 deletions include/cloysterhpc/concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ concept IsMoveable
template <typename T>
concept NotCopiableMoveable = !IsMoveable<T> && !IsCopyable<T>;
/**
* @brief Parser<P, T> means: P can parse and unparse Ts from streams. The
* @brief IsParser<P, T> means: P can parse and unparse Ts from streams. The
* parsers are allowed to throw exceptions
*/
template <typename Parser_, typename T>
concept Parser = requires(Parser_ parser, std::istream& parseInput,
concept IsParser = requires(Parser_ parser, std::istream& parseInput,
std::ostream& unparseOutput, const T& unparseInput, T& parseOutput) {
{ parser.parse(parseInput, parseOutput) } -> std::same_as<void>;
{ parser.unparse(unparseInput, unparseOutput) } -> std::same_as<void>;
Expand Down
5 changes: 2 additions & 3 deletions include/cloysterhpc/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
#ifndef CLOYSTERHPC_CONNECTION_H_
#define CLOYSTERHPC_CONNECTION_H_

#include <cloysterhpc/network.h>

#include <arpa/inet.h>
#include <boost/asio.hpp>
#include <expected>
#include <ifaddrs.h>
#include <memory>
#include <string>

#include <gsl/gsl-lite.hpp>

#include <cloysterhpc/network.h>

/* Each server can have one and only one connection to a given network, although
* it can have more than one address on the same interface. This may seem
* incorrect, but it is standard TCP networking.
Expand Down
7 changes: 4 additions & 3 deletions include/cloysterhpc/functions.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#ifndef CLOYSTERHPC_FUNCTIONS_H_
#define CLOYSTERHPC_FUNCTIONS_H_

#include "repos.h"
#include <cloysterhpc/services/repos.h>
#include <boost/process/child.hpp>
#include <boost/process/pipe.hpp>
#include <filesystem>
#include <glibmm/ustring.h>
#include <list>
#include <optional>
#include <string>
#include <vector>

#include <boost/asio.hpp>
#include <glibmm/keyfile.h>
Expand All @@ -19,8 +18,10 @@ namespace cloyster {
// Globals
extern bool dryRun;

using OS = cloyster::models::OS;
std::shared_ptr<BaseRunner> getRunner();
std::shared_ptr<RepoManager<repository, BaseRunner>> getRepoManager(const OS& osinfo);
std::shared_ptr<cloyster::services::repos::RepoManager> getRepoManager(const OS& osinfo);


/**
* A command proxy, to us to be able to get the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define CLOYSTERHPC_ANSWERFILE_H_

#include <cloysterhpc/tools/ITool.h>
#include <cloysterhpc/os.h>
#include <cloysterhpc/models/os.h>
#include <boost/asio.hpp>
#include <cloysterhpc/inifile.h>
#include <cloysterhpc/mailsystem/postfix.h>
Expand All @@ -16,6 +16,8 @@

using boost::asio::ip::address;

namespace cloyster::models {

/**
* @struct AFNode
* @brief Holds individual node settings.
Expand Down Expand Up @@ -64,6 +66,7 @@ class AnswerFile {
std::optional<address> gateway;
std::optional<std::string> domain_name;
std::optional<std::vector<std::string>> nameservers;

std::optional<std::string> con_interface;
std::optional<address> con_ip_addr;
std::optional<std::string> con_mac_addr;
Expand Down Expand Up @@ -374,4 +377,6 @@ class answerfile_validation_exception : public std::exception {
const char* what() const noexcept override { return message.c_str(); }
};

};

#endif // CLOYSTERHPC_ANSWERFILE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@

#include <cloysterhpc/dbus_client.h>
#include <cloysterhpc/diskImage.h>
#include <cloysterhpc/headnode.h>
#include <cloysterhpc/models/headnode.h>
#include <cloysterhpc/models/node.h>
#include <cloysterhpc/models/queuesystem.h>
#include <cloysterhpc/mailsystem/postfix.h>
#include <cloysterhpc/network.h>
#include <cloysterhpc/node.h>
#include <cloysterhpc/ofed.h>
#include <cloysterhpc/queuesystem/pbs.h>
#include <cloysterhpc/queuesystem/slurm.h>
#include <cloysterhpc/repos.h>
#include <cloysterhpc/runner.h>
#include <cloysterhpc/services/locale.h>
#include <cloysterhpc/services/repos.h>
#include <cloysterhpc/services/repofile.h>
#include <cloysterhpc/services/timezone.h>

// @TODO: Shouldn't Cluster be below cloyster namespace?

/**
* @class Cluster
Expand All @@ -35,13 +34,22 @@
* environment, including headnode, nodes, networks, provisioner, timezone,
* locale, and more.
*/

namespace cloyster::models {

/**
* @brief Represents the cluster state and configuration
*/
class Cluster {
public:
/**
* @enum SELinuxMode
* @brief Enumeration for SELinux modes.
*
*/
enum class SELinuxMode { Permissive, Enforcing, Disabled };

// @TODO: This class should not know about DBusClient

/**
* @enum Provisioner
Expand Down Expand Up @@ -74,9 +82,6 @@ class Cluster {
bool m_updateSystem { false };
DiskImage m_diskImage;

// Relace repository with generic repository
std::optional<RepoManager<repository, BaseRunner>> m_repos = std::nullopt;

public:
Cluster();

Expand Down Expand Up @@ -257,4 +262,6 @@ class Cluster {
std::string nodeRootPassword;
};

}; // namespace cloyster::models

#endif // CLOYSTERHPC_CLUSTER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#define CLOYSTERHPC_CPU_H_

#include <cstddef>
#include <stdexcept>

namespace cloyster::models {

class CPU {
private:
Expand Down Expand Up @@ -39,4 +40,6 @@ class CPU {
void setThreadsPerCore(std::size_t threadsPerCore);
};

}; // namespace cloyster::models

#endif // CLOYSTERHPC_CPU_H_
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

#include <cloysterhpc/connection.h>
#include <cloysterhpc/network.h>
#include <cloysterhpc/os.h>
#include <cloysterhpc/server.h>
#include <cloysterhpc/models/os.h>
#include <cloysterhpc/models/server.h>

namespace cloyster::models {
class Headnode : public Server {
public:
enum class BootTarget { Text, Graphical };
Expand All @@ -32,4 +33,7 @@ class Headnode : public Server {
void setBootTarget(BootTarget bootTarget);
};


}; // namespace cloyster::models

#endif // CLOYSTERHPC_HEADNODE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

#include <cloysterhpc/connection.h>
#include <cloysterhpc/network.h>
#include <cloysterhpc/os.h>
#include <cloysterhpc/server.h>
#include <cloysterhpc/models/os.h>
#include <cloysterhpc/models/server.h>


namespace cloyster::models {
/**
* @class Node
* @brief A class representing a node in a server cluster.
Expand Down Expand Up @@ -59,4 +61,6 @@ class Node : public Server {
const std::optional<std::string>& nodeRootPassword);
};

}; // namespace cloyster::models {

#endif // CLOYSTERHPC_NODE_H_
22 changes: 22 additions & 0 deletions include/cloysterhpc/os.h → include/cloysterhpc/models/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <string>
#include <variant>


namespace cloyster::models {
/**
* @class OS
* @brief A class representing an Operating System (OS).
Expand Down Expand Up @@ -49,6 +51,12 @@ class OS {
*/
enum class Distro { RHEL, OL, Rocky, AlmaLinux };

/**
* @enum PackageManager
* @brief What
*/
enum class PackageType { RPM, DEB };

private:
std::variant<std::monostate, Arch> m_arch;
std::variant<std::monostate, Family> m_family;
Expand Down Expand Up @@ -124,6 +132,19 @@ class OS {

gsl::not_null<package_manager*> packageManager() const;

[[nodiscard]] constexpr PackageType getPackageType() const {
switch (getDistro()) {
case Distro::RHEL:
case Distro::OL:
case Distro::Rocky:
case Distro::AlmaLinux:
return PackageType::RPM;
default:
throw std::runtime_error("Unknonw distro type");
};
}


#ifndef NDEBUG
/**
* @brief Prints the data of the OS.
Expand All @@ -134,4 +155,5 @@ class OS {
#endif
};

}; // namespace cloyster::models
#endif // CLOYSTERHPC_OS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#define CLOYSTERHPC_PBS_H_

#include <cloysterhpc/runner.h>
#include <cloysterhpc/queuesystem/queuesystem.h>
#include <cloysterhpc/models/queuesystem.h>

namespace cloyster::models {

class PBS : public QueueSystem {
public:
Expand All @@ -24,4 +26,6 @@ class PBS : public QueueSystem {
explicit PBS(const Cluster& cluster);
};

};

#endif // CLOYSTERHPC_PBS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <cloysterhpc/functions.h>

// Forward declaration of Cluster
namespace cloyster::models {

class Cluster;

class QueueSystem {
Expand All @@ -36,4 +38,6 @@ class QueueSystem {
virtual ~QueueSystem() = default;
};

};

#endif // CLOYSTERHPC_QUEUESYSTEM_H_
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#include <expected>
#include <fmt/format.h>
#include <list>
#include <regex>
#include <string>

#include <cloysterhpc/connection.h>
#include <cloysterhpc/cpu.h>
#include <cloysterhpc/os.h>
#include <cloysterhpc/models/cpu.h>
#include <cloysterhpc/models/os.h>
#include <cloysterhpc/services/bmc.h>

namespace cloyster::models {
/**
* @class Server
* @brief Represents a server in a cluster.
Expand Down Expand Up @@ -108,4 +108,6 @@ class Server {
Server() = default;
};

}; // namespace cloyster::models

#endif // CLOYSTERHPC_SERVER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#ifndef CLOYSTERHPC_SLURM_H_
#define CLOYSTERHPC_SLURM_H_

#include <cloysterhpc/queuesystem/queuesystem.h>
#include <cloysterhpc/models/queuesystem.h>

namespace cloyster::models {
/**
* @class SLURM
* @brief Manages SLURM server installation and configuration.
Expand Down Expand Up @@ -40,4 +41,5 @@ class SLURM : public QueueSystem {
static void startServer();
};

};
#endif // CLOYSTERHPC_SLURM_H_
22 changes: 17 additions & 5 deletions include/cloysterhpc/presenter/Presenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@
#ifndef CLOYSTERHPC_PRESENTER_H_
#define CLOYSTERHPC_PRESENTER_H_

#include <array>
#include <cloysterhpc/cluster.h>
#include <cloysterhpc/models/cluster.h>
#include <cloysterhpc/models/queuesystem.h>
#include <cloysterhpc/models/pbs.h>
#include <cloysterhpc/models/slurm.h>
#include <cloysterhpc/services/log.h>
#include <cloysterhpc/view/newt.h>
#include <memory>
#include <string>
#include <vector>


namespace cloyster::presenter {

using Cluster = cloyster::models::Cluster;
using QueueSystem = cloyster::models::QueueSystem;
using SLURM = cloyster::models::SLURM;
using PBS = cloyster::models::PBS;
using OS = cloyster::models::OS;
using CPU = cloyster::models::CPU;
using Node = cloyster::models::Node;

class Presenter {
protected:
Expand Down Expand Up @@ -42,4 +52,6 @@ class Presenter {
}
};

};

#endif // CLOYSTERHPC_PRESENTER_H_
3 changes: 3 additions & 0 deletions include/cloysterhpc/presenter/PresenterGeneralSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <cloysterhpc/presenter/Presenter.h>

namespace cloyster::presenter {

class PresenterGeneralSettings : public Presenter {
private:
Expand Down Expand Up @@ -38,4 +39,6 @@ class PresenterGeneralSettings : public Presenter {
std::unique_ptr<Cluster>& model, std::unique_ptr<Newt>& view);
};

};

#endif // CLOYSTERHPC_PRESENTERGENERALSETTINGS_H_
Loading

0 comments on commit 27629b4

Please sign in to comment.