added grpc and utils

This commit is contained in:
arches 2016-06-16 07:11:17 -04:00
parent 9239ad04e9
commit e116c51948
6 changed files with 81 additions and 1 deletions

View File

@ -157,6 +157,8 @@ namespace etcd
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_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); pplx::task<etcd::Response> send_asyncdelete(std::string const & key, bool recursive);
etcdv3::grpcClient grpcClient;
private: private:
pplx::task<Response> removeEntryWithKey(std::string const &entryKey); pplx::task<Response> removeEntryWithKey(std::string const &entryKey);

View File

@ -20,7 +20,7 @@ using etcdserverpb::WatchResponse;
using etcdserverpb::WatchCreateRequest; using etcdserverpb::WatchCreateRequest;
etcd::Client::Client(std::string const & address) etcd::Client::Client(std::string const & address)
: client(address) : client(address), grpcClient(address)
{ {
std::string stripped_address(address); std::string stripped_address(address);
std::string substr("http://"); std::string substr("http://");

15
v3/include/Utils.hpp Normal file
View File

@ -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

25
v3/include/grpcClient.hpp Normal file
View File

@ -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

24
v3/src/Utils.cpp Normal file
View File

@ -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());
}
}

14
v3/src/grpcClient.cpp Normal file
View File

@ -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);
}