Search in sources :

Example 1 with InterfaceConfig

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

the class GapicInterfaceContext method createGrpcRerouteMap.

private static Map<Interface, Interface> createGrpcRerouteMap(Model model, GapicProductConfig productConfig) {
    HashMap<Interface, Interface> grpcRerouteMap = new HashMap<>();
    for (Interface apiInterface : new InterfaceView().getElementIterable(model)) {
        if (!apiInterface.isReachable()) {
            continue;
        }
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        for (MethodConfig methodConfig : interfaceConfig.getMethodConfigs()) {
            String reroute = methodConfig.getRerouteToGrpcInterface();
            if (!Strings.isNullOrEmpty(reroute)) {
                Interface targetInterface = model.getSymbolTable().lookupInterface(reroute);
                grpcRerouteMap.put(targetInterface, apiInterface);
            }
        }
    }
    return grpcRerouteMap;
}
Also used : GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) MethodConfig(com.google.api.codegen.config.MethodConfig) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) HashMap(java.util.HashMap) InterfaceView(com.google.api.codegen.InterfaceView) Interface(com.google.api.tools.framework.model.Interface)

Example 2 with InterfaceConfig

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

the class GapicInterfaceContext method getMethodConfig.

/**
 * Returns the MethodConfig object of the given gRPC method.
 *
 * <p>If the method is a gRPC re-route method, returns the MethodConfig of the original method.
 */
public GapicMethodConfig getMethodConfig(MethodModel method) {
    Interface originalInterface = getInterface();
    if (getGrpcRerouteMap().containsKey(originalInterface)) {
        originalInterface = getGrpcRerouteMap().get(originalInterface);
    }
    InterfaceConfig originalInterfaceConfig = getProductConfig().getInterfaceConfig(originalInterface);
    if (originalInterfaceConfig != null) {
        return (GapicMethodConfig) originalInterfaceConfig.getMethodConfig(method);
    } else {
        throw new IllegalArgumentException("Interface config does not exist for method: " + method.getSimpleName());
    }
}
Also used : GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) Interface(com.google.api.tools.framework.model.Interface)

Example 3 with InterfaceConfig

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

the class JavaSurfaceTransformer method generateSettingsClass.

private StaticLangSettingsView generateSettingsClass(InterfaceContext context, GapicProductConfig productConfig, StaticLangApiMethodView exampleApiMethod, StaticLangStubSettingsView stubSettingsView) {
    addSettingsImports(context);
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    StaticLangSettingsView.Builder xsettingsClass = StaticLangSettingsView.newBuilder();
    String name = namer.getApiSettingsClassName(context.getInterfaceConfig());
    xsettingsClass.doc(generateSettingsDoc(context, exampleApiMethod, productConfig, name, namer.getApiWrapperClassName(context.getInterfaceConfig())));
    xsettingsClass.name(name);
    xsettingsClass.releaseLevelAnnotation(stubSettingsView.releaseLevelAnnotation());
    xsettingsClass.serviceHostname(stubSettingsView.serviceHostname());
    xsettingsClass.servicePort(stubSettingsView.servicePort());
    xsettingsClass.authScopes(stubSettingsView.authScopes());
    xsettingsClass.callSettings(apiCallableTransformer.generateCallSettings(context));
    xsettingsClass.pageStreamingDescriptors(stubSettingsView.pageStreamingDescriptors());
    xsettingsClass.batchingDescriptors(stubSettingsView.batchingDescriptors());
    xsettingsClass.retryCodesDefinitions(stubSettingsView.retryCodesDefinitions());
    xsettingsClass.hasDefaultServiceAddress(stubSettingsView.hasDefaultServiceAddress());
    xsettingsClass.hasDefaultServiceScopes(stubSettingsView.hasDefaultServiceScopes());
    xsettingsClass.hasDefaultInstance(stubSettingsView.hasDefaultInstance());
    xsettingsClass.retryParamsDefinitions(stubSettingsView.retryParamsDefinitions());
    xsettingsClass.instantiatingChannelProvider(stubSettingsView.instantiatingChannelProvider());
    xsettingsClass.transportProtocol(stubSettingsView.transportProtocol());
    xsettingsClass.useDefaultServicePortInEndpoint(stubSettingsView.useDefaultServicePortInEndpoint());
    xsettingsClass.defaultTransportProviderBuilder(stubSettingsView.defaultTransportProviderBuilder());
    xsettingsClass.stubSettingsName(getAndSaveNicknameForStubType(context, namer.getApiStubSettingsClassName(interfaceConfig)));
    return xsettingsClass.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) StaticLangSettingsView(com.google.api.codegen.viewmodel.StaticLangSettingsView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 4 with InterfaceConfig

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

the class JavaSurfaceTransformer method generateCallableFactoryClass.

private StaticLangCallableFactoryView generateCallableFactoryClass(InterfaceContext context, GapicProductConfig productConfig) {
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    addCallableFactoryImports(context);
    StaticLangCallableFactoryView.Builder callableFactory = StaticLangCallableFactoryView.newBuilder();
    callableFactory.doc(serviceTransformer.generateServiceDoc(context, null, productConfig));
    callableFactory.releaseLevelAnnotation(namer.getReleaseAnnotation(ReleaseLevel.BETA));
    callableFactory.name(namer.getCallableFactoryClassName(interfaceConfig, productConfig.getTransportProtocol()));
    if (productConfig.getTransportProtocol().equals(TransportProtocol.HTTP)) {
        callableFactory.operationStubType(context.getImportTypeTable().getAndSaveNicknameFor("com.google.api.gax.core.BackgroundResource"));
        callableFactory.operationMessage(context.getImportTypeTable().getAndSaveNicknameFor("com.google.api.gax.httpjson.ApiMessage"));
    }
    return callableFactory.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) StaticLangCallableFactoryView(com.google.api.codegen.viewmodel.StaticLangCallableFactoryView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 5 with InterfaceConfig

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

the class JavaSurfaceTransformer method generateStubSettingsClass.

private StaticLangStubSettingsView generateStubSettingsClass(InterfaceContext context, GapicProductConfig productConfig, StaticLangApiMethodView exampleApiMethod) {
    addSettingsImports(context);
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    ApiModel model = context.getApiModel();
    StaticLangStubSettingsView.Builder xsettingsClass = StaticLangStubSettingsView.newBuilder();
    xsettingsClass.releaseLevelAnnotation(context.getNamer().getReleaseAnnotation(productConfig.getReleaseLevel()));
    xsettingsClass.doc(generateSettingsDoc(context, exampleApiMethod, productConfig, context.getNamer().getApiStubSettingsClassName(interfaceConfig), namer.getApiStubInterfaceName(context.getInterfaceConfig())));
    String name = namer.getApiStubSettingsClassName(context.getInterfaceConfig());
    xsettingsClass.name(name);
    xsettingsClass.serviceHostname(productServiceConfig.getServiceHostname(context.getServiceAddress()));
    xsettingsClass.servicePort(productServiceConfig.getServicePort(context.getServiceAddress()));
    xsettingsClass.authScopes(model.getAuthScopes(productConfig));
    if (productConfig.getTransportProtocol().equals(TransportProtocol.HTTP)) {
        xsettingsClass.useDefaultServicePortInEndpoint(false);
    }
    xsettingsClass.transportProtocol(productConfig.getTransportProtocol());
    xsettingsClass.rpcTransportName(namer.getTransportClassName(productConfig.getTransportProtocol()));
    xsettingsClass.transportNameGetter(namer.getTransporNameGetMethod(productConfig.getTransportProtocol()));
    xsettingsClass.defaultTransportProviderBuilder(namer.getDefaultTransportProviderBuilder(productConfig.getTransportProtocol()));
    xsettingsClass.transportProvider(namer.getTransportProvider(productConfig.getTransportProtocol()));
    xsettingsClass.instantiatingChannelProvider(namer.getInstantiatingChannelProvider(productConfig.getTransportProtocol()));
    List<ApiCallSettingsView> apiCallSettings = apiCallableTransformer.generateCallSettings(context);
    xsettingsClass.callSettings(apiCallSettings);
    xsettingsClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptorClasses(context));
    xsettingsClass.pagedListResponseFactories(pageStreamingTransformer.generateFactoryClasses(context));
    xsettingsClass.batchingDescriptors(batchingTransformer.generateDescriptorClasses(context));
    xsettingsClass.retryCodesDefinitions(retryDefinitionsTransformer.generateRetryCodesDefinitions(context));
    xsettingsClass.retryParamsDefinitions(retryDefinitionsTransformer.generateRetryParamsDefinitions(context));
    xsettingsClass.transportProtocol(productConfig.getTransportProtocol());
    xsettingsClass.hasDefaultServiceAddress(interfaceConfig.hasDefaultServiceAddress());
    xsettingsClass.hasDefaultServiceScopes(interfaceConfig.hasDefaultServiceScopes());
    xsettingsClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
    xsettingsClass.stubInterfaceName(getAndSaveNicknameForStubType(context, namer.getApiStubInterfaceName(interfaceConfig)));
    xsettingsClass.rpcStubClassName(getAndSaveNicknameForStubType(context, namer.getApiRpcStubClassName(interfaceConfig.getInterfaceModel(), productConfig.getTransportProtocol())));
    return xsettingsClass.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ApiModel(com.google.api.codegen.config.ApiModel) StaticLangStubSettingsView(com.google.api.codegen.viewmodel.StaticLangStubSettingsView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ApiCallSettingsView(com.google.api.codegen.viewmodel.ApiCallSettingsView)

Aggregations

InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)32 InterfaceModel (com.google.api.codegen.config.InterfaceModel)12 ImmutableList (com.google.common.collect.ImmutableList)11 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)9 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)9 MethodModel (com.google.api.codegen.config.MethodModel)6 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)5 ViewModel (com.google.api.codegen.viewmodel.ViewModel)5 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)4 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)4 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)4 MethodConfig (com.google.api.codegen.config.MethodConfig)4 SingleResourceNameConfig (com.google.api.codegen.config.SingleResourceNameConfig)4 ArrayList (java.util.ArrayList)4 ApiModel (com.google.api.codegen.config.ApiModel)3 InterfaceContext (com.google.api.codegen.config.InterfaceContext)3 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)3 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)3 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)2 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)2