-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: REST LRO implementation #859
Changes from 10 commits
35cc21c
00d94ed
d7b29e0
957f69a
200fce7
8ae8e6f
cb1b534
39c7b9c
d029941
0cf77b5
84c04c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -62,7 +62,8 @@ protected TransportContext getTransportContext() { | |||||
|
||||||
@Override | ||||||
public GapicClass generate(GapicContext context, Service service) { | ||||||
TypeStore typeStore = createTypes(); | ||||||
TypeStore typeStore = createTypes(service); | ||||||
|
||||||
String className = | ||||||
getTransportContext().classNames().getTransportServiceCallableFactoryClassName(service); | ||||||
GapicClass.Kind kind = Kind.STUB; | ||||||
|
@@ -77,9 +78,9 @@ public GapicClass generate(GapicContext context, Service service) { | |||||
commentComposer.createTransportServiceCallableFactoryClassHeaderComments( | ||||||
service.name(), service.isDeprecated())) | ||||||
.setAnnotations(createClassAnnotations(service, typeStore)) | ||||||
.setImplementsTypes(createClassImplements(typeStore)) | ||||||
.setImplementsTypes(createClassImplements(typeStore, service)) | ||||||
.setName(className) | ||||||
.setMethods(createClassMethods(typeStore)) | ||||||
.setMethods(createClassMethods(service, typeStore)) | ||||||
.setScope(ScopeNode.PUBLIC) | ||||||
.build(); | ||||||
return GapicClass.create(kind, classDef); | ||||||
|
@@ -110,22 +111,23 @@ protected List<AnnotationNode> createClassAnnotations(Service service, TypeStore | |||||
* @return {@code TypeNode} containing the interface to be implemented by the generated callable | ||||||
* factory class. | ||||||
*/ | ||||||
protected abstract List<TypeNode> createClassImplements(TypeStore typeStore); | ||||||
protected abstract List<TypeNode> createClassImplements(TypeStore typeStore, Service service); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth having the consistency in the argument order with others?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is better to have ordering consistent, though there are so much code in gapic-generator in general, so things like arguments ordering is not really a consistent thing accross the generator codebase (meaning other similar methods, not this specific one necessarily). As result it is hard to define what is the "right" ordering. for this specific one it is clearly service should go first, so reordered the parsms, thanks! |
||||||
|
||||||
protected List<MethodDefinition> createClassMethods(TypeStore typeStore) { | ||||||
protected List<MethodDefinition> createClassMethods(Service service, TypeStore typeStore) { | ||||||
return Arrays.asList( | ||||||
createUnaryCallableMethod(typeStore), | ||||||
createPagedCallableMethod(typeStore), | ||||||
createBatchingCallableMethod(typeStore), | ||||||
createOperationCallableMethod(typeStore)); | ||||||
createUnaryCallableMethod(service, typeStore), | ||||||
createPagedCallableMethod(service, typeStore), | ||||||
createBatchingCallableMethod(service, typeStore), | ||||||
createOperationCallableMethod(service, typeStore)); | ||||||
} | ||||||
|
||||||
protected MethodDefinition createUnaryCallableMethod(TypeStore typeStore) { | ||||||
protected MethodDefinition createUnaryCallableMethod(Service service, TypeStore typeStore) { | ||||||
String methodVariantName = "Unary"; | ||||||
String requestTemplateName = "RequestT"; | ||||||
String responseTemplateName = "ResponseT"; | ||||||
List<String> methodTemplateNames = Arrays.asList(requestTemplateName, responseTemplateName); | ||||||
return createGenericCallableMethod( | ||||||
service, | ||||||
typeStore, | ||||||
/*methodTemplateNames=*/ methodTemplateNames, | ||||||
/*returnCallableKindName=*/ methodVariantName, | ||||||
|
@@ -140,14 +142,15 @@ protected MethodDefinition createUnaryCallableMethod(TypeStore typeStore) { | |||||
.collect(Collectors.toList())); | ||||||
} | ||||||
|
||||||
protected MethodDefinition createPagedCallableMethod(TypeStore typeStore) { | ||||||
protected MethodDefinition createPagedCallableMethod(Service service, TypeStore typeStore) { | ||||||
String methodVariantName = "Paged"; | ||||||
String requestTemplateName = "RequestT"; | ||||||
String pagedResponseTemplateName = "PagedListResponseT"; | ||||||
String responseTemplateName = "ResponseT"; | ||||||
List<String> methodTemplateNames = | ||||||
Arrays.asList(requestTemplateName, responseTemplateName, pagedResponseTemplateName); | ||||||
return createGenericCallableMethod( | ||||||
service, | ||||||
typeStore, | ||||||
/*methodTemplateNames=*/ methodTemplateNames, | ||||||
/*returnCallableKindName=*/ "Unary", | ||||||
|
@@ -162,12 +165,13 @@ protected MethodDefinition createPagedCallableMethod(TypeStore typeStore) { | |||||
.collect(Collectors.toList())); | ||||||
} | ||||||
|
||||||
protected MethodDefinition createBatchingCallableMethod(TypeStore typeStore) { | ||||||
protected MethodDefinition createBatchingCallableMethod(Service service, TypeStore typeStore) { | ||||||
String methodVariantName = "Batching"; | ||||||
String requestTemplateName = "RequestT"; | ||||||
String responseTemplateName = "ResponseT"; | ||||||
List<String> methodTemplateNames = Arrays.asList(requestTemplateName, responseTemplateName); | ||||||
return createGenericCallableMethod( | ||||||
service, | ||||||
typeStore, | ||||||
/*methodTemplateNames=*/ methodTemplateNames, | ||||||
/*returnCallableKindName=*/ "Unary", | ||||||
|
@@ -182,9 +186,11 @@ protected MethodDefinition createBatchingCallableMethod(TypeStore typeStore) { | |||||
.collect(Collectors.toList())); | ||||||
} | ||||||
|
||||||
protected abstract MethodDefinition createOperationCallableMethod(TypeStore typeStore); | ||||||
protected abstract MethodDefinition createOperationCallableMethod( | ||||||
Service service, TypeStore typeStore); | ||||||
|
||||||
protected MethodDefinition createGenericCallableMethod( | ||||||
Service service, | ||||||
TypeStore typeStore, | ||||||
List<String> methodTemplateNames, | ||||||
String returnCallableKindName, | ||||||
|
@@ -194,6 +200,7 @@ protected MethodDefinition createGenericCallableMethod( | |||||
String callSettingsVariantName, | ||||||
List<Object> callSettingsTemplateObjects) { | ||||||
return createGenericCallableMethod( | ||||||
service, | ||||||
typeStore, | ||||||
methodTemplateNames, | ||||||
returnCallableKindName, | ||||||
|
@@ -206,6 +213,7 @@ protected MethodDefinition createGenericCallableMethod( | |||||
} | ||||||
|
||||||
protected MethodDefinition createGenericCallableMethod( | ||||||
Service service, | ||||||
TypeStore typeStore, | ||||||
List<String> methodTemplateNames, | ||||||
String returnCallableKindName, | ||||||
|
@@ -257,7 +265,7 @@ protected MethodDefinition createGenericCallableMethod( | |||||
.setVariable( | ||||||
Variable.builder() | ||||||
.setName("operationsStub") | ||||||
.setType(getTransportContext().operationsStubTypes().get(0)) | ||||||
.setType(getOperationsStubType(service)) | ||||||
.build()) | ||||||
.setIsDecl(true) | ||||||
.build()); | ||||||
|
@@ -288,7 +296,16 @@ protected MethodDefinition createGenericCallableMethod( | |||||
.build(); | ||||||
} | ||||||
|
||||||
private static TypeStore createTypes() { | ||||||
protected TypeNode getOperationsStubType(Service service) { | ||||||
TypeNode opeationsStubType = service.operationServiceStubType(); | ||||||
if (opeationsStubType == null) { | ||||||
opeationsStubType = getTransportContext().operationsStubTypes().get(0); | ||||||
} | ||||||
return opeationsStubType; | ||||||
} | ||||||
|
||||||
|
||||||
private TypeStore createTypes(Service service) { | ||||||
List<Class<?>> concreteClazzes = | ||||||
Arrays.asList( | ||||||
// Gax-java classes. | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -132,7 +132,7 @@ public GapicClass generate(GapicContext context, Service service) { | |||||
String className = ClassNames.getServiceClientClassName(service); | ||||||
GapicClass.Kind kind = Kind.MAIN; | ||||||
String pakkage = service.pakkage(); | ||||||
boolean hasLroClient = service.hasLroMethods(); | ||||||
boolean hasLroClient = service.hasStandardLroMethods(); | ||||||
|
||||||
Map<String, List<String>> grpcRpcsToJavaMethodNames = new HashMap<>(); | ||||||
|
||||||
|
@@ -741,6 +741,7 @@ private static MethodDefinition createMethodDefaultMethod( | |||||
method.isPaged() | ||||||
? typeStore.get(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name())) | ||||||
: method.outputType(); | ||||||
List<AnnotationNode> annotations = new ArrayList<>(); | ||||||
if (method.hasLro()) { | ||||||
LongrunningOperation lro = method.lro(); | ||||||
methodOutputType = | ||||||
|
@@ -751,6 +752,13 @@ private static MethodDefinition createMethodDefaultMethod( | |||||
.copyAndSetGenerics( | ||||||
Arrays.asList( | ||||||
lro.responseType().reference(), lro.metadataType().reference()))); | ||||||
if (method.hasLro() && method.lro().operationServiceStubType() != null) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already checked
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, that was redundant. Removed |
||||||
annotations.add( | ||||||
AnnotationNode.withTypeAndDescription( | ||||||
typeStore.get("BetaApi"), | ||||||
"The surface for long-running operations is not stable yet and may change in the" | ||||||
+ " future.")); | ||||||
} | ||||||
} | ||||||
|
||||||
// Construct the method that accepts a request proto. | ||||||
|
@@ -792,8 +800,7 @@ private static MethodDefinition createMethodDefaultMethod( | |||||
.setArguments(Arrays.asList(requestArgVarExpr)); | ||||||
|
||||||
if (method.isDeprecated()) { | ||||||
methodBuilder = | ||||||
methodBuilder.setAnnotations(Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED))); | ||||||
annotations.add(AnnotationNode.withType(TypeNode.DEPRECATED)); | ||||||
} | ||||||
|
||||||
if (isProtoEmptyType(methodOutputType)) { | ||||||
|
@@ -805,6 +812,9 @@ private static MethodDefinition createMethodDefaultMethod( | |||||
methodBuilder = | ||||||
methodBuilder.setReturnExpr(callableMethodExpr).setReturnType(methodOutputType); | ||||||
} | ||||||
|
||||||
methodBuilder.setAnnotations(annotations); | ||||||
|
||||||
return methodBuilder.build(); | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to point to upstream