diff --git a/update_version.sh b/update_version.sh index 61b43ad0..004464c0 100644 --- a/update_version.sh +++ b/update_version.sh @@ -32,14 +32,12 @@ wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${OPE SRC=' version:.*' DST=" version: $VERSION" sed -i -e "s/$SRC/$DST/" broker/jfjoch_api.yaml -sed -i -e "s/$SRC/$DST/" writer/writer_api.yaml git rm broker/gen/model/*.cpp broker/gen/model/*.h frontend/src/openapi/models/*.ts docs/python_client/* docs/python_client/docs/* java -jar openapi-generator-cli.jar generate -i broker/jfjoch_api.yaml -o python-client/ -g python --git-host=git.psi.ch --git-repo-id jungfraujoch --git-user-id jungfraujoch --additional-properties=packageName=jfjoch_client,packageVersion=$VERSION java -jar openapi-generator-cli.jar generate -i broker/jfjoch_api.yaml -o broker/gen -g cpp-pistache-server -java -jar openapi-generator-cli.jar generate -i writer/writer_api.yaml -o writer/gen -g cpp-pistache-server cd frontend sed -i s/\".*\"/\"$VERSION\"/g src/version.ts diff --git a/writer/CMakeLists.txt b/writer/CMakeLists.txt index 6a75deed..8b060291 100644 --- a/writer/CMakeLists.txt +++ b/writer/CMakeLists.txt @@ -29,14 +29,6 @@ ADD_LIBRARY(JFJochWriter STATIC TARGET_LINK_LIBRARIES(JFJochWriter JFJochPreview JFJochImagePuller JFJochLogger JFJochHDF5Wrappers CBORStream2FrameSerialize) -AUX_SOURCE_DIRECTORY(gen/model MODEL_SOURCES) -ADD_LIBRARY(WriterAPI STATIC ${MODEL_SOURCES} gen/api/DefaultApi.cpp gen/api/DefaultApi.h JFJochWriterHttp.h JFJochWriterHttp.cpp) - -TARGET_LINK_LIBRARIES(WriterAPI JFJochWriter pistache_static) -TARGET_INCLUDE_DIRECTORIES(WriterAPI PUBLIC gen/model gen/api) - -ADD_EXECUTABLE(jfjoch_writer jfjoch_writer.cpp JFJochWriterHttp.h JFJochWriterHttp.cpp - HDF5DataFilePluginReflection.cpp - HDF5DataFilePluginReflection.h) -TARGET_LINK_LIBRARIES(jfjoch_writer JFJochWriter WriterAPI) +ADD_EXECUTABLE(jfjoch_writer jfjoch_writer.cpp) +TARGET_LINK_LIBRARIES(jfjoch_writer JFJochWriter) INSTALL(TARGETS jfjoch_writer RUNTIME COMPONENT writer) diff --git a/writer/JFJochWriterHttp.cpp b/writer/JFJochWriterHttp.cpp deleted file mode 100644 index 8f2f6830..00000000 --- a/writer/JFJochWriterHttp.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute -// SPDX-License-Identifier: GPL-3.0-only - -#include "../common/GitInfo.h" -#include "JFJochWriterHttp.h" -#include "gen/model/Writer_statistics.h" - -void JFJochWriterHttp::status_get(Pistache::Http::ResponseWriter &response) { - auto stat = writer.GetStatistics(); - org::openapitools::server::model::Writer_statistics resp_struct; - resp_struct.setNimages(stat.processed_images); - resp_struct.setPerformanceMBs(stat.performance_MBs); - resp_struct.setPerformanceHz(stat.performance_Hz); - resp_struct.setFilePrefix(stat.file_prefix); - resp_struct.setRunName(stat.run_name); - resp_struct.setRunNumber(stat.run_number); - resp_struct.setSocketNumber(stat.socket_number); - switch (stat.state) { - case StreamWriterState::Idle: - resp_struct.setState("idle"); - break; - case StreamWriterState::Started: - resp_struct.setState("started"); - break; - case StreamWriterState::Receiving: - resp_struct.setState("receiving"); - break; - case StreamWriterState::Error: - resp_struct.setState("error"); - break; - } - - nlohmann::json j = resp_struct; - response.send(Pistache::Http::Code::Ok, j.dump(), MIME(Application, Json)); -} - -void JFJochWriterHttp::cancel_post(Pistache::Http::ResponseWriter &response) { - writer.Cancel(); - response.send(Pistache::Http::Code::Ok); -} - -JFJochWriterHttp::JFJochWriterHttp(StreamWriter &in_writer, std::shared_ptr &rtr) -: DefaultApi(rtr), writer(in_writer){ - init(); -} - -void JFJochWriterHttp::version_get(Pistache::Http::ResponseWriter &response) { - response.send(Pistache::Http::Code::Ok, jfjoch_version(), MIME(Text, Plain)); -} diff --git a/writer/JFJochWriterHttp.h b/writer/JFJochWriterHttp.h deleted file mode 100644 index 6155aa6e..00000000 --- a/writer/JFJochWriterHttp.h +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute -// SPDX-License-Identifier: GPL-3.0-only - -#ifndef JUNGFRAUJOCH_JFJOCHWRITERHTTP_H -#define JUNGFRAUJOCH_JFJOCHWRITERHTTP_H - -#include -#include -#include - -#include "../common/Logger.h" -#include "StreamWriter.h" -#include "gen/api/DefaultApi.h" - -class JFJochWriterHttp : public org::openapitools::server::api::DefaultApi { - StreamWriter& writer; - - void status_get(Pistache::Http::ResponseWriter &response) override; - - void version_get(Pistache::Http::ResponseWriter &response) override; - - void cancel_post(Pistache::Http::ResponseWriter &response) override; -public: - JFJochWriterHttp(StreamWriter& writer, std::shared_ptr &rtr); -}; - - -#endif //JUNGFRAUJOCH_JFJOCHWRITERHTTP_H diff --git a/writer/gen/api/ApiBase.h b/writer/gen/api/ApiBase.h deleted file mode 100644 index 8f3f4e74..00000000 --- a/writer/gen/api/ApiBase.h +++ /dev/null @@ -1,39 +0,0 @@ -/** -* Jungfraujoch writer -* Jungfraujoch Writer Web API -* -* The version of the OpenAPI document: 1.0.0-rc.116 -* Contact: filip.leonarski@psi.ch -* -* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). -* https://openapi-generator.tech -* Do not edit the class manually. -*/ -/* - * ApiBase.h - * - * Generalization of the Api classes - */ - -#ifndef ApiBase_H_ -#define ApiBase_H_ - -#include -#include - -namespace org::openapitools::server::api -{ - -class ApiBase { -public: - explicit ApiBase(const std::shared_ptr& rtr) : router(rtr) {}; - virtual ~ApiBase() = default; - virtual void init() = 0; - -protected: - const std::shared_ptr router; -}; - -} // namespace org::openapitools::server::api - -#endif /* ApiBase_H_ */ diff --git a/writer/gen/api/DefaultApi.cpp b/writer/gen/api/DefaultApi.cpp deleted file mode 100644 index ab5c26e0..00000000 --- a/writer/gen/api/DefaultApi.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/** -* Jungfraujoch writer -* Jungfraujoch Writer Web API -* -* The version of the OpenAPI document: 1.0.0-rc.116 -* Contact: filip.leonarski@psi.ch -* -* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). -* https://openapi-generator.tech -* Do not edit the class manually. -*/ - -#include "DefaultApi.h" -#include "Helpers.h" - -namespace org::openapitools::server::api -{ - -using namespace org::openapitools::server::helpers; -using namespace org::openapitools::server::model; - -const std::string DefaultApi::base = ""; - -DefaultApi::DefaultApi(const std::shared_ptr& rtr) - : ApiBase(rtr) -{ -} - -void DefaultApi::init() { - setupRoutes(); -} - -void DefaultApi::setupRoutes() { - using namespace Pistache::Rest; - - Routes::Post(*router, base + "/cancel", Routes::bind(&DefaultApi::cancel_post_handler, this)); - Routes::Get(*router, base + "/status", Routes::bind(&DefaultApi::status_get_handler, this)); - Routes::Get(*router, base + "/version", Routes::bind(&DefaultApi::version_get_handler, this)); - - // Default handler, called when a route is not found - router->addCustomHandler(Routes::bind(&DefaultApi::default_api_default_handler, this)); -} - -void DefaultApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ - std::pair codeAndError = handleParsingException(ex); - response.send(codeAndError.first, codeAndError.second); -} - -std::pair DefaultApi::handleParsingException(const std::exception& ex) const noexcept -{ - try { - throw; - } catch (nlohmann::detail::exception &e) { - return std::make_pair(Pistache::Http::Code::Bad_Request, e.what()); - } catch (org::openapitools::server::helpers::ValidationException &e) { - return std::make_pair(Pistache::Http::Code::Bad_Request, e.what()); - } catch (std::exception &e) { - return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what()); - } -} - -void DefaultApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ - std::pair codeAndError = handleOperationException(ex); - response.send(codeAndError.first, codeAndError.second); -} - -std::pair DefaultApi::handleOperationException(const std::exception& ex) const noexcept -{ - return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what()); -} - -void DefaultApi::cancel_post_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) { - try { - - - try { - this->cancel_post(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - -} -void DefaultApi::status_get_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) { - try { - - - try { - this->status_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - -} -void DefaultApi::version_get_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) { - try { - - - try { - this->version_get(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } - - } catch (std::exception &e) { - response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); - } - -} - -void DefaultApi::default_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) { - response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist"); -} - -} // namespace org::openapitools::server::api - diff --git a/writer/gen/api/DefaultApi.h b/writer/gen/api/DefaultApi.h deleted file mode 100644 index 631eee82..00000000 --- a/writer/gen/api/DefaultApi.h +++ /dev/null @@ -1,108 +0,0 @@ -/** -* Jungfraujoch writer -* Jungfraujoch Writer Web API -* -* The version of the OpenAPI document: 1.0.0-rc.116 -* Contact: filip.leonarski@psi.ch -* -* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). -* https://openapi-generator.tech -* Do not edit the class manually. -*/ -/* - * DefaultApi.h - * - * - */ - -#ifndef DefaultApi_H_ -#define DefaultApi_H_ - - -#include "ApiBase.h" - -#include -#include -#include - -#include -#include - -#include "Writer_statistics.h" -#include - -namespace org::openapitools::server::api -{ - -class DefaultApi : public ApiBase { -public: - explicit DefaultApi(const std::shared_ptr& rtr); - ~DefaultApi() override = default; - void init() override; - - static const std::string base; - -private: - void setupRoutes(); - - void cancel_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void status_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void version_get_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - void default_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); - - /// - /// Helper function to handle unexpected Exceptions during Parameter parsing and validation. - /// May be overridden to return custom error formats. This is called inside a catch block. - /// Important: When overriding, do not call `throw ex;`, but instead use `throw;`. - /// - virtual void handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept; - - /// - /// Helper function to handle unexpected Exceptions during Parameter parsing and validation. - /// May be overridden to return custom error formats. This is called inside a catch block. - /// Important: When overriding, do not call `throw ex;`, but instead use `throw;`. - /// - virtual std::pair handleParsingException(const std::exception& ex) const noexcept; - - /// - /// Helper function to handle unexpected Exceptions during processing of the request in handler functions. - /// May be overridden to return custom error formats. This is called inside a catch block. - /// Important: When overriding, do not call `throw ex;`, but instead use `throw;`. - /// - virtual void handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept; - - /// - /// Helper function to handle unexpected Exceptions during processing of the request in handler functions. - /// May be overridden to return custom error formats. This is called inside a catch block. - /// Important: When overriding, do not call `throw ex;`, but instead use `throw;`. - /// - virtual std::pair handleOperationException(const std::exception& ex) const noexcept; - - /// - /// Cancel running data collection - /// - /// - /// It only instructs writer to cancel, but doesn't wait for cancellation actually happening. It still requires to call `/wait_till_done` - /// - virtual void cancel_post(Pistache::Http::ResponseWriter &response) = 0; - /// - /// Get writer status - /// - /// - /// - /// - virtual void status_get(Pistache::Http::ResponseWriter &response) = 0; - /// - /// - /// - /// - /// - /// - virtual void version_get(Pistache::Http::ResponseWriter &response) = 0; - -}; - -} // namespace org::openapitools::server::api - -#endif /* DefaultApi_H_ */ - diff --git a/writer/gen/model/Helpers.cpp b/writer/gen/model/Helpers.cpp deleted file mode 100644 index 3f9b99a6..00000000 --- a/writer/gen/model/Helpers.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/** -* Jungfraujoch writer -* Jungfraujoch Writer Web API -* -* The version of the OpenAPI document: 1.0.0-rc.116 -* Contact: filip.leonarski@psi.ch -* -* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). -* https://openapi-generator.tech -* Do not edit the class manually. -*/ -#include "Helpers.h" -#include - -namespace org::openapitools::server::helpers -{ - -const std::regex regexRfc3339_date(R"(^(\d{4})\-(\d{2})\-(\d{2})$)"); -const std::regex regexRfc3339_date_time( - R"(^(\d{4})\-(\d{2})\-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(\.\d+)?([Zz]|([\+\-])(\d{2}):(\d{2}))$)" -); - - -namespace -{ - // Determine if given year is a leap year - // See RFC 3339, Appendix C https://tools.ietf.org/html/rfc3339#appendix-C - bool isLeapYear(const uint16_t year) { - return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); - } - - bool validateDateValues(const uint16_t year, const uint16_t month, const uint16_t day) { - return !( - (month == 0 || month > 12) - || (day == 0) - || (month == 2 && day > (28 + (isLeapYear(year) ? 1 : 0))) - || (month <= 7 && day > (30 + month % 2)) - || (month >= 8 && day > (31 - month % 2)) - ); - } - - bool validateTimeValues(const uint16_t hours, const uint16_t minutes, const uint16_t seconds) { - return (hours <= 23) && (minutes <= 59) && (seconds <= 60); - } -} - -bool validateRfc3339_date(const std::string& str) { - std::smatch match; - const bool found = std::regex_search(str, match, regexRfc3339_date); - return found && validateDateValues(static_cast(std::stoi(match[1])), - static_cast(std::stoi(match[2])), - static_cast(std::stoi(match[3]))); -} - -bool validateRfc3339_date_time(const std::string& str) { - std::smatch match; - const bool found = std::regex_search(str, match, regexRfc3339_date_time); - return found - && validateDateValues(static_cast(std::stoi(match[1])), - static_cast(std::stoi(match[2])), - static_cast(std::stoi(match[3]))) - && validateTimeValues(static_cast(std::stoi(match[4])), - static_cast(std::stoi(match[5])), - static_cast(std::stoi(match[6]))); -} - -std::string toStringValue(const std::string &value){ - return std::string(value); -} - -std::string toStringValue(const int32_t value){ - return std::to_string(value); -} - -std::string toStringValue(const int64_t value){ - return std::to_string(value); -} - -std::string toStringValue(const bool value){ - return value ? std::string("true") : std::string("false"); -} - -std::string toStringValue(const float value){ - return std::to_string(value); -} - -std::string toStringValue(const double value){ - return std::to_string(value); -} - -bool fromStringValue(const std::string &inStr, std::string &value){ - value = std::string(inStr); - return true; -} - -bool fromStringValue(const std::string &inStr, int32_t &value){ - try { - value = std::stoi( inStr ); - } - catch (const std::invalid_argument&) { - return false; - } - return true; -} - -bool fromStringValue(const std::string &inStr, int64_t &value){ - try { - value = std::stol( inStr ); - } - catch (const std::invalid_argument&) { - return false; - } - return true; -} - -bool fromStringValue(const std::string &inStr, bool &value){ - if (inStr == "true") { - value = true; - return true; - } - if (inStr == "false") { - value = false; - return true; - } - return false; -} - -bool fromStringValue(const std::string &inStr, float &value){ - try { - value = std::stof( inStr ); - } - catch (const std::invalid_argument&) { - return false; - } - return true; -} - -bool fromStringValue(const std::string &inStr, double &value){ - try { - value = std::stod( inStr ); - } - catch (const std::invalid_argument&) { - return false; - } - return true; -} - -} // namespace org::openapitools::server::helpers diff --git a/writer/gen/model/Helpers.h b/writer/gen/model/Helpers.h deleted file mode 100644 index 6e99e8bc..00000000 --- a/writer/gen/model/Helpers.h +++ /dev/null @@ -1,146 +0,0 @@ -/** -* Jungfraujoch writer -* Jungfraujoch Writer Web API -* -* The version of the OpenAPI document: 1.0.0-rc.116 -* Contact: filip.leonarski@psi.ch -* -* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). -* https://openapi-generator.tech -* Do not edit the class manually. -*/ -/* - * Helpers.h - * - * This is the helper class for models and primitives - */ - -#ifndef Helpers_H_ -#define Helpers_H_ - -#include -#include -#include -#include -#include -#include - -namespace org::openapitools::server::helpers -{ - - class ValidationException : public std::runtime_error - { - public: - explicit ValidationException(const std::string& what) - : std::runtime_error(what) - { } - ~ValidationException() override = default; - }; - - /// - /// Validate a string against the full-date definition of RFC 3339, section 5.6. - /// - bool validateRfc3339_date(const std::string& str); - - /// - /// Validate a string against the date-time definition of RFC 3339, section 5.6. - /// - bool validateRfc3339_date_time(const std::string& str); - - namespace sfinae_helpers - { - struct NoType {}; - template NoType operator==(const T1&, const T2&); - - template class EqualsOperatorAvailable - { - public: - enum - { - value = !std::is_same< decltype(std::declval() == std::declval()), NoType >::value - }; - }; - } // namespace sfinae_helpers - - - /// - /// Determine if the given vector only has unique elements. T must provide the == operator. - /// - template - bool hasOnlyUniqueItems(const std::vector& vec) - { - static_assert(sfinae_helpers::EqualsOperatorAvailable::value, - "hasOnlyUniqueItems cannot be called, passed template type does not provide == operator."); - if (vec.size() <= 1) - { - return true; - } - // Compare every element of vec to every other element of vec. - // This isn't an elegant way to do this, since it's O(n^2), - // but it's the best solution working only with the == operator. - // This could be greatly improved if our models provided a valid hash - // and/or the < operator - for (size_t i = 0; i < vec.size() - 1; i++) - { - for (size_t j = i + 1; j < vec.size(); j++) - { - if (vec[i] == vec[j]) - { - return false; - } - } - } - return true; - } - - /// - /// Determine if the given set only has unique elements. - /// - template - bool hasOnlyUniqueItems(const std::set&) - { - return true; - } - - std::string toStringValue(const std::string &value); - std::string toStringValue(const int32_t value); - std::string toStringValue(const int64_t value); - std::string toStringValue(const bool value); - std::string toStringValue(const float value); - std::string toStringValue(const double value); - - bool fromStringValue(const std::string &inStr, std::string &value); - bool fromStringValue(const std::string &inStr, int32_t &value); - bool fromStringValue(const std::string &inStr, int64_t &value); - bool fromStringValue(const std::string &inStr, bool &value); - bool fromStringValue(const std::string &inStr, float &value); - bool fromStringValue(const std::string &inStr, double &value); - template - bool fromStringValue(const std::vector &inStr, std::vector &value){ - try{ - for(auto & item : inStr){ - T itemValue; - if(fromStringValue(item, itemValue)){ - value.push_back(itemValue); - } - } - } - catch(...){ - return false; - } - return value.size() > 0; - } - template - bool fromStringValue(const std::string &inStr, std::vector &value, char separator = ','){ - std::vector inStrings; - std::istringstream f(inStr); - std::string s; - while (std::getline(f, s, separator)) { - inStrings.push_back(s); - } - return fromStringValue(inStrings, value); - } - -} // namespace org::openapitools::server::helpers - -#endif // Helpers_H_ diff --git a/writer/gen/model/Writer_statistics.cpp b/writer/gen/model/Writer_statistics.cpp deleted file mode 100644 index c11b163a..00000000 --- a/writer/gen/model/Writer_statistics.cpp +++ /dev/null @@ -1,309 +0,0 @@ -/** -* Jungfraujoch writer -* Jungfraujoch Writer Web API -* -* The version of the OpenAPI document: 1.0.0-rc.116 -* Contact: filip.leonarski@psi.ch -* -* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). -* https://openapi-generator.tech -* Do not edit the class manually. -*/ - - -#include "Writer_statistics.h" -#include "Helpers.h" - -#include - -namespace org::openapitools::server::model -{ - -Writer_statistics::Writer_statistics() -{ - m_Nimages = 0L; - m_NimagesIsSet = false; - m_Performance_MBs = 0.0f; - m_Performance_MBsIsSet = false; - m_Performance_Hz = 0.0f; - m_Performance_HzIsSet = false; - m_Run_number = 0L; - m_Run_numberIsSet = false; - m_Run_name = ""; - m_Run_nameIsSet = false; - m_File_prefix = ""; - m_File_prefixIsSet = false; - m_Socket_number = 0L; - m_Socket_numberIsSet = false; - m_State = ""; - m_StateIsSet = false; - -} - -void Writer_statistics::validate() const -{ - std::stringstream msg; - if (!validate(msg)) - { - throw org::openapitools::server::helpers::ValidationException(msg.str()); - } -} - -bool Writer_statistics::validate(std::stringstream& msg) const -{ - return validate(msg, ""); -} - -bool Writer_statistics::validate(std::stringstream& msg, const std::string& pathPrefix) const -{ - bool success = true; - const std::string _pathPrefix = pathPrefix.empty() ? "Writer_statistics" : pathPrefix; - - - return success; -} - -bool Writer_statistics::operator==(const Writer_statistics& rhs) const -{ - return - - - - ((!nimagesIsSet() && !rhs.nimagesIsSet()) || (nimagesIsSet() && rhs.nimagesIsSet() && getNimages() == rhs.getNimages())) && - - - ((!performanceMBsIsSet() && !rhs.performanceMBsIsSet()) || (performanceMBsIsSet() && rhs.performanceMBsIsSet() && getPerformanceMBs() == rhs.getPerformanceMBs())) && - - - ((!performanceHzIsSet() && !rhs.performanceHzIsSet()) || (performanceHzIsSet() && rhs.performanceHzIsSet() && getPerformanceHz() == rhs.getPerformanceHz())) && - - - ((!runNumberIsSet() && !rhs.runNumberIsSet()) || (runNumberIsSet() && rhs.runNumberIsSet() && getRunNumber() == rhs.getRunNumber())) && - - - ((!runNameIsSet() && !rhs.runNameIsSet()) || (runNameIsSet() && rhs.runNameIsSet() && getRunName() == rhs.getRunName())) && - - - ((!filePrefixIsSet() && !rhs.filePrefixIsSet()) || (filePrefixIsSet() && rhs.filePrefixIsSet() && getFilePrefix() == rhs.getFilePrefix())) && - - - ((!socketNumberIsSet() && !rhs.socketNumberIsSet()) || (socketNumberIsSet() && rhs.socketNumberIsSet() && getSocketNumber() == rhs.getSocketNumber())) && - - - ((!stateIsSet() && !rhs.stateIsSet()) || (stateIsSet() && rhs.stateIsSet() && getState() == rhs.getState())) - - ; -} - -bool Writer_statistics::operator!=(const Writer_statistics& rhs) const -{ - return !(*this == rhs); -} - -void to_json(nlohmann::json& j, const Writer_statistics& o) -{ - j = nlohmann::json::object(); - if(o.nimagesIsSet()) - j["nimages"] = o.m_Nimages; - if(o.performanceMBsIsSet()) - j["performance_MBs"] = o.m_Performance_MBs; - if(o.performanceHzIsSet()) - j["performance_Hz"] = o.m_Performance_Hz; - if(o.runNumberIsSet()) - j["run_number"] = o.m_Run_number; - if(o.runNameIsSet()) - j["run_name"] = o.m_Run_name; - if(o.filePrefixIsSet()) - j["file_prefix"] = o.m_File_prefix; - if(o.socketNumberIsSet()) - j["socket_number"] = o.m_Socket_number; - if(o.stateIsSet()) - j["state"] = o.m_State; - -} - -void from_json(const nlohmann::json& j, Writer_statistics& o) -{ - if(j.find("nimages") != j.end()) - { - j.at("nimages").get_to(o.m_Nimages); - o.m_NimagesIsSet = true; - } - if(j.find("performance_MBs") != j.end()) - { - j.at("performance_MBs").get_to(o.m_Performance_MBs); - o.m_Performance_MBsIsSet = true; - } - if(j.find("performance_Hz") != j.end()) - { - j.at("performance_Hz").get_to(o.m_Performance_Hz); - o.m_Performance_HzIsSet = true; - } - if(j.find("run_number") != j.end()) - { - j.at("run_number").get_to(o.m_Run_number); - o.m_Run_numberIsSet = true; - } - if(j.find("run_name") != j.end()) - { - j.at("run_name").get_to(o.m_Run_name); - o.m_Run_nameIsSet = true; - } - if(j.find("file_prefix") != j.end()) - { - j.at("file_prefix").get_to(o.m_File_prefix); - o.m_File_prefixIsSet = true; - } - if(j.find("socket_number") != j.end()) - { - j.at("socket_number").get_to(o.m_Socket_number); - o.m_Socket_numberIsSet = true; - } - if(j.find("state") != j.end()) - { - j.at("state").get_to(o.m_State); - o.m_StateIsSet = true; - } - -} - -int64_t Writer_statistics::getNimages() const -{ - return m_Nimages; -} -void Writer_statistics::setNimages(int64_t const value) -{ - m_Nimages = value; - m_NimagesIsSet = true; -} -bool Writer_statistics::nimagesIsSet() const -{ - return m_NimagesIsSet; -} -void Writer_statistics::unsetNimages() -{ - m_NimagesIsSet = false; -} -float Writer_statistics::getPerformanceMBs() const -{ - return m_Performance_MBs; -} -void Writer_statistics::setPerformanceMBs(float const value) -{ - m_Performance_MBs = value; - m_Performance_MBsIsSet = true; -} -bool Writer_statistics::performanceMBsIsSet() const -{ - return m_Performance_MBsIsSet; -} -void Writer_statistics::unsetPerformance_MBs() -{ - m_Performance_MBsIsSet = false; -} -float Writer_statistics::getPerformanceHz() const -{ - return m_Performance_Hz; -} -void Writer_statistics::setPerformanceHz(float const value) -{ - m_Performance_Hz = value; - m_Performance_HzIsSet = true; -} -bool Writer_statistics::performanceHzIsSet() const -{ - return m_Performance_HzIsSet; -} -void Writer_statistics::unsetPerformance_Hz() -{ - m_Performance_HzIsSet = false; -} -int64_t Writer_statistics::getRunNumber() const -{ - return m_Run_number; -} -void Writer_statistics::setRunNumber(int64_t const value) -{ - m_Run_number = value; - m_Run_numberIsSet = true; -} -bool Writer_statistics::runNumberIsSet() const -{ - return m_Run_numberIsSet; -} -void Writer_statistics::unsetRun_number() -{ - m_Run_numberIsSet = false; -} -std::string Writer_statistics::getRunName() const -{ - return m_Run_name; -} -void Writer_statistics::setRunName(std::string const& value) -{ - m_Run_name = value; - m_Run_nameIsSet = true; -} -bool Writer_statistics::runNameIsSet() const -{ - return m_Run_nameIsSet; -} -void Writer_statistics::unsetRun_name() -{ - m_Run_nameIsSet = false; -} -std::string Writer_statistics::getFilePrefix() const -{ - return m_File_prefix; -} -void Writer_statistics::setFilePrefix(std::string const& value) -{ - m_File_prefix = value; - m_File_prefixIsSet = true; -} -bool Writer_statistics::filePrefixIsSet() const -{ - return m_File_prefixIsSet; -} -void Writer_statistics::unsetFile_prefix() -{ - m_File_prefixIsSet = false; -} -int64_t Writer_statistics::getSocketNumber() const -{ - return m_Socket_number; -} -void Writer_statistics::setSocketNumber(int64_t const value) -{ - m_Socket_number = value; - m_Socket_numberIsSet = true; -} -bool Writer_statistics::socketNumberIsSet() const -{ - return m_Socket_numberIsSet; -} -void Writer_statistics::unsetSocket_number() -{ - m_Socket_numberIsSet = false; -} -std::string Writer_statistics::getState() const -{ - return m_State; -} -void Writer_statistics::setState(std::string const& value) -{ - m_State = value; - m_StateIsSet = true; -} -bool Writer_statistics::stateIsSet() const -{ - return m_StateIsSet; -} -void Writer_statistics::unsetState() -{ - m_StateIsSet = false; -} - - -} // namespace org::openapitools::server::model - diff --git a/writer/gen/model/Writer_statistics.h b/writer/gen/model/Writer_statistics.h deleted file mode 100644 index 8174e1b1..00000000 --- a/writer/gen/model/Writer_statistics.h +++ /dev/null @@ -1,142 +0,0 @@ -/** -* Jungfraujoch writer -* Jungfraujoch Writer Web API -* -* The version of the OpenAPI document: 1.0.0-rc.116 -* Contact: filip.leonarski@psi.ch -* -* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). -* https://openapi-generator.tech -* Do not edit the class manually. -*/ -/* - * Writer_statistics.h - * - * - */ - -#ifndef Writer_statistics_H_ -#define Writer_statistics_H_ - - -#include -#include - -namespace org::openapitools::server::model -{ - -/// -/// -/// -class Writer_statistics -{ -public: - Writer_statistics(); - virtual ~Writer_statistics() = default; - - - /// - /// Validate the current data in the model. Throws a ValidationException on failure. - /// - void validate() const; - - /// - /// Validate the current data in the model. Returns false on error and writes an error - /// message into the given stringstream. - /// - bool validate(std::stringstream& msg) const; - - /// - /// Helper overload for validate. Used when one model stores another model and calls it's validate. - /// Not meant to be called outside that case. - /// - bool validate(std::stringstream& msg, const std::string& pathPrefix) const; - - bool operator==(const Writer_statistics& rhs) const; - bool operator!=(const Writer_statistics& rhs) const; - - ///////////////////////////////////////////// - /// Writer_statistics members - - /// - /// Number of images written - /// - int64_t getNimages() const; - void setNimages(int64_t const value); - bool nimagesIsSet() const; - void unsetNimages(); - /// - /// Performance in MB/s - /// - float getPerformanceMBs() const; - void setPerformanceMBs(float const value); - bool performanceMBsIsSet() const; - void unsetPerformance_MBs(); - /// - /// Performance in images/s - /// - float getPerformanceHz() const; - void setPerformanceHz(float const value); - bool performanceHzIsSet() const; - void unsetPerformance_Hz(); - /// - /// - /// - int64_t getRunNumber() const; - void setRunNumber(int64_t const value); - bool runNumberIsSet() const; - void unsetRun_number(); - /// - /// - /// - std::string getRunName() const; - void setRunName(std::string const& value); - bool runNameIsSet() const; - void unsetRun_name(); - /// - /// File prefix for the last written dataset - /// - std::string getFilePrefix() const; - void setFilePrefix(std::string const& value); - bool filePrefixIsSet() const; - void unsetFile_prefix(); - /// - /// Number of socket on `jfjoch_broker` side for the current/last data collection - /// - int64_t getSocketNumber() const; - void setSocketNumber(int64_t const value); - bool socketNumberIsSet() const; - void unsetSocket_number(); - /// - /// - /// - std::string getState() const; - void setState(std::string const& value); - bool stateIsSet() const; - void unsetState(); - - friend void to_json(nlohmann::json& j, const Writer_statistics& o); - friend void from_json(const nlohmann::json& j, Writer_statistics& o); -protected: - int64_t m_Nimages; - bool m_NimagesIsSet; - float m_Performance_MBs; - bool m_Performance_MBsIsSet; - float m_Performance_Hz; - bool m_Performance_HzIsSet; - int64_t m_Run_number; - bool m_Run_numberIsSet; - std::string m_Run_name; - bool m_Run_nameIsSet; - std::string m_File_prefix; - bool m_File_prefixIsSet; - int64_t m_Socket_number; - bool m_Socket_numberIsSet; - std::string m_State; - bool m_StateIsSet; - -}; - -} // namespace org::openapitools::server::model - -#endif /* Writer_statistics_H_ */ diff --git a/writer/jfjoch_writer.cpp b/writer/jfjoch_writer.cpp index 0c039c9b..83127672 100644 --- a/writer/jfjoch_writer.cpp +++ b/writer/jfjoch_writer.cpp @@ -1,18 +1,16 @@ // SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only +#include +#include #include #include "../common/Logger.h" -#include "JFJochWriterHttp.h" #include "StreamWriter.h" #include "../common/print_license.h" #include "../image_puller/ZMQImagePuller.h" -#include -#include static Logger logger("jfjoch_writer"); -static Pistache::Http::Endpoint *httpEndpoint; static StreamWriter *writer; volatile static bool quitok = false; @@ -20,8 +18,7 @@ void print_usage() { logger.Info("Usage ./jfjoch_writer {options}
"); logger.Info(""); logger.Info("Available options:"); - logger.Info("-R | --root_dir= Root directory for file writing"); - logger.Info("-H | --http_port= HTTP port for statistics"); + logger.Info("-d | --root_dir= Root directory for file writing"); logger.Info("-r | --zmq_repub_port= ZeroMQ port for PUSH socket to republish images"); logger.Info("-f | --zmq_file_port= ZeroMQ port for PUB socket to inform about finalized files"); logger.Info("-w | --rcv_watermark= Receiving ZeroMQ socket watermark (default = 100)"); @@ -37,7 +34,6 @@ static void sigHandler (int sig){ case SIGTERM: case SIGHUP: default: - httpEndpoint->shutdown(); quitok = true; writer->Cancel(); break; @@ -64,7 +60,6 @@ int main(int argc, char **argv) { print_license("jfjoch_writer"); - int32_t http_port = 5234; int32_t zmq_repub_port = -1; int32_t zmq_file_port = -1; std::string root_dir = ""; @@ -73,7 +68,7 @@ int main(int argc, char **argv) { bool verbose = false; static struct option long_options[] = { - {"root_dir", required_argument, 0, 'R'}, + {"root_dir", required_argument, 0, 'd'}, {"http_port", required_argument, 0, 'H'}, {"zmq_repub_port", required_argument, 0, 'r'}, {"zmq_file_port", required_argument, 0, 'f'}, @@ -85,13 +80,13 @@ int main(int argc, char **argv) { int option_index = 0; int opt; - while ((opt = getopt_long(argc, argv, "?hH:r:f:R:W:w:v",long_options, &option_index)) != -1 ) { + while ((opt = getopt_long(argc, argv, "?hH:r:f:R:d:W:w:v",long_options, &option_index)) != -1 ) { switch (opt) { case 'v': verbose = true; break; case 'H': - http_port = atoi(optarg); + // For back compatibility break; case 'r': zmq_repub_port = atoi(optarg); @@ -113,7 +108,8 @@ int main(int argc, char **argv) { case 'f': zmq_file_port = atoi(optarg); break; - case 'R': + case 'R': // back compatibility + case 'd': root_dir = std::string(optarg); break; case '?': @@ -133,12 +129,6 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - if ((http_port <= 0) || (http_port >= UINT16_MAX)) { - logger.Error("Http port must be between 1 - 65534"); - exit(EXIT_FAILURE); - } - logger.Info("HTTP service listening on port {}", http_port); - if (!root_dir.empty()) { try { std::filesystem::current_path(root_dir); @@ -162,32 +152,15 @@ int main(int argc, char **argv) { } ZMQContext context; - Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(http_port)); ZMQImagePuller puller(argv[first_argc], repub_zmq_addr, rcv_watermark, repub_watermark); writer = new StreamWriter(logger,puller,file_done_zmq_addr, verbose); - httpEndpoint = new Pistache::Http::Endpoint(addr); - - auto router = std::make_shared(); - - auto opts = Pistache::Http::Endpoint::options().threads(4); - opts.flags(Pistache::Tcp::Options::ReuseAddr); - httpEndpoint->init(opts); - std::vector sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP}; setUpUnixSignals(sigs); - std::thread writer_thread([] { - while (!quitok) - writer->Run(); - }); + while (!quitok) + writer->Run(); - JFJochWriterHttp writer_http(*writer, router); - - httpEndpoint->setHandler(router->handler()); - httpEndpoint->serve(); - writer_thread.join(); - logger.Info("Clean stop"); exit(EXIT_SUCCESS); } diff --git a/writer/redoc-static.html b/writer/redoc-static.html deleted file mode 100644 index 205911eb..00000000 --- a/writer/redoc-static.html +++ /dev/null @@ -1,311 +0,0 @@ - - - - - - Jungfraujoch writer - - - - - - - - - -

Jungfraujoch writer (1.0.0.rc_11)

Download OpenAPI specification:Download

Jungfraujoch Writer Web API

-

Get writer status

Responses

Response samples

Content type
application/json
{
  • "nimages": 0,
  • "performance_MBs": 0.1,
  • "performance_Hz": 0.1,
  • "run_number": 0,
  • "run_name": "string",
  • "file_prefix": "string",
  • "socket_number": 0,
  • "state": "idle"
}

Cancel running data collection

It only instructs writer to cancel, but doesn't wait for cancellation actually happening. -It still requires to call /wait_till_done

-

Responses

/version

Responses

- - - - diff --git a/writer/writer_api.yaml b/writer/writer_api.yaml deleted file mode 100644 index 361c771f..00000000 --- a/writer/writer_api.yaml +++ /dev/null @@ -1,77 +0,0 @@ -openapi: 3.0.3 -info: - title: Jungfraujoch writer - description: Jungfraujoch Writer Web API - version: 1.0.0-rc.116 - contact: - name: Filip Leonarski (Paul Scherrer Institute) - email: filip.leonarski@psi.ch - license: - name: GPL-3.0 - url: https://www.gnu.org/licenses/gpl-3.0.html -components: - schemas: - writer_statistics: - type: object - properties: - nimages: - type: integer - format: int64 - description: Number of images written - performance_MBs: - type: number - format: float - description: Performance in MB/s - performance_Hz: - type: number - format: float - description: Performance in images/s - run_number: - type: integer - format: int64 - run_name: - type: string - file_prefix: - type: string - description: File prefix for the last written dataset - socket_number: - type: integer - format: int64 - description: Number of socket on `jfjoch_broker` side for the current/last data collection - state: - type: string - enum: - - idle - - started - - receiving - - error -paths: - /status: - get: - summary: Get writer status - responses: - "200": - description: Statistics of the last measurement - content: - application/json: - schema: - $ref: '#/components/schemas/writer_statistics' - /cancel: - post: - summary: Cancel running data collection - description: | - It only instructs writer to cancel, but doesn't wait for cancellation actually happening. - It still requires to call `/wait_till_done` - responses: - "200": - description: Cancel message acknowledged - /version: - get: - responses: - "200": - description: Release number of Jungfraujoch - content: - text/plain: - schema: - type: string - example: 1.0.0