Skip to content

Commit bbde184

Browse files
authored
fix(mixins): enable codegen for standalone mixin APIs, add IAM integ test (#679)
* fix(mixins): enable RPC overrides to clobber mixed-in RPCs * fix(mixins): enable RPC overrides to clobber mixed-in RPCs * fix(mixins): enable RPC overrides to clobber mixed-in RPCs * fix(mixins): enable codegen for standalone mixin APIs, add IAM integ test * fix(build): Add build files and CI * chore: release 1.0.1 Release-As: 1.0.1 * fix: don't check license for blank files
1 parent 738bf8a commit bbde184

21 files changed

Lines changed: 1832 additions & 14 deletions

File tree

.githooks/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ if [ $NUM_JAVA_FILES_CHANGED -gt 0 ]
134134
then
135135
echo_status "Checking Apache License Header ..."
136136
header_check_preparation
137-
addlicense -c "Google LLC" -l apache -check $(find $PWD -type f -name '*.java')
137+
addlicense -c "Google LLC" -l apache -check $(find $PWD -type f -name '*.java' ! -iname '*PlaceholderFile.java')
138138
CHECK_STATUS=$?
139139
if [ $CHECK_STATUS != 0 ]
140140
then

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
run: bazel --batch test $(bazel query "//src/test/..." | grep "Test$") --noshow_progress
5050

5151
- name: Integration Tests
52-
run: bazel --batch test //test/integration:asset //test/integration:credentials //test/integration:kms //test/integration:logging //test/integration:redis //test/integration:library --noshow_progress
52+
run: bazel --batch test //test/integration:asset //test/integration:credentials //test/integration:iam //test/integration:kms //test/integration:logging //test/integration:redis //test/integration:library --noshow_progress
5353

5454
- uses: actions/upload-artifact@v2
5555
if: ${{ failure() }}
@@ -90,5 +90,5 @@ jobs:
9090
- name: License Header Check
9191
run: |
9292
go get -u github.com/google/addlicense
93-
addlicense -c "Google LLC" -l apache -check $(find $PWD -type f -name '*.java')
93+
addlicense -c "Google LLC" -l apache -check $(find $PWD -type f -name '*.java' ! -iname '*PlaceholderFile.java')
9494

src/main/java/com/google/api/generator/gapic/protoparser/Parser.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,20 @@ public static List<Service> parseServices(
218218
// indicator that we are not generating a GAPIC client for the mixed-in service on its own.
219219
Function<Service, String> serviceFullNameFn =
220220
s -> String.format("%s.%s", s.protoPakkage(), s.name());
221-
Set<Service> blockedCodegenMixinApis =
222-
services.stream()
223-
.filter(s -> MIXIN_ALLOWLIST.contains(serviceFullNameFn.apply(s)))
224-
.map(s -> s)
225-
.collect(Collectors.toSet());
221+
Set<Service> blockedCodegenMixinApis = new HashSet<>();
222+
Set<Service> definedServices = new HashSet<>();
223+
for (Service s : services) {
224+
if (MIXIN_ALLOWLIST.contains(serviceFullNameFn.apply(s))) {
225+
blockedCodegenMixinApis.add(s);
226+
} else {
227+
definedServices.add(s);
228+
}
229+
}
226230
// It's very unlikely the blocklisted APIs will contain the other, or any other service.
227-
boolean servicesContainBlocklistedApi = !blockedCodegenMixinApis.isEmpty();
231+
boolean servicesContainBlocklistedApi =
232+
!blockedCodegenMixinApis.isEmpty() && !definedServices.isEmpty();
233+
// Service names that are stated in the YAML file (as mixins). Used to filter
234+
// blockedCodegenMixinApis.
228235
Set<String> mixedInApis =
229236
!serviceYamlProtoOpt.isPresent()
230237
? Collections.emptySet()

src/test/java/com/google/api/generator/gapic/composer/constants/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@rules_java//java:defs.bzl", "java_binary")
2+
13
package(default_visibility = ["//visibility:public"])
24

35
filegroup(

src/test/java/com/google/api/generator/gapic/composer/defaultvalue/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@rules_java//java:defs.bzl", "java_test")
1+
load("@rules_java//java:defs.bzl", "java_proto_library", "java_test")
22

33
package(default_visibility = ["//visibility:public"])
44

src/test/java/com/google/api/generator/gapic/composer/resourcename/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@rules_java//java:defs.bzl", "java_test")
1+
load("@rules_java//java:defs.bzl", "java_proto_library", "java_test")
22

33
package(default_visibility = ["//visibility:public"])
44

test/integration/BUILD.bazel

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ load(
55
"java_gapic_test",
66
"java_grpc_library",
77
"java_proto_library",
8+
"proto_library_with_info",
89
)
910
load(
1011
"//:rules_bazel/java/integration_test.bzl",
1112
"golden_update",
1213
"integration_test",
1314
)
1415

16+
# KMS (for mixins).
17+
load("@rules_proto//proto:defs.bzl", "proto_library")
18+
1519
package(default_visibility = ["//visibility:public"])
1620

1721
####################################################
@@ -21,6 +25,7 @@ package(default_visibility = ["//visibility:public"])
2125
INTEGRATION_TEST_LIBRARIES = [
2226
"asset", # Basic case.
2327
"credentials", # Check that the capital name edge case is handled.
28+
"iam", # Mixin-only special-case API can build on its own.
2429
"kms", # Mixins, with an override in the proto file.
2530
"logging", # Java package remapping in gapic.yaml.
2631
"redis", # Has a gapic.yaml.
@@ -31,6 +36,7 @@ INTEGRATION_TEST_LIBRARIES = [
3136
API_GAPIC_TARGETS = {
3237
"asset": "@com_google_googleapis//google/cloud/asset/v1:asset_java_gapic",
3338
"credentials": "@com_google_googleapis//google/iam/credentials/v1:credentials_java_gapic",
39+
"iam": ":iam_java_gapic", # Googleapis' LRO does not have a Java Gapic.
3440
"kms": ":kms_java_gapic", # Local target because mixins are not rolled out yet.
3541
"logging": "@com_google_googleapis//google/logging/v2:logging_java_gapic",
3642
"redis": "@com_google_googleapis//google/cloud/redis/v1beta1:redis_java_gapic",
@@ -157,9 +163,35 @@ java_gapic_assembly_gradle_pkg(
157163
],
158164
)
159165

160-
# KMS (for mixins).
161-
load("@rules_proto//proto:defs.bzl", "proto_library")
162-
load("@com_google_googleapis_imports//:imports.bzl", "proto_library_with_info")
166+
# IAM (for a standalone mixed-in API).
167+
java_gapic_library(
168+
name = "iam_java_gapic",
169+
srcs = ["@com_google_googleapis//google/iam/v1:iam_proto_with_info"],
170+
grpc_service_config = "iam_grpc_service_config.json",
171+
test_deps = [
172+
"@com_google_googleapis//google/iam/v1:iam_java_grpc",
173+
],
174+
deps = [
175+
"@com_google_googleapis//google/iam/v1:iam_java_proto",
176+
],
177+
)
178+
179+
java_gapic_test(
180+
name = "iam_java_gapic_test_suite",
181+
test_classes = [
182+
"com.google.iam.v1.IAMPolicyClientTest",
183+
],
184+
runtime_deps = ["iam_java_gapic_test"],
185+
)
186+
187+
java_gapic_assembly_gradle_pkg(
188+
name = "google-cloud-iam-java",
189+
deps = [
190+
":iam_java_gapic",
191+
"@com_google_googleapis//google/iam/v1:iam_java_grpc",
192+
"@com_google_googleapis//google/iam/v1:iam_java_proto",
193+
],
194+
)
163195

164196
proto_library(
165197
name = "kms_proto",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
filegroup(
4+
name = "goldens_files",
5+
srcs = glob([
6+
"*.java",
7+
"gapic_metadata.json",
8+
]),
9+
)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.iam.v1.stub;
18+
19+
import com.google.api.gax.grpc.GrpcCallSettings;
20+
import com.google.api.gax.grpc.GrpcCallableFactory;
21+
import com.google.api.gax.grpc.GrpcStubCallableFactory;
22+
import com.google.api.gax.rpc.BatchingCallSettings;
23+
import com.google.api.gax.rpc.BidiStreamingCallable;
24+
import com.google.api.gax.rpc.ClientContext;
25+
import com.google.api.gax.rpc.ClientStreamingCallable;
26+
import com.google.api.gax.rpc.OperationCallSettings;
27+
import com.google.api.gax.rpc.OperationCallable;
28+
import com.google.api.gax.rpc.PagedCallSettings;
29+
import com.google.api.gax.rpc.ServerStreamingCallSettings;
30+
import com.google.api.gax.rpc.ServerStreamingCallable;
31+
import com.google.api.gax.rpc.StreamingCallSettings;
32+
import com.google.api.gax.rpc.UnaryCallSettings;
33+
import com.google.api.gax.rpc.UnaryCallable;
34+
import com.google.longrunning.Operation;
35+
import com.google.longrunning.stub.OperationsStub;
36+
import javax.annotation.Generated;
37+
38+
// AUTO-GENERATED DOCUMENTATION AND CLASS.
39+
/**
40+
* gRPC callable factory implementation for the IAMPolicy service API.
41+
*
42+
* <p>This class is for advanced usage.
43+
*/
44+
@Generated("by gapic-generator-java")
45+
public class GrpcIAMPolicyCallableFactory implements GrpcStubCallableFactory {
46+
47+
@Override
48+
public <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> createUnaryCallable(
49+
GrpcCallSettings<RequestT, ResponseT> grpcCallSettings,
50+
UnaryCallSettings<RequestT, ResponseT> callSettings,
51+
ClientContext clientContext) {
52+
return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext);
53+
}
54+
55+
@Override
56+
public <RequestT, ResponseT, PagedListResponseT>
57+
UnaryCallable<RequestT, PagedListResponseT> createPagedCallable(
58+
GrpcCallSettings<RequestT, ResponseT> grpcCallSettings,
59+
PagedCallSettings<RequestT, ResponseT, PagedListResponseT> callSettings,
60+
ClientContext clientContext) {
61+
return GrpcCallableFactory.createPagedCallable(grpcCallSettings, callSettings, clientContext);
62+
}
63+
64+
@Override
65+
public <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> createBatchingCallable(
66+
GrpcCallSettings<RequestT, ResponseT> grpcCallSettings,
67+
BatchingCallSettings<RequestT, ResponseT> callSettings,
68+
ClientContext clientContext) {
69+
return GrpcCallableFactory.createBatchingCallable(
70+
grpcCallSettings, callSettings, clientContext);
71+
}
72+
73+
@Override
74+
public <RequestT, ResponseT, MetadataT>
75+
OperationCallable<RequestT, ResponseT, MetadataT> createOperationCallable(
76+
GrpcCallSettings<RequestT, Operation> grpcCallSettings,
77+
OperationCallSettings<RequestT, ResponseT, MetadataT> callSettings,
78+
ClientContext clientContext,
79+
OperationsStub operationsStub) {
80+
return GrpcCallableFactory.createOperationCallable(
81+
grpcCallSettings, callSettings, clientContext, operationsStub);
82+
}
83+
84+
@Override
85+
public <RequestT, ResponseT>
86+
BidiStreamingCallable<RequestT, ResponseT> createBidiStreamingCallable(
87+
GrpcCallSettings<RequestT, ResponseT> grpcCallSettings,
88+
StreamingCallSettings<RequestT, ResponseT> callSettings,
89+
ClientContext clientContext) {
90+
return GrpcCallableFactory.createBidiStreamingCallable(
91+
grpcCallSettings, callSettings, clientContext);
92+
}
93+
94+
@Override
95+
public <RequestT, ResponseT>
96+
ServerStreamingCallable<RequestT, ResponseT> createServerStreamingCallable(
97+
GrpcCallSettings<RequestT, ResponseT> grpcCallSettings,
98+
ServerStreamingCallSettings<RequestT, ResponseT> callSettings,
99+
ClientContext clientContext) {
100+
return GrpcCallableFactory.createServerStreamingCallable(
101+
grpcCallSettings, callSettings, clientContext);
102+
}
103+
104+
@Override
105+
public <RequestT, ResponseT>
106+
ClientStreamingCallable<RequestT, ResponseT> createClientStreamingCallable(
107+
GrpcCallSettings<RequestT, ResponseT> grpcCallSettings,
108+
StreamingCallSettings<RequestT, ResponseT> callSettings,
109+
ClientContext clientContext) {
110+
return GrpcCallableFactory.createClientStreamingCallable(
111+
grpcCallSettings, callSettings, clientContext);
112+
}
113+
}

0 commit comments

Comments
 (0)