Skip to content

Commit

Permalink
Remove protobuf based entry calls. (envoyproxy#11)
Browse files Browse the repository at this point in the history
* Remove protobuf based entry calls.

* Add new file src/client_impl_test.cc

* Updated comment

* move time_v outside of union.

* Fix format.
  • Loading branch information
qiwzhang authored Jan 18, 2017
1 parent 017f722 commit 755b410
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 248 deletions.
17 changes: 14 additions & 3 deletions mixerclient/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cc_library(
srcs = [
"src/client_impl.cc",
"src/client_impl.h",
"src/transport_impl.h",
"src/stream_transport.h",
],
hdrs = [
"include/client.h",
Expand All @@ -46,7 +46,18 @@ cc_library(
)

cc_test(
name = "mixer_client_impl_test",
name = "stream_transport_test",
size = "small",
srcs = ["src/stream_transport_test.cc"],
linkopts = ["-lm"],
deps = [
":mixer_client_lib",
"//external:googletest_main",
],
)

cc_test(
name = "client_impl_test",
size = "small",
srcs = ["src/client_impl_test.cc"],
linkopts = ["-lm"],
Expand All @@ -68,4 +79,4 @@ cc_test(
":simple_lru_cache",
"//external:googletest_main",
],
)
)
38 changes: 11 additions & 27 deletions mixerclient/include/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <string>

#include "google/protobuf/stubs/status.h"
#include "mixer/api/v1/service.pb.h"
#include "options.h"
#include "transport.h"

Expand Down Expand Up @@ -67,12 +66,14 @@ struct Attributes {

// Data value
union {
std::string str_v; // for both STRING and BYTES
int64_t int64_v;
double double_v;
bool bool_v;
std::chrono::time_point<std::chrono::system_clock> time_v;
} value;
// Move types with constructor outside of union.
// It is not easy for union to support them.
std::string str_v; // for both STRING and BYTES
std::chrono::time_point<std::chrono::system_clock> time_v;
};

std::map<std::string, Value> attributes;
Expand All @@ -84,38 +85,21 @@ class MixerClient {
virtual ~MixerClient() {}

// Attribute based calls will be used.
// The protobuf message based calls will be removed.
// Callers should pass in the full set of attributes for the call.
// The client will use the full set attributes to check cache. If cache
// miss, an attribute context based on the underline gRPC stream will
// miss, an attribute context based on the underlying gRPC stream will
// be used to generate attribute_update and send that to Mixer server.
// Callers don't need response data, they only need success or failure.
// The response data from mixer will be consumed by mixer client.

// A check call.
virtual void Check(const Attributes& attributes, DoneFunc on_done) = 0;

// A report call.
virtual void Report(const Attributes& attributes, DoneFunc on_done) = 0;
virtual void Quota(const Attributes& attributes, DoneFunc on_done) = 0;

// The async call.
// on_check_done is called with the check status after cached
// check_response is returned in case of cache hit, otherwise called after
// check_response is returned from the Controller service.
//
// check_response must be alive until on_check_done is called.
virtual void Check(const ::istio::mixer::v1::CheckRequest& check_request,
::istio::mixer::v1::CheckResponse* check_response,
DoneFunc on_check_done) = 0;

// This is async call. on_report_done is always called when the
// report request is finished.
virtual void Report(const ::istio::mixer::v1::ReportRequest& report_request,
::istio::mixer::v1::ReportResponse* report_response,
DoneFunc on_report_done) = 0;

// This is async call. on_quota_done is always called when the
// quota request is finished.
virtual void Quota(const ::istio::mixer::v1::QuotaRequest& quota_request,
::istio::mixer::v1::QuotaResponse* quota_response,
DoneFunc on_quota_done) = 0;
// A quota call.
virtual void Quota(const Attributes& attributes, DoneFunc on_done) = 0;
};

// Creates a MixerClient object.
Expand Down
27 changes: 9 additions & 18 deletions mixerclient/src/client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,21 @@ MixerClientImpl::MixerClientImpl(const MixerClientOptions &options)
MixerClientImpl::~MixerClientImpl() {}

void MixerClientImpl::Check(const Attributes &attributes, DoneFunc on_done) {
on_done(Status(Code::UNIMPLEMENTED, "Method not implemented."));
CheckRequest request;
CheckResponse response;
check_transport_.Call(request, &response, on_done);
}

void MixerClientImpl::Report(const Attributes &attributes, DoneFunc on_done) {
on_done(Status(Code::UNIMPLEMENTED, "Method not implemented."));
ReportRequest request;
ReportResponse response;
report_transport_.Call(request, &response, on_done);
}

void MixerClientImpl::Quota(const Attributes &attributes, DoneFunc on_done) {
on_done(Status(Code::UNIMPLEMENTED, "Method not implemented."));
}

void MixerClientImpl::Check(const CheckRequest &request,
CheckResponse *response, DoneFunc on_done) {
check_transport_.Call(request, response, on_done);
}

void MixerClientImpl::Report(const ReportRequest &request,
ReportResponse *response, DoneFunc on_done) {
report_transport_.Call(request, response, on_done);
}

void MixerClientImpl::Quota(const QuotaRequest &request,
QuotaResponse *response, DoneFunc on_done) {
quota_transport_.Call(request, response, on_done);
QuotaRequest request;
QuotaResponse response;
quota_transport_.Call(request, &response, on_done);
}

// Creates a MixerClient object.
Expand Down
24 changes: 1 addition & 23 deletions mixerclient/src/client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define MIXERCLIENT_CLIENT_IMPL_H

#include "include/client.h"
#include "src/transport_impl.h"
#include "src/stream_transport.h"

namespace istio {
namespace mixer_client {
Expand All @@ -34,28 +34,6 @@ class MixerClientImpl : public MixerClient {
virtual void Report(const Attributes& attributes, DoneFunc on_done);
virtual void Quota(const Attributes& attributes, DoneFunc on_done);

// The async call.
// on_check_done is called with the check status after cached
// check_response is returned in case of cache hit, otherwise called after
// check_response is returned from the Controller service.
//
// check_response must be alive until on_check_done is called.
virtual void Check(const ::istio::mixer::v1::CheckRequest& check_request,
::istio::mixer::v1::CheckResponse* check_response,
DoneFunc on_check_done);

// This is async call. on_report_done is always called when the
// report request is finished.
virtual void Report(const ::istio::mixer::v1::ReportRequest& report_request,
::istio::mixer::v1::ReportResponse* report_response,
DoneFunc on_report_done);

// This is async call. on_quota_done is always called when the
// quota request is finished.
virtual void Quota(const ::istio::mixer::v1::QuotaRequest& quota_request,
::istio::mixer::v1::QuotaResponse* quota_response,
DoneFunc on_quota_done);

private:
MixerClientOptions options_;
StreamTransport<::istio::mixer::v1::CheckRequest,
Expand Down
Loading

0 comments on commit 755b410

Please sign in to comment.