227 lines
9.3 KiB
Diff
227 lines
9.3 KiB
Diff
From 92ceff55c726abfabdc6e7f54d4e67b0c6c24196 Mon Sep 17 00:00:00 2001
|
|
From: wujing <wujing50@huawei.com>
|
|
Date: Tue, 18 Jan 2022 19:59:39 +0800
|
|
Subject: [PATCH 10/16] clean the gRPC client module code
|
|
|
|
Signed-off-by: wujing <wujing50@huawei.com>
|
|
---
|
|
src/client/connect/grpc/client_base.h | 4 +-
|
|
.../connect/grpc/grpc_containers_client.cc | 2 +-
|
|
src/client/connect/grpc/grpc_images_client.cc | 37 +++++++++++--------
|
|
.../connect/grpc/grpc_volumes_client.cc | 27 +++++++-------
|
|
4 files changed, 38 insertions(+), 32 deletions(-)
|
|
|
|
diff --git a/src/client/connect/grpc/client_base.h b/src/client/connect/grpc/client_base.h
|
|
index f37bf471..dbe130cd 100644
|
|
--- a/src/client/connect/grpc/client_base.h
|
|
+++ b/src/client/connect/grpc/client_base.h
|
|
@@ -41,7 +41,7 @@ class ClientBase {
|
|
public:
|
|
explicit ClientBase(void *args)
|
|
{
|
|
- client_connect_config_t *arguments = reinterpret_cast<client_connect_config_t *>(args);
|
|
+ auto *arguments = reinterpret_cast<client_connect_config_t *>(args);
|
|
|
|
std::string socket_address = arguments->socket;
|
|
const std::string tcp_prefix = "tcp://";
|
|
@@ -207,7 +207,7 @@ protected:
|
|
|
|
std::unique_ptr<sTB> stub_;
|
|
std::string m_tlsMode { ClientBaseConstants::TLS_OFF };
|
|
- std::string m_certFile { "" };
|
|
+ std::string m_certFile;
|
|
|
|
unsigned int deadline;
|
|
};
|
|
diff --git a/src/client/connect/grpc/grpc_containers_client.cc b/src/client/connect/grpc/grpc_containers_client.cc
|
|
index 822edd8f..ebe71df9 100644
|
|
--- a/src/client/connect/grpc/grpc_containers_client.cc
|
|
+++ b/src/client/connect/grpc/grpc_containers_client.cc
|
|
@@ -2138,7 +2138,7 @@ public:
|
|
// Set common name from cert.perm
|
|
char common_name_value[ClientBaseConstants::COMMON_NAME_LEN] = { 0 };
|
|
int ret = get_common_name_from_tls_cert(m_certFile.c_str(), common_name_value,
|
|
- ClientBaseConstants::COMMON_NAME_LEN);
|
|
+ ClientBaseConstants::COMMON_NAME_LEN);
|
|
if (ret != 0) {
|
|
ERROR("Failed to get common name in: %s", m_certFile.c_str());
|
|
return -1;
|
|
diff --git a/src/client/connect/grpc/grpc_images_client.cc b/src/client/connect/grpc/grpc_images_client.cc
|
|
index 1bc12e69..50265e04 100644
|
|
--- a/src/client/connect/grpc/grpc_images_client.cc
|
|
+++ b/src/client/connect/grpc/grpc_images_client.cc
|
|
@@ -81,8 +81,8 @@ public:
|
|
for (i = 0; i < num; i++) {
|
|
const Image &image = gresponse->images(i);
|
|
if (image.has_target()) {
|
|
- const char *media_type =
|
|
- !image.target().media_type().empty() ? image.target().media_type().c_str() : "-";
|
|
+ const char *media_type = !image.target().media_type().empty() ? image.target().media_type().c_str() :
|
|
+ "-";
|
|
images_list[i].type = util_strdup_s(media_type);
|
|
const char *digest = !image.target().digest().empty() ? image.target().digest().c_str() : "-";
|
|
images_list[i].digest = util_strdup_s(digest);
|
|
@@ -336,9 +336,9 @@ public:
|
|
}
|
|
};
|
|
|
|
-class ImagesPull : public
|
|
- ClientBase<runtime::v1alpha2::ImageService, runtime::v1alpha2::ImageService::Stub, isula_pull_request,
|
|
- runtime::v1alpha2::PullImageRequest, isula_pull_response, runtime::v1alpha2::PullImageResponse> {
|
|
+class ImagesPull : public ClientBase<runtime::v1alpha2::ImageService, runtime::v1alpha2::ImageService::Stub,
|
|
+ isula_pull_request, runtime::v1alpha2::PullImageRequest, isula_pull_response,
|
|
+ runtime::v1alpha2::PullImageResponse> {
|
|
public:
|
|
explicit ImagesPull(void *args)
|
|
: ClientBase(args)
|
|
@@ -346,14 +346,15 @@ public:
|
|
}
|
|
~ImagesPull() = default;
|
|
|
|
- auto request_to_grpc(const isula_pull_request *request, runtime::v1alpha2::PullImageRequest *grequest) -> int override
|
|
+ auto request_to_grpc(const isula_pull_request *request, runtime::v1alpha2::PullImageRequest *grequest)
|
|
+ -> int override
|
|
{
|
|
if (request == nullptr) {
|
|
return -1;
|
|
}
|
|
|
|
if (request->image_name != nullptr) {
|
|
- runtime::v1alpha2::ImageSpec *image_spec = new (std::nothrow) runtime::v1alpha2::ImageSpec;
|
|
+ auto *image_spec = new (std::nothrow) runtime::v1alpha2::ImageSpec;
|
|
if (image_spec == nullptr) {
|
|
return -1;
|
|
}
|
|
@@ -364,7 +365,8 @@ public:
|
|
return 0;
|
|
}
|
|
|
|
- auto response_from_grpc(runtime::v1alpha2::PullImageResponse *gresponse, isula_pull_response *response) -> int override
|
|
+ auto response_from_grpc(runtime::v1alpha2::PullImageResponse *gresponse, isula_pull_response *response)
|
|
+ -> int override
|
|
{
|
|
if (!gresponse->image_ref().empty()) {
|
|
response->image_ref = util_strdup_s(gresponse->image_ref().c_str());
|
|
@@ -437,17 +439,20 @@ public:
|
|
return 0;
|
|
}
|
|
|
|
- auto grpc_call(ClientContext *context, const InspectImageRequest &req, InspectImageResponse *reply) -> Status override
|
|
+ auto grpc_call(ClientContext *context, const InspectImageRequest &req, InspectImageResponse *reply)
|
|
+ -> Status override
|
|
{
|
|
return stub_->Inspect(context, req, reply);
|
|
}
|
|
};
|
|
|
|
-class Login : public
|
|
- ClientBase<ImagesService, ImagesService::Stub, isula_login_request, LoginRequest,
|
|
+class Login : public ClientBase<ImagesService, ImagesService::Stub, isula_login_request, LoginRequest,
|
|
isula_login_response, LoginResponse> {
|
|
public:
|
|
- explicit Login(void *args) : ClientBase(args) {}
|
|
+ explicit Login(void *args)
|
|
+ : ClientBase(args)
|
|
+ {
|
|
+ }
|
|
~Login() = default;
|
|
|
|
auto request_to_grpc(const isula_login_request *request, LoginRequest *grequest) -> int override
|
|
@@ -511,11 +516,13 @@ public:
|
|
}
|
|
};
|
|
|
|
-class Logout : public
|
|
- ClientBase<ImagesService, ImagesService::Stub, isula_logout_request, LogoutRequest,
|
|
+class Logout : public ClientBase<ImagesService, ImagesService::Stub, isula_logout_request, LogoutRequest,
|
|
isula_logout_response, LogoutResponse> {
|
|
public:
|
|
- explicit Logout(void *args) : ClientBase(args) {}
|
|
+ explicit Logout(void *args)
|
|
+ : ClientBase(args)
|
|
+ {
|
|
+ }
|
|
~Logout() = default;
|
|
|
|
auto request_to_grpc(const isula_logout_request *request, LogoutRequest *grequest) -> int override
|
|
diff --git a/src/client/connect/grpc/grpc_volumes_client.cc b/src/client/connect/grpc/grpc_volumes_client.cc
|
|
index d8eb74b2..5d55b8c8 100644
|
|
--- a/src/client/connect/grpc/grpc_volumes_client.cc
|
|
+++ b/src/client/connect/grpc/grpc_volumes_client.cc
|
|
@@ -27,10 +27,10 @@ using grpc::ClientContext;
|
|
using grpc::Status;
|
|
|
|
class VolumeList : public ClientBase<VolumeService, VolumeService::Stub, isula_list_volume_request, ListVolumeRequest,
|
|
- isula_list_volume_response, ListVolumeResponse> {
|
|
+ isula_list_volume_response, ListVolumeResponse> {
|
|
public:
|
|
explicit VolumeList(void *args)
|
|
- : ClientBase(args)
|
|
+ : ClientBase(args)
|
|
{
|
|
}
|
|
~VolumeList() = default;
|
|
@@ -57,8 +57,8 @@ public:
|
|
response->cc = ISULAD_ERR_MEMOUT;
|
|
return -1;
|
|
}
|
|
- auto volumes = static_cast<struct isula_volume_info *>(
|
|
- util_common_calloc_s(sizeof(struct isula_volume_info) * static_cast<size_t>(num)));
|
|
+ auto *volumes = static_cast<struct isula_volume_info *>(
|
|
+ util_smart_calloc_s(sizeof(struct isula_volume_info), static_cast<size_t>(num)));
|
|
if (volumes == nullptr) {
|
|
ERROR("out of memory");
|
|
response->cc = ISULAD_ERR_MEMOUT;
|
|
@@ -89,12 +89,11 @@ public:
|
|
}
|
|
};
|
|
|
|
-class VolumeRemove : public
|
|
- ClientBase<VolumeService, VolumeService::Stub, isula_remove_volume_request, RemoveVolumeRequest,
|
|
- isula_remove_volume_response, RemoveVolumeResponse> {
|
|
+class VolumeRemove : public ClientBase<VolumeService, VolumeService::Stub, isula_remove_volume_request,
|
|
+ RemoveVolumeRequest, isula_remove_volume_response, RemoveVolumeResponse> {
|
|
public:
|
|
explicit VolumeRemove(void *args)
|
|
- : ClientBase(args)
|
|
+ : ClientBase(args)
|
|
{
|
|
}
|
|
~VolumeRemove() = default;
|
|
@@ -135,18 +134,18 @@ public:
|
|
return 0;
|
|
}
|
|
|
|
- auto grpc_call(ClientContext *context, const RemoveVolumeRequest &req, RemoveVolumeResponse *reply) -> Status override
|
|
+ auto grpc_call(ClientContext *context, const RemoveVolumeRequest &req, RemoveVolumeResponse *reply)
|
|
+ -> Status override
|
|
{
|
|
return stub_->Remove(context, req, reply);
|
|
}
|
|
};
|
|
|
|
-class VolumePrune : public
|
|
- ClientBase<VolumeService, VolumeService::Stub, isula_prune_volume_request, PruneVolumeRequest,
|
|
- isula_prune_volume_response, PruneVolumeResponse> {
|
|
+class VolumePrune : public ClientBase<VolumeService, VolumeService::Stub, isula_prune_volume_request,
|
|
+ PruneVolumeRequest, isula_prune_volume_response, PruneVolumeResponse> {
|
|
public:
|
|
explicit VolumePrune(void *args)
|
|
- : ClientBase(args)
|
|
+ : ClientBase(args)
|
|
{
|
|
}
|
|
~VolumePrune() = default;
|
|
@@ -158,7 +157,7 @@ public:
|
|
auto size = gresponse->volumes_size();
|
|
if (size != 0) {
|
|
response->volumes = static_cast<char **>(util_common_calloc_s(sizeof(char *) * size));
|
|
- if (response->volumes == NULL) {
|
|
+ if (response->volumes == nullptr) {
|
|
return -1;
|
|
}
|
|
|
|
--
|
|
2.20.1
|
|
|