-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added quota contoll without the service control client library (#93)
* Added quota contoll without the service control client library * Applied code review * Applied code review * Resolve conflicts * Resolve conflicts * Fixed format error reported by script/check-style * Fixed a bug at Aggregated::GetAuthToken that causes Segmentation Fault * Changed usage of template funcion * Applied latest changes from the repo * Applied latest changes from the repo * Applied latest changes from the repo * Adde comments * Updated log information * Applied #101 * Changed metric_cost_map to metric_cost_vector * Fixed test case compilation error * Fixed test case compilation error
- Loading branch information
1 parent
577dbd7
commit c5b9b81
Showing
20 changed files
with
511 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2017 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
#include <iostream> | ||
|
||
#include "contrib/endpoints/src/api_manager/cloud_trace/cloud_trace.h" | ||
#include "contrib/endpoints/src/api_manager/quota_control.h" | ||
#include "google/protobuf/stubs/status.h" | ||
|
||
using ::google::api_manager::utils::Status; | ||
using ::google::protobuf::util::error::Code; | ||
|
||
namespace google { | ||
namespace api_manager { | ||
|
||
void QuotaControl(std::shared_ptr<context::RequestContext> context, | ||
std::function<void(Status status)> continuation) { | ||
std::shared_ptr<cloud_trace::CloudTraceSpan> trace_span( | ||
CreateSpan(context->cloud_trace(), "QuotaControl")); | ||
|
||
if (context->method()->metric_cost_vector().size() == 0) { | ||
TRACE(trace_span) << "Quota control check is not needed"; | ||
continuation(Status::OK); | ||
return; | ||
} | ||
|
||
service_control::QuotaRequestInfo info; | ||
context->FillAllocateQuotaRequestInfo(&info); | ||
context->service_context()->service_control()->Quota( | ||
info, trace_span.get(), | ||
[context, continuation, trace_span](utils::Status status) { | ||
|
||
TRACE(trace_span) << "Quota service control request returned with " | ||
<< "status " << status.ToString(); | ||
|
||
continuation(status); | ||
}); | ||
} | ||
|
||
} // namespace service_control_client | ||
} // namespace google |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2017 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
#ifndef API_MANAGER_QUOTA_CONTROL_H_ | ||
#define API_MANAGER_QUOTA_CONTROL_H_ | ||
|
||
#include "contrib/endpoints/include/api_manager/utils/status.h" | ||
#include "contrib/endpoints/src/api_manager/context/request_context.h" | ||
|
||
namespace google { | ||
namespace api_manager { | ||
|
||
// Call service control quota. | ||
void QuotaControl(std::shared_ptr<context::RequestContext>, | ||
std::function<void(utils::Status)>); | ||
|
||
} // namespace api_manager | ||
} // namespace google | ||
|
||
#endif // API_MANAGER_QUOTA_CONTROL_H_ |
Oops, something went wrong.