Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync scheduler overhaul #15

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2ab2c11
i may have forgotten to commit along the way
carykees98 Nov 20, 2024
28f08ad
updated doxygen comments in utils.hpp and updated `read_JSON_from_file`
carykees98 Nov 20, 2024
df365f8
updated cmakelists
carykees98 Feb 7, 2025
c50837f
source changes (I need committing to be more alluring else I'll conti…
carykees98 Feb 7, 2025
6ece08c
remove mirror logging
carykees98 Feb 7, 2025
d9dd75e
removed mirror-logging dependency
carykees98 Feb 13, 2025
0eea85a
add ability to load logging level from environment variable
carykees98 Feb 13, 2025
39ea32d
successfully built sync schedule
carykees98 Feb 13, 2025
2d7005c
renamed load_config
carykees98 Feb 13, 2025
0092eea
added error printing to load_mirrors_config when file is not good
carykees98 Feb 13, 2025
c34bc92
include json_fwd
carykees98 Feb 13, 2025
2ab2c7c
changed exception names to abbreviations of the exception type
carykees98 Feb 13, 2025
7fa7f2a
renamed Project to SyncDetails
carykees98 Feb 16, 2025
71e94f5
added project catalogue using statement
carykees98 Feb 16, 2025
0fe4677
removed thread pool files
carykees98 Feb 16, 2025
cfdcc6d
moved project list to SyncScheduler from Schedule
carykees98 Feb 16, 2025
365132b
renamed Project to SyncDetails
carykees98 Feb 16, 2025
3621bd7
initialize project catalogue in initizlizer list
carykees98 Feb 16, 2025
c006931
declaration order matters, not just initialization list order
carykees98 Feb 16, 2025
7d9e455
sync-scheduler, website: Implement API for manual syncing
brendanjconnelly Feb 16, 2025
15da7b6
renamed Project to SyncDetails
carykees98 Feb 16, 2025
d274564
added project catalogue using statement
carykees98 Feb 16, 2025
f0da05f
removed thread pool files
carykees98 Feb 16, 2025
158bb97
moved project list to SyncScheduler from Schedule
carykees98 Feb 16, 2025
121c248
renamed Project to SyncDetails
carykees98 Feb 16, 2025
8106062
initialize project catalogue in initizlizer list
carykees98 Feb 16, 2025
2989966
sync-scheduler, website: Implement API for manual syncing
brendanjconnelly Feb 16, 2025
1c97b91
Fix cmake
brendanjconnelly Feb 16, 2025
6db7551
renamed Project to SyncDetails
carykees98 Feb 16, 2025
e68ca29
declaration order matters, not just initialization list order
carykees98 Feb 16, 2025
85976fa
sync-scheduler, website: Implement API for manual syncing
brendanjconnelly Feb 16, 2025
8fce6c0
renamed Project to SyncDetails
carykees98 Feb 16, 2025
ac32359
Fix cmake again
brendanjconnelly Feb 16, 2025
c3d7cad
Merge branch 'sync-scheduler-overhaul' into manual-sync-endpoint
brendanjconnelly Feb 16, 2025
63875c8
frequent commits? never heard of them unfortunately
carykees98 Feb 18, 2025
406f1a4
added JobManager to CMakeLists
carykees98 Feb 18, 2025
0d9f656
remove storage directory
carykees98 Feb 18, 2025
f6880f0
remove src-old
carykees98 Feb 18, 2025
1665a3e
remove TODO.md
carykees98 Feb 18, 2025
990a22b
renamed sync scheduler config
carykees98 Feb 18, 2025
e05408a
Merge branch 'sync-scheduler-overhaul' into manual-sync-endpoint
carykees98 Feb 18, 2025
9073c2a
Merge pull request #38 from COSI-Lab/manual-sync-endpoint
carykees98 Feb 18, 2025
78d8455
integrate manual sync
carykees98 Feb 18, 2025
73fe166
Merge branch 'main' into sync-scheduler-overhaul
carykees98 Feb 18, 2025
9919994
remove scripts directory
carykees98 Feb 18, 2025
837a669
renamed is_job_running to job_is_running
carykees98 Feb 19, 2025
8cb1ae3
check if job is running before starting new sync
carykees98 Feb 19, 2025
cb686f7
added clang-tidy for sync scheduler to disable check causing issues w…
carykees98 Feb 19, 2025
836a961
add zmq as a cmake dependency
carykees98 Feb 19, 2025
fbedfba
resolved clang tidy variable naming issues
carykees98 Feb 19, 2025
a549200
updated clang-tidy CMake config
carykees98 Feb 19, 2025
ce8f980
turned off clang tidy
carykees98 Feb 27, 2025
da43e00
updated dockerfile
carykees98 Feb 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ services:
sync-scheduler:
build: ./mirror-sync-scheduler
container_name: mirror-sync-scheduler
expose:
- 9281
volumes:
- "./mirror-sync-scheduler/storage:/storage"
- "./mirror-sync-scheduler/configs:/mirror/configs:ro"
Expand Down
2 changes: 2 additions & 0 deletions docker-compose-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ services:
sync-scheduler:
build: ./mirror-sync-scheduler
container_name: mirror-sync-scheduler
expose:
- 9281
restart: unless-stopped
volumes:
- "/storage:/storage"
Expand Down
3 changes: 3 additions & 0 deletions mirror-sync-scheduler/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
InheritParentConfig: true
Checks:
- -clang-analyzer-optin.cplusplus.UninitializedObject # spdlog causing issues
27 changes: 10 additions & 17 deletions mirror-sync-scheduler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
cmake_minimum_required(VERSION 3.22)
project(syncScheduler)
cmake_minimum_required(VERSION 3.20...3.30)

find_program(CLANG_TIDY_EXE NAMES "clang-tidy-20" "clang-tidy" REQUIRED)
set(CLANG_TIDY_COMMAND ${CLANG_TIDY_EXE} --header-filter=${CMAKE_SOURCE_DIR}/include)

add_executable(${PROJECT_NAME}
src/main.cpp
src/schedule.cpp
src/queue.cpp
)

include(FetchContent)
set(CPPZMQ_BUILD_TESTS OFF CACHE INTERNAL "")

FetchContent_Declare(json
GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG v3.11.3
project(syncScheduler
LANGUAGES CXX
)
FetchContent_MakeAvailable(json)

add_subdirectory(lib/mirror-logging)
include(cmake/fetch_deps.cmake)

add_subdirectory(src)

target_link_libraries(${PROJECT_NAME}
PUBLIC mirror-logging
PRIVATE nlohmann_json::nlohmann_json
)
21 changes: 10 additions & 11 deletions mirror-sync-scheduler/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
FROM ubuntu:24.04 as builder
RUN apt update && apt install -y g++ cmake libzmq3-dev ninja-build git
WORKDIR /mirror
COPY ./src /mirror/src
COPY ./lib /mirror/lib
COPY ./CMakeLists.txt /mirror/CMakeLists.txt
RUN cmake -S/mirror -B/mirror/build -G Ninja
RUN cmake --build /mirror/build --target clean
RUN cmake --build /mirror/build --target all
COPY src src
COPY include include
COPY cmake cmake
COPY CMakeLists.txt CMakeLists.txt
RUN cmake -B build -G Ninja
RUN cmake --build build --target all

# Run
FROM ubuntu:24.04
RUN apt update && apt install -y python3 curl wget
RUN apt install -y libzmq3-dev rsync
RUN apt update && apt install -y python3 curl wget libzmq3-dev rsync
WORKDIR /mirror
COPY --from=builder /mirror/build/syncScheduler .
RUN chmod 744 syncScheduler
ENTRYPOINT ["./syncScheduler"]
COPY --from=builder /mirror/build/src/sync_scheduler .
RUN chmod 744 sync_scheduler
ENTRYPOINT ["./sync_scheduler"]
19 changes: 19 additions & 0 deletions mirror-sync-scheduler/cmake/fetch_deps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
include(FetchContent)

FetchContent_Declare(json
GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG v3.11.3
)
FetchContent_MakeAvailable(json)

FetchContent_Declare(spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog
GIT_TAG v1.15.1
)
FetchContent_MakeAvailable(spdlog)

FetchContent_Declare(cppzmq
GIT_REPOSITORY https://github.com/zeromq/cppzmq
GIT_TAG v4.10.0
)
FetchContent_MakeAvailable(cppzmq)
7 changes: 2 additions & 5 deletions mirror-sync-scheduler/configs/sync-scheduler.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"dryrun" : true,
"queueThreads" : 8,
"logServerPort": 4001,
"logServerHost": "localhost"
}
"dry_run": true
}
60 changes: 60 additions & 0 deletions mirror-sync-scheduler/include/mirror/sync_scheduler/JobManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @file JobManager.hpp
* @author Cary Keesler
* @brief
*/

#pragma once

// System Includes
#include <sys/types.h>

// Standard Library Includes
#include <chrono>
#include <condition_variable>
#include <filesystem>
#include <map>
#include <mutex>
#include <string>
#include <thread>
#include <vector>

// Project Includes
#include <mirror/sync_scheduler/SyncJob.hpp>

namespace mirror::sync_scheduler
{
class JobManager
{
public: // Constructors
JobManager();
~JobManager();

public: // Methods
auto job_is_running(const std::string& jobName) -> bool
{
return m_ActiveJobs.contains(jobName);
}

auto start_job(
const std::string& jobName,
std::string command,
const std::filesystem::path& passwordFile
) -> bool;

private:
auto register_job(const std::string& jobName, const ::pid_t processID)
-> void;
auto kill_job(const std::string& jobName) -> void;
auto kill_all_jobs() -> void;
auto reap_processes() -> std::vector<std::string>;
auto deregister_jobs(const std::vector<std::string>& completedJobs) -> void;

private: // Members
std::map<std::string, SyncJob> m_ActiveJobs;
std::jthread m_ProcessReaper;
std::condition_variable m_SleepVariable;
std::mutex m_JobMutex;
std::mutex m_ReaperMutex;
};
} // namespace mirror::sync_scheduler
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @file ProjectCatalogue.hpp
* @author Cary Keesler
* @brief
*/

#pragma once

// Standard Library Includes
#include <map>
#include <string>

// Project Includes
#include <mirror/sync_scheduler/SyncDetails.hpp>

namespace mirror::sync_scheduler
{
using ProjectCatalogue = std::map<std::string, SyncDetails>;
} // namespace mirror::sync_scheduler
47 changes: 47 additions & 0 deletions mirror-sync-scheduler/include/mirror/sync_scheduler/Schedule.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @file Schedule.hpp
* @author Cary Keesler
* @brief
*/

#pragma once

// Standard Library Includes
#include <chrono>
#include <cstddef>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

// Third Party Library Includes
#include <nlohmann/json.hpp>

// Project Includes
#include <mirror/sync_scheduler/ProjectCatalogue.hpp>
#include <mirror/sync_scheduler/SyncDetails.hpp>

namespace mirror::sync_scheduler
{
class Schedule
{
public: // Constructors
explicit Schedule(const ProjectCatalogue& projects);

public: // Methods
[[nodiscard]]
auto get_next_sync_batch() -> std::pair<
std::chrono::time_point<std::chrono::system_clock>,
std::set<std::string>>;

private: // Methods
auto build(const ProjectCatalogue& projects) -> void;
auto verify(const ProjectCatalogue& projects) -> void;
auto determine_sync_lcm(const ProjectCatalogue& projects) -> void;

private: // Members
std::vector<std::set<std::string>> m_SyncIntervals;
std::size_t m_SyncLCM;
};
} // namespace mirror::sync_scheduler
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* @file SyncDetails.hpp
* @author Cary Keesler
* @brief
*/

#pragma once

// Standard Library Includes
#include <cstddef>
#include <cstdint>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>

// Third Party Library Includes
#include <nlohmann/json.hpp>

namespace mirror::sync_scheduler
{
enum class SyncMethod : std::uint8_t
{
SCRIPT,
RSYNC,
UNSET,
};

class SyncDetails
{
public: // Constructors
explicit SyncDetails(const nlohmann::json& project);

public: // Methods
[[nodiscard]]
auto get_syncs_per_day() const -> std::size_t
{
return m_SyncConfig.at("syncs_per_day").get<std::size_t>();
}

[[nodiscard]]
auto get_sync_method() const -> SyncMethod
{
return m_SyncMethod;
}

[[nodiscard]]
auto get_password_file() const -> nlohmann::json
{
return m_SyncConfig.value("password_file", "");
}

[[nodiscard]]
auto get_sync_config() const -> nlohmann::json
{
return m_SyncConfig;
}

private: // Methods
[[nodiscard]]
static auto compose_rsync_command(
const nlohmann::json& rsyncConfig,
const std::string& optionsKey
) -> std::string;

[[nodiscard]]
static auto generate_sync_config(const nlohmann::json& project)
-> std::pair<SyncMethod, nlohmann::json>;

[[nodiscard]]
static auto generate_rsync_config(const nlohmann::json& project)
-> std::pair<SyncMethod, nlohmann::json>;

[[nodiscard]]
static auto generate_script_config(const nlohmann::json& project)
-> std::pair<SyncMethod, nlohmann::json>;

private: // Members
SyncMethod m_SyncMethod;
nlohmann::json m_SyncConfig;
};

struct static_project_exception : std::runtime_error
{
using std::runtime_error::runtime_error;
};
} // namespace mirror::sync_scheduler
22 changes: 22 additions & 0 deletions mirror-sync-scheduler/include/mirror/sync_scheduler/SyncJob.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @file SyncJob.hpp
* @author Cary Keesler
* @brief
*/

#pragma once

// System Includes
#include <unistd.h>

// Standard Library Includes
#include <chrono>

namespace mirror::sync_scheduler
{
struct SyncJob
{
::pid_t processID = 0;
std::chrono::time_point<std::chrono::system_clock> startTime;
};
} // namespace mirror::sync_scheduler
Loading