Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[O2B-1010] Add DPL client not exposing proto #1539

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cxx-client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ protobuf_generate(
add_library(BookkeepingApi SHARED
src/grpc/GrpcBkpClient.cxx
src/grpc/services/GrpcFlpServiceClient.cxx
src/grpc/services/GrpcDplProcessExecutionClient.cxx
src/BkpClientFactory.cxx
)

Expand Down
5 changes: 5 additions & 0 deletions cxx-client/example/exampleSpecificServices.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ int main(int argc, char** argv)
}

try {
// Test of FLP counters update
auto client = BkpClientFactory::create(argv[1]);
client->flp()->updateReadoutCountersByFlpNameAndRunNumber("FLP-TPC-1", 1, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF);
std::cout << "FLP counters have been successfully updated" << std::endl;


// Test of DPL process execution
client->dplProcessExecution()->registerProcessExecution(106, o2::bkp::DplProcessType::QC_CHECKER, "SECOND-HOSTNAME", "PROCESS-NAME", "", "DEFAUlT");
} catch (std::runtime_error& error) {
std::cerr << "An error occurred: " << error.what() << std::endl;
exit(2);
Expand Down
4 changes: 4 additions & 0 deletions cxx-client/include/BookkeepingApi/BkpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <memory>
#include "FlpServiceClient.h"
#include "DplProcessExecutionClient.h"

namespace o2::bkp::api
{
Expand All @@ -25,6 +26,9 @@ class BkpClient

/// Return the client for FLP service
virtual const std::unique_ptr<FlpServiceClient>& flp() const = 0;

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

Expand Down
37 changes: 37 additions & 0 deletions cxx-client/include/BookkeepingApi/DplProcessExecutionClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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_DPLPROCESSEXECUTIONCLIENT_H
#define CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSEXECUTIONCLIENT_H

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

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

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

#endif // CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSEXECUTIONCLIENT_H
22 changes: 22 additions & 0 deletions cxx-client/include/BookkeepingApi/DplProcessType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Created by mboulais on 22/04/24.
//

#ifndef CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSTYPE_H
#define CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSTYPE_H

namespace o2::bkp
{
// Enum values map the proto values, and will map to pb generated file without need for conversion
enum class DplProcessType {
_NULL = 0,
QC_TASK = 1,
QC_CHECKER = 2,
QC_AGGREGATOR = 3,
QC_POSTPROCESSING = 4,
DISPATCHER = 5,
MERGER = 6,
};
} // namespace o2::bkp

#endif // CXX_CLIENT_BOOKKEEPINGAPI_DPLPROCESSTYPE_H
6 changes: 3 additions & 3 deletions cxx-client/include/BookkeepingApi/FlpServiceClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// Created by martin on 12/01/23.
//

#ifndef CXX_CLIENT_BOOKKEEPINGAPI_FLPSERVICECLIENT_H_
#define CXX_CLIENT_BOOKKEEPINGAPI_FLPSERVICECLIENT_H_
#ifndef CXX_CLIENT_BOOKKEEPINGAPI_FLPSERVICECLIENT_H
#define CXX_CLIENT_BOOKKEEPINGAPI_FLPSERVICECLIENT_H

#include <string>
#include <cstdint>
Expand All @@ -37,4 +37,4 @@ class FlpServiceClient
};
} // namespace o2::bkp::api

#endif // CXX_CLIENT_BOOKKEEPINGAPI_FLPSERVICECLIENT_H_
#endif // CXX_CLIENT_BOOKKEEPINGAPI_FLPSERVICECLIENT_H
8 changes: 7 additions & 1 deletion cxx-client/src/grpc/GrpcBkpClient.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "GrpcBkpClient.h"
#include <memory>
#include <grpc++/grpc++.h>
#include "flp.grpc.pb.h"

using grpc::Channel;

Expand All @@ -28,15 +27,22 @@ using std::unique_ptr;
namespace o2::bkp::api::grpc
{
using services::GrpcFlpServiceClient;
using services::GrpcDplProcessExecutionClient;

GrpcBkpClient::GrpcBkpClient(const string& uri)
{
auto channel = CreateChannel(uri, InsecureChannelCredentials());
mFlpClient = make_unique<GrpcFlpServiceClient>(channel);
mDplProcessExecutionClient = make_unique<GrpcDplProcessExecutionClient>(channel);
}

const unique_ptr<FlpServiceClient>& GrpcBkpClient::flp() const
{
return mFlpClient;
}

const std::unique_ptr<DplProcessExecutionClient>& GrpcBkpClient::dplProcessExecution() const
{
return mDplProcessExecutionClient;
}
} // namespace o2::bkp::api::grpc
4 changes: 4 additions & 0 deletions cxx-client/src/grpc/GrpcBkpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "flp.grpc.pb.h"
#include "BookkeepingApi/BkpClient.h"
#include "grpc/services/GrpcFlpServiceClient.h"
#include "grpc/services/GrpcDplProcessExecutionClient.h"

namespace o2::bkp::api::grpc
{
Expand All @@ -27,8 +28,11 @@ class GrpcBkpClient : public o2::bkp::api::BkpClient

const std::unique_ptr<FlpServiceClient>& flp() const override;

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

private:
std::unique_ptr<::o2::bkp::api::FlpServiceClient> mFlpClient;
std::unique_ptr<::o2::bkp::api::DplProcessExecutionClient> mDplProcessExecutionClient;
};
} // namespace o2::bkp::api::grpc

Expand Down
56 changes: 56 additions & 0 deletions cxx-client/src/grpc/services/GrpcDplProcessExecutionClient.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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 "GrpcDplProcessExecutionClient.h"

using grpc::ClientContext;
using o2::bkp::DplProcessType;
using o2::bookkeeping::DplProcessExecution;
using o2::bookkeeping::DplProcessExecutionCreationRequest;
using o2::bookkeeping::DplProcessExecutionService;

namespace o2::bkp
{

namespace api::grpc::services
{
GrpcDplProcessExecutionClient::GrpcDplProcessExecutionClient(const std::shared_ptr<::grpc::ChannelInterface>& channel)
{
mStub = DplProcessExecutionService::NewStub(channel);
}

void GrpcDplProcessExecutionClient::registerProcessExecution(
int runNumber,
DplProcessType type,
std::string hostname,
std::string deviceId,
std::string args,
std::string detector)
{
auto request = std::make_shared<DplProcessExecutionCreationRequest>();
request->set_runnumber(runNumber);
request->set_detectorname(detector);
request->set_processname(deviceId);
request->set_type(static_cast<o2::bookkeeping::DplProcessType>(type));
request->set_hostname(hostname);

ClientContext context;
auto response = std::make_shared<DplProcessExecution>();

auto status = mStub->Create(&context, *request, response.get());

if (!status.ok()) {
throw std::runtime_error(status.error_message());
}
}
} // namespace api::grpc::services

} // namespace o2::bkp
38 changes: 38 additions & 0 deletions cxx-client/src/grpc/services/GrpcDplProcessExecutionClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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_GRPC_SERVICES_GRPCDPLPROCESSEXECUTIONCLIENT_H
#define CXX_CLIENT_BOOKKEEPINGAPI_GRPC_SERVICES_GRPCDPLPROCESSEXECUTIONCLIENT_H

#include "BookkeepingApi/DplProcessExecutionClient.h"
#include "dplProcessExecution.grpc.pb.h"

namespace o2::bkp::api::grpc::services
{
class GrpcDplProcessExecutionClient : public ::o2::bkp::api::DplProcessExecutionClient
{
public:
explicit GrpcDplProcessExecutionClient(const std::shared_ptr<::grpc::ChannelInterface>& channel);

void registerProcessExecution(
int runNumber,
o2::bkp::DplProcessType type,
std::string hostname,
std::string deviceId,
std::string args,
std::string detector) override;

private:
std::unique_ptr<o2::bookkeeping::DplProcessExecutionService::Stub> mStub;
};
} // namespace o2::bkp::api::grpc::services

#endif // CXX_CLIENT_BOOKKEEPINGAPI_GRPC_SERVICES_GRPCDPLPROCESSEXECUTIONCLIENT_H
2 changes: 1 addition & 1 deletion proto/dplProcessExecution.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ enum DplProcessType {
DPL_PROCESS_TYPE_QC_POSTPROCESSING = 4;
DPL_PROCESS_TYPE_DISPATCHER = 5;
DPL_PROCESS_TYPE_MERGER = 6;
}
}
Loading