Skip to content

Commit

Permalink
Revert the deletion of proto client
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboulais committed May 3, 2024
1 parent 5c99837 commit 4511384
Show file tree
Hide file tree
Showing 14 changed files with 482 additions and 1 deletion.
32 changes: 31 additions & 1 deletion cxx-client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ target_link_libraries(BookkeepingApi

target_compile_features(BookkeepingApi PUBLIC cxx_std_17)

add_library(BookkeepingProtoApi SHARED
src/BkpProtoClientFactory.cxx
src/grpc/GrpcBkpProtoClient.cxx
src/grpc/services/GrpcRunProtoClient.cxx
src/grpc/services/GrpcDplProcessExecutionProtoClient.cxx
)

target_include_directories(BookkeepingProtoApi
PUBLIC $<INSTALL_INTERFACE:include> # public header once installed
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> # to build it
PRIVATE $<BUILD_INTERFACE:${PROTO_OUT_DIR}> # because of the proto generated files
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src> # private headers
)

target_link_libraries(BookkeepingProtoApi
PUBLIC BookkeepingProtos
PUBLIC protobuf::libprotobuf
PRIVATE gRPC::grpc++
)

target_compile_features(BookkeepingProtoApi PUBLIC cxx_std_17)

### EXAMPLES

add_executable(exampleSpecificService example/exampleSpecificServices.cxx)
Expand All @@ -83,6 +105,14 @@ target_link_libraries(exampleSpecificService
PUBLIC BookkeepingApi
)

add_executable(exampleProtoService example/exampleProtoServices.cxx)

target_link_libraries(exampleProtoService
PUBLIC BookkeepingProtoApi
)

target_include_directories(exampleProtoService PRIVATE $<BUILD_INTERFACE:${PROTO_OUT_DIR}>)

# PACKAGE INFO

include(CMakePackageConfigHelpers)
Expand All @@ -105,7 +135,7 @@ install(FILES
DESTINATION "include"
)

install(TARGETS BookkeepingProtos BookkeepingApi
install(TARGETS BookkeepingProtos BookkeepingApi BookkeepingProtoApi
EXPORT BookkeepingApiTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
12 changes: 12 additions & 0 deletions cxx-client/cmake/BookkeepingProtoApiConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
get_filename_component(BookkeepingProtoApi_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

find_dependency(Protobuf CONFIG REQUIRED)
find_dependency(gRPC REQUIRED)

if(NOT TARGET AliceO2::BookkeepingProtoApi)
include("${BookkeepingProtoApi_CMAKE_DIR}/BookkeepingProtoApiTargets.cmake")
endif()

message(STATUS "BookkeepingProtoApi-O2 ${BookkeepingApi_VERSION} found")
69 changes: 69 additions & 0 deletions cxx-client/example/exampleProtoServices.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#include <stdexcept>
#include <iostream>
#include <sstream>
#include "BookkeepingApi/BkpProtoClientFactory.h"
#include "run.pb.h"
#include "dplProcessExecution.pb.h"

using namespace o2::bkp::api::proto;
using namespace o2::bookkeeping;

int main(int argc, char** argv)
{
if (argc < 2) {
std::cerr << "You need to provide the gRPC URI as first argument" << std::endl;
exit(1);
}

try {
auto client = BkpProtoClientFactory::create(argv[1]);

// First option: direct implementation, using constructed request
auto request = std::make_shared<RunFetchRequest>();
request->set_runnumber(106);
request->add_relations(RUN_RELATIONS_LHC_FILL);
std::shared_ptr<RunWithRelations> run106WithRelations = client->run()->Get(request);
std::ostringstream messageStreamRun106;
messageStreamRun106 << "Retrieved run 106 info, such as time o2 start <" << run106WithRelations->run().timeo2start() << ">";
if (run106WithRelations->has_lhcfill()) {
messageStreamRun106 << " and related fill info such as fill beam type <" << run106WithRelations->lhcfill().beamtype() << ">";
}
std::cout << messageStreamRun106.str() << std::endl;

// Second option: use shortcut method
std::shared_ptr<RunWithRelations> run105WithRelations = client->run()->Get(105, { RUN_RELATIONS_LHC_FILL });
std::ostringstream messageStreamRun105;
messageStreamRun105 << "Retrieved run 105 info, such as time o2 start <" << run106WithRelations->run().timeo2start() << ">";
if (run106WithRelations->has_lhcfill()) {
messageStreamRun105 << " and related fill info such as fill beam type <" << run106WithRelations->lhcfill().beamtype() << ">";
}
std::cout << messageStreamRun105.str() << std::endl;

// Test of DPL process execution
auto creationRequest = std::make_shared<DplProcessExecutionCreationRequest>();
creationRequest->set_runnumber(106);
creationRequest->set_detectorname("DETECTOR");
creationRequest->set_processname("PROCESS-NAME");
creationRequest->set_type(o2::bookkeeping::DPL_PROCESS_TYPE_MERGER);
creationRequest->set_hostname("HOSTNAME");
std::shared_ptr<DplProcessExecution> dplProcessExecution = client->dplProcessExecution()->Create(creationRequest);

// Short version
client->dplProcessExecution()->registerProcessExecution(106, o2::bookkeeping::DPL_PROCESS_TYPE_QC_CHECKER, "SECOND-HOSTNAME", "PROCESS-NAME", "", "DEFAUlT");
} catch (std::runtime_error& error) {
std::cerr << "An error occurred: " << error.what() << std::endl;
exit(2);
}
return 0;
}
32 changes: 32 additions & 0 deletions cxx-client/include/BookkeepingApi/BkpProtoClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef CXX_CLIENT_BOOKKEEPINGAPI_BKPPROTOCLIENT_H
#define CXX_CLIENT_BOOKKEEPINGAPI_BKPPROTOCLIENT_H

#include <memory>
#include "RunProtoClient.h"
#include "DplProcessExecutionProtoClient.h"

namespace o2::bkp::api::proto {
class BkpProtoClient {
public:
virtual ~BkpProtoClient() = default;

/// Returns the implementation of the Run service defined in run.proto
virtual const std::unique_ptr<RunProtoClient>& run() const = 0;

/// Returns the implementation of the DPL process execution service defined in dpl-process-execution.proto
virtual const std::unique_ptr<DplProcessExecutionProtoClient>& dplProcessExecution() const = 0;
};
}

#endif // CXX_CLIENT_BOOKKEEPINGAPI_BKPPROTOCLIENT_H
22 changes: 22 additions & 0 deletions cxx-client/include/BookkeepingApi/BkpProtoClientFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Created by mboulais on 02/03/23.
//

#ifndef CXX_CLIENT_BOOKKEEPINGAPI_BKPPROTOCLIENTFACTORY_H
#define CXX_CLIENT_BOOKKEEPINGAPI_BKPPROTOCLIENTFACTORY_H

#include <memory>
#include "BkpProtoClient.h"

namespace o2::bkp::api::proto {
class BkpProtoClientFactory {
public:
BkpProtoClientFactory() = delete;

/// Provides a Bookkeeping proto API client configured from a given configuration URI
/// Proto api implements the services defined in the proto files
static ::std::unique_ptr<BkpProtoClient> create(const ::std::string& gRPCUri);
};
}

#endif // CXX_CLIENT_BOOKKEEPINGAPI_BKPPROTOCLIENTFACTORY_H
40 changes: 40 additions & 0 deletions cxx-client/include/BookkeepingApi/DplProcessExecutionProtoClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSEXECUTIONPROTOCLIENT_H
#define CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSEXECUTIONPROTOCLIENT_H

#include <memory>
#include "dplProcessExecution.pb.h"

namespace o2::bkp::api::proto
{
class DplProcessExecutionProtoClient
{
public:
virtual ~DplProcessExecutionProtoClient() = default;

/// Returns the implementation of the DPL process execution service defined in dplProcessExecution.proto
virtual std::shared_ptr<o2::bookkeeping::DplProcessExecution> Create(std::shared_ptr<o2::bookkeeping::DplProcessExecutionCreationRequest> request) = 0;

/// Register the execution fo a DPL process
virtual void registerProcessExecution(
int runNumber,
o2::bookkeeping::DplProcessType type,
std::string hostname,
std::string deviceId,
std::string args,
std::string detector
) = 0;
};
} // namespace o2::bkp::api::proto

#endif // CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSEXECUTIONPROTOCLIENT_H
26 changes: 26 additions & 0 deletions cxx-client/include/BookkeepingApi/RunProtoClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Created by mboulais on 02/03/23.
//

#ifndef CXX_CLIENT_BOOKKEEPINGAPI_RUNPROTOCLIENT_H
#define CXX_CLIENT_BOOKKEEPINGAPI_RUNPROTOCLIENT_H

#include <memory>
#include "run.pb.h"

namespace o2::bkp::api::proto
{
class RunProtoClient
{
public:
virtual ~RunProtoClient() = default;

/// Returns the run corresponding to the given run number with optionally its relations
virtual std::shared_ptr<bookkeeping::RunWithRelations> Get(const int runNumber, const std::vector<o2::bookkeeping::RunRelations>& relations) = 0;

/// Returns the run and the asked relations defined in the given request
virtual std::shared_ptr<o2::bookkeeping::RunWithRelations> Get(std::shared_ptr<o2::bookkeeping::RunFetchRequest> request) = 0;
};
} // namespace o2::bkp::api::proto

#endif // CXX_CLIENT_BOOKKEEPINGAPI_RUNPROTOCLIENT_H
10 changes: 10 additions & 0 deletions cxx-client/src/BkpProtoClientFactory.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "BookkeepingApi/BkpProtoClientFactory.h"
#include "grpc/GrpcBkpProtoClient.h"

namespace o2::bkp::api::proto
{
std::unique_ptr<BkpProtoClient> BkpProtoClientFactory::create(const std::string& gRPCUri)
{
return std::make_unique<grpc::GrpcBkpProtoClient>(gRPCUri);
}
}; // namespace o2::bkp::api
40 changes: 40 additions & 0 deletions cxx-client/src/grpc/GrpcBkpProtoClient.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#include "GrpcBkpProtoClient.h"
#include <grpc++/grpc++.h>
#include <memory>
#include "grpc/services/GrpcRunProtoClient.h"
#include "grpc/services/GrpcDplProcessExecutionProtoClient.h"

using grpc::InsecureChannelCredentials;
using o2::bkp::api::proto::RunProtoClient;
using std::make_unique;

namespace o2::bkp::api::proto::grpc
{
GrpcBkpProtoClient::GrpcBkpProtoClient(const std::string& uri)
{
auto channel = CreateChannel(uri, InsecureChannelCredentials());
mRunClient = make_unique<services::GrpcRunProtoClient>(channel);
mDplProcessExecutionClient = make_unique<services::GrpcDplProcessExecutionProtoClient>(channel);
}

const std::unique_ptr<RunProtoClient>& GrpcBkpProtoClient::run() const
{
return mRunClient;
}

const std::unique_ptr<DplProcessExecutionProtoClient>& GrpcBkpProtoClient::dplProcessExecution() const
{
return mDplProcessExecutionClient;
}
} // namespace o2::bkp::api::proto
35 changes: 35 additions & 0 deletions cxx-client/src/grpc/GrpcBkpProtoClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef CXX_CLIENT_BOOKKEEPINGAPI_GRPCBKPPROTOCLIENT_H
#define CXX_CLIENT_BOOKKEEPINGAPI_GRPCBKPPROTOCLIENT_H

#include "BookkeepingApi/BkpProtoClient.h"

namespace o2::bkp::api::proto::grpc
{
class GrpcBkpProtoClient : public BkpProtoClient
{
public:
explicit GrpcBkpProtoClient(const std::string& uri);
~GrpcBkpProtoClient() override = default;

const std::unique_ptr<RunProtoClient>& run() const override;

const std::unique_ptr<DplProcessExecutionProtoClient>& dplProcessExecution() const override;

private:
std::unique_ptr<::o2::bkp::api::proto::RunProtoClient> mRunClient;
std::unique_ptr<::o2::bkp::api::proto::DplProcessExecutionProtoClient> mDplProcessExecutionClient;
};
} // namespace o2::bkp::api::proto

#endif // CXX_CLIENT_BOOKKEEPINGAPI_GRPCBKPPROTOCLIENT_H
Loading

0 comments on commit 4511384

Please sign in to comment.