List tidy
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 11s

This commit is contained in:
Your Name
2025-05-24 17:00:43 +12:00
parent b3398582ca
commit 60907e5e02
18 changed files with 128 additions and 89 deletions

View File

@ -53,7 +53,7 @@ namespace dropshell
namespace shared_commands
{
bool backupdata_service(const server_config &server_env, const std::string &service)
bool backupdata_service(const ServerConfig &server_env, const std::string &service)
{
ASSERT(server_env.is_valid(), "Invalid server environment for " + server_env.get_server_name());
std::string server = server_env.get_server_name();

View File

@ -103,7 +103,7 @@ namespace dropshell
if (server_name.empty() || template_name.empty() || service_name.empty())
return false;
server_config server_info(server_name);
ServerConfig server_info(server_name);
if (!server_info.is_valid())
{
error << "Server " << server_name << " is not valid" << std::endl;

View File

@ -52,7 +52,7 @@ namespace dropshell
bool nuke_service(const std::string &server, const std::string &service)
{
server_config server_env(server);
ServerConfig server_env(server);
// step 1 - nuke on remote server.
if (server_env.is_valid())

View File

@ -63,7 +63,7 @@ namespace dropshell
// ------------------------------------------------------------------------------------------------
// install service over ssh : SHARED COMMAND
// ------------------------------------------------------------------------------------------------
bool install_service(const server_config &server_env, const std::string &service)
bool install_service(const ServerConfig &server_env, const std::string &service)
{
std::string server = server_env.get_server_name();
LocalServiceInfo service_info = get_service_info(server_env.get_server_name(), service);
@ -271,7 +271,7 @@ namespace dropshell
return 0;
}
int install_server(const server_config &server)
int install_server(const ServerConfig &server)
{
// install the dropshell agent on the given server.
maketitle("Installing dropshell agent on " + server.get_server_name(), sColour::INFO);
@ -321,7 +321,7 @@ namespace dropshell
return rval;
// install the dropshell agent on all servers.
std::vector<server_config> servers = get_configured_servers();
std::vector<ServerConfig> servers = get_configured_servers();
for (const auto &server : servers)
{
rval = install_server(server);
@ -364,7 +364,7 @@ namespace dropshell
return 1;
}
server_config server_env(server);
ServerConfig server_env(server);
ASSERT(server_env.is_valid(), "Invalid server environment for " + server);
if (safearg(ctx.args, 1) == "all")
{

View File

@ -83,44 +83,61 @@ void list_servers() {
tableprint tp("All DropShell Servers");
tp.add_row({"Name", "Address", "User", "Health", "Ports"});
info << "Checking "<<servers.size() << " servers: " << std::flush;
typedef std::map<std::string, shared_commands::ServiceStatus> tServiceStatusMap;
std::vector<tServiceStatusMap> service_status_maps;
typedef struct {dropshell::ServerConfig server; dropshell::UserConfig user;} server_user_pair;
std::vector<server_user_pair> server_user_pairs;
for (const auto& server : servers)
for (const auto& user : server.get_users())
server_user_pairs.push_back({server, user});
// mutex for the tableprint
std::mutex tp_mutex;
info << "Checking "<<server_user_pairs.size() << " agents: " << std::flush;
int checked = 0;
transwarp::parallel exec{servers.size()};
auto task = transwarp::for_each(exec, servers.begin(), servers.end(), [&](const server_config& server) {
server_config server_env(server.get_server_name());
transwarp::parallel exec{server_user_pairs.size()};
auto task = transwarp::for_each(exec, server_user_pairs.begin(), server_user_pairs.end(), [&](const server_user_pair& sup) {
ServerConfig server_env(sup.server.get_server_name());
if (!server_env.is_valid())
{
error << "Invalid server environment for " << server.get_server_name() << std::endl;
error << "Invalid server environment for " << sup.server.get_server_name() << std::endl;
return;
}
int first=true;
for (const auto &user : server_env.get_users())
{
std::map<std::string, shared_commands::ServiceStatus> status = shared_commands::get_all_services_status(server.get_server_name(),user.user);
std::string serviceticks = "";
std::string ports_used_str = "";
std::set<int> ports_used;
std::set<int> ports_used;
std::string serviceticks = "";
for (const auto& [service_name, service_status] : status) {
ports_used.insert(service_status.ports.begin(), service_status.ports.end());
serviceticks += shared_commands::HealthStatus2String(service_status.health) + " ";
}
std::string ports_used_str = "";
for (const auto& port : ports_used)
ports_used_str += std::to_string(port) + " ";
std::map<std::string, shared_commands::ServiceStatus> status = shared_commands::get_all_services_status(sup.server.get_server_name(),sup.user.user);
tp.add_row({(first ? server.get_server_name() : ""), (first ? server.get_SSH_HOST() : ""), user.user, serviceticks, ports_used_str});
first = false;
}
for (const auto& [service_name, service_status] : status) {
ports_used.insert(service_status.ports.begin(), service_status.ports.end());
serviceticks += shared_commands::HealthStatus2String(service_status.health) + " ";
}
++checked;
// print out a tick character for each server checked.
info << checked << "" << std::flush;
for (const auto& port : ports_used)
ports_used_str += std::to_string(port) + " ";
// critical section
{
std::lock_guard<std::mutex> lock(tp_mutex);
tp.add_row({sup.server.get_server_name(), sup.server.get_SSH_HOST(), sup.user.user, serviceticks, ports_used_str});
++checked;
// print out a tick character for each server checked.
info << checked << "" << std::flush;
}
});
task->wait();
info << std::endl << std::endl;
tp.sort({0,2});
tp.print();
}
@ -128,7 +145,7 @@ void list_servers() {
void show_server_details(const std::string& server_name) {
server_config env(server_name);
ServerConfig env(server_name);
if (!env.is_valid()) {
error << "Error: Invalid server environment file: " << server_name << std::endl;
return;

View File

@ -92,7 +92,7 @@ namespace dropshell
std::string service = ctx.args[1];
std::string backup_arg = ctx.args[2];
server_config server_env(server);
ServerConfig server_env(server);
if (!server_env.is_valid())
{
error << "Server " << server << " is not valid" << std::endl;
@ -189,7 +189,7 @@ namespace dropshell
{ // installing fresh service
info << "4) Install of fresh service..." << std::endl;
server_config server_env(server);
ServerConfig server_env(server);
if (!shared_commands::install_service(server_env, service))
return 1;
}

View File

@ -21,7 +21,7 @@ namespace dropshell
if (ctx.args.size() == 0)
{ // just the command, no args yet.
// list servers
std::vector<server_config> servers = get_configured_servers();
std::vector<ServerConfig> servers = get_configured_servers();
for (const auto &server : servers)
{
rawout << server.get_server_name() << std::endl;
@ -54,7 +54,7 @@ namespace dropshell
bool rsync_tree_to_remote(
const std::string &local_path,
const std::string &remote_path,
const server_config &server_env,
const ServerConfig &server_env,
bool silent,
std::string user)
{
@ -85,7 +85,7 @@ namespace dropshell
// ------------------------------------------------------------------------------------------------
// cRemoteTempFolder : SHARED CLASS
// ------------------------------------------------------------------------------------------------
cRemoteTempFolder::cRemoteTempFolder(const server_config &server_env, std::string user) :
cRemoteTempFolder::cRemoteTempFolder(const ServerConfig &server_env, std::string user) :
mServerEnv(server_env), mUser(user)
{
std::string p = remotepath(server_env.get_server_name(),user).temp_files() + "/" + random_alphanumeric_string(10);
@ -110,7 +110,7 @@ namespace dropshell
// ------------------------------------------------------------------------------------------------
// get_all_services_status : SHARED COMMAND
// ------------------------------------------------------------------------------------------------
std::map<std::string, ServiceStatus> get_all_services_status(const server_config & server_env)
std::map<std::string, ServiceStatus> get_all_services_status(const ServerConfig & server_env)
{
std::map<std::string, ServiceStatus> status;
for (const auto& user : server_env.get_users()) {
@ -119,7 +119,7 @@ namespace dropshell
return status;
}
std::map<std::string, ServiceStatus> get_all_services_status(const server_config & server_env, std::string user)
std::map<std::string, ServiceStatus> get_all_services_status(const ServerConfig & server_env, std::string user)
{
std::map<std::string, ServiceStatus> status;
std::string server_name = server_env.get_server_name();
@ -216,7 +216,7 @@ namespace dropshell
// ------------------------------------------------------------------------------------------------
HealthStatus is_healthy(const std::string &server, const std::string &service)
{
server_config env(server);
ServerConfig env(server);
if (!env.is_valid())
{
error << "Server service not initialized" << std::endl;
@ -309,7 +309,7 @@ namespace dropshell
// ------------------------------------------------------------------------------------------------
// scp_file_to_remote : SHARED COMMAND
// ------------------------------------------------------------------------------------------------
bool scp_file_to_remote(const server_config &server_env, const std::string &local_path, const std::string &remote_path, bool silent, std::string user)
bool scp_file_to_remote(const ServerConfig &server_env, const std::string &local_path, const std::string &remote_path, bool silent, std::string user)
{
if (!server_env.is_valid())
{
@ -324,7 +324,7 @@ namespace dropshell
// ------------------------------------------------------------------------------------------------
// scp_file_from_remote : SHARED COMMAND
// ------------------------------------------------------------------------------------------------
bool scp_file_from_remote(const server_config &server_env, const std::string &remote_path, const std::string &local_path, bool silent, std::string user)
bool scp_file_from_remote(const ServerConfig &server_env, const std::string &remote_path, const std::string &local_path, bool silent, std::string user)
{
if (!server_env.is_valid())
{

View File

@ -31,26 +31,26 @@ namespace dropshell
class cRemoteTempFolder
{
public:
cRemoteTempFolder(const server_config &server_env, std::string user); // create a temp folder on the remote server
cRemoteTempFolder(const ServerConfig &server_env, std::string user); // create a temp folder on the remote server
~cRemoteTempFolder(); // delete the temp folder on the remote server
std::string path() const; // get the path to the temp folder on the remote server
private:
std::string mPath;
const server_config &mServerEnv;
const ServerConfig &mServerEnv;
std::string mUser;
};
bool rsync_tree_to_remote(
const std::string &local_path,
const std::string &remote_path,
const server_config &server_env,
const ServerConfig &server_env,
bool silent,
std::string user);
std::string get_arch();
std::map<std::string, ServiceStatus> get_all_services_status(const server_config & server_env);
std::map<std::string, ServiceStatus> get_all_services_status(const server_config & server_env, std::string user);
std::map<std::string, ServiceStatus> get_all_services_status(const ServerConfig & server_env);
std::map<std::string, ServiceStatus> get_all_services_status(const ServerConfig & server_env, std::string user);
std::string healthtick(const std::string &server, const std::string &service);
std::string HealthStatus2String(HealthStatus status);
@ -81,20 +81,20 @@ namespace dropshell
std::string mDatetime;
};
bool scp_file_to_remote(const server_config &server_env, const std::string &local_path, const std::string &remote_path, bool silent, std::string user);
bool scp_file_from_remote(const server_config &server_env, const std::string &remote_path, const std::string &local_path, bool silent, std::string user);
bool scp_file_to_remote(const ServerConfig &server_env, const std::string &local_path, const std::string &remote_path, bool silent, std::string user);
bool scp_file_from_remote(const ServerConfig &server_env, const std::string &remote_path, const std::string &local_path, bool silent, std::string user);
// defined in backupdata.cpp, used by restoredata.cpp.
bool backupdata_service(const server_config &server_env, const std::string& service);
bool backupdata_service(const ServerConfig &server_env, const std::string& service);
// defined in uninstall.cpp
bool uninstall_service(const server_config &server_env, const std::string &service);
bool uninstall_service(const ServerConfig &server_env, const std::string &service);
// defined in nuke.cpp
bool nuke_service(const std::string &server, const std::string &service);
// defined in install.cpp
bool install_service(const server_config &server_env, const std::string &service);
bool install_service(const ServerConfig &server_env, const std::string &service);
// defined in create-service.cpp
bool create_service(const std::string &server_name, const std::string &template_name, const std::string &service_name, std::string user_override="");

View File

@ -42,7 +42,7 @@ namespace dropshell
bool ssh_into_server(const std::string &server, std::string user)
{
server_config server_env(server);
ServerConfig server_env(server);
if (!server_env.is_valid())
{
error << "Server " << server << " is not valid" << std::endl;
@ -54,7 +54,7 @@ namespace dropshell
bool ssh_into_service(const std::string &server, const std::string &service)
{
server_config server_env(server);
ServerConfig server_env(server);
if (!server_env.is_valid())
{
error << "Server " << server << " is not valid" << std::endl;
@ -109,7 +109,7 @@ namespace dropshell
server = arg1;
// get the first user from the server.env file, and ssh in as that user.
server_config server_env(server);
ServerConfig server_env(server);
if (!server_env.is_valid())
{
error << "Server " << server << " is not valid" << std::endl;

View File

@ -44,7 +44,7 @@ namespace dropshell
bool start_service(const std::string &server, const std::string &service)
{
server_config server_env(server);
ServerConfig server_env(server);
if (!server_env.is_valid())
{
error << "Server " << server << " is not valid" << std::endl;

View File

@ -44,7 +44,7 @@ namespace dropshell
bool stop_service(const std::string &server, const std::string &service)
{
server_config server_env(server);
ServerConfig server_env(server);
if (!server_env.is_valid())
{
error << "Server " << server << " is not valid" << std::endl;

View File

@ -42,7 +42,7 @@ namespace dropshell
} uninstall_command_register;
namespace shared_commands {
bool uninstall_service(const server_config & server_env, const std::string &service)
bool uninstall_service(const ServerConfig & server_env, const std::string &service)
{
ASSERT(server_env.is_valid(), "Invalid server environment for " + server_env.get_server_name());
std::string server = server_env.get_server_name();