-
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.
feat: Add multiple methods of new services (#482)
- Loading branch information
Showing
12 changed files
with
652 additions
and
18 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
packages/cpp/ArmoniK.Api.Client/header/events/EventsClient.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,21 @@ | ||
#pragma once | ||
|
||
#include "events_common.pb.h" | ||
#include "events_service.grpc.pb.h" | ||
|
||
namespace armonik { | ||
namespace api { | ||
namespace client { | ||
class EventsClient { | ||
public: | ||
explicit EventsClient(std::unique_ptr<armonik::api::grpc::v1::events::Events::StubInterface> stub) | ||
: stub(std::move(stub)) {} | ||
|
||
void wait_for_result_availability(std::string session_id, std::vector<std::string> result_ids); | ||
|
||
private: | ||
std::unique_ptr<armonik::api::grpc::v1::events::Events::StubInterface> stub; | ||
}; | ||
} // namespace client | ||
} // namespace api | ||
} // namespace armonik |
27 changes: 27 additions & 0 deletions
27
packages/cpp/ArmoniK.Api.Client/header/partitions/PartitionsClient.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,27 @@ | ||
#pragma once | ||
|
||
#include "partitions_common.pb.h" | ||
#include "partitions_service.grpc.pb.h" | ||
|
||
namespace armonik { | ||
namespace api { | ||
namespace client { | ||
|
||
class PartitionsClient { | ||
public: | ||
explicit PartitionsClient(std::unique_ptr<armonik::api::grpc::v1::partitions::Partitions::StubInterface> stub) | ||
: stub(std::move(stub)){}; | ||
std::vector<armonik::api::grpc::v1::partitions::PartitionRaw> | ||
list_partitions(armonik::api::grpc::v1::partitions::Filters filters, int32_t &total, int32_t page = -1, | ||
int32_t page_size = 500, | ||
armonik::api::grpc::v1::partitions::ListPartitionsRequest::Sort sort = default_sort()); | ||
|
||
armonik::api::grpc::v1::partitions::PartitionRaw get_partition(std::string partition_id); | ||
|
||
private: | ||
std::unique_ptr<armonik::api::grpc::v1::partitions::Partitions::StubInterface> stub; | ||
static armonik::api::grpc::v1::partitions::ListPartitionsRequest::Sort default_sort(); | ||
}; | ||
} // namespace client | ||
} // namespace api | ||
} // namespace armonik |
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
39 changes: 39 additions & 0 deletions
39
packages/cpp/ArmoniK.Api.Client/header/versions/VersionsClient.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,39 @@ | ||
#pragma once | ||
|
||
#include "versions_common.pb.h" | ||
#include "versions_service.grpc.pb.h" | ||
|
||
namespace armonik { | ||
namespace api { | ||
namespace client { | ||
|
||
/** | ||
* @brief Data structure for components version | ||
* @param api ArmoniK API version | ||
* @param core ArmoniK CORE version | ||
*/ | ||
struct versions_info { | ||
std::string api; | ||
std::string core; | ||
}; | ||
|
||
/** | ||
* Versions Client wrapper | ||
*/ | ||
class VersionsClient { | ||
public: | ||
explicit VersionsClient(std::unique_ptr<armonik::api::grpc::v1::versions::Versions::StubInterface> stub) | ||
: stub(std::move(stub)){}; | ||
|
||
/** | ||
* Get versions of ArmoniK components | ||
* @return Mapping between component names and their versions | ||
*/ | ||
versions_info list_versions(); | ||
|
||
private: | ||
std::unique_ptr<armonik::api::grpc::v1::versions::Versions::StubInterface> stub; | ||
}; | ||
} // namespace client | ||
} // namespace api | ||
} // namespace armonik |
82 changes: 82 additions & 0 deletions
82
packages/cpp/ArmoniK.Api.Client/source/events/EventsClient.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,82 @@ | ||
#include "events/EventsClient.h" | ||
#include "events_common.pb.h" | ||
#include "events_service.grpc.pb.h" | ||
#include "exceptions/ArmoniKApiException.h" | ||
#include "objects.pb.h" | ||
|
||
using armonik::api::grpc::v1::events::EventSubscriptionRequest; | ||
using armonik::api::grpc::v1::events::EventSubscriptionResponse; | ||
using armonik::api::grpc::v1::result_status::ResultStatus; | ||
using namespace armonik::api::grpc::v1::events; | ||
|
||
namespace armonik { | ||
namespace api { | ||
namespace client { | ||
|
||
void EventsClient::wait_for_result_availability(std::string session_id, std::vector<std::string> result_ids) { | ||
|
||
::grpc::ClientContext context; | ||
EventSubscriptionRequest request; | ||
|
||
EventSubscriptionResponse response; | ||
|
||
armonik::api::grpc::v1::results::Filters filters; | ||
armonik::api::grpc::v1::results::FilterField filter_field; | ||
filter_field.mutable_field()->mutable_result_raw_field()->set_field( | ||
armonik::api::grpc::v1::results::RESULT_RAW_ENUM_FIELD_RESULT_ID); | ||
filter_field.mutable_filter_string()->set_operator_(grpc::v1::FILTER_STRING_OPERATOR_EQUAL); | ||
for (auto &&result_id : result_ids) { | ||
filter_field.mutable_filter_string()->set_value(result_id); | ||
*filters.mutable_or_()->Add()->mutable_and_()->Add() = filter_field; | ||
} | ||
|
||
*request.mutable_session_id() = std::move(session_id); | ||
*request.mutable_results_filters() = filters; | ||
request.add_returned_events(static_cast<EventsEnum>(EventSubscriptionResponse::UpdateCase::kResultStatusUpdate)); | ||
request.add_returned_events(static_cast<EventsEnum>(EventSubscriptionResponse::UpdateCase::kNewResult)); | ||
|
||
auto stream = stub->GetEvents(&context, request); | ||
if (!stream) { | ||
throw armonik::api::common::exceptions::ArmoniKApiException("Result has been aborted"); | ||
} | ||
|
||
while (stream->Read(&response)) { | ||
std::string update_or_new; | ||
switch (response.update_case()) { | ||
case EventSubscriptionResponse::UpdateCase::kResultStatusUpdate: | ||
switch (response.mutable_result_status_update()->status()) { | ||
case ResultStatus::RESULT_STATUS_COMPLETED: | ||
update_or_new = response.mutable_result_status_update()->result_id(); | ||
break; | ||
case ResultStatus::RESULT_STATUS_ABORTED: | ||
throw armonik::api::common::exceptions::ArmoniKApiException("Result has been aborted"); | ||
default: | ||
break; | ||
} | ||
break; | ||
case EventSubscriptionResponse::UpdateCase::kNewResult: | ||
switch (response.mutable_new_result()->status()) { | ||
case ResultStatus::RESULT_STATUS_COMPLETED: | ||
update_or_new = response.mutable_new_result()->result_id(); | ||
break; | ||
case ResultStatus::RESULT_STATUS_ABORTED: | ||
throw armonik::api::common::exceptions::ArmoniKApiException("Result has been aborted"); | ||
default: | ||
break; | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
if (!update_or_new.empty()) { | ||
result_ids.erase(std::remove(result_ids.begin(), result_ids.end(), update_or_new), result_ids.end()); | ||
if (result_ids.empty()) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} // namespace client | ||
} // namespace api | ||
} // namespace armonik |
83 changes: 83 additions & 0 deletions
83
packages/cpp/ArmoniK.Api.Client/source/partitions/PartitionsClient.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,83 @@ | ||
#include <utility> | ||
|
||
#include "exceptions/ArmoniKApiException.h" | ||
#include "partitions/PartitionsClient.h" | ||
|
||
using namespace armonik::api::grpc::v1::partitions; | ||
|
||
namespace armonik { | ||
namespace api { | ||
namespace client { | ||
|
||
std::vector<PartitionRaw> PartitionsClient::list_partitions(Filters filters, int32_t &total, int32_t page, | ||
int32_t page_size, ListPartitionsRequest::Sort sort) { | ||
::grpc::ClientContext context; | ||
ListPartitionsRequest request; | ||
ListPartitionsResponse response; | ||
|
||
*request.mutable_filters() = std::move(filters); | ||
*request.mutable_sort() = std::move(sort); | ||
request.set_page_size(page_size); | ||
|
||
if (page >= 0) { | ||
request.set_page(page); | ||
::grpc::ClientContext context; | ||
auto status = stub->ListPartitions(&context, request, &response); | ||
if (!status.ok()) { | ||
throw armonik::api::common::exceptions::ArmoniKApiException("Unable to list partitions " + | ||
status.error_message()); | ||
} | ||
total = response.total(); | ||
return {std::make_move_iterator(response.partitions().begin()), | ||
std::make_move_iterator(response.partitions().end())}; | ||
} else { | ||
std::vector<PartitionRaw> rawPartitions; | ||
int current_page = 0; | ||
do { | ||
request.set_page(current_page); | ||
::grpc::ClientContext context; | ||
auto status = stub->ListPartitions(&context, request, &response); | ||
if (!status.ok()) { | ||
throw armonik::api::common::exceptions::ArmoniKApiException("Unable to list partitions " + | ||
status.error_message()); | ||
} | ||
rawPartitions.insert(rawPartitions.end(), std::make_move_iterator(response.partitions().begin()), | ||
std::make_move_iterator(response.partitions().end())); | ||
if (response.partitions_size() >= page_size) { | ||
current_page++; | ||
} | ||
|
||
response.clear_partitions(); | ||
} while ((int32_t)rawPartitions.size() < response.total()); | ||
|
||
total = response.total(); | ||
|
||
return rawPartitions; | ||
} | ||
} | ||
|
||
PartitionRaw PartitionsClient::get_partition(std::string partition_id) { | ||
::grpc::ClientContext context; | ||
GetPartitionRequest request; | ||
GetPartitionResponse response; | ||
|
||
*request.mutable_id() = std::move(partition_id); | ||
auto status = stub->GetPartition(&context, request, &response); | ||
if (!status.ok()) { | ||
throw armonik::api::common::exceptions::ArmoniKApiException("Could not get partition : " + status.error_message()); | ||
} | ||
|
||
return std::move(*response.mutable_partition()); | ||
} | ||
|
||
ListPartitionsRequest::Sort PartitionsClient::default_sort() { | ||
ListPartitionsRequest::Sort sort; | ||
sort.set_direction(grpc::v1::sort_direction::SORT_DIRECTION_ASC); | ||
sort.mutable_field()->mutable_partition_raw_field()->set_field( | ||
grpc::v1::partitions::PARTITION_RAW_ENUM_FIELD_PRIORITY); | ||
return sort; | ||
} | ||
|
||
} // namespace client | ||
} // namespace api | ||
} // namespace armonik |
Oops, something went wrong.