feat: REST GAPIC (REGAPIC) Support for Java #3275
Changes from 7 commits
7666bdf
59c36da
45022ca
7b32072
e2b56c0
0bae1fc
676b82c
63d4e38
0f4eee3
4395976
3157ca5
6045612
9219acf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,7 @@ def java_gapic_srcjar( | |
package = None, | ||
service_yaml = None, | ||
grpc_service_config = None, | ||
transport_protocol = None, | ||
**kwargs): | ||
raw_srcjar_name = "%s_raw" % name | ||
|
||
|
@@ -90,6 +91,7 @@ def java_gapic_srcjar( | |
language = "java", | ||
package = package, | ||
grpc_service_config = grpc_service_config, | ||
transport_protocol = transport_protocol, | ||
**kwargs | ||
) | ||
|
||
|
@@ -132,6 +134,7 @@ def java_gapic_library( | |
package = None, | ||
gen_resource_name = True, | ||
grpc_service_config = None, | ||
transport_protocol = None, | ||
deps = [], | ||
test_deps = [], | ||
**kwargs): | ||
|
@@ -144,6 +147,7 @@ def java_gapic_library( | |
artifact_type = "GAPIC_CODE", | ||
package = package, | ||
grpc_service_config = grpc_service_config, | ||
transport_protocol = transport_protocol, | ||
**kwargs | ||
) | ||
|
||
|
@@ -162,10 +166,7 @@ def java_gapic_library( | |
"@com_google_protobuf//:protobuf_java", | ||
"@com_google_api_api_common//jar", | ||
"@com_google_api_gax_java//gax:gax", | ||
"@com_google_api_gax_java//gax-grpc:gax_grpc", | ||
"@com_google_guava_guava//jar", | ||
"@io_grpc_grpc_java//core:core", | ||
"@io_grpc_grpc_java//protobuf:protobuf", | ||
"@com_google_code_findbugs_jsr305//jar", | ||
"@org_threeten_threetenbp//jar", | ||
"@io_opencensus_opencensus_api//jar", | ||
|
@@ -175,6 +176,17 @@ def java_gapic_library( | |
"@javax_annotation_javax_annotation_api//jar", | ||
] | ||
|
||
if transport_protocol == "http": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like either HTTP or gRPC will be generated, not both. Would it make sense to make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed |
||
actual_deps += [ | ||
"@com_google_api_gax_java//gax-httpjson:gax_httpjson", | ||
] | ||
else: | ||
actual_deps += [ | ||
"@com_google_api_gax_java//gax-grpc:gax_grpc", | ||
"@io_grpc_grpc_java//core:core", | ||
"@io_grpc_grpc_java//protobuf:protobuf", | ||
] | ||
|
||
native.java_library( | ||
name = name, | ||
srcs = [":%s.srcjar" % srcjar_name], | ||
|
@@ -183,16 +195,24 @@ def java_gapic_library( | |
) | ||
|
||
actual_test_deps = test_deps + [ | ||
"@com_google_api_gax_java//gax-grpc:gax_grpc_testlib", | ||
"@com_google_api_gax_java//gax:gax_testlib", | ||
"@com_google_code_gson_gson//jar", | ||
"@io_grpc_grpc_java//auth:auth", | ||
"@io_grpc_grpc_netty_shaded//jar", | ||
"@io_grpc_grpc_java//stub:stub", | ||
"@io_opencensus_opencensus_contrib_grpc_metrics//jar", | ||
"@junit_junit//jar", | ||
] | ||
|
||
if transport_protocol == "http": | ||
actual_test_deps += [ | ||
"@com_google_api_gax_java//gax-httpjson:gax_httpjson_testlib", | ||
] | ||
else: | ||
actual_test_deps += [ | ||
"@com_google_api_gax_java//gax-grpc:gax_grpc_testlib", | ||
"@io_grpc_grpc_java//auth:auth", | ||
"@io_grpc_grpc_netty_shaded//jar", | ||
"@io_grpc_grpc_java//stub:stub", | ||
"@io_opencensus_opencensus_contrib_grpc_metrics//jar", | ||
] | ||
|
||
native.java_library( | ||
name = "%s_test" % name, | ||
srcs = [":%s-test.srcjar" % srcjar_name], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,14 @@ public class GeneratorMain { | |
.argName("GRPC-SERVICE-CONFIG") | ||
.required(false) | ||
.build(); | ||
private static final Option TRANSPORT_PROTOCOL = | ||
Option.builder() | ||
.longOpt("transport_protocol") | ||
.desc("Transport used by the generated clients.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest removing the comment above and including the info in the description: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, but keeping |
||
.hasArg() | ||
.argName("TRANSPORT-PROTOCOL") | ||
.required(false) | ||
.build(); | ||
|
||
public static void printAvailableCommands() { | ||
System.err.println(" Available artifact types:"); | ||
|
@@ -249,6 +257,7 @@ public static void gapicGeneratorMain(ArtifactType artifactType, String[] args) | |
options.addOption(OUTPUT_OPTION); | ||
options.addOption(SAMPLE_YAML_NONREQUIRED_OPTION); | ||
options.addOption(GRPC_SERVICE_CONFIG_OPTION); | ||
options.addOption(TRANSPORT_PROTOCOL); | ||
Option enabledArtifactsOption = | ||
Option.builder() | ||
.longOpt("enabled_artifacts") | ||
|
@@ -299,6 +308,10 @@ public static void gapicGeneratorMain(ArtifactType artifactType, String[] args) | |
|
||
checkFile(toolOptions.get(ToolOptions.DESCRIPTOR_SET)); | ||
|
||
if (cl.getOptionValue(TRANSPORT_PROTOCOL.getLongOpt()) != null) { | ||
toolOptions.set( | ||
GapicGeneratorApp.TRANSPORT_PROTOCOL, cl.getOptionValue(TRANSPORT_PROTOCOL.getLongOpt())); | ||
} | ||
if (cl.getOptionValues(SERVICE_YAML_NONREQUIRED_OPTION.getLongOpt()) != null) { | ||
toolOptions.set( | ||
ToolOptions.CONFIG_FILES, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,7 +135,7 @@ public GapicProductConfig withPackageName(String packageName) { | |
@Nullable | ||
public static GapicProductConfig create( | ||
Model model, ConfigProto configProto, TargetLanguage language) { | ||
return create(model, configProto, null, null, null, language, null); | ||
return create(model, configProto, null, null, null, language, null, TransportProtocol.GRPC); | ||
} | ||
|
||
/** | ||
|
@@ -159,7 +159,8 @@ public static GapicProductConfig create( | |
@Nullable String protoPackage, | ||
@Nullable String clientPackage, | ||
TargetLanguage language, | ||
@Nullable ServiceConfig grpcServiceConfig) { | ||
@Nullable ServiceConfig grpcServiceConfig, | ||
TransportProtocol transportProtocol) { | ||
vchudnov-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
final String defaultPackage; | ||
SymbolTable symbolTable = model.getSymbolTable(); | ||
|
@@ -305,7 +306,7 @@ public static GapicProductConfig create( | |
return null; | ||
} | ||
|
||
TransportProtocol transportProtocol = TransportProtocol.GRPC; | ||
// TransportProtocol transportProtocol = TransportProtocol.GRPC; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cruft? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
|
||
String clientPackageName; | ||
LanguageSettingsProto settings = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we please document the valid values of
transport_protocol
somewhere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the code to match it the main regapic spec. Those values are documented there (and this argument was changed from transport_protocol to just transport). The values are
grpc
,rest
,grpc+rest
. This implementation does not supportgrpc+rest
because it is not needed for GCE (the main thing we need now), and investing time end effort into supporting the proper grpc+rest in monolith is probably not worth it.Added the list of possible values in the comment for the corresponding command line argumetn in
GeneratorMain
.