Skip to content

Commit 7d01533

Browse files
authored
transcoding: Remove MethodInfo (istio#359)
* transcoding: Remove MethodInfo * fix test lib path * fix test
1 parent 7aa227b commit 7d01533

File tree

5 files changed

+21
-36
lines changed

5 files changed

+21
-36
lines changed

contrib/endpoints/src/grpc/transcoding/BUILD

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ cc_test(
3939
"transcoder_test.cc",
4040
],
4141
data = [
42-
"@httpjson_transcoding//src:testdata/bookstore_service.pb.txt",
42+
"@httpjson_transcoding//test:testdata/bookstore_service.pb.txt",
4343
],
4444
deps = [
4545
":transcoding_endpoints",
46-
"@httpjson_transcoding//src:bookstore_test_proto",
47-
"@httpjson_transcoding//src:test_common",
46+
"@httpjson_transcoding//test:bookstore_test_proto",
47+
"@httpjson_transcoding//test:test_common",
4848
"//external:googletest_main",
4949
],
5050
)

contrib/endpoints/src/grpc/transcoding/transcoder_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
#include <string>
2020
#include <vector>
2121

22+
#include "bookstore.pb.h"
2223
#include "contrib/endpoints/include/api_manager/method.h"
2324
#include "contrib/endpoints/include/api_manager/method_call_info.h"
2425
#include "contrib/endpoints/src/grpc/transcoding/transcoder_factory.h"
2526
#include "google/protobuf/io/zero_copy_stream.h"
2627
#include "google/protobuf/stubs/strutil.h"
2728
#include "google/protobuf/util/message_differencer.h"
2829
#include "gtest/gtest.h"
29-
#include "src/bookstore.pb.h"
3030
#include "src/message_reader.h"
31-
#include "src/test_common.h"
3231
#include "src/transcoder.h"
32+
#include "test/test_common.h"
3333

3434
namespace google {
3535
namespace api_manager {
@@ -127,7 +127,7 @@ class TranscoderTest : public ::testing::Test {
127127
// in a test.
128128
bool LoadService(const std::string &config_pb_txt_file) {
129129
if (!::google::grpc::transcoding::testing::LoadService(
130-
config_pb_txt_file, "external/httpjson_transcoding/src/testdata/",
130+
config_pb_txt_file, "external/httpjson_transcoding/test/testdata/",
131131
&service_)) {
132132
return false;
133133
}

repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ cc_library(
160160
def transcoding_repositories(bind=True):
161161
native.git_repository(
162162
name = "httpjson_transcoding",
163-
commit = "d91a0fae8f9248c6b317abfa55b773fd62873818",
163+
commit = "193aa283914ba701c12cfdfa5967c1c4210468e3",
164164
remote = "https://github.com/grpc-ecosystem/grpc-httpjson-transcoding.git",
165165
)
166166

src/envoy/transcoding/config.cc

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ Config::Config(const Json::Object& config) {
9292
}
9393
}
9494

95-
google::grpc::transcoding::PathMatcherBuilder<MethodInfo*> pmb;
95+
google::grpc::transcoding::PathMatcherBuilder<
96+
const google::protobuf::MethodDescriptor*>
97+
pmb;
9698

9799
for (const auto& service_name : config.getStringArray("services")) {
98100
auto service = descriptor_pool_.FindServiceByName(service_name);
@@ -103,34 +105,30 @@ Config::Config(const Json::Object& config) {
103105
for (int i = 0; i < service->method_count(); ++i) {
104106
auto method = service->method(i);
105107

106-
auto method_info = new MethodInfo(method);
107-
methods_.emplace_back(method_info);
108108
auto http_rule = method->options().GetExtension(google::api::http);
109109

110110
log().debug("/" + service->full_name() + "/" + method->name());
111111
log().debug(http_rule.DebugString());
112112

113113
switch (http_rule.pattern_case()) {
114114
case ::google::api::HttpRule::kGet:
115-
pmb.Register("GET", http_rule.get(), http_rule.body(), method_info);
115+
pmb.Register("GET", http_rule.get(), http_rule.body(), method);
116116
break;
117117
case ::google::api::HttpRule::kPut:
118-
pmb.Register("PUT", http_rule.put(), http_rule.body(), method_info);
118+
pmb.Register("PUT", http_rule.put(), http_rule.body(), method);
119119
break;
120120
case ::google::api::HttpRule::kPost:
121-
pmb.Register("POST", http_rule.post(), http_rule.body(), method_info);
121+
pmb.Register("POST", http_rule.post(), http_rule.body(), method);
122122
break;
123123
case ::google::api::HttpRule::kDelete:
124-
pmb.Register("DELETE", http_rule.delete_(), http_rule.body(),
125-
method_info);
124+
pmb.Register("DELETE", http_rule.delete_(), http_rule.body(), method);
126125
break;
127126
case ::google::api::HttpRule::kPatch:
128-
pmb.Register("PATCH", http_rule.patch(), http_rule.body(),
129-
method_info);
127+
pmb.Register("PATCH", http_rule.patch(), http_rule.body(), method);
130128
break;
131129
case ::google::api::HttpRule::kCustom:
132130
pmb.Register(http_rule.custom().kind(), http_rule.custom().path(),
133-
http_rule.body(), method_info);
131+
http_rule.body(), method);
134132
break;
135133
default:
136134
break;
@@ -164,14 +162,13 @@ Status Config::CreateTranscoder(
164162

165163
RequestInfo request_info;
166164
std::vector<VariableBinding> variable_bidings;
167-
auto method_info = path_matcher_->Lookup(
165+
method_descriptor = path_matcher_->Lookup(
168166
method, path, args, &variable_bidings, &request_info.body_field_path);
169-
if (!method_info) {
167+
if (!method_descriptor) {
170168
return Status(Code::NOT_FOUND,
171169
"Could not resolve " + path + " to a method");
172170
}
173171

174-
method_descriptor = method_info->method();
175172
auto status = MethodToRequestInfo(method_descriptor, &request_info);
176173
if (!status.ok()) {
177174
return status;

src/envoy/transcoding/config.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,6 @@ namespace Transcoding {
3333

3434
class Instance;
3535

36-
class MethodInfo {
37-
public:
38-
MethodInfo(const google::protobuf::MethodDescriptor* method)
39-
: method_(method) {}
40-
const std::set<std::string> system_query_parameter_names() const {
41-
return std::set<std::string>();
42-
}
43-
const google::protobuf::MethodDescriptor* method() const { return method_; }
44-
45-
private:
46-
const google::protobuf::MethodDescriptor* method_;
47-
};
48-
4936
// VariableBinding specifies a value for a single field in the request message.
5037
// When transcoding HTTP/REST/JSON to gRPC/proto the request message is
5138
// constructed using the HTTP body and the variable bindings (specified through
@@ -76,8 +63,9 @@ class Config : public Logger::Loggable<Logger::Id::config> {
7663

7764
private:
7865
google::protobuf::DescriptorPool descriptor_pool_;
79-
google::grpc::transcoding::PathMatcherPtr<MethodInfo*> path_matcher_;
80-
std::vector<std::unique_ptr<MethodInfo>> methods_;
66+
google::grpc::transcoding::PathMatcherPtr<
67+
const google::protobuf::MethodDescriptor*>
68+
path_matcher_;
8169
std::unique_ptr<google::grpc::transcoding::TypeHelper> type_helper_;
8270
};
8371

0 commit comments

Comments
 (0)