diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f501b4692b1af799c7ce4ccb70bc15352eccb57..76386eeb049506259cf53f42a1b42af21cc1387d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,7 @@ ELSE(DEFINED PackageOnly) add_subdirectory(cmdline) add_subdirectory(xroot_plugins) + add_subdirectory(frontend_svc) add_subdirectory(catalogue) add_subdirectory(common) diff --git a/eos_cta/CMakeLists.txt b/eos_cta/CMakeLists.txt index b10e0c446887766787e91ddbb7515e8364868106..f44e0d160d18d72bba5fcac24cd4254e55cd8455 100644 --- a/eos_cta/CMakeLists.txt +++ b/eos_cta/CMakeLists.txt @@ -24,23 +24,31 @@ set(PROTOBUF_EOS_CTA_DIR ${XRD_SSI_PB_DIR}/eos_cta/protobuf) file(GLOB ProtoFilesEosCta "${PROTOBUF_EOS_CTA_DIR}/*.proto") set(PROTOBUF_MIGRATION_DIR ${PROJECT_SOURCE_DIR}/migration/grpc-proto/protobuf) file(GLOB ProtoFilesMigration "${PROTOBUF_MIGRATION_DIR}/*.proto") +set(PROTOBUF_FRONTEND_DIR ${PROJECT_SOURCE_DIR}/frontend_svc/grpc-proto/protobuf) +file(GLOB ProtoFilesFrontendCta "${PROTOBUF_FRONTEND_DIR}/*.proto") # Compile protobufs -set(PROTOBUF3_INCLUDE_PATH ${PROTOBUF_EOS_CTA_DIR}:${PROTOBUF_MIGRATION_DIR}) +set(PROTOBUF3_INCLUDE_PATH ${PROTOBUF_EOS_CTA_DIR}:${PROTOBUF_MIGRATION_DIR}:${PROTOBUF_FRONTEND_DIR}:${PROTOBUF3_INCLUDE_DIRS}) PROTOBUF3_GENERATE_CPP(ProtoSourcesEosCta ProtoHeadersEosCta ${ProtoFilesEosCta}) PROTOBUF3_GENERATE_CPP(ProtoSourcesMigration ProtoHeadersMigration ${ProtoFilesMigration}) +PROTOBUF3_GENERATE_CPP(ProtoSourcesFrontendCta ProtoHeadersFrontendCta ${ProtoFilesFrontendCta}) # Compile gRPC code set(GRPC_PROTOBUF_PATH "${CMAKE_BINARY_DIR}/eos_cta/") grpc_generate_cpp(ProtoGrpcSourcesMigration ProtoGrpcHeadersMigration ${GRPC_PROTOBUF_PATH} ${ProtoFilesMigration}) +# depends on CTA_EOS definitions +set(PROTOBUF3_IMPORT_DIRS "${PROTOBUF_EOS_CTA_DIR}:${PROTOBUF3_INCLUDE_DIRS}") +grpc_generate_cpp(ProtoGrpcSourcesFrontendCta ProtoGrpcHeadersFrontendCta ${GRPC_PROTOBUF_PATH} ${ProtoFilesFrontendCta}) set_source_files_properties( ${ProtoSourcesEosCta} ${ProtoHeadersEosCta} ${ProtoSourcesMigration} ${ProtoHeadersMigration} ${ProtoGrpcSourcesMigration} ${ProtoGrpcHeadersMigration} + ${ProtoSourcesFrontendCta} ${ProtoHeadersFrontendCta} + ${ProtoGrpcSourcesFrontendCta} ${ProtoGrpcHeadersFrontendCta} PROPERTIES GENERATED TRUE) -foreach(PROTO_SRC ${ProtoSourcesEosCta} ${ProtoSourcesMigration} ${ProtoGrpcSourcesMigration}) +foreach(PROTO_SRC ${ProtoSourcesEosCta} ${ProtoSourcesMigration} ${ProtoGrpcSourcesMigration} ${ProtoSourcesFrontendCta} ${ProtoGrpcSourcesFrontendCta}) set_property(SOURCE ${PROTO_SRC} PROPERTY COMPILE_FLAGS " -Wno-missing-field-initializers -fPIC -Wno-narrowing -Wno-implicit-fallthrough") endforeach(PROTO_SRC) @@ -55,3 +63,11 @@ set_target_properties(EosMigration PROPERTIES LINKER_LANGUAGE CXX POSITION_INDEPENDENT_CODE TRUE) target_link_libraries(EosMigration ${PROTOBUF3_GRPC_LIBRARIES}) + +add_library(CtaGRpc ${ProtoSourcesFrontendCta} ${ProtoGrpcSourcesFrontendCta}) +set_target_properties(CtaGRpc PROPERTIES + LINKER_LANGUAGE CXX + POSITION_INDEPENDENT_CODE TRUE) +target_link_libraries(CtaGRpc ${PROTOBUF3_GRPC_LIBRARIES}) + +add_dependencies(CtaGRpc XrdSsiPbEosCta) \ No newline at end of file diff --git a/frontend_svc/CMakeLists.txt b/frontend_svc/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..99784ce9ea7019fbb9b59bf3a23cd190a5488666 --- /dev/null +++ b/frontend_svc/CMakeLists.txt @@ -0,0 +1,18 @@ +# @project The CERN Tape Archive (CTA) +# @copyright 2021 DESY +# @license This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +cmake_minimum_required (VERSION 2.6) + +add_subdirectory(gRPC) diff --git a/frontend_svc/gRPC/CMakeLists.txt b/frontend_svc/gRPC/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f23f78ff266527fbe6819aa5d24b2ef9388bb911 --- /dev/null +++ b/frontend_svc/gRPC/CMakeLists.txt @@ -0,0 +1,27 @@ +# @project The CERN Tape Archive (CTA) +# @copyright Copyright(C) 2021 DESY +# @license This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +cmake_minimum_required (VERSION 2.6) + +find_package(Protobuf3 REQUIRED) + +include_directories(${CMAKE_BINARY_DIR}/eos_cta + ${PROTOBUF3_INCLUDE_DIRS}) + +add_executable(frontend-grpc-svc FrontendGRpcSvc.cpp) +target_link_libraries(frontend-grpc-svc CtaGRpc + ${PROTOBUF3_LIBRARIES} ${GRPC_GRPC++_LIBRARY} + ctascheduler ctacommon ctaobjectstore ctacatalogue) +set_property(TARGET frontend-grpc-svc APPEND PROPERTY INSTALL_RPATH ${PROTOBUF3_RPATH}) \ No newline at end of file diff --git a/frontend_svc/gRPC/FrontendGRpcSvc.cpp b/frontend_svc/gRPC/FrontendGRpcSvc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..985e38fa9fb7a39e24d99cb037e6b56bcd750b45 --- /dev/null +++ b/frontend_svc/gRPC/FrontendGRpcSvc.cpp @@ -0,0 +1,76 @@ +/* + * @project The CERN Tape Archive (CTA) + * @copyright Copyright(C) 2021 CERN + * @copyright Copyright(C) 2021 DESY + * @license This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include "FrontendGRpcSvc.h" +#include "version.h" + +using grpc::Server; +using grpc::ServerBuilder; +using grpc::ServerContext; +using grpc::Status; + +using cta::rpc::CtaRpc; + +#include "common/log/SyslogLogger.hpp" +#include "common/log/StdoutLogger.hpp" +#include "common/log/FileLogger.hpp" +#include "common/log/LogLevel.hpp" + + +class CtaRpcImpl final : public CtaRpc::Service { + + Status Version(::grpc::ServerContext* context, const ::google::protobuf::Empty* request, ::cta::admin::Version* response) override { + response->set_cta_version(CTA_VERSION); + response->set_xrootd_ssi_protobuf_interface_version("gPRC-frontend v0.0.1"); + return Status::OK; + } +}; + + +using namespace cta; + +int main(const int argc, char *const *const argv) { + + std::unique_ptr <cta::log::Logger> m_log; + m_log.reset(new log::StdoutLogger("cta-dev", "cta-grpc-frontend")); + + log::LogContext lc(*m_log); + + std::string server_address("0.0.0.0:17017"); + + CtaRpcImpl svc; + +// grpc::EnableDefaultHealthCheckService(true); +// grpc::reflection::InitProtoReflectionServerBuilderPlugin(); + + ServerBuilder builder; + // Listen on the given address without any authentication mechanism. + builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); + // Register "service" as the instance through which we'll communicate with + // clients. In this case it corresponds to an *synchronous* service. + builder.RegisterService(&svc); + // Finally assemble the server. + std::unique_ptr <Server> server(builder.BuildAndStart()); + + lc.log(log::INFO, "Listening on socket address: " + server_address); + + // Wait for the server to shutdown. Note that some other thread must be + // responsible for shutting down the server for this call to ever return. + server->Wait(); + + +} \ No newline at end of file diff --git a/frontend_svc/gRPC/FrontendGRpcSvc.h b/frontend_svc/gRPC/FrontendGRpcSvc.h new file mode 100644 index 0000000000000000000000000000000000000000..1cc74194dd7fb38f08b15f40f193b1dc50453ec5 --- /dev/null +++ b/frontend_svc/gRPC/FrontendGRpcSvc.h @@ -0,0 +1,22 @@ + +#ifndef CTA_FRONTENDGRPCSVC_H +#define CTA_FRONTENDGRPCSVC_H + + +#include <grpcpp/grpcpp.h> + +#include "catalogue/CatalogueFactoryFactory.hpp" +#include "rdbms/Login.hpp" +#include <common/Configuration.hpp> +#include <common/utils/utils.hpp> +#include <scheduler/Scheduler.hpp> +#include <scheduler/OStoreDB/OStoreDBInit.hpp> +#include "common/log/SyslogLogger.hpp" +#include "common/log/StdoutLogger.hpp" +#include "common/log/FileLogger.hpp" +#include "common/log/LogLevel.hpp" + +#include "cta_rpc.grpc.pb.h" + + +#endif //CTA_FRONTENDGRPCSVC_H diff --git a/frontend_svc/grpc-proto/protobuf/cta_rpc.proto b/frontend_svc/grpc-proto/protobuf/cta_rpc.proto new file mode 100644 index 0000000000000000000000000000000000000000..15d1d722eb4fd2fc6132a9ffed26aa7169613c20 --- /dev/null +++ b/frontend_svc/grpc-proto/protobuf/cta_rpc.proto @@ -0,0 +1,18 @@ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "ch.cern.cta.rpc"; +option optimize_for = CODE_SIZE; +package cta.rpc; + +import "google/protobuf/empty.proto"; + +import "cta_admin.proto"; + +// +// gRPC interface to CTA frontend +// +service CtaRpc { + rpc Version (google.protobuf.Empty) returns (cta.admin.Version) {} +} \ No newline at end of file