All checks were successful
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 8m17s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 7m34s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 8m36s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 8m8s
Build Packages / build:rpm (rocky8) (push) Successful in 8m7s
Build Packages / Generate python client (push) Successful in 14s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 8m5s
Build Packages / Create release (push) Has been skipped
Build Packages / Build documentation (push) Successful in 29s
Build Packages / build:rpm (rocky9) (push) Successful in 8m53s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 7m4s
Build Packages / Unit tests (push) Successful in 1h9m13s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 10m42s
This is an UNSTABLE release and not recommended for production use (please use rc.111 instead). * jfjoch_broker: Default spot finding settings can be configured via config JSON * jfjoch_viewer: FFT analysis of data in the dataset plot Reviewed-on: #22 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch> Co-committed-by: Filip Leonarski <filip.leonarski@psi.ch>
145 lines
4.2 KiB
C++
145 lines
4.2 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
// Using OpenAPI licensed with Apache License 2.0
|
|
|
|
#include <vector>
|
|
#include <csignal>
|
|
#include <fstream>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include "../common/Logger.h"
|
|
|
|
#include "JFJochBrokerHttp.h"
|
|
|
|
#include "JFJochBrokerParser.h"
|
|
#include "../writer/HDF5Objects.h"
|
|
#include "../common/print_license.h"
|
|
#include "../detector_control/DectrisSimplonClient.h"
|
|
|
|
static Pistache::Http::Endpoint *httpEndpoint;
|
|
|
|
static void sigHandler [[noreturn]] (int sig){
|
|
switch(sig){
|
|
case SIGINT:
|
|
case SIGQUIT:
|
|
case SIGTERM:
|
|
case SIGHUP:
|
|
default:
|
|
httpEndpoint->shutdown();
|
|
break;
|
|
}
|
|
exit(0);
|
|
}
|
|
|
|
static void setUpUnixSignals(std::vector<int> quitSignals) {
|
|
sigset_t blocking_mask;
|
|
sigemptyset(&blocking_mask);
|
|
for (auto sig : quitSignals)
|
|
sigaddset(&blocking_mask, sig);
|
|
|
|
struct sigaction sa;
|
|
sa.sa_handler = sigHandler;
|
|
sa.sa_mask = blocking_mask;
|
|
sa.sa_flags = 0;
|
|
|
|
for (auto sig : quitSignals)
|
|
sigaction(sig, &sa, nullptr);
|
|
}
|
|
|
|
int main (int argc, char **argv) {
|
|
RegisterHDF5Filter();
|
|
|
|
print_license("jfjoch_broker");
|
|
|
|
if ((argc == 1) || (argc > 3)) {
|
|
std::cout << "Usage ./jfjoch_broker <JSON config> {<TCP http port>}" << std::endl;
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
uint16_t http_port = 5232;
|
|
if (argc >= 3) http_port = atoi(argv[2]);
|
|
|
|
Logger logger("jfjoch_broker");
|
|
|
|
org::openapitools::server::model::Jfjoch_settings settings;
|
|
|
|
std::ifstream file(argv[1]);
|
|
try {
|
|
nlohmann::json input = nlohmann::json::parse(file);
|
|
settings = input;
|
|
settings.validate();
|
|
logger.Info("JSON configuration file read properly");
|
|
} catch (const std::exception &e) {
|
|
logger.Error("Error reading JSON configuration file: " + std::string(e.what()));
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
if (settings.verboseIsSet() && settings.isVerbose())
|
|
logger.Verbose(true);
|
|
else
|
|
logger.Verbose(false);
|
|
|
|
std::unique_ptr<ImagePusher> image_pusher = ParseImagePusher(settings);
|
|
|
|
if (image_pusher)
|
|
logger.Info(image_pusher->PrintSetup());
|
|
|
|
std::vector<DetectorSetup> det_setup;
|
|
for (const auto &d: settings.getDetector())
|
|
det_setup.push_back(ParseDetectorSetup(d));
|
|
|
|
if (det_setup.empty()) {
|
|
logger.Error("At least one detector need to be defined in the config file");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
DiffractionExperiment experiment(det_setup[0]);
|
|
ParseFacilityConfiguration(settings, experiment);
|
|
|
|
SpotFindingSettings spot_finding_settings = ParseSpotFindingSettings(settings);
|
|
|
|
AcquisitionDeviceGroup aq_devices;
|
|
ParseAcquisitionDeviceGroup(settings, aq_devices);
|
|
|
|
experiment.DataStreams(aq_devices.size());
|
|
|
|
int32_t send_buffer_size_MiB = settings.getImageBufferMiB();
|
|
std::unique_ptr<JFJochReceiverService> receiver
|
|
= std::make_unique<JFJochReceiverService>(aq_devices, logger, *image_pusher, send_buffer_size_MiB);
|
|
ParseReceiverSettings(settings, *receiver);
|
|
|
|
Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(http_port));
|
|
|
|
httpEndpoint = new Pistache::Http::Endpoint((addr));
|
|
|
|
auto router = std::make_shared<Pistache::Rest::Router>();
|
|
|
|
auto opts = Pistache::Http::Endpoint::options().threads(8).maxRequestSize(64*1024*1024);
|
|
opts.flags(Pistache::Tcp::Options::ReuseAddr);
|
|
|
|
httpEndpoint->init(opts);
|
|
|
|
if (settings.sslIsSet()) {
|
|
auto ssl = settings.getSsl();
|
|
httpEndpoint->useSSL(ssl.getCertificate(), ssl.getKey(), true);
|
|
// We allow compression. While this introduces certain vulnerabilities, but risk is so small we ignore this.
|
|
}
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
std::vector<int> sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP};
|
|
setUpUnixSignals(sigs);
|
|
|
|
JFJochBrokerHttp broker(experiment, spot_finding_settings, router);
|
|
broker.FrontendDirectory(settings.getFrontendDirectory());
|
|
|
|
for (const auto &d: det_setup)
|
|
broker.AddDetectorSetup(d);
|
|
|
|
if (receiver)
|
|
broker.Services().Receiver(receiver.get());
|
|
|
|
httpEndpoint->setHandler(router->handler());
|
|
httpEndpoint->serve();
|
|
|
|
httpEndpoint->shutdown();
|
|
} |