From 000146b547e3698267d0e12ffd1c1f222b74491b Mon Sep 17 00:00:00 2001 From: Jacob Geiger Date: Tue, 23 Feb 2016 16:51:58 -0800 Subject: [PATCH] Python VGen update for bundling Introduces bundling into Python VGen. To accomodate bundling, the defaults/options system has been reworked; ApiCallDefaults is removed. Instead, a dictionary is maintained which associates defaults to each method; the values in the dictionary are then merged with any CallOptions passed in while a call is being made. A corresponding change to GAX is here: https://github.com/googleapis/gax-python/pull/28/ Note that it is not currently possible to override the bundling defaults when calling the API constructor; a later change will add the ability to pass in a dictionary mapping method names to bundlers in order to provide this functionality. Change-Id: I434a6026882fa57ec0d4672bff8be4f4102c4a82 --- .../main/resources/io/gapi/vgen/py/main.snip | 127 ++++++++----- .../csharp_extensions_library.baseline | 51 +++++ .../io/gapi/vgen/testdata/go_library.baseline | 38 ++++ .../gapi/vgen/testdata/java_library.baseline | 64 ++++++- .../java/io/gapi/vgen/testdata/library.proto | 23 +++ .../io/gapi/vgen/testdata/library_veneer.yaml | 19 ++ .../vgen/testdata/python_library.baseline | 179 ++++++++++++------ .../python_no_path_templates.baseline | 11 +- 8 files changed, 401 insertions(+), 111 deletions(-) diff --git a/vgen/src/main/resources/io/gapi/vgen/py/main.snip b/vgen/src/main/resources/io/gapi/vgen/py/main.snip index 8c3ca74e09..fe56e9fea9 100644 --- a/vgen/src/main/resources/io/gapi/vgen/py/main.snip +++ b/vgen/src/main/resources/io/gapi/vgen/py/main.snip @@ -48,8 +48,7 @@ @private serviceClass(service) @let path_templates = {@pathTemplateSection(service)}, \ - documentation = {@comments(service)}, \ - page_descriptors = {@pageDescriptorSection(service)} + documentation = {@comments(service)} class {@context.getVeneerName(service)}(object): @if documentation {@documentation} @@ -57,10 +56,6 @@ @end {@constantSection(service)} - @if page_descriptors - {@page_descriptors} - - @end @if path_templates {@path_templates} @@ -90,6 +85,12 @@ ) @end +@private methodConfigDict(service) + @join method : service.getMethods + method: MethodConfig( + @end +@end + @private initMethodSection(service) @let stubModule = pyproto.getPbFileName(service), \ stubService = service.getSimpleName() @@ -127,10 +128,8 @@ through this client :type timeout: int """ - self.defaults = api_callable.ApiCallDefaults( - timeout=timeout, - max_attempts=max_attempts, - is_idempotent_retrying=is_idempotent_retrying) + self._defaults = dict() + {@defaultsSection(service)} self.stub = config.create_stub( {@stubModule}.beta_create_{@stubService}_stub, @@ -142,23 +141,74 @@ @end @end -@private pageDescriptorName(method) - _{@context.upperCamelToUpperUnderscore(method.getSimpleName())}_DESCRIPTOR +@private defaultsSection(service) + @join method : service.getMethods + @let methodConfig = context.getApiConfig.getInterfaceConfig(service).getMethodConfig(method), \ + methodName = context.upperCamelToLowerUnderscore(method.getSimpleName), \ + isPageStreaming = methodConfig.isPageStreaming(), \ + isBundling = methodConfig.isBundling() + self._defaults['{@methodName}'] = CallSettings( + timeout=timeout, + @if context.isIdempotent(method) + is_retrying=is_idempotent_retrying, + @end + max_attempts=max_attempts, + @if isPageStreaming + @let pageStreaming = methodConfig.getPageStreaming(), \ + requestToken = pageStreaming.getRequestTokenField().getSimpleName(), \ + responseToken = pageStreaming.getResponseTokenField().getSimpleName(), \ + resources = pageStreaming.getResourcesField().getSimpleName() + page_descriptor=PageDescriptor( + '{@requestToken}', + '{@responseToken}', + '{@resources}', + ), + @end + @end + @if isBundling + @let bundling = methodConfig.getBundling(), \ + count = bundling.getElementCountThreshold(), \ + bytes = bundling.getRequestByteThreshold(), \ + delay = bundling.getDelayThresholdMillis() + bundler=bundling.Executor(BundleOptions( + @if count + element_count_threshold={@count}, + @end + @if bytes + request_bytesize_threshold={@bytes}, + @end + @if delay + delay_threshold={@delay} + @end + ) + bundle_descriptor=BundleDescriptor( + {@bundleDescriptorBody(bundling, method)} + ), + @end + @end + ) + @end + @end @end -@private pageDescriptorSection(service) - @let interfaceConfig = context.getApiConfig.getInterfaceConfig(service) - @join method : context.messages.filterPageStreamingMethods(interfaceConfig, service.getMethods) - @let pageStreaming = interfaceConfig.getMethodConfig(method).getPageStreaming(), \ - requestToken = pageStreaming.getRequestTokenField().getSimpleName(), \ - responseToken = pageStreaming.getResponseTokenField().getSimpleName(), \ - resources = pageStreaming.getResourcesField().getSimpleName() - {@pageDescriptorName(method)} = PageDescriptor( - '{@requestToken}', - '{@responseToken}', - '{@resources}', - ) - @end +@private bundleDescriptorBody(bundling, method) + @let bundledField = bundling.getBundledField().getSimpleName(), \ + discriminatorFields = bundling.getDiscriminatorFields() + @if {@bundling.hasSubresponseField} + '{@bundledField}', + [ + @join fieldSelector : bundling.getDiscriminatorFields() on {@", "}.add(BREAK) + '{@fieldSelector.getParamName}' + @end + ], + 'subresponse_field={@bundling.getSubresponseField().getSimpleName()}', + @else + '{@bundledField}', + [ + @join fieldSelector : bundling.getDiscriminatorFields() on {@", "}.add(BREAK) + '{@fieldSelector.getParamName}' + @end + ] @end @end @end @@ -227,14 +277,8 @@ @end @private callableConstructor(method) - @if context.isIdempotent(method) - return api_callable.ApiCallable( - self.stub.{@method.getSimpleName()}, options=options, defaults=self.defaults, - is_idempotent=True)(req) - @else - return api_callable.ApiCallable( - self.stub.{@method.getSimpleName()}, options=options, defaults=self.defaults)(req) - @end + return api_callable.ApiCallable( + self.stub.{@method.getSimpleName()}, settings=settings)(req) @end @private flattenedMethod(service, method) @@ -256,15 +300,9 @@ @if {@defaultMutableValues(flattenedParams)} {@defaultMutableValues(flattenedParams)} @end - @if {@isPageStreamingRequest} - standard_options = api_callable.CallOptions( - page_streaming={@pageDescriptorName(method)}) - @else - standard_options = api_callable.CallOptions() - @end - standard_options.update(options) req = {@methodInputModule}.{@inputTypeName}( {@namedParameters(flattenedParams)}) + settings = self._defaults['{@methodName}'].merge(options) {@callableConstructor(method)} @else def {@methodName}( @@ -273,15 +311,8 @@ @if documentation {@documentation} @end - @if {@isPageStreamingRequest} - standard_options = api_callable.CallOptions( - page_streaming={@pageDescriptorName(method)}) - @else - standard_options = api_callable.CallOptions() - @end - standard_options.update(options) - standard_options.normalize() req = {@methodInputModule}.{@inputTypeName}() + settings = self._defaults['{@methodName}'].merge(options) {@callableConstructor(method)} @end @end diff --git a/vgen/src/test/java/io/gapi/vgen/testdata/csharp_extensions_library.baseline b/vgen/src/test/java/io/gapi/vgen/testdata/csharp_extensions_library.baseline index d3a117e993..a00b16a108 100644 --- a/vgen/src/test/java/io/gapi/vgen/testdata/csharp_extensions_library.baseline +++ b/vgen/src/test/java/io/gapi/vgen/testdata/csharp_extensions_library.baseline @@ -392,6 +392,57 @@ namespace Google.Example.Library.V1 return @this.CreateBookAsync(request, cancellationToken: cancellationToken).ResponseAsync; } + /// + /// Creates a series of books. + /// + /// + /// The shelf in which the series is created. + /// + /// + /// The books to publish in the series. + /// + /// + /// The edition of the series + /// + public static PublishSeriesResponse PublishSeries(this LibraryService.ILibraryServiceClient @this, Shelf shelf, IEnumerable books, uint edition) + { + PublishSeriesRequest request = new PublishSeriesRequest + { + Shelf = shelf, + Books = { books }, + Edition = edition, + }; + + return @this.PublishSeries(request); + } + /// + /// Creates a series of books. + /// + /// + /// The shelf in which the series is created. + /// + /// + /// The books to publish in the series. + /// + /// + /// The edition of the series + /// + /// + /// The cancellation token for the asynchronous operation. This defaults to the default + /// cancellation token, equivalent to . + /// + public static Task PublishSeriesAsync(this LibraryService.ILibraryServiceClient @this, Shelf shelf, IEnumerable books, uint edition, CancellationToken cancellationToken = default(CancellationToken)) + { + PublishSeriesRequest request = new PublishSeriesRequest + { + Shelf = shelf, + Books = { books }, + Edition = edition, + }; + + return @this.PublishSeriesAsync(request, cancellationToken: cancellationToken).ResponseAsync; + } + /// /// Gets a book. /// diff --git a/vgen/src/test/java/io/gapi/vgen/testdata/go_library.baseline b/vgen/src/test/java/io/gapi/vgen/testdata/go_library.baseline index 56b657a3ac..717cbef9bc 100644 --- a/vgen/src/test/java/io/gapi/vgen/testdata/go_library.baseline +++ b/vgen/src/test/java/io/gapi/vgen/testdata/go_library.baseline @@ -324,6 +324,44 @@ func (api *LibraryServiceApi) createBook(ctx context.Context, req interface{}) ( // AUTO-GENERATED DOCUMENTATION AND METHOD -- see instructions at the top of the file for editing. +// Creates a series of books. +// +// +func (api *LibraryServiceApi) PublishSeries(ctx context.Context, req *google_example_library_v1.PublishSeriesRequest, opts ...gax.CallOption) (*google_example_library_v1.PublishSeriesResponse, error) { + opts = append(api.CallOptions, opts...) + resp, err := gax.Invoke(ctx, req, api.publishSeries, opts...) + if err != nil { + return nil, err + } + return resp.(*google_example_library_v1.PublishSeriesResponse), nil +} + +// AUTO-GENERATED DOCUMENTATION AND METHOD -- see instructions at the top of the file for editing. + +// Creates a series of books. +// +// shelf: The shelf in which the series is created. +// +// books: The books to publish in the series. +// +// edition: The edition of the series +// +// +// +func (api *LibraryServiceApi) PublishSeriesWith(ctx context.Context, shelf *google_example_library_v1.Shelf, books []*google_example_library_v1.Book, edition uint32, opts ...gax.CallOption) (*google_example_library_v1.PublishSeriesResponse, error) { + return api.PublishSeries(ctx, &google_example_library_v1.PublishSeriesRequest{ + Shelf: shelf, + Books: books, + Edition: edition, + }, opts...) +} + +func (api *LibraryServiceApi) publishSeries(ctx context.Context, req interface{}) (interface{}, error) { + return api.client.PublishSeries(ctx, req.(*google_example_library_v1.PublishSeriesRequest)) +} + +// AUTO-GENERATED DOCUMENTATION AND METHOD -- see instructions at the top of the file for editing. + // Gets a book. // // diff --git a/vgen/src/test/java/io/gapi/vgen/testdata/java_library.baseline b/vgen/src/test/java/io/gapi/vgen/testdata/java_library.baseline index 2ae44e0069..937249c199 100644 --- a/vgen/src/test/java/io/gapi/vgen/testdata/java_library.baseline +++ b/vgen/src/test/java/io/gapi/vgen/testdata/java_library.baseline @@ -58,6 +58,8 @@ import com.google.example.library.v1.ListShelvesRequest; import com.google.example.library.v1.ListShelvesResponse; import com.google.example.library.v1.MergeShelvesRequest; import com.google.example.library.v1.MoveBookRequest; +import com.google.example.library.v1.PublishSeriesRequest; +import com.google.example.library.v1.PublishSeriesResponse; import com.google.example.library.v1.Shelf; import com.google.example.library.v1.SomeMessage; import com.google.example.library.v1.UpdateBookRequest; @@ -68,6 +70,7 @@ import io.grpc.Status; import java.io.IOException; import java.util.EnumMap; import java.util.HashMap; +import java.util.List; import java.util.Map; // Manually-added imports: add custom (non-generated) imports after this point. @@ -95,7 +98,7 @@ import java.util.Map; public class LibraryServiceApi implements AutoCloseable { public enum MethodIdentifier { - CREATE_SHELF, GET_SHELF, LIST_SHELVES, DELETE_SHELF, MERGE_SHELVES, CREATE_BOOK, GET_BOOK, LIST_BOOKS, DELETE_BOOK, UPDATE_BOOK, MOVE_BOOK + CREATE_SHELF, GET_SHELF, LIST_SHELVES, DELETE_SHELF, MERGE_SHELVES, CREATE_BOOK, PUBLISH_SERIES, GET_BOOK, LIST_BOOKS, DELETE_BOOK, UPDATE_BOOK, MOVE_BOOK } // ========= @@ -136,6 +139,7 @@ public class LibraryServiceApi implements AutoCloseable { retryableCodes.put(MethodIdentifier.DELETE_SHELF, definition.get("idempotent")); retryableCodes.put(MethodIdentifier.MERGE_SHELVES, definition.get("non_idempotent")); retryableCodes.put(MethodIdentifier.CREATE_BOOK, definition.get("non_idempotent")); + retryableCodes.put(MethodIdentifier.PUBLISH_SERIES, definition.get("non_idempotent")); retryableCodes.put(MethodIdentifier.GET_BOOK, definition.get("idempotent")); retryableCodes.put(MethodIdentifier.LIST_BOOKS, definition.get("idempotent")); retryableCodes.put(MethodIdentifier.DELETE_BOOK, definition.get("idempotent")); @@ -173,6 +177,7 @@ public class LibraryServiceApi implements AutoCloseable { retryParams.put(MethodIdentifier.DELETE_SHELF, definition.get("default")); retryParams.put(MethodIdentifier.MERGE_SHELVES, definition.get("default")); retryParams.put(MethodIdentifier.CREATE_BOOK, definition.get("default")); + retryParams.put(MethodIdentifier.PUBLISH_SERIES, definition.get("default")); retryParams.put(MethodIdentifier.GET_BOOK, definition.get("default")); retryParams.put(MethodIdentifier.LIST_BOOKS, definition.get("default")); retryParams.put(MethodIdentifier.DELETE_BOOK, definition.get("default")); @@ -193,6 +198,8 @@ public class LibraryServiceApi implements AutoCloseable { MERGE_SHELVES = ApiCallable.create(LibraryServiceGrpc.METHOD_MERGE_SHELVES); private static final ApiCallable CREATE_BOOK = ApiCallable.create(LibraryServiceGrpc.METHOD_CREATE_BOOK); + private static final ApiCallable + PUBLISH_SERIES = ApiCallable.create(LibraryServiceGrpc.METHOD_PUBLISH_SERIES); private static final ApiCallable GET_BOOK = ApiCallable.create(LibraryServiceGrpc.METHOD_GET_BOOK); private static final ApiCallable @@ -770,6 +777,61 @@ public class LibraryServiceApi implements AutoCloseable { .bind(channel); } + // ----- publishSeries ----- + + // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. + /** + * Creates a series of books. + * + * + * + * + * @param shelf The shelf in which the series is created. + * @param books The books to publish in the series. + * @param edition The edition of the series + */ + public PublishSeriesResponse publishSeries(Shelf shelf, List books, int edition) { + PublishSeriesRequest request = + PublishSeriesRequest.newBuilder() + .setShelf(shelf) + .addAllBooks(books) + .setEdition(edition) + .build(); + + return publishSeries(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. + /** + * Creates a series of books. + * + * + * + * + * @param request The request object containing all of the parameters for the API call. + */ + public PublishSeriesResponse publishSeries(PublishSeriesRequest request) { + return publishSeriesCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. + /** + * Creates a series of books. + * + * + * + */ + public ApiCallable publishSeriesCallable() { + ImmutableSet retryableCodes = + retryCodesConfig.get(MethodIdentifier.PUBLISH_SERIES); + RetryParams retryParams = + retryParamsConfig.get(MethodIdentifier.PUBLISH_SERIES); + return PUBLISH_SERIES + .retryableOn(retryableCodes) + .retrying(retryParams, settings.getExecutor()) + .bind(channel); + } + // ----- getBook ----- // AUTO-GENERATED DOCUMENTATION AND METHOD - see instructions at the top of the file for editing. diff --git a/vgen/src/test/java/io/gapi/vgen/testdata/library.proto b/vgen/src/test/java/io/gapi/vgen/testdata/library.proto index a5e1d3ed6e..5ac5ffbe05 100644 --- a/vgen/src/test/java/io/gapi/vgen/testdata/library.proto +++ b/vgen/src/test/java/io/gapi/vgen/testdata/library.proto @@ -66,6 +66,11 @@ service LibraryService { option (google.api.http) = { post: "/v1/{name=shelves/*}/books" body: "book" }; } + // Creates a series of books. + rpc PublishSeries(PublishSeriesRequest) returns (PublishSeriesResponse) { + option (google.api.http) = { post: "/v1:publish" body: "*" }; + } + // Gets a book. rpc GetBook(GetBookRequest) returns (Book) { option (google.api.http) = { get: "/v1/{name=shelves/*/books/*}" }; @@ -230,6 +235,24 @@ message CreateBookRequest { Book book = 2; } +// Request message for LibraryService.PublishSeries. +message PublishSeriesRequest { + // The shelf in which the series is created. + Shelf shelf = 1; + + // The books to publish in the series. + repeated Book books = 2; + + // The edition of the series + uint32 edition = 3; +} + +// Response message for LibraryService.PublishSeries. +message PublishSeriesResponse { + // The names of the books in the series that were published + repeated string book_names = 1; +} + // Request message for LibraryService.GetBook. message GetBookRequest { // The name of the book to retrieve. diff --git a/vgen/src/test/java/io/gapi/vgen/testdata/library_veneer.yaml b/vgen/src/test/java/io/gapi/vgen/testdata/library_veneer.yaml index 48e25d32f8..91f13919f9 100644 --- a/vgen/src/test/java/io/gapi/vgen/testdata/library_veneer.yaml +++ b/vgen/src/test/java/io/gapi/vgen/testdata/library_veneer.yaml @@ -79,6 +79,25 @@ interfaces: - book retry_codes_name: non_idempotent retry_params_name: default + - name: PublishSeries + flattening: + groups: + - parameters: + - shelf + - books + - edition + retry_codes_name: non_idempotent + retry_params_name: default + bundling: + thresholds: + element_count_threshold: 6 + delay_threshold_millis: 500 + bundle_descriptor: + bundled_field: books + discriminator_fields: + - edition + - shelf.name + subresponse_field: book_names - name: GetBook flattening: groups: diff --git a/vgen/src/test/java/io/gapi/vgen/testdata/python_library.baseline b/vgen/src/test/java/io/gapi/vgen/testdata/python_library.baseline index 1d0e925106..2b2c27dfba 100644 --- a/vgen/src/test/java/io/gapi/vgen/testdata/python_library.baseline +++ b/vgen/src/test/java/io/gapi/vgen/testdata/python_library.baseline @@ -58,17 +58,6 @@ class LibraryServiceApi(object): 'https://www.googleapis.com/auth/cloud-platform', ) - _LIST_SHELVES_DESCRIPTOR = PageDescriptor( - 'page_token', - 'next_page_token', - 'shelves', - ) - _LIST_BOOKS_DESCRIPTOR = PageDescriptor( - 'page_token', - 'next_page_token', - 'books', - ) - _SHELF_PATH_TEMPLATE = PathTemplate( 'shelves/{shelf}') _BOOK_PATH_TEMPLATE = PathTemplate( @@ -123,10 +112,83 @@ class LibraryServiceApi(object): through this client :type timeout: int """ - self.defaults = api_callable.ApiCallDefaults( + self._defaults = dict() + self._defaults['create_shelf'] = CallSettings( + timeout=timeout, + max_attempts=max_attempts, + ) + self._defaults['get_shelf'] = CallSettings( + timeout=timeout, + is_retrying=is_idempotent_retrying, + max_attempts=max_attempts, + ) + self._defaults['list_shelves'] = CallSettings( + timeout=timeout, + is_retrying=is_idempotent_retrying, + max_attempts=max_attempts, + page_descriptor=PageDescriptor( + 'page_token', + 'next_page_token', + 'shelves', + ), + ) + self._defaults['delete_shelf'] = CallSettings( + timeout=timeout, + is_retrying=is_idempotent_retrying, + max_attempts=max_attempts, + ) + self._defaults['merge_shelves'] = CallSettings( + timeout=timeout, + max_attempts=max_attempts, + ) + self._defaults['create_book'] = CallSettings( + timeout=timeout, + max_attempts=max_attempts, + ) + self._defaults['publish_series'] = CallSettings( + timeout=timeout, + max_attempts=max_attempts, + bundler=bundling.Executor(BundleOptions( + element_count_threshold=6, + delay_threshold=500 + ) + bundle_descriptor=BundleDescriptor( + 'books', + [ + 'edition', + 'shelf.name' + ] + ), + ) + self._defaults['get_book'] = CallSettings( + timeout=timeout, + is_retrying=is_idempotent_retrying, + max_attempts=max_attempts, + ) + self._defaults['list_books'] = CallSettings( timeout=timeout, + is_retrying=is_idempotent_retrying, max_attempts=max_attempts, - is_idempotent_retrying=is_idempotent_retrying) + page_descriptor=PageDescriptor( + 'page_token', + 'next_page_token', + 'books', + ), + ) + self._defaults['delete_book'] = CallSettings( + timeout=timeout, + is_retrying=is_idempotent_retrying, + max_attempts=max_attempts, + ) + self._defaults['update_book'] = CallSettings( + timeout=timeout, + is_retrying=is_idempotent_retrying, + max_attempts=max_attempts, + ) + self._defaults['move_book'] = CallSettings( + timeout=timeout, + max_attempts=max_attempts, + ) self.stub = config.create_stub( library_pb2.beta_create_LibraryService_stub, @@ -158,12 +220,11 @@ class LibraryServiceApi(object): """ if shelf is None: shelf = library_pb2.Shelf() - standard_options = api_callable.CallOptions() - standard_options.update(options) req = library_pb2.CreateShelfRequest( shelf=shelf) + settings = self._defaults['create_shelf'].merge(options) return api_callable.ApiCallable( - self.stub.CreateShelf, options=options, defaults=self.defaults)(req) + self.stub.CreateShelf, settings=settings)(req) def get_shelf( self, @@ -183,15 +244,13 @@ class LibraryServiceApi(object): message = library_pb2.SomeMessage() if string_builder is None: string_builder = library_pb2.StringBuilder() - standard_options = api_callable.CallOptions() - standard_options.update(options) req = library_pb2.GetShelfRequest( name=name, message=message, string_builder=string_builder) + settings = self._defaults['get_shelf'].merge(options) return api_callable.ApiCallable( - self.stub.GetShelf, options=options, defaults=self.defaults, - is_idempotent=True)(req) + self.stub.GetShelf, settings=settings)(req) def list_shelves( self, @@ -201,14 +260,10 @@ class LibraryServiceApi(object): :type options: api_callable.CallOptions """ - standard_options = api_callable.CallOptions( - page_streaming=_LIST_SHELVES_DESCRIPTOR) - standard_options.update(options) - standard_options.normalize() req = library_pb2.ListShelvesRequest() + settings = self._defaults['list_shelves'].merge(options) return api_callable.ApiCallable( - self.stub.ListShelves, options=options, defaults=self.defaults, - is_idempotent=True)(req) + self.stub.ListShelves, settings=settings)(req) def delete_shelf( self, @@ -220,13 +275,11 @@ class LibraryServiceApi(object): :type name: string :type options: api_callable.CallOptions """ - standard_options = api_callable.CallOptions() - standard_options.update(options) req = library_pb2.DeleteShelfRequest( name=name) + settings = self._defaults['delete_shelf'].merge(options) return api_callable.ApiCallable( - self.stub.DeleteShelf, options=options, defaults=self.defaults, - is_idempotent=True)(req) + self.stub.DeleteShelf, settings=settings)(req) def merge_shelves( self, @@ -242,13 +295,12 @@ class LibraryServiceApi(object): :type other_shelf_name: string :type options: api_callable.CallOptions """ - standard_options = api_callable.CallOptions() - standard_options.update(options) req = library_pb2.MergeShelvesRequest( name=name, other_shelf_name=other_shelf_name) + settings = self._defaults['merge_shelves'].merge(options) return api_callable.ApiCallable( - self.stub.MergeShelves, options=options, defaults=self.defaults)(req) + self.stub.MergeShelves, settings=settings)(req) def create_book( self, @@ -264,13 +316,38 @@ class LibraryServiceApi(object): """ if book is None: book = library_pb2.Book() - standard_options = api_callable.CallOptions() - standard_options.update(options) req = library_pb2.CreateBookRequest( name=name, book=book) + settings = self._defaults['create_book'].merge(options) + return api_callable.ApiCallable( + self.stub.CreateBook, settings=settings)(req) + + def publish_series( + self, + shelf=None, + books=None, + edition=0, + options=None): + """ + Creates a series of books. + + :type shelf: library_pb2.Shelf + :type books: list of library_pb2.Book + :type edition: uint32 + :type options: api_callable.CallOptions + """ + if shelf is None: + shelf = library_pb2.Shelf() + if books is None: + books = [] + req = library_pb2.PublishSeriesRequest( + shelf=shelf, + books=books, + edition=edition) + settings = self._defaults['publish_series'].merge(options) return api_callable.ApiCallable( - self.stub.CreateBook, options=options, defaults=self.defaults)(req) + self.stub.PublishSeries, settings=settings)(req) def get_book( self, @@ -282,13 +359,11 @@ class LibraryServiceApi(object): :type name: string :type options: api_callable.CallOptions """ - standard_options = api_callable.CallOptions() - standard_options.update(options) req = library_pb2.GetBookRequest( name=name) + settings = self._defaults['get_book'].merge(options) return api_callable.ApiCallable( - self.stub.GetBook, options=options, defaults=self.defaults, - is_idempotent=True)(req) + self.stub.GetBook, settings=settings)(req) def list_books( self, @@ -302,15 +377,12 @@ class LibraryServiceApi(object): :type filter: string :type options: api_callable.CallOptions """ - standard_options = api_callable.CallOptions( - page_streaming=_LIST_BOOKS_DESCRIPTOR) - standard_options.update(options) req = library_pb2.ListBooksRequest( name=name, filter=filter_) + settings = self._defaults['list_books'].merge(options) return api_callable.ApiCallable( - self.stub.ListBooks, options=options, defaults=self.defaults, - is_idempotent=True)(req) + self.stub.ListBooks, settings=settings)(req) def delete_book( self, @@ -322,13 +394,11 @@ class LibraryServiceApi(object): :type name: string :type options: api_callable.CallOptions """ - standard_options = api_callable.CallOptions() - standard_options.update(options) req = library_pb2.DeleteBookRequest( name=name) + settings = self._defaults['delete_book'].merge(options) return api_callable.ApiCallable( - self.stub.DeleteBook, options=options, defaults=self.defaults, - is_idempotent=True)(req) + self.stub.DeleteBook, settings=settings)(req) def update_book( self, @@ -352,16 +422,14 @@ class LibraryServiceApi(object): update_mask = protobuf_field_mask_pb2.FieldMask() if physical_mask is None: physical_mask = v1_field_mask_pb2.FieldMask() - standard_options = api_callable.CallOptions() - standard_options.update(options) req = library_pb2.UpdateBookRequest( name=name, book=book, update_mask=update_mask, physical_mask=physical_mask) + settings = self._defaults['update_book'].merge(options) return api_callable.ApiCallable( - self.stub.UpdateBook, options=options, defaults=self.defaults, - is_idempotent=True)(req) + self.stub.UpdateBook, settings=settings)(req) def move_book( self, @@ -375,11 +443,10 @@ class LibraryServiceApi(object): :type other_shelf_name: string :type options: api_callable.CallOptions """ - standard_options = api_callable.CallOptions() - standard_options.update(options) req = library_pb2.MoveBookRequest( name=name, other_shelf_name=other_shelf_name) + settings = self._defaults['move_book'].merge(options) return api_callable.ApiCallable( - self.stub.MoveBook, options=options, defaults=self.defaults)(req) + self.stub.MoveBook, settings=settings)(req) diff --git a/vgen/src/test/java/io/gapi/vgen/testdata/python_no_path_templates.baseline b/vgen/src/test/java/io/gapi/vgen/testdata/python_no_path_templates.baseline index 0229144e72..9853c006f8 100644 --- a/vgen/src/test/java/io/gapi/vgen/testdata/python_no_path_templates.baseline +++ b/vgen/src/test/java/io/gapi/vgen/testdata/python_no_path_templates.baseline @@ -74,10 +74,11 @@ class NoTemplatesServiceApi(object): through this client :type timeout: int """ - self.defaults = api_callable.ApiCallDefaults( + self._defaults = dict() + self._defaults['increment'] = CallSettings( timeout=timeout, max_attempts=max_attempts, - is_idempotent_retrying=is_idempotent_retrying) + ) self.stub = config.create_stub( no_path_templates_pb2.beta_create_NoTemplatesService_stub, @@ -101,10 +102,8 @@ class NoTemplatesServiceApi(object): self, options=None): """:type options: api_callable.CallOptions""" - standard_options = api_callable.CallOptions() - standard_options.update(options) - standard_options.normalize() req = no_path_templates_pb2.IncrementRequest() + settings = self._defaults['increment'].merge(options) return api_callable.ApiCallable( - self.stub.Increment, options=options, defaults=self.defaults)(req) + self.stub.Increment, settings=settings)(req)