diff --git a/contrib/endpoints/repositories.bzl b/contrib/endpoints/repositories.bzl index 3aebfb83bc8..77770863d72 100644 --- a/contrib/endpoints/repositories.bzl +++ b/contrib/endpoints/repositories.bzl @@ -198,7 +198,7 @@ def servicecontrol_client_repositories(bind=True): native.git_repository( name = "servicecontrol_client_git", - commit = "069bc7156d92a2d84929309d69610c76f6b8dab9", + commit = "c815b890f6ac60e9dc57f80c97b1bccc9930c073", remote = "https://github.com/cloudendpoints/service-control-client-cxx.git", ) diff --git a/contrib/endpoints/src/api_manager/service_control/aggregated.cc b/contrib/endpoints/src/api_manager/service_control/aggregated.cc index 625d55728c2..adf507d521a 100644 --- a/contrib/endpoints/src/api_manager/service_control/aggregated.cc +++ b/contrib/endpoints/src/api_manager/service_control/aggregated.cc @@ -31,8 +31,7 @@ using ::google::api_manager::utils::Status; using ::google::protobuf::util::error::Code; using ::google::service_control_client::CheckAggregationOptions; -// TODO(jaebong) enable this after service_control_client library is updated -// using ::google::service_control_client::QuotaAggregationOptions; +using ::google::service_control_client::QuotaAggregationOptions; using ::google::service_control_client::ReportAggregationOptions; using ::google::service_control_client::ServiceControlClient; using ::google::service_control_client::ServiceControlClientOptions; @@ -98,9 +97,6 @@ CheckAggregationOptions GetCheckAggregationOptions( kCheckAggregationExpirationMs); } -// TODO(jaebong) enable this after service_control_client library is updated -/* -// TODO(jaebong): - need to add quota configuration // Generate QuotaAggregationOptions QuotaAggregationOptions GetQuotaAggregationOptions( const ServerConfig* server_config) { @@ -118,7 +114,6 @@ QuotaAggregationOptions GetQuotaAggregationOptions( return option; } -*/ // Generates ReportAggregationOptions. ReportAggregationOptions GetReportAggregationOptions( @@ -209,9 +204,7 @@ Status Aggregated::Init() { // env->StartPeriodicTimer doens't work at constructor. ServiceControlClientOptions options( GetCheckAggregationOptions(server_config_), - // TODO(jaebong) enable this after service_control_client library is - // updated - // GetQuotaAggregationOptions(server_config_), + GetQuotaAggregationOptions(server_config_), GetReportAggregationOptions(server_config_)); std::stringstream ss; @@ -228,13 +221,9 @@ Status Aggregated::Init() { const CheckRequest& request, CheckResponse* response, TransportDoneFunc on_done) { Call(request, response, on_done, nullptr); }; - /* - // TODO(jaebong) enable this after service_control_client library is updated - options.quota_transport = [this]( - const AllocateQuotaRequest& request, AllocateQuotaResponse* response, - TransportDoneFunc on_done) { Call(request, response, on_done, nullptr); - }; - */ + options.quota_transport = [this]( + const AllocateQuotaRequest& request, AllocateQuotaResponse* response, + TransportDoneFunc on_done) { Call(request, response, on_done, nullptr); }; options.report_transport = [this]( const ReportRequest& request, ReportResponse* response, @@ -412,9 +401,12 @@ void Aggregated::Quota(const QuotaRequestInfo& info, delete response; }; - // TODO(jaebong) Temporarily call Chemist directly instead of using service - // control client library - Call(*request, response, quota_on_done, trace_span.get()); + client_->Quota(*request, response, quota_on_done, + [trace_span, this](const AllocateQuotaRequest& request, + AllocateQuotaResponse* response, + TransportDoneFunc on_done) { + Call(request, response, on_done, trace_span.get()); + }); // There is no reference to request anymore at this point and it is safe to // free request now. diff --git a/contrib/endpoints/src/api_manager/service_control/aggregated_test.cc b/contrib/endpoints/src/api_manager/service_control/aggregated_test.cc index cc88308b8ba..c51b2b5f6aa 100644 --- a/contrib/endpoints/src/api_manager/service_control/aggregated_test.cc +++ b/contrib/endpoints/src/api_manager/service_control/aggregated_test.cc @@ -32,6 +32,7 @@ using ::google::api_manager::utils::Status; using ::google::protobuf::util::error::Code; using ::google::service_control_client::ServiceControlClient; using ::google::service_control_client::TransportCheckFunc; +using ::google::service_control_client::TransportQuotaFunc; using ::google::service_control_client::TransportReportFunc; using ::testing::Return; using ::testing::Invoke; @@ -89,6 +90,15 @@ class MockServiceControClient : public ServiceControlClient { CheckResponse*)); MOCK_METHOD4(Check, void(const CheckRequest&, CheckResponse*, DoneCallback, TransportCheckFunc)); + + MOCK_METHOD2(Quota, + ::google::protobuf::util::Status(const AllocateQuotaRequest&, + AllocateQuotaResponse*)); + MOCK_METHOD3(Quota, void(const AllocateQuotaRequest&, AllocateQuotaResponse*, + DoneCallback)); + MOCK_METHOD4(Quota, void(const AllocateQuotaRequest&, AllocateQuotaResponse*, + DoneCallback, TransportQuotaFunc)); + MOCK_METHOD3(Report, void(const ReportRequest&, ReportResponse*, DoneCallback)); MOCK_METHOD2(Report, ::google::protobuf::util::Status(const ReportRequest&, diff --git a/contrib/endpoints/src/api_manager/service_control/proto.cc b/contrib/endpoints/src/api_manager/service_control/proto.cc index ebc20cb696e..f9ca43909b0 100644 --- a/contrib/endpoints/src/api_manager/service_control/proto.cc +++ b/contrib/endpoints/src/api_manager/service_control/proto.cc @@ -936,7 +936,6 @@ utils::Status Proto::FillAllocateQuotaRequest( std::string(info.api_key)); } - // TODO(jaebong) - Read from service conf? // allocate_operation.quota_mode operation->set_quota_mode( ::google::api::servicecontrol::v1::QuotaOperation_QuotaMode::