Compiles.
This commit is contained in:
parent
95185d3149
commit
27e5cce367
@ -372,33 +372,6 @@ std::string service_runner::HealthStatus2String(HealthStatus status)
|
||||
return ":error:";
|
||||
}
|
||||
|
||||
bool service_runner::ensure_service_dropshell_files_up_to_date()
|
||||
{
|
||||
if (!mServerEnv.is_valid()) {
|
||||
std::cerr << "Error: Server service not initialized" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if the service template and config are up to date on the remote server.
|
||||
service_versions versions(mServer, mService);
|
||||
if (versions.remote_up_to_date())
|
||||
return true;
|
||||
|
||||
if (!versions.remote_template_is_up_to_date()) {
|
||||
std::cerr << "Error: Service template is not up to date on the remote server" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!versions.remote_config_is_up_to_date()) {
|
||||
std::cerr << "Error: Service config is not up to date on the remote server" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO - actually update things!
|
||||
|
||||
versions.update_stored_remote_versions();
|
||||
return versions.remote_up_to_date();
|
||||
}
|
||||
|
||||
std::string service_runner::healthmark()
|
||||
{
|
||||
|
@ -60,9 +60,6 @@ class service_runner {
|
||||
static std::map<std::string, ServiceStatus> get_all_services_status(std::string server_name);
|
||||
static std::string HealthStatus2String(HealthStatus status);
|
||||
|
||||
// ensure the service related dropshell files (template and config) are up to date on the remote server.
|
||||
bool ensure_service_dropshell_files_up_to_date();
|
||||
|
||||
private:
|
||||
// install the service over ssh, using the credentials from server.env (via server_env.hpp), by:
|
||||
// 1. check if the server_name exists, and the service_name refers to a valid template
|
||||
@ -111,33 +108,6 @@ void interactive_ssh(const std::string & server_name, const std::string & comman
|
||||
void edit_server(const std::string & server_name);
|
||||
bool edit_file(const std::string & file_path);
|
||||
|
||||
// check if the service template and config are up to date on the remote server.
|
||||
class service_versions {
|
||||
public:
|
||||
service_versions(const std::string & server_name, const std::string & service_name);
|
||||
|
||||
bool remote_up_to_date() { return remote_template_is_up_to_date() && remote_config_is_up_to_date(); }
|
||||
|
||||
bool remote_template_is_up_to_date() { return get_version_remote_service_template() == calculate_version_local_service_template(); }
|
||||
bool remote_config_is_up_to_date() { return get_version_remote_config() == calculate_version_local_config(); }
|
||||
|
||||
uint64_t calculate_version_local_service_template();
|
||||
uint64_t calculate_version_local_config();
|
||||
|
||||
void update_stored_remote_versions();
|
||||
uint64_t get_version_remote_config();
|
||||
uint64_t get_version_remote_service_template();
|
||||
|
||||
private:
|
||||
uint64_t calculate_version_remote_service_template();
|
||||
uint64_t calculate_version_remote_config();
|
||||
|
||||
private:
|
||||
std::string m_server_name;
|
||||
std::string m_service_name;
|
||||
};
|
||||
|
||||
|
||||
} // namespace dropshell
|
||||
|
||||
#endif // SERVICE_RUNNER_HPP
|
||||
|
@ -12,10 +12,10 @@
|
||||
#include "utils/utils.hpp"
|
||||
#include "templates.hpp"
|
||||
#include "config.hpp"
|
||||
#include "utils/assert.hpp"
|
||||
|
||||
namespace dropshell {
|
||||
|
||||
|
||||
std::set<std::string> template_source_local::get_template_list() {
|
||||
std::set<std::string> templates;
|
||||
|
||||
@ -76,7 +76,40 @@
|
||||
std::cout << std::string(60, '-') << std::endl;
|
||||
}
|
||||
|
||||
void template_manager::create_template(const std::string& template_name) {
|
||||
std::set<std::string> template_manager::get_template_list()
|
||||
{
|
||||
std::set<std::string> templates;
|
||||
for (const auto& source : mSources) {
|
||||
auto source_templates = source->get_template_list();
|
||||
templates.insert(source_templates.begin(), source_templates.end());
|
||||
}
|
||||
return templates;
|
||||
}
|
||||
|
||||
bool template_manager::has_template(const std::string &template_name)
|
||||
{
|
||||
template_source_interface* source = get_source(template_name);
|
||||
if (!source)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template_info template_manager::get_template_info(const std::string &template_name)
|
||||
{
|
||||
template_source_interface* source = get_source(template_name);
|
||||
if (!source) {
|
||||
return template_info();
|
||||
}
|
||||
return source->get_template_info(template_name);
|
||||
}
|
||||
|
||||
bool template_manager::template_command_exists(const std::string &template_name, const std::string &command)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void template_manager::create_template(const std::string &template_name)
|
||||
{
|
||||
// 1. Create a new directory in the user templates directory
|
||||
std::vector<std::string> local_server_definition_paths = gConfig().get_local_server_definition_paths();
|
||||
|
||||
@ -156,6 +189,25 @@
|
||||
test_template(new_template_path);
|
||||
}
|
||||
|
||||
void template_manager::load_sources()
|
||||
{
|
||||
ASSERT(mSources.empty());
|
||||
auto local_template_paths = gConfig().get_template_local_paths();
|
||||
if (local_template_paths.empty()) {
|
||||
std::cerr << "Error: No local template paths found" << std::endl;
|
||||
std::cerr << "Run 'dropshell edit' to add one to the DropShell config" << std::endl;
|
||||
return;
|
||||
}
|
||||
for (const auto& path : local_template_paths) {
|
||||
mSources.push_back(std::make_unique<template_source_local>(path));
|
||||
}
|
||||
|
||||
auto registry_urls = gConfig().get_template_registry_urls();
|
||||
for (const auto& url : registry_urls) {
|
||||
mSources.push_back(std::make_unique<template_source_registry>(url));
|
||||
}
|
||||
}
|
||||
|
||||
bool template_manager::required_file(std::string path, std::string template_name)
|
||||
{
|
||||
if (!std::filesystem::exists(path)) {
|
||||
@ -165,6 +217,16 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
template_source_interface *template_manager::get_source(const std::string &template_name)
|
||||
{
|
||||
for (const auto& source : mSources) {
|
||||
if (source->has_template(template_name)) {
|
||||
return source.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool template_manager::test_template(const std::string &template_path)
|
||||
{
|
||||
std::string template_name = std::filesystem::path(template_path).filename().string();
|
||||
@ -227,4 +289,34 @@
|
||||
return instance;
|
||||
}
|
||||
|
||||
std::set<std::string> template_source_registry::get_template_list()
|
||||
{
|
||||
#pragma message("TODO: Implement template_source_registry::get_template_list")
|
||||
return std::set<std::string>();
|
||||
}
|
||||
|
||||
bool template_source_registry::has_template(const std::string& template_name)
|
||||
{
|
||||
#pragma message("TODO: Implement template_source_registry::has_template")
|
||||
return false;
|
||||
}
|
||||
|
||||
template_info template_source_registry::get_template_info(const std::string& template_name)
|
||||
{
|
||||
#pragma message("TODO: Implement template_source_registry::get_template_info")
|
||||
return template_info();
|
||||
}
|
||||
|
||||
bool template_source_registry::template_command_exists(const std::string& template_name, const std::string& command)
|
||||
{
|
||||
#pragma message("TODO: Implement template_source_registry::template_command_exists")
|
||||
return false;
|
||||
}
|
||||
|
||||
std::filesystem::path template_source_registry::get_cache_dir()
|
||||
{
|
||||
#pragma message("TODO: Implement template_source_registry::get_cache_dir")
|
||||
return std::filesystem::path();
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
||||
|
@ -86,6 +86,7 @@ class template_manager {
|
||||
private:
|
||||
void load_sources();
|
||||
bool required_file(std::string path, std::string template_name);
|
||||
template_source_interface* get_source(const std::string& template_name);
|
||||
|
||||
private:
|
||||
bool mLoaded;
|
||||
|
Loading…
x
Reference in New Issue
Block a user