-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
296 additions
and
60 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef ARMONIK_API_RESULTSCLIENT_H | ||
#define ARMONIK_API_RESULTSCLIENT_H | ||
|
||
#include <results_service.grpc.pb.h> | ||
|
||
namespace API_CLIENT_NAMESPACE { | ||
class ResultsClient { | ||
public: | ||
explicit ResultsClient(std::unique_ptr<armonik::api::grpc::v1::results::Results::Stub> stub) | ||
: stub(std::move(stub)) {} | ||
|
||
std::map<std::string, std::string> create_results(std::string_view session_id, const std::vector<std::string> &names); | ||
void upload_result_data(const std::string &session_id, const std::string &result_id, std::string_view payload); | ||
|
||
private: | ||
std::unique_ptr<armonik::api::grpc::v1::results::Results::Stub> stub; | ||
}; | ||
} // namespace API_CLIENT_NAMESPACE | ||
|
||
#endif // ARMONIK_API_RESULTSCLIENT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include "submitter/ResultsClient.h" | ||
#include "exceptions/ArmoniKApiException.h" | ||
#include <sstream> | ||
|
||
namespace API_CLIENT_NAMESPACE { | ||
|
||
std::map<std::string, std::string> ResultsClient::create_results(std::string_view session_id, | ||
const std::vector<std::string> &names) { | ||
std::map<std::string, std::string> mapping; | ||
grpc::ClientContext context; | ||
armonik::api::grpc::v1::results::CreateResultsMetaDataRequest results_request; | ||
armonik::api::grpc::v1::results::CreateResultsMetaDataResponse results_response; | ||
|
||
// Creates the result creation requests | ||
std::vector<armonik::api::grpc::v1::results::CreateResultsMetaDataRequest_ResultCreate> results_create; | ||
results_create.reserve(names.size()); | ||
for (auto &&name : names) { | ||
armonik::api::grpc::v1::results::CreateResultsMetaDataRequest_ResultCreate result_create; | ||
result_create.set_name(name); | ||
results_create.push_back(result_create); | ||
} | ||
|
||
results_request.mutable_results()->Add(results_create.begin(), results_create.end()); | ||
*results_request.mutable_session_id() = session_id; | ||
|
||
// Creates the results | ||
auto status = stub->CreateResultsMetaData(&context, results_request, &results_response); | ||
|
||
if (!status.ok()) { | ||
std::stringstream message; | ||
message << "Error: " << status.error_code() << ": " << status.error_message() | ||
<< ". details : " << status.error_details() << std::endl; | ||
auto str = message.str(); | ||
std::cerr << "Could not create results for submit: " << str << std::endl; | ||
throw ArmoniK::Api::Common::exceptions::ArmoniKApiException(str); | ||
} | ||
|
||
for (auto &&res : results_response.results()) { | ||
mapping.insert({res.name(), res.result_id()}); | ||
} | ||
return mapping; | ||
} | ||
void ResultsClient::upload_result_data(const std::string &session_id, const std::string &result_id, | ||
std::string_view payload) { | ||
grpc::ClientContext context; | ||
armonik::api::grpc::v1::results::ResultsServiceConfigurationResponse configuration; | ||
auto status = stub->GetServiceConfiguration(&context, armonik::api::grpc::v1::Empty(), &configuration); | ||
if (!status.ok()) { | ||
throw ArmoniK::Api::Common::exceptions::ArmoniKApiException("Unable to get result configuration : " + | ||
status.error_message()); | ||
} | ||
|
||
size_t maxChunkSize = configuration.data_chunk_max_size(); | ||
|
||
armonik::api::grpc::v1::results::UploadResultDataResponse response; | ||
// response.set_allocated_result(new armonik::api::grpc::v1::results::ResultRaw()); | ||
grpc::ClientContext streamContext; | ||
auto stream = stub->UploadResultData(&streamContext, &response); | ||
armonik::api::grpc::v1::results::UploadResultDataRequest request; | ||
request.mutable_id()->set_session_id(session_id); | ||
request.mutable_id()->set_result_id(result_id); | ||
stream->Write(request); | ||
size_t offset = 0; | ||
|
||
while (offset < payload.size()) { | ||
size_t chunkSize = std::min(maxChunkSize, payload.size() - offset); | ||
|
||
*request.mutable_data_chunk() = payload.substr(offset, chunkSize); | ||
if (!stream->Write(request)) { | ||
throw ArmoniK::Api::Common::exceptions::ArmoniKApiException("Unable to continue upload result"); | ||
} | ||
offset += chunkSize; | ||
} | ||
|
||
if (!stream->WritesDone()) { | ||
throw ArmoniK::Api::Common::exceptions::ArmoniKApiException("Unable to upload result"); | ||
} | ||
status = stream->Finish(); | ||
if (!status.ok()) { | ||
throw ArmoniK::Api::Common::exceptions::ArmoniKApiException("Unable to finish upload result " + | ||
status.error_message()); | ||
} | ||
} | ||
} // namespace API_CLIENT_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.