use of com.google.api.codegen.RetryParamsDefinitionProto in project toolkit by googleapis.
the class DiscoGapicInterfaceConfig method createInterfaceConfig.
static DiscoGapicInterfaceConfig createInterfaceConfig(DiscoApiModel model, TargetLanguage language, InterfaceConfigProto interfaceConfigProto, String interfaceNameOverride, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs) {
RetryCodesConfig retryCodesConfig = RetryCodesConfig.create(interfaceConfigProto);
ImmutableMap<String, RetryParamsDefinitionProto> retrySettingsDefinition = RetryDefinitionsTransformer.createRetrySettingsDefinition(interfaceConfigProto);
List<DiscoGapicMethodConfig> methodConfigs = null;
ImmutableMap<String, DiscoGapicMethodConfig> methodConfigMap = null;
if (retryCodesConfig != null && retrySettingsDefinition != null) {
methodConfigMap = createMethodConfigMap(model, language, interfaceConfigProto, messageConfigs, resourceNameConfigs, retryCodesConfig, retrySettingsDefinition.keySet());
methodConfigs = orderMethodConfigs(methodConfigMap, interfaceConfigProto);
}
// TODO(andrealin) Make non-null smokeTestConfig.
SmokeTestConfig smokeTestConfig = null;
// TODO(andrealin) IAM permissions configs.
ImmutableList<String> requiredConstructorParams = ImmutableList.copyOf(interfaceConfigProto.getRequiredConstructorParamsList());
for (String param : interfaceConfigProto.getRequiredConstructorParamsList()) {
if (!CONSTRUCTOR_PARAMS.contains(param)) {
model.getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unsupported constructor param: %s", param));
}
}
ImmutableSet.Builder<SingleResourceNameConfig> resourcesBuilder = ImmutableSet.builder();
for (CollectionConfigProto collectionConfigProto : interfaceConfigProto.getCollectionsList()) {
String entityName = collectionConfigProto.getEntityName();
ResourceNameConfig resourceName = resourceNameConfigs.get(entityName);
if (!(resourceName instanceof SingleResourceNameConfig)) {
model.getDiagCollector().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);
}
ImmutableSet<SingleResourceNameConfig> singleResourceNames = resourcesBuilder.build();
ImmutableMap.Builder<MethodConfig, SingleResourceNameConfig> methodToSingleResourceNameMap = ImmutableMap.builder();
if (methodConfigs != null) {
for (MethodConfig methodConfig : methodConfigs) {
Method method = ((DiscoveryMethodModel) methodConfig.getMethodModel()).getDiscoMethod();
String canonicalMethodPath = DiscoGapicParser.getCanonicalPath(method.flatPath());
for (SingleResourceNameConfig nameConfig : singleResourceNames) {
if (nameConfig.getNamePattern().equals(canonicalMethodPath)) {
methodToSingleResourceNameMap.put(methodConfig, nameConfig);
}
}
}
}
String manualDoc = Strings.nullToEmpty(interfaceConfigProto.getLangDoc().get(language.toString().toLowerCase())).trim();
String interfaceName = interfaceNameOverride != null ? interfaceNameOverride : DiscoGapicParser.getInterfaceName(interfaceConfigProto.getName()).toUpperCamel();
if (model.getDiagCollector().hasErrors()) {
return null;
} else {
return new AutoValue_DiscoGapicInterfaceConfig(retryCodesConfig, retrySettingsDefinition, requiredConstructorParams, manualDoc, interfaceNameOverride, new DiscoInterfaceModel(interfaceName, model), smokeTestConfig, methodToSingleResourceNameMap.build(), methodConfigs, methodConfigMap, singleResourceNames);
}
}
use of com.google.api.codegen.RetryParamsDefinitionProto in project toolkit by googleapis.
the class GapicInterfaceConfig method createInterfaceConfig.
/**
* Creates an instance of GapicInterfaceConfig based on ConfigProto, linking up method
* configurations with specified methods in methodConfigMap. On errors, null will be returned, and
* diagnostics are reported to the model.
*/
@Nullable
static GapicInterfaceConfig createInterfaceConfig(DiagCollector diagCollector, TargetLanguage language, TransportProtocol transportProtocol, String defaultPackageName, GapicInterfaceInput interfaceInput, String interfaceNameOverride, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs, ProtoParser protoParser, GrpcGapicRetryMapping grpcGapicRetryMapping) {
Interface apiInterface = interfaceInput.getInterface();
Map<Method, MethodConfigProto> methodsToGenerate = interfaceInput.getMethodsToGenerate();
InterfaceConfigProto interfaceConfigProto = interfaceInput.getInterfaceConfigProto();
RetryCodesConfig retryCodesConfig;
ImmutableMap<String, RetryParamsDefinitionProto> retrySettingsDefinition;
if (grpcGapicRetryMapping != null) {
// use the gRPC ServiceConfig retry mapping as the source
retryCodesConfig = RetryCodesConfig.create(grpcGapicRetryMapping, interfaceConfigProto.getName());
retrySettingsDefinition = RetryDefinitionsTransformer.createRetryDefinitionsFromGRPCServiceConfig(grpcGapicRetryMapping, interfaceConfigProto.getName());
} else {
// use the GAPIC config as the source of retry
retryCodesConfig = RetryCodesConfig.create(interfaceConfigProto, new ArrayList<>(interfaceInput.getMethodsToGenerate().keySet()), protoParser);
retrySettingsDefinition = RetryDefinitionsTransformer.createRetrySettingsDefinition(interfaceConfigProto);
}
ImmutableMap<String, GapicMethodConfig> methodConfigsMap;
List<GapicMethodConfig> methodConfigs;
if (retryCodesConfig != null && retrySettingsDefinition != null) {
methodConfigsMap = createMethodConfigMap(diagCollector, language, transportProtocol, defaultPackageName, methodsToGenerate, messageConfigs, resourceNameConfigs, retryCodesConfig, retrySettingsDefinition.keySet(), protoParser, grpcGapicRetryMapping, interfaceInput.getInterfaceConfigProto().getName());
if (methodConfigsMap == null) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Error constructing methodConfigMap"));
return null;
}
methodConfigs = ImmutableList.copyOf(methodConfigsMap.values());
} else {
methodConfigsMap = ImmutableMap.of();
methodConfigs = ImmutableList.of();
}
SmokeTestConfig smokeTestConfig = createSmokeTestConfig(diagCollector, apiInterface, interfaceConfigProto);
ImmutableList<String> requiredConstructorParams = ImmutableList.copyOf(interfaceConfigProto.getRequiredConstructorParamsList());
for (String param : interfaceConfigProto.getRequiredConstructorParamsList()) {
if (!CONSTRUCTOR_PARAMS.contains(param)) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unsupported constructor param: %s", param));
}
}
ImmutableSet.Builder<SingleResourceNameConfig> resourcesBuilder = ImmutableSet.builder();
if (!protoParser.isProtoAnnotationsEnabled()) {
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);
}
} else {
addDeprecatedResources(diagCollector, resourcesBuilder, interfaceConfigProto, language);
}
ImmutableSet<SingleResourceNameConfig> singleResourceNames = resourcesBuilder.build();
String manualDoc = Strings.nullToEmpty(interfaceConfigProto.getLangDoc().get(language.toString().toLowerCase())).trim();
if (diagCollector.hasErrors()) {
return null;
} else {
return new AutoValue_GapicInterfaceConfig(interfaceNameOverride, new ProtoInterfaceModel(apiInterface), methodConfigs, smokeTestConfig, methodConfigsMap, retryCodesConfig, retrySettingsDefinition, requiredConstructorParams, singleResourceNames, manualDoc);
}
}
Aggregations