Skip to content

Commit

Permalink
fix(mixins): enable codegen for standalone mixin APIs, add IAM integ …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
miraleung committed Mar 3, 2021
1 parent 738bf8a commit bbde184
Show file tree
Hide file tree
Showing 21 changed files with 1,832 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .githooks/pre-commit
Expand Up @@ -134,7 +134,7 @@ if [ $NUM_JAVA_FILES_CHANGED -gt 0 ]
then
echo_status "Checking Apache License Header ..."
header_check_preparation
addlicense -c "Google LLC" -l apache -check $(find $PWD -type f -name '*.java')
addlicense -c "Google LLC" -l apache -check $(find $PWD -type f -name '*.java' ! -iname '*PlaceholderFile.java')
CHECK_STATUS=$?
if [ $CHECK_STATUS != 0 ]
then
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Expand Up @@ -49,7 +49,7 @@ jobs:
run: bazel --batch test $(bazel query "//src/test/..." | grep "Test$") --noshow_progress

- name: Integration Tests
run: bazel --batch test //test/integration:asset //test/integration:credentials //test/integration:kms //test/integration:logging //test/integration:redis //test/integration:library --noshow_progress
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

- uses: actions/upload-artifact@v2
if: ${{ failure() }}
Expand Down Expand Up @@ -90,5 +90,5 @@ jobs:
- name: License Header Check
run: |
go get -u github.com/google/addlicense
addlicense -c "Google LLC" -l apache -check $(find $PWD -type f -name '*.java')
addlicense -c "Google LLC" -l apache -check $(find $PWD -type f -name '*.java' ! -iname '*PlaceholderFile.java')
Expand Up @@ -218,13 +218,20 @@ public static List<Service> parseServices(
// indicator that we are not generating a GAPIC client for the mixed-in service on its own.
Function<Service, String> serviceFullNameFn =
s -> String.format("%s.%s", s.protoPakkage(), s.name());
Set<Service> blockedCodegenMixinApis =
services.stream()
.filter(s -> MIXIN_ALLOWLIST.contains(serviceFullNameFn.apply(s)))
.map(s -> s)
.collect(Collectors.toSet());
Set<Service> blockedCodegenMixinApis = new HashSet<>();
Set<Service> definedServices = new HashSet<>();
for (Service s : services) {
if (MIXIN_ALLOWLIST.contains(serviceFullNameFn.apply(s))) {
blockedCodegenMixinApis.add(s);
} else {
definedServices.add(s);
}
}
// It's very unlikely the blocklisted APIs will contain the other, or any other service.
boolean servicesContainBlocklistedApi = !blockedCodegenMixinApis.isEmpty();
boolean servicesContainBlocklistedApi =
!blockedCodegenMixinApis.isEmpty() && !definedServices.isEmpty();
// Service names that are stated in the YAML file (as mixins). Used to filter
// blockedCodegenMixinApis.
Set<String> mixedInApis =
!serviceYamlProtoOpt.isPresent()
? Collections.emptySet()
Expand Down
@@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_binary")

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

filegroup(
Expand Down
@@ -1,4 +1,4 @@
load("@rules_java//java:defs.bzl", "java_test")
load("@rules_java//java:defs.bzl", "java_proto_library", "java_test")

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

Expand Down
@@ -1,4 +1,4 @@
load("@rules_java//java:defs.bzl", "java_test")
load("@rules_java//java:defs.bzl", "java_proto_library", "java_test")

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

Expand Down
38 changes: 35 additions & 3 deletions test/integration/BUILD.bazel
Expand Up @@ -5,13 +5,17 @@ load(
"java_gapic_test",
"java_grpc_library",
"java_proto_library",
"proto_library_with_info",
)
load(
"//:rules_bazel/java/integration_test.bzl",
"golden_update",
"integration_test",
)

# KMS (for mixins).
load("@rules_proto//proto:defs.bzl", "proto_library")

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

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

# KMS (for mixins).
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@com_google_googleapis_imports//:imports.bzl", "proto_library_with_info")
# IAM (for a standalone mixed-in API).
java_gapic_library(
name = "iam_java_gapic",
srcs = ["@com_google_googleapis//google/iam/v1:iam_proto_with_info"],
grpc_service_config = "iam_grpc_service_config.json",
test_deps = [
"@com_google_googleapis//google/iam/v1:iam_java_grpc",
],
deps = [
"@com_google_googleapis//google/iam/v1:iam_java_proto",
],
)

java_gapic_test(
name = "iam_java_gapic_test_suite",
test_classes = [
"com.google.iam.v1.IAMPolicyClientTest",
],
runtime_deps = ["iam_java_gapic_test"],
)

java_gapic_assembly_gradle_pkg(
name = "google-cloud-iam-java",
deps = [
":iam_java_gapic",
"@com_google_googleapis//google/iam/v1:iam_java_grpc",
"@com_google_googleapis//google/iam/v1:iam_java_proto",
],
)

proto_library(
name = "kms_proto",
Expand Down
9 changes: 9 additions & 0 deletions test/integration/goldens/iam/BUILD.bazel
@@ -0,0 +1,9 @@
package(default_visibility = ["//visibility:public"])

filegroup(
name = "goldens_files",
srcs = glob([
"*.java",
"gapic_metadata.json",
]),
)
113 changes: 113 additions & 0 deletions test/integration/goldens/iam/GrpcIAMPolicyCallableFactory.java
@@ -0,0 +1,113 @@
/*
* Copyright 2020 Google LLC
*
* 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
*
* https://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.
*/

package com.google.iam.v1.stub;

import com.google.api.gax.grpc.GrpcCallSettings;
import com.google.api.gax.grpc.GrpcCallableFactory;
import com.google.api.gax.grpc.GrpcStubCallableFactory;
import com.google.api.gax.rpc.BatchingCallSettings;
import com.google.api.gax.rpc.BidiStreamingCallable;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.ClientStreamingCallable;
import com.google.api.gax.rpc.OperationCallSettings;
import com.google.api.gax.rpc.OperationCallable;
import com.google.api.gax.rpc.PagedCallSettings;
import com.google.api.gax.rpc.ServerStreamingCallSettings;
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.api.gax.rpc.StreamingCallSettings;
import com.google.api.gax.rpc.UnaryCallSettings;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.longrunning.Operation;
import com.google.longrunning.stub.OperationsStub;
import javax.annotation.Generated;

// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
* gRPC callable factory implementation for the IAMPolicy service API.
*
* <p>This class is for advanced usage.
*/
@Generated("by gapic-generator-java")
public class GrpcIAMPolicyCallableFactory implements GrpcStubCallableFactory {

@Override
public <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> createUnaryCallable(
GrpcCallSettings<RequestT, ResponseT> grpcCallSettings,
UnaryCallSettings<RequestT, ResponseT> callSettings,
ClientContext clientContext) {
return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext);
}

@Override
public <RequestT, ResponseT, PagedListResponseT>
UnaryCallable<RequestT, PagedListResponseT> createPagedCallable(
GrpcCallSettings<RequestT, ResponseT> grpcCallSettings,
PagedCallSettings<RequestT, ResponseT, PagedListResponseT> callSettings,
ClientContext clientContext) {
return GrpcCallableFactory.createPagedCallable(grpcCallSettings, callSettings, clientContext);
}

@Override
public <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> createBatchingCallable(
GrpcCallSettings<RequestT, ResponseT> grpcCallSettings,
BatchingCallSettings<RequestT, ResponseT> callSettings,
ClientContext clientContext) {
return GrpcCallableFactory.createBatchingCallable(
grpcCallSettings, callSettings, clientContext);
}

@Override
public <RequestT, ResponseT, MetadataT>
OperationCallable<RequestT, ResponseT, MetadataT> createOperationCallable(
GrpcCallSettings<RequestT, Operation> grpcCallSettings,
OperationCallSettings<RequestT, ResponseT, MetadataT> callSettings,
ClientContext clientContext,
OperationsStub operationsStub) {
return GrpcCallableFactory.createOperationCallable(
grpcCallSettings, callSettings, clientContext, operationsStub);
}

@Override
public <RequestT, ResponseT>
BidiStreamingCallable<RequestT, ResponseT> createBidiStreamingCallable(
GrpcCallSettings<RequestT, ResponseT> grpcCallSettings,
StreamingCallSettings<RequestT, ResponseT> callSettings,
ClientContext clientContext) {
return GrpcCallableFactory.createBidiStreamingCallable(
grpcCallSettings, callSettings, clientContext);
}

@Override
public <RequestT, ResponseT>
ServerStreamingCallable<RequestT, ResponseT> createServerStreamingCallable(
GrpcCallSettings<RequestT, ResponseT> grpcCallSettings,
ServerStreamingCallSettings<RequestT, ResponseT> callSettings,
ClientContext clientContext) {
return GrpcCallableFactory.createServerStreamingCallable(
grpcCallSettings, callSettings, clientContext);
}

@Override
public <RequestT, ResponseT>
ClientStreamingCallable<RequestT, ResponseT> createClientStreamingCallable(
GrpcCallSettings<RequestT, ResponseT> grpcCallSettings,
StreamingCallSettings<RequestT, ResponseT> callSettings,
ClientContext clientContext) {
return GrpcCallableFactory.createClientStreamingCallable(
grpcCallSettings, callSettings, clientContext);
}
}

0 comments on commit bbde184

Please sign in to comment.