Search in sources :

Example 1 with InterfaceConfigProto

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

the class GapicProductConfig method createInterfaceConfigMap.

private static ImmutableMap<String, InterfaceConfig> createInterfaceConfigMap(DiagCollector diagCollector, ConfigProto configProto, LanguageSettingsProto languageSettings, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs, SymbolTable symbolTable) {
    ImmutableMap.Builder<String, InterfaceConfig> interfaceConfigMap = ImmutableMap.builder();
    for (InterfaceConfigProto interfaceConfigProto : configProto.getInterfacesList()) {
        Interface apiInterface = symbolTable.lookupInterface(interfaceConfigProto.getName());
        if (apiInterface == null || !apiInterface.isReachable()) {
            diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "interface not found: %s", interfaceConfigProto.getName()));
            continue;
        }
        String interfaceNameOverride = languageSettings.getInterfaceNames().get(interfaceConfigProto.getName());
        GapicInterfaceConfig interfaceConfig = GapicInterfaceConfig.createInterfaceConfig(diagCollector, configProto.getLanguage(), interfaceConfigProto, apiInterface, interfaceNameOverride, messageConfigs, resourceNameConfigs);
        if (interfaceConfig == null) {
            continue;
        }
        interfaceConfigMap.put(interfaceConfigProto.getName(), interfaceConfig);
    }
    if (diagCollector.getErrorCount() > 0) {
        return null;
    } else {
        return interfaceConfigMap.build();
    }
}
Also used : InterfaceConfigProto(com.google.api.codegen.InterfaceConfigProto) ImmutableMap(com.google.common.collect.ImmutableMap) Interface(com.google.api.tools.framework.model.Interface)

Example 2 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) {
    ImmutableMap.Builder<String, InterfaceConfig> interfaceConfigMap = ImmutableMap.builder();
    for (InterfaceConfigProto interfaceConfigProto : configProto.getInterfacesList()) {
        String interfaceNameOverride = languageSettings.getInterfaceNames().get(interfaceConfigProto.getName());
        DiscoGapicInterfaceConfig interfaceConfig = DiscoGapicInterfaceConfig.createInterfaceConfig(model, configProto.getLanguage(), 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 3 with InterfaceConfigProto

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

the class RetryDefinitionsTransformerTest method testWithInterfaceOnly.

@Test
public void testWithInterfaceOnly() {
    // During GAPIC config migration, we should only create retry codes for methods named in the
    // GAPIC config.
    // TODO(andrealin): Remove this once methods are generated by default.
    InterfaceConfigProto bareBonesConfigProto = InterfaceConfigProto.newBuilder().addMethods(MethodConfigProto.newBuilder().setName(GET_HTTP_METHOD_NAME)).addMethods(MethodConfigProto.newBuilder().setName(NON_IDEMPOTENT_METHOD_NAME)).addMethods(MethodConfigProto.newBuilder().setName(PERMISSION_DENIED_METHOD_NAME)).build();
    RetryCodesConfig retryCodesConfig = RetryCodesConfig.create(bareBonesConfigProto, apiInterface.getMethods(), protoParser);
    Map<String, ImmutableList<String>> retryCodesDef = retryCodesConfig.getRetryCodesDefinition();
    Map<String, String> retryCodesMap = retryCodesConfig.getMethodRetryNames();
    assertThat(retryCodesMap).hasSize(3);
    String getHttpRetryName = retryCodesMap.get(GET_HTTP_METHOD_NAME);
    String nonIdempotentRetryName = retryCodesMap.get(NON_IDEMPOTENT_METHOD_NAME);
    String permissionDeniedRetryName = retryCodesMap.get(PERMISSION_DENIED_METHOD_NAME);
    assertThat(getHttpRetryName).isEqualTo(RetryTransformer.RETRY_CODES_IDEMPOTENT_NAME);
    assertThat(nonIdempotentRetryName).isEqualTo(RetryTransformer.RETRY_CODES_NON_IDEMPOTENT_NAME);
    assertThat(permissionDeniedRetryName).isEqualTo(RetryTransformer.RETRY_CODES_NON_IDEMPOTENT_NAME);
    // httpGetMethod was an HTTP Get method, so it has two codes by default; config proto didn't
    // have a retry config.
    assertThat(retryCodesDef.get(getHttpRetryName)).isEqualTo(RetryCodesConfig.RETRY_CODES_FOR_HTTP_GET);
    // Method from protofile has
    // [] for retry codes.
    assertThat(retryCodesDef.get(nonIdempotentRetryName).size()).isEqualTo(0);
    // For permissionDeniedMethod, proto method gives [PERMISSION_DENIED].
    assertThat(retryCodesDef.get(permissionDeniedRetryName).size()).isEqualTo(0);
// assertThat(retryCodesDef.get(permissionDeniedRetryName).iterator().next())
// .isEqualTo(PERMISSION_DENIED.name());
}
Also used : InterfaceConfigProto(com.google.api.codegen.InterfaceConfigProto) ImmutableList(com.google.common.collect.ImmutableList) RetryCodesConfig(com.google.api.codegen.config.RetryCodesConfig) Test(org.junit.Test)

Example 4 with InterfaceConfigProto

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

the class GapicProductConfig method createInterfaceInputsWithGapicConfigOnly.

private static ImmutableList<GapicInterfaceInput> createInterfaceInputsWithGapicConfigOnly(DiagCollector diagCollector, List<InterfaceConfigProto> interfaceConfigProtosList, ImmutableMap<String, Interface> protoInterfaces, SymbolTable symbolTable, TargetLanguage language) {
    // Maps name of interfaces to found interfaces from proto.
    Map<String, Interface> interfaceMap = new LinkedHashMap<>(protoInterfaces);
    // Maps name of interfaces to found InterfaceConfigs from config yamls.
    Map<String, InterfaceConfigProto> interfaceConfigProtos = new LinkedHashMap<>();
    // Parse GAPIC config for interfaceConfigProtos.
    for (InterfaceConfigProto interfaceConfigProto : interfaceConfigProtosList) {
        Interface apiInterface = symbolTable.lookupInterface(interfaceConfigProto.getName());
        if (apiInterface == null) {
            List<String> interfaces = symbolTable.getInterfaces().stream().map(ProtoElement::getFullName).collect(Collectors.toList());
            String interfacesString = String.join(",", interfaces);
            diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "interface not found: %s. Interfaces: [%s]", interfaceConfigProto.getName(), interfacesString));
            continue;
        }
        if (!apiInterface.isReachable()) {
            diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "interface not reachable: %s.", interfaceConfigProto.getName()));
            continue;
        }
        interfaceConfigProtos.put(interfaceConfigProto.getName(), interfaceConfigProto);
        interfaceMap.put(interfaceConfigProto.getName(), apiInterface);
    }
    return createGapicInterfaceInputList(diagCollector, language, interfaceMap.values(), interfaceConfigProtos);
}
Also used : InterfaceConfigProto(com.google.api.codegen.InterfaceConfigProto)

Example 5 with InterfaceConfigProto

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

the class GapicProductConfig method createGapicInterfaceInputList.

private static ImmutableList<GapicInterfaceInput> createGapicInterfaceInputList(DiagCollector diagCollector, TargetLanguage language, Iterable<Interface> interfaceList, Map<String, InterfaceConfigProto> interfaceConfigProtos) {
    // Store info about each Interface in a GapicInterfaceInput object.
    ImmutableList.Builder<GapicInterfaceInput> interfaceInputs = ImmutableList.builder();
    for (Interface apiInterface : interfaceList) {
        String serviceFullName = apiInterface.getFullName();
        GapicInterfaceInput.Builder interfaceInput = GapicInterfaceInput.newBuilder().setInterface(apiInterface);
        InterfaceConfigProto interfaceConfigProto = interfaceConfigProtos.getOrDefault(serviceFullName, InterfaceConfigProto.getDefaultInstance());
        interfaceInput.setInterfaceConfigProto(interfaceConfigProto);
        Map<Method, MethodConfigProto> methodsToGenerate;
        methodsToGenerate = findMethodsToGenerateWithConfigYaml(apiInterface, interfaceConfigProto, language, diagCollector);
        if (methodsToGenerate == null) {
            return null;
        }
        interfaceInput.setMethodsToGenerate(methodsToGenerate);
        interfaceInputs.add(interfaceInput.build());
    }
    return interfaceInputs.build();
}
Also used : InterfaceConfigProto(com.google.api.codegen.InterfaceConfigProto) ImmutableList(com.google.common.collect.ImmutableList) MethodConfigProto(com.google.api.codegen.MethodConfigProto)

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