Search in sources :

Example 6 with InterfaceConfigProto

use of com.google.api.codegen.InterfaceConfigProto in project toolkit by googleapis.

the class GapicProductConfig method createDiscoGapicInterfaceConfigMap.

private static ImmutableMap<String, InterfaceConfig> createDiscoGapicInterfaceConfigMap(DiscoApiModel model, ConfigProto configProto, LanguageSettingsProto languageSettings, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs, TargetLanguage language) {
    ImmutableMap.Builder<String, InterfaceConfig> interfaceConfigMap = ImmutableMap.builder();
    for (InterfaceConfigProto interfaceConfigProto : configProto.getInterfacesList()) {
        String interfaceNameOverride = languageSettings.getInterfaceNamesMap().get(interfaceConfigProto.getName());
        DiscoGapicInterfaceConfig interfaceConfig = DiscoGapicInterfaceConfig.createInterfaceConfig(model, language, interfaceConfigProto, interfaceNameOverride, messageConfigs, resourceNameConfigs);
        if (interfaceConfig == null) {
            continue;
        }
        interfaceConfigMap.put(interfaceConfigProto.getName(), interfaceConfig);
    }
    if (model.getDiagCollector().getErrorCount() > 0) {
        return null;
    } else {
        return interfaceConfigMap.build();
    }
}
Also used : InterfaceConfigProto(com.google.api.codegen.InterfaceConfigProto) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with InterfaceConfigProto

use of com.google.api.codegen.InterfaceConfigProto 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

InterfaceConfigProto (com.google.api.codegen.InterfaceConfigProto)7 ImmutableMap (com.google.common.collect.ImmutableMap)3 MethodConfigProto (com.google.api.codegen.MethodConfigProto)2 Interface (com.google.api.tools.framework.model.Interface)2 ImmutableList (com.google.common.collect.ImmutableList)2 CollectionConfigProto (com.google.api.codegen.CollectionConfigProto)1 DeprecatedCollectionConfigProto (com.google.api.codegen.DeprecatedCollectionConfigProto)1 RetryParamsDefinitionProto (com.google.api.codegen.RetryParamsDefinitionProto)1 RetryCodesConfig (com.google.api.codegen.config.RetryCodesConfig)1 Method (com.google.api.tools.framework.model.Method)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1