use of com.google.api.codegen.viewmodel.RetryParamsDefinitionView in project toolkit by googleapis.
the class ApiCallableTransformer method generateApiCallableSettings.
public ApiCallSettingsView generateApiCallableSettings(MethodContext context, ApiCallableImplType callableImplType) {
SurfaceNamer namer = context.getNamer();
ImportTypeTable typeTable = context.getTypeTable();
MethodModel method = context.getMethodModel();
MethodConfig methodConfig = context.getMethodConfig();
Map<String, RetryCodesDefinitionView> retryCodesByKey = new HashMap<>();
for (RetryCodesDefinitionView retryCodes : retryDefinitionsTransformer.generateRetryCodesDefinitions(context.getSurfaceInterfaceContext())) {
retryCodesByKey.put(retryCodes.key(), retryCodes);
}
Map<String, RetryParamsDefinitionView> retryParamsByKey = new HashMap<>();
for (RetryParamsDefinitionView retryParams : retryDefinitionsTransformer.generateRetryParamsDefinitions(context.getSurfaceInterfaceContext())) {
retryParamsByKey.put(retryParams.key(), retryParams);
}
ApiCallSettingsView.Builder settings = ApiCallSettingsView.newBuilder();
settings.methodName(namer.getApiMethodName(method, VisibilityConfig.PUBLIC));
settings.asyncMethodName(namer.getAsyncApiMethodName(method, VisibilityConfig.PUBLIC));
settings.requestTypeName(method.getAndSaveRequestTypeName(context.getTypeTable(), context.getNamer()));
settings.responseTypeName(method.getAndSaveResponseTypeName(context.getTypeTable(), context.getNamer()));
settings.grpcTypeName(typeTable.getAndSaveNicknameFor(context.getGrpcContainerTypeName()));
settings.grpcMethodConstant(namer.getGrpcMethodConstant(method));
settings.retryCodesName(methodConfig.getRetryCodesConfigName());
settings.retryCodesView(retryCodesByKey.get(methodConfig.getRetryCodesConfigName()));
settings.retryParamsName(methodConfig.getRetrySettingsConfigName());
settings.retryParamsView(retryParamsByKey.get(methodConfig.getRetrySettingsConfigName()));
settings.visibility(namer.getVisiblityKeyword(methodConfig.getVisibility()));
String notImplementedPrefix = "ApiCallableTransformer.generateApiCallableSettings - ";
settings.resourceTypeName(namer.getNotImplementedString(notImplementedPrefix + "resourceTypeName"));
settings.pagedListResponseTypeName(namer.getNotImplementedString(notImplementedPrefix + "pagedListResponseTypeName"));
settings.pageStreamingDescriptorName(namer.getNotImplementedString(notImplementedPrefix + "pageStreamingDescriptorName"));
settings.pagedListResponseFactoryName(namer.getNotImplementedString(notImplementedPrefix + "pagedListResponseFactoryName"));
settings.batchingDescriptorName(namer.getNotImplementedString(notImplementedPrefix + "batchingDescriptorName"));
settings.memberName(namer.getSettingsMemberName(method));
settings.settingsGetFunction(namer.getSettingsFunctionName(method));
settings.type(callableImplType);
switch(callableImplType) {
case BidiStreamingApiCallable:
case ClientStreamingApiCallable:
case ServerStreamingApiCallable:
settings.type(ApiCallableImplType.of(methodConfig.getGrpcStreamingType()));
if (methodConfig.getGrpcStreaming().hasResourceField()) {
FieldModel resourceType = methodConfig.getGrpcStreaming().getResourcesField();
settings.resourceTypeName(typeTable.getAndSaveNicknameForElementType(resourceType));
}
settings.grpcStreamingType(methodConfig.getGrpcStreaming().getType());
break;
case PagedApiCallable:
settings.type(ApiCallableImplType.PagedApiCallable);
FieldModel resourceField = methodConfig.getPageStreaming().getResourcesField();
settings.resourceTypeName(typeTable.getAndSaveNicknameForElementType(resourceField));
settings.pagedListResponseTypeName(namer.getAndSavePagedResponseTypeName(context, methodConfig.getPageStreaming().getResourcesFieldConfig()));
settings.pageStreamingDescriptorName(namer.getPageStreamingDescriptorConstName(method));
settings.pagedListResponseFactoryName(namer.getPagedListResponseFactoryConstName(method));
break;
case BatchingApiCallable:
settings.type(ApiCallableImplType.BatchingApiCallable);
settings.batchingDescriptorName(namer.getBatchingDescriptorConstName(method));
settings.batchingConfig(batchingTransformer.generateBatchingConfig(context));
break;
case OperationApiCallable:
settings.type(ApiCallableImplType.OperationApiCallable);
settings.operationMethod(lroTransformer.generateDetailView(context));
settings.memberName(namer.getOperationSettingsMemberName(method));
settings.settingsGetFunction(namer.getOperationSettingsFunctionName(method));
break;
case SimpleApiCallable:
break;
default:
throw new IllegalStateException("Unhandled ApiCallableImplType enum value: " + callableImplType);
}
return settings.build();
}
use of com.google.api.codegen.viewmodel.RetryParamsDefinitionView in project toolkit by googleapis.
the class RetryDefinitionsTransformer method generateRetryParamsDefinitions.
public List<RetryParamsDefinitionView> generateRetryParamsDefinitions(InterfaceContext context) {
List<RetryParamsDefinitionView> definitions = new ArrayList<>();
SurfaceNamer namer = context.getNamer();
for (Entry<String, RetrySettings> retryCodesDef : context.getInterfaceConfig().getRetrySettingsDefinition().entrySet()) {
RetrySettings settings = retryCodesDef.getValue();
RetryParamsDefinitionView.Builder params = RetryParamsDefinitionView.newBuilder();
params.key(retryCodesDef.getKey());
params.name(namer.publicMethodName(Name.from(retryCodesDef.getKey())));
params.retryBackoffMethodName(namer.retryBackoffMethodName(retryCodesDef.getKey()));
params.timeoutBackoffMethodName(namer.timeoutBackoffMethodName(retryCodesDef.getKey()));
params.initialRetryDelay(settings.getInitialRetryDelay());
params.retryDelayMultiplier(settings.getRetryDelayMultiplier());
params.maxRetryDelay(settings.getMaxRetryDelay());
params.initialRpcTimeout(settings.getInitialRpcTimeout());
params.rpcTimeoutMultiplier(settings.getRpcTimeoutMultiplier());
params.maxRpcTimeout(settings.getMaxRpcTimeout());
params.totalTimeout(settings.getTotalTimeout());
definitions.add(params.build());
}
return definitions;
}
Aggregations