Search in sources :

Example 6 with RetryParamsDefinitionProto

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);
    }
}
Also used : RetryParamsDefinitionProto(com.google.api.codegen.RetryParamsDefinitionProto) Method(com.google.api.codegen.discovery.Method) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSet(com.google.common.collect.ImmutableSet) CollectionConfigProto(com.google.api.codegen.CollectionConfigProto)

Example 7 with RetryParamsDefinitionProto

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);
    }
}
Also used : InterfaceConfigProto(com.google.api.codegen.InterfaceConfigProto) ArrayList(java.util.ArrayList) Method(com.google.api.tools.framework.model.Method) RetryParamsDefinitionProto(com.google.api.codegen.RetryParamsDefinitionProto) ImmutableSet(com.google.common.collect.ImmutableSet) MethodConfigProto(com.google.api.codegen.MethodConfigProto) Interface(com.google.api.tools.framework.model.Interface) CollectionConfigProto(com.google.api.codegen.CollectionConfigProto) DeprecatedCollectionConfigProto(com.google.api.codegen.DeprecatedCollectionConfigProto) Nullable(javax.annotation.Nullable)

Aggregations

RetryParamsDefinitionProto (com.google.api.codegen.RetryParamsDefinitionProto)7 ImmutableMap (com.google.common.collect.ImmutableMap)3 CollectionConfigProto (com.google.api.codegen.CollectionConfigProto)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ArrayList (java.util.ArrayList)2 ConfigProto (com.google.api.codegen.ConfigProto)1 DeprecatedCollectionConfigProto (com.google.api.codegen.DeprecatedCollectionConfigProto)1 InterfaceConfigProto (com.google.api.codegen.InterfaceConfigProto)1 MethodConfigProto (com.google.api.codegen.MethodConfigProto)1 MixedPathTestDataLocator (com.google.api.codegen.MixedPathTestDataLocator)1 RetryCodesDefinitionProto (com.google.api.codegen.RetryCodesDefinitionProto)1 MethodConfig (com.google.api.codegen.config.MethodConfig)1 MethodModel (com.google.api.codegen.config.MethodModel)1 Method (com.google.api.codegen.discovery.Method)1 Name (com.google.api.codegen.grpc.MethodConfig.Name)1 RetryPolicy (com.google.api.codegen.grpc.MethodConfig.RetryPolicy)1 ServiceConfig (com.google.api.codegen.grpc.ServiceConfig)1 RetryConfigDefinitionView (com.google.api.codegen.viewmodel.RetryConfigDefinitionView)1 RetrySettings (com.google.api.gax.retrying.RetrySettings)1