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;
}
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());
}
}
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();
}
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();
}
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();
}
Aggregations