From 338d9c38b9c7f1b5e75493a2e3437c50785c561c Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 2 Aug 2022 07:39:02 -0700 Subject: [PATCH] chore(all): auto-regenerate gapics (#6458) This is an auto-generated regeneration of the gapic clients by cloud.google.com/go/internal/gapicgen. Once the corresponding genproto PR is submitted, genbot will update this PR with a newer dependency to the newer version of genproto and assign reviewers to this PR. If you have been assigned to review this PR, please: - Ensure that the version of genproto in go.mod has been updated. - Ensure that CI is passing. If it's failing, it requires your manual attention. - Approve and submit this PR if you believe it's ready to ship. Corresponding genproto PR: https://github.com/googleapis/go-genproto/pull/870 Changes: docs(container): BinaryAuthorization.enabled field is marked as deprecated PiperOrigin-RevId: 464729666 Source-Link: https://github.com/googleapis/googleapis/commit/c77c0672449e87c8fd65e31c62c72cc87f3e131c feat(retail): new model service to manage recommendation models feat: support case insensitive match on search facets feat: allow disabling spell check in search requests feat: allow adding labels in search requests feat: allow returning min/max values on search numeric facets feat: allow using serving configs as an alias of placements feat: allow enabling recommendation filtering on custom attributes feat: return output BigQuery table on product / event export response feat: allow skiping default branch protection when doing product full import docs: keep the API doc up-to-date with recent changes PiperOrigin-RevId: 464664497 Source-Link: https://github.com/googleapis/googleapis/commit/c30c9ccfd90bebbe16375d19a666e2651e81931f chore(compute): add py_test target for compute (#728) Source-Link: https://github.com/googleapis/googleapis/commit/d7f756815b4435272ba36ca10e739bf448e54b66 fix(datacatalog): fix datacatalog resource name config PiperOrigin-RevId: 464572702 Source-Link: https://github.com/googleapis/googleapis/commit/9f82a84ccb226617cf2195574776d83708c4998e chore(bigquery/connection): deprecate the AwsCrossAccountRole property feat: add Azure Properties to Connection Azure properties are used by BigQuery Omni in Azure regions. PiperOrigin-RevId: 464570667 Source-Link: https://github.com/googleapis/googleapis/commit/75905af5ab6cd89c354dcfb9d9ca0bfdd4d581b4 feat(retail): support case insensitive match on search facets feat: allow to return min/max values on search numeric facets feat: allow to use serving configs as an alias of placements docs: keep the API doc up-to-date with recent changes PiperOrigin-RevId: 464560246 Source-Link: https://github.com/googleapis/googleapis/commit/139f56eefb531a0d47bd52720160103a2b9e7fe5 --- bigquery/go.mod | 2 +- bigquery/go.sum | 4 +- compute/go.mod | 10 +- compute/go.sum | 20 +- container/go.mod | 4 +- container/go.sum | 8 +- go.mod | 2 +- go.sum | 4 +- internal/generated/snippets/go.mod | 2 +- internal/generated/snippets/go.sum | 3 +- internal/godocfx/go.mod | 2 +- internal/godocfx/go.sum | 4 +- retail/apiv2/catalog_client.go | 140 +++ retail/apiv2/catalog_client_example_test.go | 47 + retail/apiv2/completion_client.go | 94 ++ .../apiv2/completion_client_example_test.go | 48 + retail/apiv2/gapic_metadata.json | 60 ++ retail/apiv2/prediction_client.go | 97 +- .../apiv2/prediction_client_example_test.go | 48 + retail/apiv2/product_client.go | 147 ++- retail/apiv2/product_client_example_test.go | 47 + retail/apiv2/search_client.go | 95 +- retail/apiv2/search_client_example_test.go | 47 + retail/apiv2/user_event_client.go | 94 ++ .../apiv2/user_event_client_example_test.go | 48 + retail/apiv2alpha/catalog_client.go | 140 +++ .../apiv2alpha/catalog_client_example_test.go | 47 + retail/apiv2alpha/completion_client.go | 94 ++ .../completion_client_example_test.go | 48 + retail/apiv2alpha/control_client.go | 105 ++- .../apiv2alpha/control_client_example_test.go | 47 + retail/apiv2alpha/gapic_metadata.json | 134 +++ retail/apiv2alpha/model_client.go | 835 ++++++++++++++++++ .../apiv2alpha/model_client_example_test.go | 238 +++++ retail/apiv2alpha/prediction_client.go | 97 +- .../prediction_client_example_test.go | 48 + retail/apiv2alpha/product_client.go | 146 ++- .../apiv2alpha/product_client_example_test.go | 47 + retail/apiv2alpha/search_client.go | 95 +- .../apiv2alpha/search_client_example_test.go | 47 + retail/apiv2alpha/serving_config_client.go | 95 ++ .../serving_config_client_example_test.go | 47 + retail/apiv2alpha/user_event_client.go | 94 ++ .../user_event_client_example_test.go | 48 + retail/go.mod | 2 +- retail/go.sum | 4 +- 46 files changed, 3446 insertions(+), 89 deletions(-) create mode 100644 retail/apiv2alpha/model_client.go create mode 100644 retail/apiv2alpha/model_client_example_test.go diff --git a/bigquery/go.mod b/bigquery/go.mod index fb1355e86b7..c6a8436dc38 100644 --- a/bigquery/go.mod +++ b/bigquery/go.mod @@ -14,7 +14,7 @@ require ( golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f google.golang.org/api v0.90.0 - google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f + google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.0 ) diff --git a/bigquery/go.sum b/bigquery/go.sum index 44a1d5731eb..d4856744403 100644 --- a/bigquery/go.sum +++ b/bigquery/go.sum @@ -604,8 +604,8 @@ google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac/go.mod h1:KEWEmljW google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= -google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f h1:XVHpVMvPs4MtH3h6cThzKs2snNexcfd35vQx2T3IuIY= -google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= +google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 h1:QntLWYqZeuBtJkth3m/6DLznnI0AHJr+AgJXvVh/izw= +google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/compute/go.mod b/compute/go.mod index 27303e64c90..ac0a78128ed 100644 --- a/compute/go.mod +++ b/compute/go.mod @@ -6,8 +6,8 @@ require ( cloud.google.com/go v0.102.1 github.com/google/go-cmp v0.5.8 github.com/googleapis/gax-go/v2 v2.4.0 - google.golang.org/api v0.85.0 - google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad + google.golang.org/api v0.90.0 + google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.0 ) @@ -17,9 +17,9 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect go.opencensus.io v0.23.0 // indirect - golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 // indirect - golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb // indirect - golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect + golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect + golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect + golang.org/x/sys v0.0.0-20220624220833-87e55d714810 // indirect golang.org/x/text v0.3.7 // indirect google.golang.org/appengine v1.6.7 // indirect ) diff --git a/compute/go.sum b/compute/go.sum index 1ad63a9364f..89d2eca151f 100644 --- a/compute/go.sum +++ b/compute/go.sum @@ -161,6 +161,7 @@ github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.0.0-20220520183353-fd19c99a87aa/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8= github.com/googleapis/enterprise-certificate-proxy v0.1.0 h1:zO8WHNx/MYiAKJ3d5spxZXZE6KHmIQGQcAzwUzV7qQw= github.com/googleapis/enterprise-certificate-proxy v0.1.0/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8= @@ -289,8 +290,8 @@ golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 h1:Yqz/iviulwKwAREEeUd3nbBFn0XuyJqkoft2IlrvOhc= -golang.org/x/net v0.0.0-20220617184016-355a448f1bc9/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e h1:TsQ7F31D3bUCLeqPT0u+yjp1guoArKaNKmCr22PYgTQ= +golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -310,8 +311,9 @@ golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= -golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb h1:8tDJ3aechhddbdPAxpycgXHJRMLpk/Ab+aa4OgdN5/g= golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb/go.mod h1:jaDAt6Dkxork7LmZnYtzbRWj0W47D86a3TGe0YHBvmE= +golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 h1:+jnHzr9VPj32ykQVai5DNahi9+NSp7yYuCsl5eAQtL0= +golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2/go.mod h1:jaDAt6Dkxork7LmZnYtzbRWj0W47D86a3TGe0YHBvmE= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -382,8 +384,8 @@ golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c h1:aFV+BgZ4svzjfabn8ERpuB4JI4N6/rdy1iusx77G3oU= -golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220624220833-87e55d714810 h1:rHZQSjJdAI4Xf5Qzeh2bBc5YJIkPFVM6oDtMFYmgws0= +golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -496,8 +498,8 @@ google.golang.org/api v0.75.0/go.mod h1:pU9QmyHLnzlpar1Mjt4IbapUCy8J+6HD6GeELN69 google.golang.org/api v0.78.0/go.mod h1:1Sg78yoMLOhlQTeF+ARBoytAcH1NNyyl390YMy6rKmw= google.golang.org/api v0.80.0/go.mod h1:xY3nI94gbvBrE0J6NHXhxOmW97HG7Khjkku6AFB3Hyg= google.golang.org/api v0.84.0/go.mod h1:NTsGnUFJMYROtiquksZHBWtHfeMC7iYthki7Eq3pa8o= -google.golang.org/api v0.85.0 h1:8rJoHuRxx+vCmZtAO/3k1dRLvYNVyTJtZ5oaFZvhgvc= -google.golang.org/api v0.85.0/go.mod h1:AqZf8Ep9uZ2pyTvgL+x0D3Zt0eoT9b5E8fmzfu6FO2g= +google.golang.org/api v0.90.0 h1:WMnUWAvihIClUYFNeFA69VTuR3duKS3IalMGDQcLvq8= +google.golang.org/api v0.90.0/go.mod h1:+Sem1dnrKlrXMR/X0bPnMWyluQe4RsNoYfmNLhOIkzw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -584,8 +586,10 @@ google.golang.org/genproto v0.0.0-20220518221133-4f43b3371335/go.mod h1:RAyBrSAP google.golang.org/genproto v0.0.0-20220523171625-347a074981d8/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= -google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad h1:kqrS+lhvaMHCxul6sKQvKJ8nAAhlVItmZV822hYFH/U= google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= +google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= +google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 h1:QntLWYqZeuBtJkth3m/6DLznnI0AHJr+AgJXvVh/izw= +google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/container/go.mod b/container/go.mod index 588cbdcb7bd..7f0710f6531 100644 --- a/container/go.mod +++ b/container/go.mod @@ -6,8 +6,8 @@ require ( cloud.google.com/go v0.102.1 github.com/golang/protobuf v1.5.2 github.com/googleapis/gax-go/v2 v2.4.0 - google.golang.org/api v0.86.0 - google.golang.org/genproto v0.0.0-20220706132729-d86698d07c53 + google.golang.org/api v0.90.0 + google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.0 ) diff --git a/container/go.sum b/container/go.sum index 27e96c0fcbb..3ea1c90a5cd 100644 --- a/container/go.sum +++ b/container/go.sum @@ -501,8 +501,8 @@ google.golang.org/api v0.75.0/go.mod h1:pU9QmyHLnzlpar1Mjt4IbapUCy8J+6HD6GeELN69 google.golang.org/api v0.78.0/go.mod h1:1Sg78yoMLOhlQTeF+ARBoytAcH1NNyyl390YMy6rKmw= google.golang.org/api v0.80.0/go.mod h1:xY3nI94gbvBrE0J6NHXhxOmW97HG7Khjkku6AFB3Hyg= google.golang.org/api v0.84.0/go.mod h1:NTsGnUFJMYROtiquksZHBWtHfeMC7iYthki7Eq3pa8o= -google.golang.org/api v0.86.0 h1:ZAnyOHQFIuWso1BodVfSaRyffD74T9ERGFa3k1fNk/U= -google.golang.org/api v0.86.0/go.mod h1:+Sem1dnrKlrXMR/X0bPnMWyluQe4RsNoYfmNLhOIkzw= +google.golang.org/api v0.90.0 h1:WMnUWAvihIClUYFNeFA69VTuR3duKS3IalMGDQcLvq8= +google.golang.org/api v0.90.0/go.mod h1:+Sem1dnrKlrXMR/X0bPnMWyluQe4RsNoYfmNLhOIkzw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -591,8 +591,8 @@ google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac/go.mod h1:KEWEmljW google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= -google.golang.org/genproto v0.0.0-20220706132729-d86698d07c53 h1:liFd7OL799HvMNYG5xozhUoWDj944y+zXPDOhu4PyaM= -google.golang.org/genproto v0.0.0-20220706132729-d86698d07c53/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= +google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 h1:QntLWYqZeuBtJkth3m/6DLznnI0AHJr+AgJXvVh/izw= +google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/go.mod b/go.mod index 2b4325af579..862faa2856d 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f google.golang.org/api v0.90.0 - google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f + google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.0 ) diff --git a/go.sum b/go.sum index 44bb27ee0fa..0b6259e62f1 100644 --- a/go.sum +++ b/go.sum @@ -600,8 +600,8 @@ google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac/go.mod h1:KEWEmljW google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= -google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f h1:XVHpVMvPs4MtH3h6cThzKs2snNexcfd35vQx2T3IuIY= -google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= +google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 h1:QntLWYqZeuBtJkth3m/6DLznnI0AHJr+AgJXvVh/izw= +google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/internal/generated/snippets/go.mod b/internal/generated/snippets/go.mod index d5b14f84364..0db3de7126e 100644 --- a/internal/generated/snippets/go.mod +++ b/internal/generated/snippets/go.mod @@ -120,7 +120,7 @@ require ( cloud.google.com/go/workflows v1.1.0 github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect google.golang.org/api v0.90.0 - google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f + google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 ) require ( diff --git a/internal/generated/snippets/go.sum b/internal/generated/snippets/go.sum index ca9048edb46..b181fcca073 100644 --- a/internal/generated/snippets/go.sum +++ b/internal/generated/snippets/go.sum @@ -229,8 +229,9 @@ google.golang.org/genproto v0.0.0-20220718134204-073382fd740c/go.mod h1:GkXuJDJ6 google.golang.org/genproto v0.0.0-20220719170305-83ca9fad585f/go.mod h1:GkXuJDJ6aQ7lnJcRF+SJVgFdQhypqgl3LB1C9vabdRE= google.golang.org/genproto v0.0.0-20220720214146-176da50484ac/go.mod h1:GkXuJDJ6aQ7lnJcRF+SJVgFdQhypqgl3LB1C9vabdRE= google.golang.org/genproto v0.0.0-20220725144611-272f38e5d71b/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= -google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f h1:XVHpVMvPs4MtH3h6cThzKs2snNexcfd35vQx2T3IuIY= google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= +google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 h1:QntLWYqZeuBtJkth3m/6DLznnI0AHJr+AgJXvVh/izw= +google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= diff --git a/internal/godocfx/go.mod b/internal/godocfx/go.mod index b98c7d83c41..9fbf8887653 100644 --- a/internal/godocfx/go.mod +++ b/internal/godocfx/go.mod @@ -32,7 +32,7 @@ require ( golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect google.golang.org/api v0.90.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f // indirect + google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 // indirect google.golang.org/grpc v1.48.0 // indirect google.golang.org/protobuf v1.28.0 // indirect ) diff --git a/internal/godocfx/go.sum b/internal/godocfx/go.sum index f99f8dda46c..b30ac5750c8 100644 --- a/internal/godocfx/go.sum +++ b/internal/godocfx/go.sum @@ -272,8 +272,8 @@ google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90/go.mod h1:KEWEmljW google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220622131801-db39fadba55f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= -google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f h1:XVHpVMvPs4MtH3h6cThzKs2snNexcfd35vQx2T3IuIY= -google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= +google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 h1:QntLWYqZeuBtJkth3m/6DLznnI0AHJr+AgJXvVh/izw= +google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= diff --git a/retail/apiv2/catalog_client.go b/retail/apiv2/catalog_client.go index fb48f7bcf1c..4cb0173dfed 100644 --- a/retail/apiv2/catalog_client.go +++ b/retail/apiv2/catalog_client.go @@ -29,6 +29,7 @@ import ( "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" @@ -43,6 +44,8 @@ type CatalogCallOptions struct { UpdateCatalog []gax.CallOption SetDefaultBranch []gax.CallOption GetDefaultBranch []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultCatalogGRPCClientOptions() []option.ClientOption { @@ -107,6 +110,19 @@ func defaultCatalogCallOptions() *CatalogCallOptions { }) }), }, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -119,6 +135,8 @@ type internalCatalogClient interface { UpdateCatalog(context.Context, *retailpb.UpdateCatalogRequest, ...gax.CallOption) (*retailpb.Catalog, error) SetDefaultBranch(context.Context, *retailpb.SetDefaultBranchRequest, ...gax.CallOption) error GetDefaultBranch(context.Context, *retailpb.GetDefaultBranchRequest, ...gax.CallOption) (*retailpb.GetDefaultBranchResponse, error) + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // CatalogClient is a client for interacting with Retail API. @@ -212,6 +230,16 @@ func (c *CatalogClient) GetDefaultBranch(ctx context.Context, req *retailpb.GetD return c.internalClient.GetDefaultBranch(ctx, req, opts...) } +// GetOperation is a utility method from google.longrunning.Operations. +func (c *CatalogClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *CatalogClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // catalogGRPCClient is a client for interacting with Retail API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -228,6 +256,8 @@ type catalogGRPCClient struct { // The gRPC API client. catalogClient retailpb.CatalogServiceClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -262,6 +292,7 @@ func NewCatalogClient(ctx context.Context, opts ...option.ClientOption) (*Catalo disableDeadlines: disableDeadlines, catalogClient: retailpb.NewCatalogServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -399,6 +430,68 @@ func (c *catalogGRPCClient) GetDefaultBranch(ctx context.Context, req *retailpb. return resp, nil } +func (c *catalogGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *catalogGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + // CatalogIterator manages a stream of *retailpb.Catalog. type CatalogIterator struct { items []*retailpb.Catalog @@ -445,3 +538,50 @@ func (it *CatalogIterator) takeBuf() interface{} { it.items = nil return b } + +// OperationIterator manages a stream of *longrunningpb.Operation. +type OperationIterator struct { + items []*longrunningpb.Operation + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*longrunningpb.Operation, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *OperationIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *OperationIterator) Next() (*longrunningpb.Operation, error) { + var item *longrunningpb.Operation + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *OperationIterator) bufLen() int { + return len(it.items) +} + +func (it *OperationIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/retail/apiv2/catalog_client_example_test.go b/retail/apiv2/catalog_client_example_test.go index ac36966245d..ee5047820fe 100644 --- a/retail/apiv2/catalog_client_example_test.go +++ b/retail/apiv2/catalog_client_example_test.go @@ -22,6 +22,7 @@ import ( retail "cloud.google.com/go/retail/apiv2" "google.golang.org/api/iterator" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewCatalogClient() { @@ -119,3 +120,49 @@ func ExampleCatalogClient_GetDefaultBranch() { // TODO: Use resp. _ = resp } + +func ExampleCatalogClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewCatalogClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleCatalogClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewCatalogClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/apiv2/completion_client.go b/retail/apiv2/completion_client.go index 4bcf7f15eb8..c0b8ddb8880 100644 --- a/retail/apiv2/completion_client.go +++ b/retail/apiv2/completion_client.go @@ -26,6 +26,7 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" "google.golang.org/api/option" "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" @@ -34,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCompletionClientHook clientHook @@ -42,6 +44,8 @@ var newCompletionClientHook clientHook type CompletionCallOptions struct { CompleteQuery []gax.CallOption ImportCompletionData []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultCompletionGRPCClientOptions() []option.ClientOption { @@ -82,6 +86,19 @@ func defaultCompletionCallOptions() *CompletionCallOptions { }) }), }, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -93,6 +110,8 @@ type internalCompletionClient interface { CompleteQuery(context.Context, *retailpb.CompleteQueryRequest, ...gax.CallOption) (*retailpb.CompleteQueryResponse, error) ImportCompletionData(context.Context, *retailpb.ImportCompletionDataRequest, ...gax.CallOption) (*ImportCompletionDataOperation, error) ImportCompletionDataOperation(name string) *ImportCompletionDataOperation + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // CompletionClient is a client for interacting with Retail API. @@ -164,6 +183,16 @@ func (c *CompletionClient) ImportCompletionDataOperation(name string) *ImportCom return c.internalClient.ImportCompletionDataOperation(name) } +// GetOperation is a utility method from google.longrunning.Operations. +func (c *CompletionClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *CompletionClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // completionGRPCClient is a client for interacting with Retail API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -185,6 +214,8 @@ type completionGRPCClient struct { // Users should not Close this client. LROClient **lroauto.OperationsClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -222,6 +253,7 @@ func NewCompletionClient(ctx context.Context, opts ...option.ClientOption) (*Com disableDeadlines: disableDeadlines, completionClient: retailpb.NewCompletionServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -309,6 +341,68 @@ func (c *completionGRPCClient) ImportCompletionData(ctx context.Context, req *re }, nil } +func (c *completionGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *completionGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + // ImportCompletionDataOperation manages a long-running operation from ImportCompletionData. type ImportCompletionDataOperation struct { lro *longrunning.Operation diff --git a/retail/apiv2/completion_client_example_test.go b/retail/apiv2/completion_client_example_test.go index 4012d498d04..8061e20e05d 100644 --- a/retail/apiv2/completion_client_example_test.go +++ b/retail/apiv2/completion_client_example_test.go @@ -20,7 +20,9 @@ import ( "context" retail "cloud.google.com/go/retail/apiv2" + "google.golang.org/api/iterator" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewCompletionClient() { @@ -79,3 +81,49 @@ func ExampleCompletionClient_ImportCompletionData() { // TODO: Use resp. _ = resp } + +func ExampleCompletionClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewCompletionClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleCompletionClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewCompletionClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/apiv2/gapic_metadata.json b/retail/apiv2/gapic_metadata.json index ab18ecfd24d..3de151a535e 100644 --- a/retail/apiv2/gapic_metadata.json +++ b/retail/apiv2/gapic_metadata.json @@ -15,11 +15,21 @@ "GetDefaultBranch" ] }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, "ListCatalogs": { "methods": [ "ListCatalogs" ] }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "SetDefaultBranch": { "methods": [ "SetDefaultBranch" @@ -44,10 +54,20 @@ "CompleteQuery" ] }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, "ImportCompletionData": { "methods": [ "ImportCompletionData" ] + }, + "ListOperations": { + "methods": [ + "ListOperations" + ] } } } @@ -58,6 +78,16 @@ "grpc": { "libraryClient": "PredictionClient", "rpcs": { + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "Predict": { "methods": [ "Predict" @@ -92,6 +122,11 @@ "DeleteProduct" ] }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, "GetProduct": { "methods": [ "GetProduct" @@ -102,6 +137,11 @@ "ImportProducts" ] }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "ListProducts": { "methods": [ "ListProducts" @@ -136,6 +176,16 @@ "grpc": { "libraryClient": "SearchClient", "rpcs": { + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "Search": { "methods": [ "Search" @@ -155,11 +205,21 @@ "CollectUserEvent" ] }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, "ImportUserEvents": { "methods": [ "ImportUserEvents" ] }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "PurgeUserEvents": { "methods": [ "PurgeUserEvents" diff --git a/retail/apiv2/prediction_client.go b/retail/apiv2/prediction_client.go index b294d74e840..89c118a64d1 100644 --- a/retail/apiv2/prediction_client.go +++ b/retail/apiv2/prediction_client.go @@ -24,20 +24,25 @@ import ( "time" gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" "google.golang.org/api/option" "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newPredictionClientHook clientHook // PredictionCallOptions contains the retry settings for each method of PredictionClient. type PredictionCallOptions struct { - Predict []gax.CallOption + Predict []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultPredictionGRPCClientOptions() []option.ClientOption { @@ -66,6 +71,19 @@ func defaultPredictionCallOptions() *PredictionCallOptions { }) }), }, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -75,6 +93,8 @@ type internalPredictionClient interface { setGoogleClientInfo(...string) Connection() *grpc.ClientConn Predict(context.Context, *retailpb.PredictRequest, ...gax.CallOption) (*retailpb.PredictResponse, error) + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // PredictionClient is a client for interacting with Retail API. @@ -116,6 +136,16 @@ func (c *PredictionClient) Predict(ctx context.Context, req *retailpb.PredictReq return c.internalClient.Predict(ctx, req, opts...) } +// GetOperation is a utility method from google.longrunning.Operations. +func (c *PredictionClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *PredictionClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // predictionGRPCClient is a client for interacting with Retail API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -132,6 +162,8 @@ type predictionGRPCClient struct { // The gRPC API client. predictionClient retailpb.PredictionServiceClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -166,6 +198,7 @@ func NewPredictionClient(ctx context.Context, opts ...option.ClientOption) (*Pre disableDeadlines: disableDeadlines, predictionClient: retailpb.NewPredictionServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -217,3 +250,65 @@ func (c *predictionGRPCClient) Predict(ctx context.Context, req *retailpb.Predic } return resp, nil } + +func (c *predictionGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *predictionGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} diff --git a/retail/apiv2/prediction_client_example_test.go b/retail/apiv2/prediction_client_example_test.go index 07bb0107499..d049e3cb12f 100644 --- a/retail/apiv2/prediction_client_example_test.go +++ b/retail/apiv2/prediction_client_example_test.go @@ -20,7 +20,9 @@ import ( "context" retail "cloud.google.com/go/retail/apiv2" + "google.golang.org/api/iterator" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewPredictionClient() { @@ -54,3 +56,49 @@ func ExamplePredictionClient_Predict() { // TODO: Use resp. _ = resp } + +func ExamplePredictionClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewPredictionClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePredictionClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewPredictionClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/apiv2/product_client.go b/retail/apiv2/product_client.go index d6956503818..ed484d5dc3e 100644 --- a/retail/apiv2/product_client.go +++ b/retail/apiv2/product_client.go @@ -53,6 +53,8 @@ type ProductCallOptions struct { RemoveFulfillmentPlaces []gax.CallOption AddLocalInventories []gax.CallOption RemoveLocalInventories []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultProductGRPCClientOptions() []option.ClientOption { @@ -201,6 +203,19 @@ func defaultProductCallOptions() *ProductCallOptions { }) }), }, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -226,6 +241,8 @@ type internalProductClient interface { AddLocalInventoriesOperation(name string) *AddLocalInventoriesOperation RemoveLocalInventories(context.Context, *retailpb.RemoveLocalInventoriesRequest, ...gax.CallOption) (*RemoveLocalInventoriesOperation, error) RemoveLocalInventoriesOperation(name string) *RemoveLocalInventoriesOperation + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // ProductClient is a client for interacting with Retail API. @@ -320,18 +337,21 @@ func (c *ProductClient) ImportProductsOperation(name string) *ImportProductsOper // enqueued and processed downstream. As a consequence, when a response is // returned, updates are not immediately manifested in the // Product queried by -// GetProduct or -// ListProducts. +// ProductService.GetProduct +// or +// ProductService.ListProducts. // // When inventory is updated with -// CreateProduct and -// UpdateProduct, the -// specified inventory field value(s) will overwrite any existing value(s) +// ProductService.CreateProduct +// and +// ProductService.UpdateProduct, +// the specified inventory field value(s) will overwrite any existing value(s) // while ignoring the last update time for this field. Furthermore, the last // update time for the specified inventory fields will be overwritten to the // time of the -// CreateProduct or -// UpdateProduct +// ProductService.CreateProduct +// or +// ProductService.UpdateProduct // request. // // If no inventory fields are set in @@ -343,10 +363,10 @@ func (c *ProductClient) ImportProductsOperation(name string) *ImportProductsOper // then any existing inventory information will be preserved. // // Pre-existing inventory information can only be updated with -// SetInventory, +// ProductService.SetInventory, // ProductService.AddFulfillmentPlaces, // and -// RemoveFulfillmentPlaces. +// ProductService.RemoveFulfillmentPlaces. // // This feature is only available for users who have Retail Search enabled. // Please enable Retail Search on Cloud Console before using this feature. @@ -369,8 +389,9 @@ func (c *ProductClient) SetInventoryOperation(name string) *SetInventoryOperatio // enqueued and processed downstream. As a consequence, when a response is // returned, the added place IDs are not immediately manifested in the // Product queried by -// GetProduct or -// ListProducts. +// ProductService.GetProduct +// or +// ProductService.ListProducts. // // This feature is only available for users who have Retail Search enabled. // Please enable Retail Search on Cloud Console before using this feature. @@ -393,8 +414,9 @@ func (c *ProductClient) AddFulfillmentPlacesOperation(name string) *AddFulfillme // enqueued and processed downstream. As a consequence, when a response is // returned, the removed place IDs are not immediately manifested in the // Product queried by -// GetProduct or -// ListProducts. +// ProductService.GetProduct +// or +// ProductService.ListProducts. // // This feature is only available for users who have Retail Search enabled. // Please enable Retail Search on Cloud Console before using this feature. @@ -418,13 +440,15 @@ func (c *ProductClient) RemoveFulfillmentPlacesOperation(name string) *RemoveFul // and processed downstream. As a consequence, when a response is returned, // updates are not immediately manifested in the // Product queried by -// GetProduct or -// ListProducts. +// ProductService.GetProduct +// or +// ProductService.ListProducts. // // Local inventory information can only be modified using this method. -// CreateProduct and -// UpdateProduct has no -// effect on local inventories. +// ProductService.CreateProduct +// and +// ProductService.UpdateProduct +// has no effect on local inventories. // // This feature is only available for users who have Retail Search enabled. // Please enable Retail Search on Cloud Console before using this feature. @@ -446,13 +470,15 @@ func (c *ProductClient) AddLocalInventoriesOperation(name string) *AddLocalInven // enqueued and processed downstream. As a consequence, when a response is // returned, removals are not immediately manifested in the // Product queried by -// GetProduct or -// ListProducts. +// ProductService.GetProduct +// or +// ProductService.ListProducts. // // Local inventory information can only be removed using this method. -// CreateProduct and -// UpdateProduct has no -// effect on local inventories. +// ProductService.CreateProduct +// and +// ProductService.UpdateProduct +// has no effect on local inventories. // // This feature is only available for users who have Retail Search enabled. // Please enable Retail Search on Cloud Console before using this feature. @@ -466,6 +492,16 @@ func (c *ProductClient) RemoveLocalInventoriesOperation(name string) *RemoveLoca return c.internalClient.RemoveLocalInventoriesOperation(name) } +// GetOperation is a utility method from google.longrunning.Operations. +func (c *ProductClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *ProductClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // productGRPCClient is a client for interacting with Retail API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -487,6 +523,8 @@ type productGRPCClient struct { // Users should not Close this client. LROClient **lroauto.OperationsClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -522,6 +560,7 @@ func NewProductClient(ctx context.Context, opts ...option.ClientOption) (*Produc disableDeadlines: disableDeadlines, productClient: retailpb.NewProductServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -836,6 +875,68 @@ func (c *productGRPCClient) RemoveLocalInventories(ctx context.Context, req *ret }, nil } +func (c *productGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *productGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + // AddFulfillmentPlacesOperation manages a long-running operation from AddFulfillmentPlaces. type AddFulfillmentPlacesOperation struct { lro *longrunning.Operation diff --git a/retail/apiv2/product_client_example_test.go b/retail/apiv2/product_client_example_test.go index 4905ec1cc37..30a74c4adb3 100644 --- a/retail/apiv2/product_client_example_test.go +++ b/retail/apiv2/product_client_example_test.go @@ -22,6 +22,7 @@ import ( retail "cloud.google.com/go/retail/apiv2" "google.golang.org/api/iterator" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewProductClient() { @@ -289,3 +290,49 @@ func ExampleProductClient_RemoveLocalInventories() { // TODO: Use resp. _ = resp } + +func ExampleProductClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewProductClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleProductClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewProductClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/apiv2/search_client.go b/retail/apiv2/search_client.go index 3ceda377091..13124c5d2f4 100644 --- a/retail/apiv2/search_client.go +++ b/retail/apiv2/search_client.go @@ -29,6 +29,7 @@ import ( "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" @@ -39,7 +40,9 @@ var newSearchClientHook clientHook // SearchCallOptions contains the retry settings for each method of SearchClient. type SearchCallOptions struct { - Search []gax.CallOption + Search []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultSearchGRPCClientOptions() []option.ClientOption { @@ -68,6 +71,19 @@ func defaultSearchCallOptions() *SearchCallOptions { }) }), }, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -77,6 +93,8 @@ type internalSearchClient interface { setGoogleClientInfo(...string) Connection() *grpc.ClientConn Search(context.Context, *retailpb.SearchRequest, ...gax.CallOption) *SearchResponse_SearchResultIterator + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // SearchClient is a client for interacting with Retail API. @@ -124,6 +142,16 @@ func (c *SearchClient) Search(ctx context.Context, req *retailpb.SearchRequest, return c.internalClient.Search(ctx, req, opts...) } +// GetOperation is a utility method from google.longrunning.Operations. +func (c *SearchClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *SearchClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // searchGRPCClient is a client for interacting with Retail API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -140,6 +168,8 @@ type searchGRPCClient struct { // The gRPC API client. searchClient retailpb.SearchServiceClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -177,6 +207,7 @@ func NewSearchClient(ctx context.Context, opts ...option.ClientOption) (*SearchC disableDeadlines: disableDeadlines, searchClient: retailpb.NewSearchServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -252,6 +283,68 @@ func (c *searchGRPCClient) Search(ctx context.Context, req *retailpb.SearchReque return it } +func (c *searchGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *searchGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + // SearchResponse_SearchResultIterator manages a stream of *retailpb.SearchResponse_SearchResult. type SearchResponse_SearchResultIterator struct { items []*retailpb.SearchResponse_SearchResult diff --git a/retail/apiv2/search_client_example_test.go b/retail/apiv2/search_client_example_test.go index b6405a8cd43..8c7841a35e9 100644 --- a/retail/apiv2/search_client_example_test.go +++ b/retail/apiv2/search_client_example_test.go @@ -22,6 +22,7 @@ import ( retail "cloud.google.com/go/retail/apiv2" "google.golang.org/api/iterator" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewSearchClient() { @@ -61,3 +62,49 @@ func ExampleSearchClient_Search() { _ = resp } } + +func ExampleSearchClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewSearchClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSearchClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewSearchClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/apiv2/user_event_client.go b/retail/apiv2/user_event_client.go index 9811ae9949f..73d2330d05f 100644 --- a/retail/apiv2/user_event_client.go +++ b/retail/apiv2/user_event_client.go @@ -26,6 +26,7 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" "google.golang.org/api/option" "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" @@ -35,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newUserEventClientHook clientHook @@ -46,6 +48,8 @@ type UserEventCallOptions struct { PurgeUserEvents []gax.CallOption ImportUserEvents []gax.CallOption RejoinUserEvents []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultUserEventGRPCClientOptions() []option.ClientOption { @@ -122,6 +126,19 @@ func defaultUserEventCallOptions() *UserEventCallOptions { }) }), }, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -138,6 +155,8 @@ type internalUserEventClient interface { ImportUserEventsOperation(name string) *ImportUserEventsOperation RejoinUserEvents(context.Context, *retailpb.RejoinUserEventsRequest, ...gax.CallOption) (*RejoinUserEventsOperation, error) RejoinUserEventsOperation(name string) *RejoinUserEventsOperation + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // UserEventClient is a client for interacting with Retail API. @@ -242,6 +261,16 @@ func (c *UserEventClient) RejoinUserEventsOperation(name string) *RejoinUserEven return c.internalClient.RejoinUserEventsOperation(name) } +// GetOperation is a utility method from google.longrunning.Operations. +func (c *UserEventClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *UserEventClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // userEventGRPCClient is a client for interacting with Retail API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -263,6 +292,8 @@ type userEventGRPCClient struct { // Users should not Close this client. LROClient **lroauto.OperationsClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -297,6 +328,7 @@ func NewUserEventClient(ctx context.Context, opts ...option.ClientOption) (*User disableDeadlines: disableDeadlines, userEventClient: retailpb.NewUserEventServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -454,6 +486,68 @@ func (c *userEventGRPCClient) RejoinUserEvents(ctx context.Context, req *retailp }, nil } +func (c *userEventGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *userEventGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + // ImportUserEventsOperation manages a long-running operation from ImportUserEvents. type ImportUserEventsOperation struct { lro *longrunning.Operation diff --git a/retail/apiv2/user_event_client_example_test.go b/retail/apiv2/user_event_client_example_test.go index bec13d512bb..c5fd26a008d 100644 --- a/retail/apiv2/user_event_client_example_test.go +++ b/retail/apiv2/user_event_client_example_test.go @@ -20,7 +20,9 @@ import ( "context" retail "cloud.google.com/go/retail/apiv2" + "google.golang.org/api/iterator" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewUserEventClient() { @@ -149,3 +151,49 @@ func ExampleUserEventClient_RejoinUserEvents() { // TODO: Use resp. _ = resp } + +func ExampleUserEventClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewUserEventClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleUserEventClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewUserEventClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/apiv2alpha/catalog_client.go b/retail/apiv2alpha/catalog_client.go index 7c45dfe3a25..50a2767074e 100644 --- a/retail/apiv2alpha/catalog_client.go +++ b/retail/apiv2alpha/catalog_client.go @@ -29,6 +29,7 @@ import ( "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" @@ -50,6 +51,8 @@ type CatalogCallOptions struct { AddCatalogAttribute []gax.CallOption RemoveCatalogAttribute []gax.CallOption ReplaceCatalogAttribute []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultCatalogGRPCClientOptions() []option.ClientOption { @@ -198,6 +201,19 @@ func defaultCatalogCallOptions() *CatalogCallOptions { }) }), }, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -217,6 +233,8 @@ type internalCatalogClient interface { AddCatalogAttribute(context.Context, *retailpb.AddCatalogAttributeRequest, ...gax.CallOption) (*retailpb.AttributesConfig, error) RemoveCatalogAttribute(context.Context, *retailpb.RemoveCatalogAttributeRequest, ...gax.CallOption) (*retailpb.AttributesConfig, error) ReplaceCatalogAttribute(context.Context, *retailpb.ReplaceCatalogAttributeRequest, ...gax.CallOption) (*retailpb.AttributesConfig, error) + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // CatalogClient is a client for interacting with Retail API. @@ -371,6 +389,16 @@ func (c *CatalogClient) ReplaceCatalogAttribute(ctx context.Context, req *retail return c.internalClient.ReplaceCatalogAttribute(ctx, req, opts...) } +// GetOperation is a utility method from google.longrunning.Operations. +func (c *CatalogClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *CatalogClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // catalogGRPCClient is a client for interacting with Retail API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -387,6 +415,8 @@ type catalogGRPCClient struct { // The gRPC API client. catalogClient retailpb.CatalogServiceClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -421,6 +451,7 @@ func NewCatalogClient(ctx context.Context, opts ...option.ClientOption) (*Catalo disableDeadlines: disableDeadlines, catalogClient: retailpb.NewCatalogServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -712,6 +743,68 @@ func (c *catalogGRPCClient) ReplaceCatalogAttribute(ctx context.Context, req *re return resp, nil } +func (c *catalogGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *catalogGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + // CatalogIterator manages a stream of *retailpb.Catalog. type CatalogIterator struct { items []*retailpb.Catalog @@ -758,3 +851,50 @@ func (it *CatalogIterator) takeBuf() interface{} { it.items = nil return b } + +// OperationIterator manages a stream of *longrunningpb.Operation. +type OperationIterator struct { + items []*longrunningpb.Operation + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*longrunningpb.Operation, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *OperationIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *OperationIterator) Next() (*longrunningpb.Operation, error) { + var item *longrunningpb.Operation + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *OperationIterator) bufLen() int { + return len(it.items) +} + +func (it *OperationIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/retail/apiv2alpha/catalog_client_example_test.go b/retail/apiv2alpha/catalog_client_example_test.go index 97fcc677f3a..27dbb173229 100644 --- a/retail/apiv2alpha/catalog_client_example_test.go +++ b/retail/apiv2alpha/catalog_client_example_test.go @@ -22,6 +22,7 @@ import ( retail "cloud.google.com/go/retail/apiv2alpha" "google.golang.org/api/iterator" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewCatalogClient() { @@ -259,3 +260,49 @@ func ExampleCatalogClient_ReplaceCatalogAttribute() { // TODO: Use resp. _ = resp } + +func ExampleCatalogClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewCatalogClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleCatalogClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewCatalogClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/apiv2alpha/completion_client.go b/retail/apiv2alpha/completion_client.go index 65e470e4317..87383cf9c13 100644 --- a/retail/apiv2alpha/completion_client.go +++ b/retail/apiv2alpha/completion_client.go @@ -26,6 +26,7 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" "google.golang.org/api/option" "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" @@ -34,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCompletionClientHook clientHook @@ -42,6 +44,8 @@ var newCompletionClientHook clientHook type CompletionCallOptions struct { CompleteQuery []gax.CallOption ImportCompletionData []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultCompletionGRPCClientOptions() []option.ClientOption { @@ -82,6 +86,19 @@ func defaultCompletionCallOptions() *CompletionCallOptions { }) }), }, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -93,6 +110,8 @@ type internalCompletionClient interface { CompleteQuery(context.Context, *retailpb.CompleteQueryRequest, ...gax.CallOption) (*retailpb.CompleteQueryResponse, error) ImportCompletionData(context.Context, *retailpb.ImportCompletionDataRequest, ...gax.CallOption) (*ImportCompletionDataOperation, error) ImportCompletionDataOperation(name string) *ImportCompletionDataOperation + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // CompletionClient is a client for interacting with Retail API. @@ -164,6 +183,16 @@ func (c *CompletionClient) ImportCompletionDataOperation(name string) *ImportCom return c.internalClient.ImportCompletionDataOperation(name) } +// GetOperation is a utility method from google.longrunning.Operations. +func (c *CompletionClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *CompletionClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // completionGRPCClient is a client for interacting with Retail API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -185,6 +214,8 @@ type completionGRPCClient struct { // Users should not Close this client. LROClient **lroauto.OperationsClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -222,6 +253,7 @@ func NewCompletionClient(ctx context.Context, opts ...option.ClientOption) (*Com disableDeadlines: disableDeadlines, completionClient: retailpb.NewCompletionServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -309,6 +341,68 @@ func (c *completionGRPCClient) ImportCompletionData(ctx context.Context, req *re }, nil } +func (c *completionGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *completionGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + // ImportCompletionDataOperation manages a long-running operation from ImportCompletionData. type ImportCompletionDataOperation struct { lro *longrunning.Operation diff --git a/retail/apiv2alpha/completion_client_example_test.go b/retail/apiv2alpha/completion_client_example_test.go index 5f8b6eb3f5f..26905524267 100644 --- a/retail/apiv2alpha/completion_client_example_test.go +++ b/retail/apiv2alpha/completion_client_example_test.go @@ -20,7 +20,9 @@ import ( "context" retail "cloud.google.com/go/retail/apiv2alpha" + "google.golang.org/api/iterator" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewCompletionClient() { @@ -79,3 +81,49 @@ func ExampleCompletionClient_ImportCompletionData() { // TODO: Use resp. _ = resp } + +func ExampleCompletionClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewCompletionClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleCompletionClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewCompletionClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/apiv2alpha/control_client.go b/retail/apiv2alpha/control_client.go index 3ed7ca9a215..e4155069247 100644 --- a/retail/apiv2alpha/control_client.go +++ b/retail/apiv2alpha/control_client.go @@ -21,6 +21,7 @@ import ( "fmt" "math" "net/url" + "time" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -28,7 +29,9 @@ import ( "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" + "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" "google.golang.org/protobuf/proto" ) @@ -37,11 +40,13 @@ var newControlClientHook clientHook // ControlCallOptions contains the retry settings for each method of ControlClient. type ControlCallOptions struct { - CreateControl []gax.CallOption - DeleteControl []gax.CallOption - UpdateControl []gax.CallOption - GetControl []gax.CallOption - ListControls []gax.CallOption + CreateControl []gax.CallOption + DeleteControl []gax.CallOption + UpdateControl []gax.CallOption + GetControl []gax.CallOption + ListControls []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultControlGRPCClientOptions() []option.ClientOption { @@ -63,6 +68,19 @@ func defaultControlCallOptions() *ControlCallOptions { UpdateControl: []gax.CallOption{}, GetControl: []gax.CallOption{}, ListControls: []gax.CallOption{}, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -76,6 +94,8 @@ type internalControlClient interface { UpdateControl(context.Context, *retailpb.UpdateControlRequest, ...gax.CallOption) (*retailpb.Control, error) GetControl(context.Context, *retailpb.GetControlRequest, ...gax.CallOption) (*retailpb.Control, error) ListControls(context.Context, *retailpb.ListControlsRequest, ...gax.CallOption) *ControlIterator + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // ControlClient is a client for interacting with Retail API. @@ -148,6 +168,16 @@ func (c *ControlClient) ListControls(ctx context.Context, req *retailpb.ListCont return c.internalClient.ListControls(ctx, req, opts...) } +// GetOperation is a utility method from google.longrunning.Operations. +func (c *ControlClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *ControlClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // controlGRPCClient is a client for interacting with Retail API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -164,6 +194,8 @@ type controlGRPCClient struct { // The gRPC API client. controlClient retailpb.ControlServiceClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -198,6 +230,7 @@ func NewControlClient(ctx context.Context, opts ...option.ClientOption) (*Contro disableDeadlines: disableDeadlines, controlClient: retailpb.NewControlServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -337,6 +370,68 @@ func (c *controlGRPCClient) ListControls(ctx context.Context, req *retailpb.List return it } +func (c *controlGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *controlGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + // ControlIterator manages a stream of *retailpb.Control. type ControlIterator struct { items []*retailpb.Control diff --git a/retail/apiv2alpha/control_client_example_test.go b/retail/apiv2alpha/control_client_example_test.go index eb09a93206c..e7b27328bf0 100644 --- a/retail/apiv2alpha/control_client_example_test.go +++ b/retail/apiv2alpha/control_client_example_test.go @@ -22,6 +22,7 @@ import ( retail "cloud.google.com/go/retail/apiv2alpha" "google.golang.org/api/iterator" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewControlClient() { @@ -139,3 +140,49 @@ func ExampleControlClient_ListControls() { _ = resp } } + +func ExampleControlClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewControlClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleControlClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewControlClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/apiv2alpha/gapic_metadata.json b/retail/apiv2alpha/gapic_metadata.json index 1c5bd7cab06..c330e2bafa5 100644 --- a/retail/apiv2alpha/gapic_metadata.json +++ b/retail/apiv2alpha/gapic_metadata.json @@ -30,11 +30,21 @@ "GetDefaultBranch" ] }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, "ListCatalogs": { "methods": [ "ListCatalogs" ] }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "RemoveCatalogAttribute": { "methods": [ "RemoveCatalogAttribute" @@ -79,10 +89,20 @@ "CompleteQuery" ] }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, "ImportCompletionData": { "methods": [ "ImportCompletionData" ] + }, + "ListOperations": { + "methods": [ + "ListOperations" + ] } } } @@ -108,11 +128,21 @@ "GetControl" ] }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, "ListControls": { "methods": [ "ListControls" ] }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "UpdateControl": { "methods": [ "UpdateControl" @@ -122,11 +152,75 @@ } } }, + "ModelService": { + "clients": { + "grpc": { + "libraryClient": "ModelClient", + "rpcs": { + "CreateModel": { + "methods": [ + "CreateModel" + ] + }, + "DeleteModel": { + "methods": [ + "DeleteModel" + ] + }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, + "ListModels": { + "methods": [ + "ListModels" + ] + }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, + "PauseModel": { + "methods": [ + "PauseModel" + ] + }, + "ResumeModel": { + "methods": [ + "ResumeModel" + ] + }, + "TuneModel": { + "methods": [ + "TuneModel" + ] + }, + "UpdateModel": { + "methods": [ + "UpdateModel" + ] + } + } + } + } + }, "PredictionService": { "clients": { "grpc": { "libraryClient": "PredictionClient", "rpcs": { + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "Predict": { "methods": [ "Predict" @@ -161,6 +255,11 @@ "DeleteProduct" ] }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, "GetProduct": { "methods": [ "GetProduct" @@ -171,6 +270,11 @@ "ImportProducts" ] }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "ListProducts": { "methods": [ "ListProducts" @@ -210,6 +314,16 @@ "grpc": { "libraryClient": "SearchClient", "rpcs": { + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "Search": { "methods": [ "Search" @@ -239,11 +353,21 @@ "DeleteServingConfig" ] }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, "GetServingConfig": { "methods": [ "GetServingConfig" ] }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "ListServingConfigs": { "methods": [ "ListServingConfigs" @@ -273,11 +397,21 @@ "CollectUserEvent" ] }, + "GetOperation": { + "methods": [ + "GetOperation" + ] + }, "ImportUserEvents": { "methods": [ "ImportUserEvents" ] }, + "ListOperations": { + "methods": [ + "ListOperations" + ] + }, "PurgeUserEvents": { "methods": [ "PurgeUserEvents" diff --git a/retail/apiv2alpha/model_client.go b/retail/apiv2alpha/model_client.go new file mode 100644 index 00000000000..392ae8f8145 --- /dev/null +++ b/retail/apiv2alpha/model_client.go @@ -0,0 +1,835 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package retail + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "cloud.google.com/go/longrunning" + lroauto "cloud.google.com/go/longrunning/autogen" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" +) + +var newModelClientHook clientHook + +// ModelCallOptions contains the retry settings for each method of ModelClient. +type ModelCallOptions struct { + CreateModel []gax.CallOption + PauseModel []gax.CallOption + ResumeModel []gax.CallOption + DeleteModel []gax.CallOption + ListModels []gax.CallOption + UpdateModel []gax.CallOption + TuneModel []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption +} + +func defaultModelGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("retail.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("retail.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://retail.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultModelCallOptions() *ModelCallOptions { + return &ModelCallOptions{ + CreateModel: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + PauseModel: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ResumeModel: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeleteModel: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListModels: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateModel: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + TuneModel: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// internalModelClient is an interface that defines the methods available from Retail API. +type internalModelClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + CreateModel(context.Context, *retailpb.CreateModelRequest, ...gax.CallOption) (*CreateModelOperation, error) + CreateModelOperation(name string) *CreateModelOperation + PauseModel(context.Context, *retailpb.PauseModelRequest, ...gax.CallOption) (*retailpb.Model, error) + ResumeModel(context.Context, *retailpb.ResumeModelRequest, ...gax.CallOption) (*retailpb.Model, error) + DeleteModel(context.Context, *retailpb.DeleteModelRequest, ...gax.CallOption) error + ListModels(context.Context, *retailpb.ListModelsRequest, ...gax.CallOption) *ModelIterator + UpdateModel(context.Context, *retailpb.UpdateModelRequest, ...gax.CallOption) (*retailpb.Model, error) + TuneModel(context.Context, *retailpb.TuneModelRequest, ...gax.CallOption) (*TuneModelOperation, error) + TuneModelOperation(name string) *TuneModelOperation + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator +} + +// ModelClient is a client for interacting with Retail API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Service for performing CRUD operations on models. +// Recommendation models contain all the metadata necessary to generate a set of +// models for the Predict() api. A model is queried +// indirectly via a ServingConfig, which associates a model with a +// given Placement (e.g. Frequently Bought Together on Home Page). +// +// This service allows customers to e.g.: +// +// Initiate training of a model. +// +// Pause training of an existing model. +// +// List all the available models along with their metadata. +// +// Control their tuning schedule. +type ModelClient struct { + // The internal transport-dependent client. + internalClient internalModelClient + + // The call options for this service. + CallOptions *ModelCallOptions + + // LROClient is used internally to handle long-running operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient *lroauto.OperationsClient +} + +// Wrapper methods routed to the internal client. + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *ModelClient) Close() error { + return c.internalClient.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *ModelClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *ModelClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// CreateModel creates a new model. +func (c *ModelClient) CreateModel(ctx context.Context, req *retailpb.CreateModelRequest, opts ...gax.CallOption) (*CreateModelOperation, error) { + return c.internalClient.CreateModel(ctx, req, opts...) +} + +// CreateModelOperation returns a new CreateModelOperation from a given name. +// The name must be that of a previously created CreateModelOperation, possibly from a different process. +func (c *ModelClient) CreateModelOperation(name string) *CreateModelOperation { + return c.internalClient.CreateModelOperation(name) +} + +// PauseModel pauses the training of an existing model. +func (c *ModelClient) PauseModel(ctx context.Context, req *retailpb.PauseModelRequest, opts ...gax.CallOption) (*retailpb.Model, error) { + return c.internalClient.PauseModel(ctx, req, opts...) +} + +// ResumeModel resumes the training of an existing model. +func (c *ModelClient) ResumeModel(ctx context.Context, req *retailpb.ResumeModelRequest, opts ...gax.CallOption) (*retailpb.Model, error) { + return c.internalClient.ResumeModel(ctx, req, opts...) +} + +// DeleteModel deletes an existing model. +func (c *ModelClient) DeleteModel(ctx context.Context, req *retailpb.DeleteModelRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteModel(ctx, req, opts...) +} + +// ListModels lists all the models linked to this event store. +func (c *ModelClient) ListModels(ctx context.Context, req *retailpb.ListModelsRequest, opts ...gax.CallOption) *ModelIterator { + return c.internalClient.ListModels(ctx, req, opts...) +} + +// UpdateModel update of model metadata. Only fields that +// currently can be updated are: filtering_option, periodic_tuning_state. +// If other values are provided, this API method will ignore them. +func (c *ModelClient) UpdateModel(ctx context.Context, req *retailpb.UpdateModelRequest, opts ...gax.CallOption) (*retailpb.Model, error) { + return c.internalClient.UpdateModel(ctx, req, opts...) +} + +// TuneModel tunes an existing model. +func (c *ModelClient) TuneModel(ctx context.Context, req *retailpb.TuneModelRequest, opts ...gax.CallOption) (*TuneModelOperation, error) { + return c.internalClient.TuneModel(ctx, req, opts...) +} + +// TuneModelOperation returns a new TuneModelOperation from a given name. +// The name must be that of a previously created TuneModelOperation, possibly from a different process. +func (c *ModelClient) TuneModelOperation(name string) *TuneModelOperation { + return c.internalClient.TuneModelOperation(name) +} + +// GetOperation is a utility method from google.longrunning.Operations. +func (c *ModelClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *ModelClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + +// modelGRPCClient is a client for interacting with Retail API over gRPC transport. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type modelGRPCClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // Points back to the CallOptions field of the containing ModelClient + CallOptions **ModelCallOptions + + // The gRPC API client. + modelClient retailpb.ModelServiceClient + + // LROClient is used internally to handle long-running operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient **lroauto.OperationsClient + + operationsClient longrunningpb.OperationsClient + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewModelClient creates a new model service client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// Service for performing CRUD operations on models. +// Recommendation models contain all the metadata necessary to generate a set of +// models for the Predict() api. A model is queried +// indirectly via a ServingConfig, which associates a model with a +// given Placement (e.g. Frequently Bought Together on Home Page). +// +// This service allows customers to e.g.: +// +// Initiate training of a model. +// +// Pause training of an existing model. +// +// List all the available models along with their metadata. +// +// Control their tuning schedule. +func NewModelClient(ctx context.Context, opts ...option.ClientOption) (*ModelClient, error) { + clientOpts := defaultModelGRPCClientOptions() + if newModelClientHook != nil { + hookOpts, err := newModelClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + client := ModelClient{CallOptions: defaultModelCallOptions()} + + c := &modelGRPCClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + modelClient: retailpb.NewModelServiceClient(connPool), + CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), + } + c.setGoogleClientInfo() + + client.internalClient = c + + client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) + if err != nil { + // This error "should not happen", since we are just reusing old connection pool + // and never actually need to dial. + // If this does happen, we could leak connp. However, we cannot close conn: + // If the user invoked the constructor with option.WithGRPCConn, + // we would close a connection that's still in use. + // TODO: investigate error conditions. + return nil, err + } + c.LROClient = &client.LROClient + return &client, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *modelGRPCClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *modelGRPCClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *modelGRPCClient) Close() error { + return c.connPool.Close() +} + +func (c *modelGRPCClient) CreateModel(ctx context.Context, req *retailpb.CreateModelRequest, opts ...gax.CallOption) (*CreateModelOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).CreateModel[0:len((*c.CallOptions).CreateModel):len((*c.CallOptions).CreateModel)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.modelClient.CreateModel(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateModelOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *modelGRPCClient) PauseModel(ctx context.Context, req *retailpb.PauseModelRequest, opts ...gax.CallOption) (*retailpb.Model, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).PauseModel[0:len((*c.CallOptions).PauseModel):len((*c.CallOptions).PauseModel)], opts...) + var resp *retailpb.Model + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.modelClient.PauseModel(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *modelGRPCClient) ResumeModel(ctx context.Context, req *retailpb.ResumeModelRequest, opts ...gax.CallOption) (*retailpb.Model, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ResumeModel[0:len((*c.CallOptions).ResumeModel):len((*c.CallOptions).ResumeModel)], opts...) + var resp *retailpb.Model + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.modelClient.ResumeModel(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *modelGRPCClient) DeleteModel(ctx context.Context, req *retailpb.DeleteModelRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).DeleteModel[0:len((*c.CallOptions).DeleteModel):len((*c.CallOptions).DeleteModel)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.modelClient.DeleteModel(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *modelGRPCClient) ListModels(ctx context.Context, req *retailpb.ListModelsRequest, opts ...gax.CallOption) *ModelIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListModels[0:len((*c.CallOptions).ListModels):len((*c.CallOptions).ListModels)], opts...) + it := &ModelIterator{} + req = proto.Clone(req).(*retailpb.ListModelsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*retailpb.Model, string, error) { + resp := &retailpb.ListModelsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.modelClient.ListModels(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetModels(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + +func (c *modelGRPCClient) UpdateModel(ctx context.Context, req *retailpb.UpdateModelRequest, opts ...gax.CallOption) (*retailpb.Model, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "model.name", url.QueryEscape(req.GetModel().GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).UpdateModel[0:len((*c.CallOptions).UpdateModel):len((*c.CallOptions).UpdateModel)], opts...) + var resp *retailpb.Model + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.modelClient.UpdateModel(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *modelGRPCClient) TuneModel(ctx context.Context, req *retailpb.TuneModelRequest, opts ...gax.CallOption) (*TuneModelOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).TuneModel[0:len((*c.CallOptions).TuneModel):len((*c.CallOptions).TuneModel)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.modelClient.TuneModel(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &TuneModelOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *modelGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *modelGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + +// CreateModelOperation manages a long-running operation from CreateModel. +type CreateModelOperation struct { + lro *longrunning.Operation +} + +// CreateModelOperation returns a new CreateModelOperation from a given name. +// The name must be that of a previously created CreateModelOperation, possibly from a different process. +func (c *modelGRPCClient) CreateModelOperation(name string) *CreateModelOperation { + return &CreateModelOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *CreateModelOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*retailpb.Model, error) { + var resp retailpb.Model + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *CreateModelOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*retailpb.Model, error) { + var resp retailpb.Model + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *CreateModelOperation) Metadata() (*retailpb.CreateModelMetadata, error) { + var meta retailpb.CreateModelMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *CreateModelOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *CreateModelOperation) Name() string { + return op.lro.Name() +} + +// TuneModelOperation manages a long-running operation from TuneModel. +type TuneModelOperation struct { + lro *longrunning.Operation +} + +// TuneModelOperation returns a new TuneModelOperation from a given name. +// The name must be that of a previously created TuneModelOperation, possibly from a different process. +func (c *modelGRPCClient) TuneModelOperation(name string) *TuneModelOperation { + return &TuneModelOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *TuneModelOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*retailpb.TuneModelResponse, error) { + var resp retailpb.TuneModelResponse + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *TuneModelOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*retailpb.TuneModelResponse, error) { + var resp retailpb.TuneModelResponse + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *TuneModelOperation) Metadata() (*retailpb.TuneModelMetadata, error) { + var meta retailpb.TuneModelMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *TuneModelOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *TuneModelOperation) Name() string { + return op.lro.Name() +} + +// ModelIterator manages a stream of *retailpb.Model. +type ModelIterator struct { + items []*retailpb.Model + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*retailpb.Model, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *ModelIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *ModelIterator) Next() (*retailpb.Model, error) { + var item *retailpb.Model + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *ModelIterator) bufLen() int { + return len(it.items) +} + +func (it *ModelIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/retail/apiv2alpha/model_client_example_test.go b/retail/apiv2alpha/model_client_example_test.go new file mode 100644 index 00000000000..6d0496018d2 --- /dev/null +++ b/retail/apiv2alpha/model_client_example_test.go @@ -0,0 +1,238 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package retail_test + +import ( + "context" + + retail "cloud.google.com/go/retail/apiv2alpha" + "google.golang.org/api/iterator" + retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" +) + +func ExampleNewModelClient() { + ctx := context.Background() + c, err := retail.NewModelClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleModelClient_CreateModel() { + ctx := context.Background() + c, err := retail.NewModelClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &retailpb.CreateModelRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/retail/v2alpha#CreateModelRequest. + } + op, err := c.CreateModel(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleModelClient_PauseModel() { + ctx := context.Background() + c, err := retail.NewModelClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &retailpb.PauseModelRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/retail/v2alpha#PauseModelRequest. + } + resp, err := c.PauseModel(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleModelClient_ResumeModel() { + ctx := context.Background() + c, err := retail.NewModelClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &retailpb.ResumeModelRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/retail/v2alpha#ResumeModelRequest. + } + resp, err := c.ResumeModel(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleModelClient_DeleteModel() { + ctx := context.Background() + c, err := retail.NewModelClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &retailpb.DeleteModelRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/retail/v2alpha#DeleteModelRequest. + } + err = c.DeleteModel(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleModelClient_ListModels() { + ctx := context.Background() + c, err := retail.NewModelClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &retailpb.ListModelsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/retail/v2alpha#ListModelsRequest. + } + it := c.ListModels(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleModelClient_UpdateModel() { + ctx := context.Background() + c, err := retail.NewModelClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &retailpb.UpdateModelRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/retail/v2alpha#UpdateModelRequest. + } + resp, err := c.UpdateModel(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleModelClient_TuneModel() { + ctx := context.Background() + c, err := retail.NewModelClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &retailpb.TuneModelRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/retail/v2alpha#TuneModelRequest. + } + op, err := c.TuneModel(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleModelClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewModelClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleModelClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewModelClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/apiv2alpha/prediction_client.go b/retail/apiv2alpha/prediction_client.go index cd8ef3ddf4c..e29f1911bb0 100644 --- a/retail/apiv2alpha/prediction_client.go +++ b/retail/apiv2alpha/prediction_client.go @@ -24,20 +24,25 @@ import ( "time" gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" "google.golang.org/api/option" "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newPredictionClientHook clientHook // PredictionCallOptions contains the retry settings for each method of PredictionClient. type PredictionCallOptions struct { - Predict []gax.CallOption + Predict []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultPredictionGRPCClientOptions() []option.ClientOption { @@ -66,6 +71,19 @@ func defaultPredictionCallOptions() *PredictionCallOptions { }) }), }, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -75,6 +93,8 @@ type internalPredictionClient interface { setGoogleClientInfo(...string) Connection() *grpc.ClientConn Predict(context.Context, *retailpb.PredictRequest, ...gax.CallOption) (*retailpb.PredictResponse, error) + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // PredictionClient is a client for interacting with Retail API. @@ -116,6 +136,16 @@ func (c *PredictionClient) Predict(ctx context.Context, req *retailpb.PredictReq return c.internalClient.Predict(ctx, req, opts...) } +// GetOperation is a utility method from google.longrunning.Operations. +func (c *PredictionClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *PredictionClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // predictionGRPCClient is a client for interacting with Retail API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -132,6 +162,8 @@ type predictionGRPCClient struct { // The gRPC API client. predictionClient retailpb.PredictionServiceClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -166,6 +198,7 @@ func NewPredictionClient(ctx context.Context, opts ...option.ClientOption) (*Pre disableDeadlines: disableDeadlines, predictionClient: retailpb.NewPredictionServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -217,3 +250,65 @@ func (c *predictionGRPCClient) Predict(ctx context.Context, req *retailpb.Predic } return resp, nil } + +func (c *predictionGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *predictionGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} diff --git a/retail/apiv2alpha/prediction_client_example_test.go b/retail/apiv2alpha/prediction_client_example_test.go index 2584c54bb8b..89a63162562 100644 --- a/retail/apiv2alpha/prediction_client_example_test.go +++ b/retail/apiv2alpha/prediction_client_example_test.go @@ -20,7 +20,9 @@ import ( "context" retail "cloud.google.com/go/retail/apiv2alpha" + "google.golang.org/api/iterator" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewPredictionClient() { @@ -54,3 +56,49 @@ func ExamplePredictionClient_Predict() { // TODO: Use resp. _ = resp } + +func ExamplePredictionClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewPredictionClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePredictionClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewPredictionClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/apiv2alpha/product_client.go b/retail/apiv2alpha/product_client.go index 47d8bdb05d1..b2c6082bb3b 100644 --- a/retail/apiv2alpha/product_client.go +++ b/retail/apiv2alpha/product_client.go @@ -54,6 +54,8 @@ type ProductCallOptions struct { RemoveFulfillmentPlaces []gax.CallOption AddLocalInventories []gax.CallOption RemoveLocalInventories []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultProductGRPCClientOptions() []option.ClientOption { @@ -214,6 +216,19 @@ func defaultProductCallOptions() *ProductCallOptions { }) }), }, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -241,6 +256,8 @@ type internalProductClient interface { AddLocalInventoriesOperation(name string) *AddLocalInventoriesOperation RemoveLocalInventories(context.Context, *retailpb.RemoveLocalInventoriesRequest, ...gax.CallOption) (*RemoveLocalInventoriesOperation, error) RemoveLocalInventoriesOperation(name string) *RemoveLocalInventoriesOperation + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // ProductClient is a client for interacting with Retail API. @@ -316,8 +333,9 @@ func (c *ProductClient) DeleteProduct(ctx context.Context, req *retailpb.DeleteP // Products, this operation could take // hours to complete. Before the operation completes, some // Products may still be returned by -// GetProduct or -// ListProducts. +// ProductService.GetProduct +// or +// ProductService.ListProducts. // // Depending on the number of Products, // this operation could take hours to complete. To get a sample of @@ -336,7 +354,7 @@ func (c *ProductClient) PurgeProductsOperation(name string) *PurgeProductsOperat // ImportProducts bulk import of multiple Products. // -// Request processing may be synchronous. No partial updating is supported. +// Request processing may be synchronous. // Non-existing items are created. // // Note that it is possible for a subset of the @@ -361,20 +379,21 @@ func (c *ProductClient) ImportProductsOperation(name string) *ImportProductsOper // enqueued and processed downstream. As a consequence, when a response is // returned, updates are not immediately manifested in the // Product queried by -// GetProduct or -// ListProducts. +// ProductService.GetProduct +// or +// ProductService.ListProducts. // // When inventory is updated with -// CreateProduct +// ProductService.CreateProduct // and -// UpdateProduct, +// ProductService.UpdateProduct, // the specified inventory field value(s) will overwrite any existing value(s) // while ignoring the last update time for this field. Furthermore, the last // update time for the specified inventory fields will be overwritten to the // time of the -// CreateProduct +// ProductService.CreateProduct // or -// UpdateProduct +// ProductService.UpdateProduct // request. // // If no inventory fields are set in @@ -386,10 +405,10 @@ func (c *ProductClient) ImportProductsOperation(name string) *ImportProductsOper // then any existing inventory information will be preserved. // // Pre-existing inventory information can only be updated with -// SetInventory, -// AddFulfillmentPlaces, +// ProductService.SetInventory, +// ProductService.AddFulfillmentPlaces, // and -// RemoveFulfillmentPlaces. +// ProductService.RemoveFulfillmentPlaces. // // This feature is only available for users who have Retail Search enabled. // Please enable Retail Search on Cloud Console before using this feature. @@ -412,8 +431,9 @@ func (c *ProductClient) SetInventoryOperation(name string) *SetInventoryOperatio // enqueued and processed downstream. As a consequence, when a response is // returned, the added place IDs are not immediately manifested in the // Product queried by -// GetProduct or -// ListProducts. +// ProductService.GetProduct +// or +// ProductService.ListProducts. // // This feature is only available for users who have Retail Search enabled. // Please enable Retail Search on Cloud Console before using this feature. @@ -436,8 +456,9 @@ func (c *ProductClient) AddFulfillmentPlacesOperation(name string) *AddFulfillme // enqueued and processed downstream. As a consequence, when a response is // returned, the removed place IDs are not immediately manifested in the // Product queried by -// GetProduct or -// ListProducts. +// ProductService.GetProduct +// or +// ProductService.ListProducts. // // This feature is only available for users who have Retail Search enabled. // Please enable Retail Search on Cloud Console before using this feature. @@ -461,13 +482,14 @@ func (c *ProductClient) RemoveFulfillmentPlacesOperation(name string) *RemoveFul // and processed downstream. As a consequence, when a response is returned, // updates are not immediately manifested in the // Product queried by -// GetProduct or -// ListProducts. +// ProductService.GetProduct +// or +// ProductService.ListProducts. // // Local inventory information can only be modified using this method. -// CreateProduct +// ProductService.CreateProduct // and -// UpdateProduct +// ProductService.UpdateProduct // has no effect on local inventories. // // This feature is only available for users who have Retail Search enabled. @@ -490,13 +512,14 @@ func (c *ProductClient) AddLocalInventoriesOperation(name string) *AddLocalInven // enqueued and processed downstream. As a consequence, when a response is // returned, removals are not immediately manifested in the // Product queried by -// GetProduct or -// ListProducts. +// ProductService.GetProduct +// or +// ProductService.ListProducts. // // Local inventory information can only be removed using this method. -// CreateProduct +// ProductService.CreateProduct // and -// UpdateProduct +// ProductService.UpdateProduct // has no effect on local inventories. // // This feature is only available for users who have Retail Search enabled. @@ -511,6 +534,16 @@ func (c *ProductClient) RemoveLocalInventoriesOperation(name string) *RemoveLoca return c.internalClient.RemoveLocalInventoriesOperation(name) } +// GetOperation is a utility method from google.longrunning.Operations. +func (c *ProductClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *ProductClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // productGRPCClient is a client for interacting with Retail API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -532,6 +565,8 @@ type productGRPCClient struct { // Users should not Close this client. LROClient **lroauto.OperationsClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -567,6 +602,7 @@ func NewProductClient(ctx context.Context, opts ...option.ClientOption) (*Produc disableDeadlines: disableDeadlines, productClient: retailpb.NewProductServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -905,6 +941,68 @@ func (c *productGRPCClient) RemoveLocalInventories(ctx context.Context, req *ret }, nil } +func (c *productGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *productGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + // AddFulfillmentPlacesOperation manages a long-running operation from AddFulfillmentPlaces. type AddFulfillmentPlacesOperation struct { lro *longrunning.Operation diff --git a/retail/apiv2alpha/product_client_example_test.go b/retail/apiv2alpha/product_client_example_test.go index 9a7903ff922..b9224538ce4 100644 --- a/retail/apiv2alpha/product_client_example_test.go +++ b/retail/apiv2alpha/product_client_example_test.go @@ -22,6 +22,7 @@ import ( retail "cloud.google.com/go/retail/apiv2alpha" "google.golang.org/api/iterator" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewProductClient() { @@ -314,3 +315,49 @@ func ExampleProductClient_RemoveLocalInventories() { // TODO: Use resp. _ = resp } + +func ExampleProductClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewProductClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleProductClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewProductClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/apiv2alpha/search_client.go b/retail/apiv2alpha/search_client.go index c171cdf2a28..cbeef8f9c1c 100644 --- a/retail/apiv2alpha/search_client.go +++ b/retail/apiv2alpha/search_client.go @@ -29,6 +29,7 @@ import ( "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" @@ -39,7 +40,9 @@ var newSearchClientHook clientHook // SearchCallOptions contains the retry settings for each method of SearchClient. type SearchCallOptions struct { - Search []gax.CallOption + Search []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultSearchGRPCClientOptions() []option.ClientOption { @@ -68,6 +71,19 @@ func defaultSearchCallOptions() *SearchCallOptions { }) }), }, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -77,6 +93,8 @@ type internalSearchClient interface { setGoogleClientInfo(...string) Connection() *grpc.ClientConn Search(context.Context, *retailpb.SearchRequest, ...gax.CallOption) *SearchResponse_SearchResultIterator + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // SearchClient is a client for interacting with Retail API. @@ -124,6 +142,16 @@ func (c *SearchClient) Search(ctx context.Context, req *retailpb.SearchRequest, return c.internalClient.Search(ctx, req, opts...) } +// GetOperation is a utility method from google.longrunning.Operations. +func (c *SearchClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *SearchClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // searchGRPCClient is a client for interacting with Retail API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -140,6 +168,8 @@ type searchGRPCClient struct { // The gRPC API client. searchClient retailpb.SearchServiceClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -177,6 +207,7 @@ func NewSearchClient(ctx context.Context, opts ...option.ClientOption) (*SearchC disableDeadlines: disableDeadlines, searchClient: retailpb.NewSearchServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -252,6 +283,68 @@ func (c *searchGRPCClient) Search(ctx context.Context, req *retailpb.SearchReque return it } +func (c *searchGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *searchGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + // SearchResponse_SearchResultIterator manages a stream of *retailpb.SearchResponse_SearchResult. type SearchResponse_SearchResultIterator struct { items []*retailpb.SearchResponse_SearchResult diff --git a/retail/apiv2alpha/search_client_example_test.go b/retail/apiv2alpha/search_client_example_test.go index fa1674533fe..e620c1324b2 100644 --- a/retail/apiv2alpha/search_client_example_test.go +++ b/retail/apiv2alpha/search_client_example_test.go @@ -22,6 +22,7 @@ import ( retail "cloud.google.com/go/retail/apiv2alpha" "google.golang.org/api/iterator" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewSearchClient() { @@ -61,3 +62,49 @@ func ExampleSearchClient_Search() { _ = resp } } + +func ExampleSearchClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewSearchClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSearchClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewSearchClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/apiv2alpha/serving_config_client.go b/retail/apiv2alpha/serving_config_client.go index 99e84eb472e..ec459da19f2 100644 --- a/retail/apiv2alpha/serving_config_client.go +++ b/retail/apiv2alpha/serving_config_client.go @@ -21,6 +21,7 @@ import ( "fmt" "math" "net/url" + "time" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -28,7 +29,9 @@ import ( "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" + "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" "google.golang.org/protobuf/proto" ) @@ -44,6 +47,8 @@ type ServingConfigCallOptions struct { ListServingConfigs []gax.CallOption AddControl []gax.CallOption RemoveControl []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultServingConfigGRPCClientOptions() []option.ClientOption { @@ -67,6 +72,19 @@ func defaultServingConfigCallOptions() *ServingConfigCallOptions { ListServingConfigs: []gax.CallOption{}, AddControl: []gax.CallOption{}, RemoveControl: []gax.CallOption{}, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -82,6 +100,8 @@ type internalServingConfigClient interface { ListServingConfigs(context.Context, *retailpb.ListServingConfigsRequest, ...gax.CallOption) *ServingConfigIterator AddControl(context.Context, *retailpb.AddControlRequest, ...gax.CallOption) (*retailpb.ServingConfig, error) RemoveControl(context.Context, *retailpb.RemoveControlRequest, ...gax.CallOption) (*retailpb.ServingConfig, error) + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // ServingConfigClient is a client for interacting with Retail API. @@ -171,6 +191,16 @@ func (c *ServingConfigClient) RemoveControl(ctx context.Context, req *retailpb.R return c.internalClient.RemoveControl(ctx, req, opts...) } +// GetOperation is a utility method from google.longrunning.Operations. +func (c *ServingConfigClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *ServingConfigClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // servingConfigGRPCClient is a client for interacting with Retail API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -187,6 +217,8 @@ type servingConfigGRPCClient struct { // The gRPC API client. servingConfigClient retailpb.ServingConfigServiceClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -221,6 +253,7 @@ func NewServingConfigClient(ctx context.Context, opts ...option.ClientOption) (* disableDeadlines: disableDeadlines, servingConfigClient: retailpb.NewServingConfigServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -394,6 +427,68 @@ func (c *servingConfigGRPCClient) RemoveControl(ctx context.Context, req *retail return resp, nil } +func (c *servingConfigGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *servingConfigGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + // ServingConfigIterator manages a stream of *retailpb.ServingConfig. type ServingConfigIterator struct { items []*retailpb.ServingConfig diff --git a/retail/apiv2alpha/serving_config_client_example_test.go b/retail/apiv2alpha/serving_config_client_example_test.go index 22a09a1ab81..b0874f20372 100644 --- a/retail/apiv2alpha/serving_config_client_example_test.go +++ b/retail/apiv2alpha/serving_config_client_example_test.go @@ -22,6 +22,7 @@ import ( retail "cloud.google.com/go/retail/apiv2alpha" "google.golang.org/api/iterator" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewServingConfigClient() { @@ -179,3 +180,49 @@ func ExampleServingConfigClient_RemoveControl() { // TODO: Use resp. _ = resp } + +func ExampleServingConfigClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewServingConfigClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleServingConfigClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewServingConfigClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/apiv2alpha/user_event_client.go b/retail/apiv2alpha/user_event_client.go index b044baac622..ddd4384f452 100644 --- a/retail/apiv2alpha/user_event_client.go +++ b/retail/apiv2alpha/user_event_client.go @@ -26,6 +26,7 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" "google.golang.org/api/option" "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" @@ -35,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newUserEventClientHook clientHook @@ -46,6 +48,8 @@ type UserEventCallOptions struct { PurgeUserEvents []gax.CallOption ImportUserEvents []gax.CallOption RejoinUserEvents []gax.CallOption + GetOperation []gax.CallOption + ListOperations []gax.CallOption } func defaultUserEventGRPCClientOptions() []option.ClientOption { @@ -122,6 +126,19 @@ func defaultUserEventCallOptions() *UserEventCallOptions { }) }), }, + GetOperation: []gax.CallOption{}, + ListOperations: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.DeadlineExceeded, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 300000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, } } @@ -138,6 +155,8 @@ type internalUserEventClient interface { ImportUserEventsOperation(name string) *ImportUserEventsOperation RejoinUserEvents(context.Context, *retailpb.RejoinUserEventsRequest, ...gax.CallOption) (*RejoinUserEventsOperation, error) RejoinUserEventsOperation(name string) *RejoinUserEventsOperation + GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) + ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator } // UserEventClient is a client for interacting with Retail API. @@ -242,6 +261,16 @@ func (c *UserEventClient) RejoinUserEventsOperation(name string) *RejoinUserEven return c.internalClient.RejoinUserEventsOperation(name) } +// GetOperation is a utility method from google.longrunning.Operations. +func (c *UserEventClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + return c.internalClient.GetOperation(ctx, req, opts...) +} + +// ListOperations is a utility method from google.longrunning.Operations. +func (c *UserEventClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + return c.internalClient.ListOperations(ctx, req, opts...) +} + // userEventGRPCClient is a client for interacting with Retail API over gRPC transport. // // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. @@ -263,6 +292,8 @@ type userEventGRPCClient struct { // Users should not Close this client. LROClient **lroauto.OperationsClient + operationsClient longrunningpb.OperationsClient + // The x-goog-* metadata to be sent with each request. xGoogMetadata metadata.MD } @@ -297,6 +328,7 @@ func NewUserEventClient(ctx context.Context, opts ...option.ClientOption) (*User disableDeadlines: disableDeadlines, userEventClient: retailpb.NewUserEventServiceClient(connPool), CallOptions: &client.CallOptions, + operationsClient: longrunningpb.NewOperationsClient(connPool), } c.setGoogleClientInfo() @@ -454,6 +486,68 @@ func (c *userEventGRPCClient) RejoinUserEvents(ctx context.Context, req *retailp }, nil } +func (c *userEventGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *userEventGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) + it := &OperationIterator{} + req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { + resp := &longrunningpb.ListOperationsResponse{} + if pageToken != "" { + req.PageToken = pageToken + } + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else if pageSize != 0 { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetOperations(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + + return it +} + // ImportUserEventsOperation manages a long-running operation from ImportUserEvents. type ImportUserEventsOperation struct { lro *longrunning.Operation diff --git a/retail/apiv2alpha/user_event_client_example_test.go b/retail/apiv2alpha/user_event_client_example_test.go index 89a3507638e..d25f3eec9df 100644 --- a/retail/apiv2alpha/user_event_client_example_test.go +++ b/retail/apiv2alpha/user_event_client_example_test.go @@ -20,7 +20,9 @@ import ( "context" retail "cloud.google.com/go/retail/apiv2alpha" + "google.golang.org/api/iterator" retailpb "google.golang.org/genproto/googleapis/cloud/retail/v2alpha" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" ) func ExampleNewUserEventClient() { @@ -149,3 +151,49 @@ func ExampleUserEventClient_RejoinUserEvents() { // TODO: Use resp. _ = resp } + +func ExampleUserEventClient_GetOperation() { + ctx := context.Background() + c, err := retail.NewUserEventClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.GetOperationRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#GetOperationRequest. + } + resp, err := c.GetOperation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleUserEventClient_ListOperations() { + ctx := context.Background() + c, err := retail.NewUserEventClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &longrunningpb.ListOperationsRequest{ + // TODO: Fill request struct fields. + // See https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#ListOperationsRequest. + } + it := c.ListOperations(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/retail/go.mod b/retail/go.mod index 26801f86a62..d1ded8e568c 100644 --- a/retail/go.mod +++ b/retail/go.mod @@ -6,7 +6,7 @@ require ( cloud.google.com/go v0.102.1 github.com/googleapis/gax-go/v2 v2.4.0 google.golang.org/api v0.90.0 - google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f + google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 google.golang.org/grpc v1.48.0 google.golang.org/protobuf v1.28.0 ) diff --git a/retail/go.sum b/retail/go.sum index caab9727337..a7e6429c6f8 100644 --- a/retail/go.sum +++ b/retail/go.sum @@ -589,8 +589,8 @@ google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac/go.mod h1:KEWEmljW google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= -google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f h1:XVHpVMvPs4MtH3h6cThzKs2snNexcfd35vQx2T3IuIY= -google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= +google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 h1:QntLWYqZeuBtJkth3m/6DLznnI0AHJr+AgJXvVh/izw= +google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=