added grpc and utils
This commit is contained in:
parent
9239ad04e9
commit
e116c51948
|
|
@ -156,6 +156,8 @@ namespace etcd
|
|||
pplx::task<etcd::Response> send_get(std::string const & key);
|
||||
pplx::task<etcd::Response> send_asyncmodify_if(std::string const & key, std::string const & value, std::string const & old_value);
|
||||
pplx::task<etcd::Response> send_asyncdelete(std::string const & key, bool recursive);
|
||||
|
||||
etcdv3::grpcClient grpcClient;
|
||||
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ using etcdserverpb::WatchResponse;
|
|||
using etcdserverpb::WatchCreateRequest;
|
||||
|
||||
etcd::Client::Client(std::string const & address)
|
||||
: client(address)
|
||||
: client(address), grpcClient(address)
|
||||
{
|
||||
std::string stripped_address(address);
|
||||
std::string substr("http://");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef __UTILS_HPP__
|
||||
#define __UTILS_HPP__
|
||||
|
||||
#include "v3/include/AsyncRangeResponse.hpp"
|
||||
#include "v3/include/grpcClient.hpp"
|
||||
|
||||
namespace etcdv3
|
||||
{
|
||||
namespace Utils
|
||||
{
|
||||
etcdv3::AsyncRangeResponse* getKey(std::string const & key, etcdv3::grpcClient& client);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef __GRPC_CLIENT_HPP__
|
||||
#define __GRPC_CLIENT_HPP__
|
||||
|
||||
#include <grpc++/grpc++.h>
|
||||
#include "proto/rpc.grpc.pb.h"
|
||||
#include "v3/include/AsyncRangeResponse.hpp"
|
||||
|
||||
|
||||
using grpc::Channel;
|
||||
using etcdserverpb::PutRequest;
|
||||
using etcdserverpb::RangeRequest;
|
||||
using etcdserverpb::KV;
|
||||
|
||||
namespace etcdv3
|
||||
{
|
||||
|
||||
class grpcClient
|
||||
{
|
||||
public:
|
||||
grpcClient(std::string const & address);
|
||||
std::unique_ptr<KV::Stub> stub_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#include "v3/include/AsyncRangeResponse.hpp"
|
||||
#include "proto/rpc.grpc.pb.h"
|
||||
using etcdserverpb::RangeRequest;
|
||||
|
||||
#include "v3/include/Utils.hpp"
|
||||
|
||||
|
||||
etcdv3::AsyncRangeResponse* etcdv3::Utils::getKey(std::string const & key, etcdv3::grpcClient& client)
|
||||
{
|
||||
RangeRequest get_request;
|
||||
get_request.set_key(key);
|
||||
etcdv3::AsyncRangeResponse* resp= new etcdv3::AsyncRangeResponse();
|
||||
|
||||
resp->status = client.stub_->Range(&resp->context, get_request, &resp->reply);
|
||||
|
||||
if(resp->status.ok())
|
||||
{
|
||||
return resp;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error(resp->status.error_message());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
#include "v3/include/grpcClient.hpp"
|
||||
|
||||
etcdv3::grpcClient::grpcClient(std::string const & address)
|
||||
{
|
||||
std::string stripped_address(address);
|
||||
std::string substr("http://");
|
||||
std::string::size_type i = stripped_address.find(substr);
|
||||
if(i != std::string::npos)
|
||||
{
|
||||
stripped_address.erase(i,substr.length());
|
||||
}
|
||||
std::shared_ptr<Channel> channel = grpc::CreateChannel(stripped_address, grpc::InsecureChannelCredentials());
|
||||
stub_= KV::NewStub(channel);
|
||||
}
|
||||
Loading…
Reference in New Issue