Skip to content

Commit

Permalink
Merge in gapic_config_v2 (googleapis#2721)
Browse files Browse the repository at this point in the history
* Add Gapic config v2 (googleapis#2665)
* Whittling down config_v2 (googleapis#2666)
* Add ConfigV2 Validator (googleapis#2672)
* AutoValue LongRunningConfig; always use gapic config's polling settings (googleapis#2698)
* ResourceNameOneofConfig fixes (googleapis#2704)
* Start parsing GAPIC config v2 (googleapis#2703)
* Bring back timeout millis in GAPIC config v2 (googleapis#2708)
* Resource names across different protofiles (googleapis#2711)
* Fix missing default retries (googleapis#2718)
* Bug fixes for gapic config v2 parsing (googleapis#2717)
  • Loading branch information
andreamlin authored and busunkim96 committed Nov 7, 2019
1 parent 0db3a51 commit 15cce16
Show file tree
Hide file tree
Showing 31 changed files with 1,347 additions and 377 deletions.
11 changes: 9 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ _COMPILE_DEPS = [
"@com_fasterxml_jackson_core_jackson_databind//jar",
"@com_google_api_api_common//jar",
"@com_google_api_api_compiler//jar",
"@com_google_api_api_compiler_testing//jar",
"@com_google_api_grpc_proto_google_common_protos__com_google_api_codegen//jar",
"@com_google_auto_value_auto_value//jar",
"@com_google_auto_value_auto_value_annotations//jar",
Expand All @@ -31,7 +32,6 @@ _COMPILE_DEPS = [
]

_TEST_COMPILE_DEPS = [
"@com_google_api_api_compiler_testing//jar",
"@com_google_truth_truth//jar",
"@junit_junit//jar",
"@pl_pragmatists_JUnitParams//jar",
Expand Down Expand Up @@ -60,9 +60,16 @@ proto_library(
deps = ["@com_google_protobuf//:wrappers_proto"],
)

proto_library(
name = "config_v2_proto",
srcs = ["src/main/proto/com/google/api/codegen/v2/config_v2.proto"],
deps = ["@com_google_protobuf//:wrappers_proto"],
)

java_proto_library(
name = "config_java_proto",
deps = [":config_proto"],
deps = [":config_proto",
":config_v2_proto"],
)

java_binary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ static DiscoGapicInterfaceConfig createInterfaceConfig(
ResourceNameMessageConfigs messageConfigs,
ImmutableMap<String, ResourceNameConfig> resourceNameConfigs) {

RetryCodesConfig retryCodesConfig =
RetryCodesConfig.create(model.getDiagCollector(), interfaceConfigProto);
RetryCodesConfig retryCodesConfig = RetryCodesConfig.create(interfaceConfigProto);
ImmutableMap<String, RetryParamsDefinitionProto> retrySettingsDefinition =
RetryDefinitionsTransformer.createRetrySettingsDefinition(interfaceConfigProto);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public abstract class FixedResourceNameConfig implements ResourceNameConfig {

public abstract String getFixedValue();

@Nullable
@Override
public abstract ProtoFile getAssignedProtoFile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -118,7 +119,6 @@ static GapicInterfaceConfig createInterfaceConfig(

RetryCodesConfig retryCodesConfig =
RetryCodesConfig.create(
diagCollector,
interfaceConfigProto,
new ArrayList<>(interfaceInput.getMethodsToGenerate().keySet()),
protoParser);
Expand Down Expand Up @@ -164,19 +164,32 @@ static GapicInterfaceConfig createInterfaceConfig(
}

ImmutableList.Builder<SingleResourceNameConfig> resourcesBuilder = ImmutableList.builder();
for (CollectionConfigProto collectionConfigProto : interfaceConfigProto.getCollectionsList()) {
String entityName = collectionConfigProto.getEntityName();
ResourceNameConfig resourceName = resourceNameConfigs.get(entityName);
if (!(resourceName instanceof SingleResourceNameConfig)) {
diagCollector.addDiag(
Diag.error(
SimpleLocation.TOPLEVEL,
"Inconsistent configuration - single resource name %s specified for interface, "
+ " but was not found in GapicProductConfig configuration.",
entityName));
return null;
if (protoParser.isProtoAnnotationsEnabled()) {
resourceNameConfigs
.values()
.stream()
.filter(
r ->
r.getResourceNameType() == ResourceNameType.SINGLE
&& Objects.equals(r.getAssignedProtoFile(), apiInterface.getFile()))
.map(r -> (SingleResourceNameConfig) r)
.forEach(resourcesBuilder::add);
} else {
for (CollectionConfigProto collectionConfigProto :
interfaceConfigProto.getCollectionsList()) {
String entityName = collectionConfigProto.getEntityName();
ResourceNameConfig resourceName = resourceNameConfigs.get(entityName);
if (!(resourceName instanceof SingleResourceNameConfig)) {
diagCollector.addDiag(
Diag.error(
SimpleLocation.TOPLEVEL,
"Inconsistent configuration - single resource name %s specified for interface, "
+ " but was not found in GapicProductConfig configuration.",
entityName));
return null;
}
resourcesBuilder.add((SingleResourceNameConfig) resourceName);
}
resourcesBuilder.add((SingleResourceNameConfig) resourceName);
}
ImmutableList<SingleResourceNameConfig> singleResourceNames = resourcesBuilder.build();

Expand Down
Loading

0 comments on commit 15cce16

Please sign in to comment.