From b6febcc05337395f6839931b113e58c9d5acd3d5 Mon Sep 17 00:00:00 2001 From: Ian Roddis Date: Thu, 3 Jun 2021 18:43:37 -0300 Subject: [PATCH] Checkpointing work, fighting with cmake --- cmake/Pistache.cmake | 12 ++++++-- daggy/CMakeLists.txt | 8 +++-- daggy/include/daggy/Executor.hpp | 4 ++- daggy/include/daggy/Server.hpp | 29 +++++++++++++++++ daggy/src/Server.cpp | 53 ++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 daggy/include/daggy/Server.hpp create mode 100644 daggy/src/Server.cpp diff --git a/cmake/Pistache.cmake b/cmake/Pistache.cmake index cf113a3..a4d07b2 100644 --- a/cmake/Pistache.cmake +++ b/cmake/Pistache.cmake @@ -1,9 +1,15 @@ -project(pistache NONE) include(ExternalProject) -ExternalProject_Add(pistache +set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/external) + +ExternalProject_Add(pistache_extern GIT_REPOSITORY https://github.com/pistacheio/pistache.git GIT_TAG master + #CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} INSTALL_COMMAND "" - TEST_COMMAND "" ) +# include_directories(${EXTERNAL_INSTALL_LOCATION}/include) +# link_directories(${EXTERNAL_INSTALL_LOCATION}/lib) + +#add_library(pistache STATIC IMPORTED GLOBAL) +#SET_PROPERTY(TARGET pistache IMPORTED_LOCATION ${EXTERNA_INSTALL_LOCATION}) diff --git a/daggy/CMakeLists.txt b/daggy/CMakeLists.txt index 15c3b86..f8c70ea 100644 --- a/daggy/CMakeLists.txt +++ b/daggy/CMakeLists.txt @@ -1,5 +1,9 @@ project(daggy) +ExternalProject_Add_StepDependencies(pistache_extern build) + file(GLOB SOURCES src/*.cpp) -add_library(daggy SHARED ${SOURCES}) -target_include_directories(daggy PUBLIC include) +add_library(${PROJECT_NAME} SHARED ${SOURCES}) +target_include_directories(${PROJECT_NAME} PUBLIC include) +add_dependencies(${PROJECT_NAME} pistache_extern) +target_link_libraries(${PROJECT_NAME} pistache_static pthread) diff --git a/daggy/include/daggy/Executor.hpp b/daggy/include/daggy/Executor.hpp index a9e822c..840077b 100644 --- a/daggy/include/daggy/Executor.hpp +++ b/daggy/include/daggy/Executor.hpp @@ -29,8 +29,10 @@ namespace daggy { class Executor { public: - Executor(size_t maxParallelism) : maxParallelism_(maxPA + Executor(size_t maxParallelism) : maxParallelism_(maxParallelism); virtual const std::string getName() const = 0; + + // This will block if the executor is full virtual std::future runTask(Task & task) = 0; private: size_t maxParallelism_; diff --git a/daggy/include/daggy/Server.hpp b/daggy/include/daggy/Server.hpp new file mode 100644 index 0000000..90ab7df --- /dev/null +++ b/daggy/include/daggy/Server.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include + +#include + +namespace daggy { + class Server { + public: + Server(Address addr) + : endpoint_(addr) + , desc("Daggy API", "0.1") + {} + + void init(int threads = 1); + void start(); + + private: + void createDescription(); + + + Pistache::Http::Endpoint endpoint_; + Pistache::Rest::Description desc_; + Pistache::Router router_; + + }; +} diff --git a/daggy/src/Server.cpp b/daggy/src/Server.cpp new file mode 100644 index 0000000..4e631e4 --- /dev/null +++ b/daggy/src/Server.cpp @@ -0,0 +1,53 @@ +#include + +namespace daggy { + void Server::init(int threads = 1) { + auto opts = Http::Endpoint::options() + .threads(threads) + ; + endpoint_->init(opts); + createDescription(); + } + + void Server::start() { + router.initFromDescription(desc_); + + httpEndpoint->setHandler(router.handler()); + httpEndpoint->serve(); + } + + void Server::createDescription() { + desc_ + .info() + .license("Apache", "http://www.apache.org/licenses/LICENSE-2.0") + ; + + + auto backendErrorResponse = desc_.response(Http::Code::Internal_Server_Error, "An error occured with the backend"); + + desc_ + .schemes(Rest::Scheme::Http) + .basePath("/v1") + .produces(MIME(Application, Json)) + .consumes(MIME(Application, Json)); + + desc_ + .route(desc_.get("/ready")) + .bind(&Generic::handleReady) + .response(Http::Code::Ok, "Response to the /ready call") + .hide(); + + auto versionPath = desc_.path("/v1"); + + auto accountsPath = versionPath.path("/accounts"); + + /* + accountsPath + .route(desc_.get("/all")) + .bind(&BankerService::retrieveAllAccounts, this) + .produces(MIME(Application, Json), MIME(Application, Xml)) + .response(Http::Code::Ok, "The list of all account"); + */ + + } +}