From 877b90a4e3823fa5d62819539aca4c8ec0e7fd3b Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Mon, 16 Jun 2025 12:37:12 +0000 Subject: [PATCH 01/35] WIP --- .../storage_control_anywhere_cache_test.rb | 38 ++++++++++++++++ .../storage_control_create_anywhere_cache.rb | 45 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb create mode 100644 google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb diff --git a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb new file mode 100644 index 000000000000..3d9c327d8679 --- /dev/null +++ b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb @@ -0,0 +1,38 @@ +# Copyright 2024 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 +# +# http://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. + +require_relative "helper" +require_relative "../storage_control_create_anywhere_cache" +require 'pry' + +describe "Storage Control Anywhere Cache" do + let(:bucket_name) { random_bucket_name } + let(:storage_client) { Google::Cloud::Storage.new } + let(:project_name) { storage_client.project } + + before :all do + create_bucket_helper bucket_name + end + + after do + delete_bucket_helper bucket_name + end + + it "Gets the storage layout" do + # layout_name = "projects/_/buckets/#{bucket_name}/storageLayout" + # binding.pry + + create_anywhere_cache bucket_name: bucket_name, project_name: project_name + end +end diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb new file mode 100644 index 000000000000..17345c75c3a5 --- /dev/null +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -0,0 +1,45 @@ +# Copyright 2025 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 +# +# http://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. + +# [START storage_control_create_folder] +def create_anywhere_cache bucket_name:, project_name: + # The ID of your GCS bucket + # bucket_name = "your-unique-bucket-name" + + # The name of the folder to be created + # folder_name = "folder-name" + + require "google/cloud/storage/control/v2" + require "pry" + + # Create a client object. The client can be reused for multiple calls. + client = Google::Cloud::Storage::Control::V2::StorageControl::Client + parent = "projects/#{project_name}/locations/global" + # Create a request. Replace the placeholder values with actual data. + request = Google::Cloud::Storage::Control::V2::CreateAnywhereCacheRequest.new( + parent: parent + + ) +binding.pry +# Call the create_anywhere_cache method. +result = client.create_anywhere_cache request +# cache: Google::Cloud::Storage::Control::V2::AnywhereCache.new( +# name: "#{parent}/anywhereCaches/your-cache-id", +# ttl: { seconds: 3600 } # 1 hour TTL +# ), + +end +# [END storage_control_create_folder] + +create_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ From e036c60d798e9c766712d0bff939e810d7b85a09 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 20 Jun 2025 05:10:51 +0000 Subject: [PATCH 02/35] wip --- .../storage_control_anywhere_cache_test.rb | 9 ++-- .../storage_control_create_anywhere_cache.rb | 46 ++++++++++++------- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb index 3d9c327d8679..bf6c118a9c74 100644 --- a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb +++ b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb @@ -22,17 +22,16 @@ let(:project_name) { storage_client.project } before :all do - create_bucket_helper bucket_name + @bucket = create_bucket_helper bucket_name end after do delete_bucket_helper bucket_name end - it "Gets the storage layout" do - # layout_name = "projects/_/buckets/#{bucket_name}/storageLayout" - # binding.pry + it "create Anywhere cache" do + binding.pry - create_anywhere_cache bucket_name: bucket_name, project_name: project_name + create_anywhere_cache bucket_name: bucket_name, project_name: project_name, zone: @bucket.location end end diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index 17345c75c3a5..7a5cd3ecc69c 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -12,34 +12,48 @@ # See the License for the specific language governing permissions and # limitations under the License. -# [START storage_control_create_folder] -def create_anywhere_cache bucket_name:, project_name: +# [START storage_control_create_anywhere_cache] +def create_anywhere_cache bucket_name:, project_name:, zone: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - # The name of the folder to be created - # folder_name = "folder-name" - require "google/cloud/storage/control/v2" + require "google/cloud/storage/control" + require "google/cloud/storage/control/v2" + require "pry" # Create a client object. The client can be reused for multiple calls. - client = Google::Cloud::Storage::Control::V2::StorageControl::Client - parent = "projects/#{project_name}/locations/global" + client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + parent = "projects/_/buckets/#{bucket_name}" + + anywhere_cache = Google::Cloud::Storage::Control::V2::AnywhereCache.new( + name: "test_cache_shubhangi", + zone: zone + ) # Create a request. Replace the placeholder values with actual data. request = Google::Cloud::Storage::Control::V2::CreateAnywhereCacheRequest.new( - parent: parent - + parent: parent, + anywhere_cache: anywhere_cache ) -binding.pry # Call the create_anywhere_cache method. -result = client.create_anywhere_cache request -# cache: Google::Cloud::Storage::Control::V2::AnywhereCache.new( -# name: "#{parent}/anywhereCaches/your-cache-id", -# ttl: { seconds: 3600 } # 1 hour TTL -# ), + +result = client.create_anywhere_cache(request) end -# [END storage_control_create_folder] +# [END storage_control_create_anywhere_cache] create_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ + +# request=> +# , +# request_id: ""> + +# GRPC::InvalidArgument: 3:This operation does not support custom billing projects at this time.. debug_error_string:{UNKNOWN:Error received from peer ipv4:64.233.189.207:443 {grpc_status:3, grpc_message:"This operation does not support custom billing projects at this time."}} \ No newline at end of file From 33a8d557ecdb7356ca32d87adc838f48b150a4ae Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 20 Jun 2025 05:11:00 +0000 Subject: [PATCH 03/35] wip --- .../samples/acceptance/storage_control_anywhere_cache_test.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb index bf6c118a9c74..cbd9fb9a1603 100644 --- a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb +++ b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb @@ -30,8 +30,6 @@ end it "create Anywhere cache" do - binding.pry - create_anywhere_cache bucket_name: bucket_name, project_name: project_name, zone: @bucket.location end end From 7f5d121c3b0497921c19f371dc3ca1d383dfbcc1 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 20 Jun 2025 11:10:46 +0000 Subject: [PATCH 04/35] get and list working --- .../storage_control_anywhere_cache_test.rb | 34 +++++++++++--- .../storage_control_get_anywhere_cache.rb | 42 +++++++++++++++++ .../storage_control_list_anywhere_caches.rb | 47 +++++++++++++++++++ 3 files changed, 116 insertions(+), 7 deletions(-) create mode 100644 google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb create mode 100644 google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb diff --git a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb index cbd9fb9a1603..78efb8a8f03b 100644 --- a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb +++ b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb @@ -14,22 +14,42 @@ require_relative "helper" require_relative "../storage_control_create_anywhere_cache" +require_relative "../storage_control_list_anywhere_caches" +require_relative "../storage_control_get_anywhere_cache" + require 'pry' describe "Storage Control Anywhere Cache" do - let(:bucket_name) { random_bucket_name } + let(:bucket_name) { 'ruby_7' } let(:storage_client) { Google::Cloud::Storage.new } - let(:project_name) { storage_client.project } + let(:zone) {'us-east1-b'} +# let(:zone) {@bucket.location} before :all do - @bucket = create_bucket_helper bucket_name + @bucket= storage_client.bucket bucket_name + # @bucket = create_bucket_helper bucket_name end - after do - delete_bucket_helper bucket_name +# after do +# delete_bucket_helper bucket_name +# end + +# it "create Anywhere cache" do +# create_anywhere_cache bucket_name: bucket_name, project_name: project_name, zone: @bucket.location +# end + + it "list Anywhere cache" do + out, _err = capture_io do + list_anywhere_caches bucket_name: bucket_name + end + + assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" end - it "create Anywhere cache" do - create_anywhere_cache bucket_name: bucket_name, project_name: project_name, zone: @bucket.location + it "Get Anywhere cache" do + out, _err = capture_io do + get_anywhere_cache bucket_name: bucket_name, zone: zone + end + assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" end end diff --git a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb new file mode 100644 index 000000000000..a7a5c47992c4 --- /dev/null +++ b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb @@ -0,0 +1,42 @@ +# Copyright 2025 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 +# +# http://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. + +# [START storage_control_create_anywhere_cache] +def get_anywhere_cache bucket_name:, zone: + # The ID of your GCS bucket + # bucket_name = "your-unique-bucket-name" + + + require "google/cloud/storage/control" + require "google/cloud/storage/control/v2" + + require "pry" + + # Create a client object. The client can be reused for multiple calls. + client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + parent = "projects/_/buckets/#{bucket_name}" + name= "#{parent}/anywhereCaches/#{zone}" + + # Create a request. Replace the placeholder values with actual data. + request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( + name: name, + ) +# Call the create_anywhere_cache method. + +result = client.get_anywhere_cache(request) +puts result +end +# [END storage_control_create_anywhere_cache] + +create_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb new file mode 100644 index 000000000000..1f94f7757157 --- /dev/null +++ b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb @@ -0,0 +1,47 @@ +# Copyright 2025 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 +# +# http://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. + +# [START storage_control_create_anywhere_caches] +def list_anywhere_caches bucket_name: + # The ID of your GCS bucket + # bucket_name = "your-unique-bucket-name" + + + require "google/cloud/storage/control" + require "google/cloud/storage/control/v2" + + require "pry" + + # Create a client object. The client can be reused for multiple calls. + client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + parent = "projects/_/buckets/#{bucket_name}" + + # anywhere_cache = Google::Cloud::Storage::Control::V2::AnywhereCache.new( + # name: "test_cache_shubhangi", + # zone: zone + # ) + # Create a request. Replace the placeholder values with actual data. + request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new( + parent: parent + ) +# Call the create_anywhere_cache method. + + result = client.list_anywhere_caches(request) + result.response.anywhere_caches.each do |item| + puts item.name + end + +end +# [END storage_control_create_anywhere_caches] + list_anywhere_caches bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ From 1dcd5bb918498830af1c71d33defb586682a62f1 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 24 Jun 2025 11:38:53 +0000 Subject: [PATCH 05/35] pause_disable_resume_working --- .../storage_control_anywhere_cache_test.rb | 32 ++++++++++++++ .../storage_control_create_anywhere_cache.rb | 9 ++-- .../storage_control_disable_anywhere_cache.rb | 40 +++++++++++++++++ .../storage_control_get_anywhere_cache.rb | 32 +++++++------- .../storage_control_list_anywhere_caches.rb | 20 +++------ .../storage_control_pause_anywhere_cache.rb | 39 ++++++++++++++++ .../storage_control_resume_anywhere_cache.rb | 41 +++++++++++++++++ .../storage_control_update_anywhere_cache.rb | 44 +++++++++++++++++++ 8 files changed, 222 insertions(+), 35 deletions(-) create mode 100644 google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb create mode 100644 google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb create mode 100644 google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb create mode 100644 google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb diff --git a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb index 78efb8a8f03b..ed5c5724cb56 100644 --- a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb +++ b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb @@ -16,6 +16,10 @@ require_relative "../storage_control_create_anywhere_cache" require_relative "../storage_control_list_anywhere_caches" require_relative "../storage_control_get_anywhere_cache" +require_relative "../storage_control_update_anywhere_cache" +require_relative "../storage_control_pause_anywhere_cache" +require_relative "../storage_control_resume_anywhere_cache" +require_relative "../storage_control_disable_anywhere_cache" require 'pry' @@ -52,4 +56,32 @@ end assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" end + + it "Pause Anywhere cache" do + out, _err = capture_io do + pause_anywhere_cache bucket_name: bucket_name, zone: zone + end + assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" + end + + it "Resume Anywhere cache" do + out, _err = capture_io do + resume_anywhere_cache bucket_name: bucket_name, zone: zone + end + assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" + end + + it "Disable Anywhere cache" do + out, _err = capture_io do + resume_anywhere_cache bucket_name: bucket_name, zone: zone + end + assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" + end + +# it "Update Anywhere cache" do +# out, _err = capture_io do +# update_anywhere_cache bucket_name: bucket_name, zone: zone +# end +# assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" +# end end diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index 7a5cd3ecc69c..3cfee86babaf 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -13,7 +13,7 @@ # limitations under the License. # [START storage_control_create_anywhere_cache] -def create_anywhere_cache bucket_name:, project_name:, zone: +def create_anywhere_cache bucket_name:, zone: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" @@ -21,14 +21,13 @@ def create_anywhere_cache bucket_name:, project_name:, zone: require "google/cloud/storage/control" require "google/cloud/storage/control/v2" - require "pry" - # Create a client object. The client can be reused for multiple calls. client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new parent = "projects/_/buckets/#{bucket_name}" + name= "#{parent}/anywhereCaches/#{zone}" anywhere_cache = Google::Cloud::Storage::Control::V2::AnywhereCache.new( - name: "test_cache_shubhangi", + name: name, zone: zone ) # Create a request. Replace the placeholder values with actual data. @@ -40,6 +39,8 @@ def create_anywhere_cache bucket_name:, project_name:, zone: result = client.create_anywhere_cache(request) +puts result + end # [END storage_control_create_anywhere_cache] diff --git a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb new file mode 100644 index 000000000000..9bcdd5c375cc --- /dev/null +++ b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb @@ -0,0 +1,40 @@ +# Copyright 2025 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 +# +# http://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. + +# [START storage_control_create_anywhere_cache] +def disable_anywhere_cache bucket_name:, zone: + # The ID of your GCS bucket + # bucket_name = "your-unique-bucket-name" + + + require "google/cloud/storage/control" + require "google/cloud/storage/control/v2" + + # Create a client object. The client can be reused for multiple calls. + client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + parent = "projects/_/buckets/#{bucket_name}" + name= "#{parent}/anywhereCaches/#{zone}" + + # Create a request. Replace the placeholder values with actual data. + request = Google::Cloud::Storage::Control::V2::DisableAnywhereCacheRequest.new( + name: name + ) + # Call the disable_anywhere_cache method. + + result = client.disable_anywhere_cache(request) + puts result +end +# [END storage_control_create_anywhere_cache] + +disable_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb index a7a5c47992c4..4fd3e01e0898 100644 --- a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb @@ -12,31 +12,29 @@ # See the License for the specific language governing permissions and # limitations under the License. -# [START storage_control_create_anywhere_cache] +# [START storage_control_get_anywhere_cache] def get_anywhere_cache bucket_name:, zone: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" require "google/cloud/storage/control" - require "google/cloud/storage/control/v2" + require "google/cloud/storage/control/v2" - require "pry" + # Create a client object. The client can be reused for multiple calls. + client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + parent = "projects/_/buckets/#{bucket_name}" + name= "#{parent}/anywhereCaches/#{zone}" - # Create a client object. The client can be reused for multiple calls. - client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new - parent = "projects/_/buckets/#{bucket_name}" - name= "#{parent}/anywhereCaches/#{zone}" + # Create a request. Replace the placeholder values with actual data. + request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( + name: name + ) + # Call the create_anywhere_cache method. - # Create a request. Replace the placeholder values with actual data. - request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( - name: name, - ) -# Call the create_anywhere_cache method. - -result = client.get_anywhere_cache(request) -puts result + result = client.get_anywhere_cache(request) + puts result end -# [END storage_control_create_anywhere_cache] +# [END storage_control_get_anywhere_cache] -create_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ +get_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb index 1f94f7757157..165b0649eba1 100644 --- a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb +++ b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb @@ -12,36 +12,28 @@ # See the License for the specific language governing permissions and # limitations under the License. -# [START storage_control_create_anywhere_caches] +# [START storage_control_list_anywhere_caches] def list_anywhere_caches bucket_name: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - require "google/cloud/storage/control" require "google/cloud/storage/control/v2" - require "pry" - # Create a client object. The client can be reused for multiple calls. client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new parent = "projects/_/buckets/#{bucket_name}" - # anywhere_cache = Google::Cloud::Storage::Control::V2::AnywhereCache.new( - # name: "test_cache_shubhangi", - # zone: zone - # ) - # Create a request. Replace the placeholder values with actual data. request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new( parent: parent ) -# Call the create_anywhere_cache method. + # Call the create_anywhere_cache method. result = client.list_anywhere_caches(request) - result.response.anywhere_caches.each do |item| - puts item.name - end + result.response.anywhere_caches.each do |item| + puts item.name + end end -# [END storage_control_create_anywhere_caches] +# [END storage_control_list_anywhere_caches] list_anywhere_caches bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb new file mode 100644 index 000000000000..30a2289888b9 --- /dev/null +++ b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb @@ -0,0 +1,39 @@ +# Copyright 2025 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 +# +# http://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. + +# [START storage_control_create_anywhere_cache] +def pause_anywhere_cache bucket_name:, zone: + # The ID of your GCS bucket + # bucket_name = "your-unique-bucket-name" + + + require "google/cloud/storage/control" + require "google/cloud/storage/control/v2" + + + # Create a client object. The client can be reused for multiple calls. + client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + parent = "projects/_/buckets/#{bucket_name}" + name= "#{parent}/anywhereCaches/#{zone}" +# Create a request. Replace the placeholder values with actual data. + request = Google::Cloud::Storage::Control::V2::PauseAnywhereCacheRequest.new( + name: name + ) + # Call the create_anywhere_cache method. + result = client.pause_anywhere_cache(request) + puts result +end +# [END storage_control_pause_anywhere_cache] + +pause_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb new file mode 100644 index 000000000000..64ad27697b73 --- /dev/null +++ b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb @@ -0,0 +1,41 @@ +# Copyright 2025 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 +# +# http://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. + +# [START storage_control_resume_anywhere_cache] +def resume_anywhere_cache bucket_name:, zone: + # The ID of your GCS bucket + # bucket_name = "your-unique-bucket-name" + + + require "google/cloud/storage/control" + require "google/cloud/storage/control/v2" + + + # Create a client object. The client can be reused for multiple calls. + client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + parent = "projects/_/buckets/#{bucket_name}" + name= "#{parent}/anywhereCaches/#{zone}" + + # Create a request. Replace the placeholder values with actual data. + request = Google::Cloud::Storage::Control::V2::ResumeAnywhereCacheRequest.new( + name: name + ) + # Call the resume_anywhere_cache method. + + result = client.resume_anywhere_cache(request) + puts result +end +# [END storage_control_resume_anywhere_cache] + +resume_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb new file mode 100644 index 000000000000..d0c03d5218a2 --- /dev/null +++ b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb @@ -0,0 +1,44 @@ +# Copyright 2025 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 +# +# http://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. + +# [START storage_control_update_anywhere_cache] +def update_anywhere_cache bucket_name:, zone: + # The ID of your GCS bucket + # bucket_name = "your-unique-bucket-name" + + require "google/cloud/storage/control" + require "google/cloud/storage/control/v2" + + # Create a client object. The client can be reused for multiple calls. + client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + parent = "projects/_/buckets/#{bucket_name}" + name= "#{parent}/anywhereCaches/#{zone}" + binding.pry + + + # Create a request. Replace the placeholder values with actual data. + request = Google::Cloud::Storage::Control::V2::UpdateAnywhereCacheRequest.new( + request_id: name + ) + # Call the update_anywhere_cache method. + + result = client.update_anywhere_cache(request1) + puts result +end +# [END storage_control_update_anywhere_cache] + +update_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ + +# => , admission_policy: "admit-on-first-miss", state: "running", create_time: , update_time: , pending_update: false>, update_mask: , request_id: ""> +# Google::Cloud::InvalidArgumentError: 3:Please specify anywhere_cache.name in request.. debug_error_string:{UNKNOWN:Error received from peer ipv4:108.177.97.207:443 {grpc_message:"Please specify anywhere_cache.name in request.", grpc_status:3} From f99baa4ca40047e757984e911e445cab481bceaf Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 1 Jul 2025 11:43:43 +0000 Subject: [PATCH 06/35] adding all samples --- .../storage_control_anywhere_cache_test.rb | 87 ------------------- .../storage_control_create_anywhere_cache.rb | 66 ++++++-------- .../storage_control_disable_anywhere_cache.rb | 13 ++- .../storage_control_get_anywhere_cache.rb | 11 +-- .../storage_control_list_anywhere_caches.rb | 19 ++-- .../storage_control_pause_anywhere_cache.rb | 22 ++--- .../storage_control_resume_anywhere_cache.rb | 27 +++--- .../storage_control_update_anywhere_cache.rb | 46 +++++----- 8 files changed, 99 insertions(+), 192 deletions(-) delete mode 100644 google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb diff --git a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb deleted file mode 100644 index ed5c5724cb56..000000000000 --- a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb +++ /dev/null @@ -1,87 +0,0 @@ -# Copyright 2024 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 -# -# http://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. - -require_relative "helper" -require_relative "../storage_control_create_anywhere_cache" -require_relative "../storage_control_list_anywhere_caches" -require_relative "../storage_control_get_anywhere_cache" -require_relative "../storage_control_update_anywhere_cache" -require_relative "../storage_control_pause_anywhere_cache" -require_relative "../storage_control_resume_anywhere_cache" -require_relative "../storage_control_disable_anywhere_cache" - -require 'pry' - -describe "Storage Control Anywhere Cache" do - let(:bucket_name) { 'ruby_7' } - let(:storage_client) { Google::Cloud::Storage.new } - let(:zone) {'us-east1-b'} -# let(:zone) {@bucket.location} - - before :all do - @bucket= storage_client.bucket bucket_name - # @bucket = create_bucket_helper bucket_name - end - -# after do -# delete_bucket_helper bucket_name -# end - -# it "create Anywhere cache" do -# create_anywhere_cache bucket_name: bucket_name, project_name: project_name, zone: @bucket.location -# end - - it "list Anywhere cache" do - out, _err = capture_io do - list_anywhere_caches bucket_name: bucket_name - end - - assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" - end - - it "Get Anywhere cache" do - out, _err = capture_io do - get_anywhere_cache bucket_name: bucket_name, zone: zone - end - assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" - end - - it "Pause Anywhere cache" do - out, _err = capture_io do - pause_anywhere_cache bucket_name: bucket_name, zone: zone - end - assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" - end - - it "Resume Anywhere cache" do - out, _err = capture_io do - resume_anywhere_cache bucket_name: bucket_name, zone: zone - end - assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" - end - - it "Disable Anywhere cache" do - out, _err = capture_io do - resume_anywhere_cache bucket_name: bucket_name, zone: zone - end - assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" - end - -# it "Update Anywhere cache" do -# out, _err = capture_io do -# update_anywhere_cache bucket_name: bucket_name, zone: zone -# end -# assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" -# end -end diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index 3cfee86babaf..11f69247543c 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -17,44 +17,34 @@ def create_anywhere_cache bucket_name:, zone: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - - require "google/cloud/storage/control" - require "google/cloud/storage/control/v2" - - # Create a client object. The client can be reused for multiple calls. - client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new - parent = "projects/_/buckets/#{bucket_name}" - name= "#{parent}/anywhereCaches/#{zone}" - - anywhere_cache = Google::Cloud::Storage::Control::V2::AnywhereCache.new( - name: name, - zone: zone - ) - # Create a request. Replace the placeholder values with actual data. - request = Google::Cloud::Storage::Control::V2::CreateAnywhereCacheRequest.new( - parent: parent, - anywhere_cache: anywhere_cache - ) -# Call the create_anywhere_cache method. - -result = client.create_anywhere_cache(request) - -puts result - + # Zone where you want to create cache + # zone = "your-zone-name" + + require "google/cloud/storage/control/v2" + + # Create a client object. The client can be reused for multiple calls. + client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + parent = "projects/_/buckets/#{bucket_name}" + name = "#{parent}/anywhereCaches/#{zone}" + + anywhere_cache = Google::Cloud::Storage::Control::V2::AnywhereCache.new( + name: name, + zone: zone + ) + # Create a request. Replace the placeholder values with actual data. + request = Google::Cloud::Storage::Control::V2::CreateAnywhereCacheRequest.new( + parent: parent, + anywhere_cache: anywhere_cache + ) + # Call the create_anywhere_cache method. + result = client.create_anywhere_cache request + + if result.instance_of?(Gapic::Operation) + puts "Anywhere cache created" + else + puts "operation failed" + end end # [END storage_control_create_anywhere_cache] -create_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ - -# request=> -# , -# request_id: ""> - -# GRPC::InvalidArgument: 3:This operation does not support custom billing projects at this time.. debug_error_string:{UNKNOWN:Error received from peer ipv4:64.233.189.207:443 {grpc_status:3, grpc_message:"This operation does not support custom billing projects at this time."}} \ No newline at end of file +create_anywhere_cache bucket_name: ARGV.shift, zone: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb index 9bcdd5c375cc..4fea9bd7f668 100644 --- a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb @@ -17,24 +17,23 @@ def disable_anywhere_cache bucket_name:, zone: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - - require "google/cloud/storage/control" + # Zone where you want to create cache + # zone = "your-zone-name" require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new parent = "projects/_/buckets/#{bucket_name}" - name= "#{parent}/anywhereCaches/#{zone}" + name = "#{parent}/anywhereCaches/#{zone}" # Create a request. Replace the placeholder values with actual data. request = Google::Cloud::Storage::Control::V2::DisableAnywhereCacheRequest.new( - name: name + name: name ) # Call the disable_anywhere_cache method. - - result = client.disable_anywhere_cache(request) + result = client.disable_anywhere_cache request puts result end # [END storage_control_create_anywhere_cache] -disable_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ +disable_anywhere_cache bucket_name: ARGV.shift, zone: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb index 4fd3e01e0898..3220104bc8f1 100644 --- a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb @@ -17,24 +17,25 @@ def get_anywhere_cache bucket_name:, zone: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" + # Zone where you want to create cache + # zone = "your-zone-name" - require "google/cloud/storage/control" require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new parent = "projects/_/buckets/#{bucket_name}" - name= "#{parent}/anywhereCaches/#{zone}" + name = "#{parent}/anywhereCaches/#{zone}" # Create a request. Replace the placeholder values with actual data. request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( - name: name + name: name ) # Call the create_anywhere_cache method. - result = client.get_anywhere_cache(request) + result = client.get_anywhere_cache request puts result end # [END storage_control_get_anywhere_cache] -get_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ +get_anywhere_cache bucket_name: ARGV.shift, zone: ARGV.shift if $PROGRAM_NAME == __FILE__ \ No newline at end of file diff --git a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb index 165b0649eba1..97672a2a8747 100644 --- a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb +++ b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb @@ -17,23 +17,22 @@ def list_anywhere_caches bucket_name: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - require "google/cloud/storage/control" - require "google/cloud/storage/control/v2" + require "google/cloud/storage/control/v2" - # Create a client object. The client can be reused for multiple calls. - client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new - parent = "projects/_/buckets/#{bucket_name}" + # Create a client object. The client can be reused for multiple calls. + client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + parent = "projects/_/buckets/#{bucket_name}" - request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new( - parent: parent - ) + request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new( + parent: parent + ) # Call the create_anywhere_cache method. + result = client.list_anywhere_caches request - result = client.list_anywhere_caches(request) result.response.anywhere_caches.each do |item| puts item.name end end # [END storage_control_list_anywhere_caches] - list_anywhere_caches bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ +list_anywhere_caches bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb index 30a2289888b9..1f84462e0504 100644 --- a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb @@ -17,23 +17,23 @@ def pause_anywhere_cache bucket_name:, zone: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" + # Zone where you want to create cache + # zone = "your-zone-name" - require "google/cloud/storage/control" - require "google/cloud/storage/control/v2" + require "google/cloud/storage/control/v2" - - # Create a client object. The client can be reused for multiple calls. - client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new - parent = "projects/_/buckets/#{bucket_name}" - name= "#{parent}/anywhereCaches/#{zone}" -# Create a request. Replace the placeholder values with actual data. + # Create a client object. The client can be reused for multiple calls. + client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + parent = "projects/_/buckets/#{bucket_name}" + name = "#{parent}/anywhereCaches/#{zone}" + # Create a request. Replace the placeholder values with actual data. request = Google::Cloud::Storage::Control::V2::PauseAnywhereCacheRequest.new( name: name - ) + ) # Call the create_anywhere_cache method. - result = client.pause_anywhere_cache(request) + result = client.pause_anywhere_cache request puts result end # [END storage_control_pause_anywhere_cache] -pause_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ +pause_anywhere_cache bucket_name: ARGV.shift, zone: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb index 64ad27697b73..9e2abf1be2f1 100644 --- a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb @@ -17,25 +17,24 @@ def resume_anywhere_cache bucket_name:, zone: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" + # Zone where you want to create cache + # zone = "your-zone-name" - require "google/cloud/storage/control" - require "google/cloud/storage/control/v2" + require "google/cloud/storage/control/v2" + # Create a client object. The client can be reused for multiple calls. + client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + parent = "projects/_/buckets/#{bucket_name}" + name = "#{parent}/anywhereCaches/#{zone}" - # Create a client object. The client can be reused for multiple calls. - client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new - parent = "projects/_/buckets/#{bucket_name}" - name= "#{parent}/anywhereCaches/#{zone}" - - # Create a request. Replace the placeholder values with actual data. - request = Google::Cloud::Storage::Control::V2::ResumeAnywhereCacheRequest.new( - name: name - ) + # Create a request. Replace the placeholder values with actual data. + request = Google::Cloud::Storage::Control::V2::ResumeAnywhereCacheRequest.new( + name: name + ) # Call the resume_anywhere_cache method. - - result = client.resume_anywhere_cache(request) + result = client.resume_anywhere_cache request puts result end # [END storage_control_resume_anywhere_cache] -resume_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ +resume_anywhere_cache bucket_name: ARGV.shift, zone: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb index d0c03d5218a2..7bd70a08dc16 100644 --- a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb @@ -17,28 +17,34 @@ def update_anywhere_cache bucket_name:, zone: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - require "google/cloud/storage/control" - require "google/cloud/storage/control/v2" - - # Create a client object. The client can be reused for multiple calls. - client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new - parent = "projects/_/buckets/#{bucket_name}" - name= "#{parent}/anywhereCaches/#{zone}" - binding.pry - - - # Create a request. Replace the placeholder values with actual data. - request = Google::Cloud::Storage::Control::V2::UpdateAnywhereCacheRequest.new( - request_id: name - ) + # Zone where you want to create cache + # zone = "your-zone-name" + require "google/cloud/storage/control/v2" + + # Create a client object. The client can be reused for multiple calls. + client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + parent = "projects/_/buckets/#{bucket_name}" + name = "#{parent}/anywhereCaches/#{zone}" + + anywhere_cache = Google::Cloud::Storage::Control::V2::AnywhereCache.new( + name: name, + ttl: 7200 + ) + mask = Google::Protobuf::FieldMask.new paths: ["ttl"] + # Create a request. Replace the placeholder values with actual data. + request = Google::Cloud::Storage::Control::V2::UpdateAnywhereCacheRequest.new( + anywhere_cache: anywhere_cache, + update_mask: mask + ) # Call the update_anywhere_cache method. + result = client.update_anywhere_cache request - result = client.update_anywhere_cache(request1) - puts result + if result.instance_of? Gapic::Operation + puts "Anywhere cache updated" + else + puts "operation failed" + end end # [END storage_control_update_anywhere_cache] -update_anywhere_cache bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ - -# => , admission_policy: "admit-on-first-miss", state: "running", create_time: , update_time: , pending_update: false>, update_mask: , request_id: ""> -# Google::Cloud::InvalidArgumentError: 3:Please specify anywhere_cache.name in request.. debug_error_string:{UNKNOWN:Error received from peer ipv4:108.177.97.207:443 {grpc_message:"Please specify anywhere_cache.name in request.", grpc_status:3} +update_anywhere_cache bucket_name: ARGV.shift, zone: ARGV.shift if $PROGRAM_NAME == __FILE__ From 65d5833e4e457c0559ac4cbb4bbd246a3337a435 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 3 Jul 2025 08:05:02 +0000 Subject: [PATCH 07/35] adding comments --- .../storage_control_create_anywhere_cache.rb | 8 +++---- .../storage_control_disable_anywhere_cache.rb | 21 ++++++++++--------- .../storage_control_list_anywhere_caches.rb | 7 +++---- .../storage_control_pause_anywhere_cache.rb | 21 ++++++++++--------- .../storage_control_resume_anywhere_cache.rb | 14 ++++++------- .../storage_control_update_anywhere_cache.rb | 17 ++++++++------- 6 files changed, 45 insertions(+), 43 deletions(-) diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index 11f69247543c..927b25a29eb0 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -23,7 +23,7 @@ def create_anywhere_cache bucket_name:, zone: require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. - client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new parent = "projects/_/buckets/#{bucket_name}" name = "#{parent}/anywhereCaches/#{zone}" @@ -31,20 +31,20 @@ def create_anywhere_cache bucket_name:, zone: name: name, zone: zone ) + # Create a request. Replace the placeholder values with actual data. request = Google::Cloud::Storage::Control::V2::CreateAnywhereCacheRequest.new( parent: parent, anywhere_cache: anywhere_cache ) # Call the create_anywhere_cache method. - result = client.create_anywhere_cache request + result = storage_control_client.create_anywhere_cache request if result.instance_of?(Gapic::Operation) - puts "Anywhere cache created" + puts "AnywhereCache created - #{result.name}" else puts "operation failed" end end # [END storage_control_create_anywhere_cache] - create_anywhere_cache bucket_name: ARGV.shift, zone: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb index 4fea9bd7f668..e3e20e288a0b 100644 --- a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb @@ -12,28 +12,29 @@ # See the License for the specific language governing permissions and # limitations under the License. -# [START storage_control_create_anywhere_cache] -def disable_anywhere_cache bucket_name:, zone: +# [START storage_control_disable_anywhere_cache] +def disable_anywhere_cache bucket_name:, anywhere_cache_id: + require "google/cloud/storage/control/v2" + # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - # Zone where you want to create cache - # zone = "your-zone-name" - require "google/cloud/storage/control/v2" + # A value that, along with the bucket's name, uniquely identifies the cache + # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache # Create a client object. The client can be reused for multiple calls. - client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new parent = "projects/_/buckets/#{bucket_name}" - name = "#{parent}/anywhereCaches/#{zone}" + name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" # Create a request. Replace the placeholder values with actual data. request = Google::Cloud::Storage::Control::V2::DisableAnywhereCacheRequest.new( name: name ) # Call the disable_anywhere_cache method. - result = client.disable_anywhere_cache request - puts result + result = storage_control_client.disable_anywhere_cache request + puts "AnywhereCache #{result.name} #{result.state}" end -# [END storage_control_create_anywhere_cache] +# [END storage_control_disable_anywhere_cache] disable_anywhere_cache bucket_name: ARGV.shift, zone: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb index 97672a2a8747..5babbc8dce32 100644 --- a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb +++ b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb @@ -20,19 +20,18 @@ def list_anywhere_caches bucket_name: require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. - client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new parent = "projects/_/buckets/#{bucket_name}" request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new( parent: parent ) - # Call the create_anywhere_cache method. - result = client.list_anywhere_caches request + # Call the list_anywhere_caches method. + result = storage_control_client.list_anywhere_caches request result.response.anywhere_caches.each do |item| puts item.name end - end # [END storage_control_list_anywhere_caches] list_anywhere_caches bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb index 1f84462e0504..0f163c197153 100644 --- a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb @@ -13,26 +13,27 @@ # limitations under the License. # [START storage_control_create_anywhere_cache] -def pause_anywhere_cache bucket_name:, zone: +def pause_anywhere_cache bucket_name:, anywhere_cache_id: + require "google/cloud/storage/control/v2" + # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - # Zone where you want to create cache - # zone = "your-zone-name" - - require "google/cloud/storage/control/v2" + # A value that, along with the bucket's name, uniquely identifies the cache + # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache # Create a client object. The client can be reused for multiple calls. - client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new parent = "projects/_/buckets/#{bucket_name}" - name = "#{parent}/anywhereCaches/#{zone}" + name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" + # Create a request. Replace the placeholder values with actual data. request = Google::Cloud::Storage::Control::V2::PauseAnywhereCacheRequest.new( name: name ) - # Call the create_anywhere_cache method. - result = client.pause_anywhere_cache request - puts result + # Call the pause_anywhere_cache method. + result = storage_control_client.pause_anywhere_cache request + puts "AnywhereCache #{result.name} #{result.state}" end # [END storage_control_pause_anywhere_cache] diff --git a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb index 9e2abf1be2f1..a38fc7f21d0d 100644 --- a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb @@ -13,19 +13,19 @@ # limitations under the License. # [START storage_control_resume_anywhere_cache] -def resume_anywhere_cache bucket_name:, zone: +def resume_anywhere_cache bucket_name:, anywhere_cache_id: + require "google/cloud/storage/control/v2" + # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - # Zone where you want to create cache - # zone = "your-zone-name" - - require "google/cloud/storage/control/v2" + # A value that, along with the bucket's name, uniquely identifies the cache + # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache # Create a client object. The client can be reused for multiple calls. client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new parent = "projects/_/buckets/#{bucket_name}" - name = "#{parent}/anywhereCaches/#{zone}" + name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" # Create a request. Replace the placeholder values with actual data. request = Google::Cloud::Storage::Control::V2::ResumeAnywhereCacheRequest.new( @@ -33,7 +33,7 @@ def resume_anywhere_cache bucket_name:, zone: ) # Call the resume_anywhere_cache method. result = client.resume_anywhere_cache request - puts result + puts "AnywhereCache #{result.name} #{result.state}" end # [END storage_control_resume_anywhere_cache] diff --git a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb index 7bd70a08dc16..8d0ce8e4817a 100644 --- a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb @@ -13,18 +13,19 @@ # limitations under the License. # [START storage_control_update_anywhere_cache] -def update_anywhere_cache bucket_name:, zone: +def update_anywhere_cache bucket_name:, anywhere_cache_id: + require "google/cloud/storage/control/v2" + # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - # Zone where you want to create cache - # zone = "your-zone-name" - require "google/cloud/storage/control/v2" + # A value that, along with the bucket's name, uniquely identifies the cache + # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache # Create a client object. The client can be reused for multiple calls. - client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new parent = "projects/_/buckets/#{bucket_name}" - name = "#{parent}/anywhereCaches/#{zone}" + name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" anywhere_cache = Google::Cloud::Storage::Control::V2::AnywhereCache.new( name: name, @@ -37,10 +38,10 @@ def update_anywhere_cache bucket_name:, zone: update_mask: mask ) # Call the update_anywhere_cache method. - result = client.update_anywhere_cache request + result = storage_control_client.update_anywhere_cache request if result.instance_of? Gapic::Operation - puts "Anywhere cache updated" + puts "AnywhereCache updated - #{result.name}" else puts "operation failed" end From d8498e45cbd45abd12d6e615e66617b99590d767 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 3 Jul 2025 08:07:33 +0000 Subject: [PATCH 08/35] adding comment --- .../samples/storage_control_create_anywhere_cache.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index 927b25a29eb0..f7d56cb95058 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -14,14 +14,14 @@ # [START storage_control_create_anywhere_cache] def create_anywhere_cache bucket_name:, zone: + require "google/cloud/storage/control/v2" + # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" # Zone where you want to create cache # zone = "your-zone-name" - require "google/cloud/storage/control/v2" - # Create a client object. The client can be reused for multiple calls. storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new parent = "projects/_/buckets/#{bucket_name}" From 842bdf2be2371fee99c9ba9e90f527d1d92af14b Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 3 Jul 2025 08:29:08 +0000 Subject: [PATCH 09/35] updates --- .../storage_control_create_anywhere_cache.rb | 3 +++ .../storage_control_disable_anywhere_cache.rb | 5 +++- .../storage_control_get_anywhere_cache.rb | 26 ++++++++++--------- .../storage_control_list_anywhere_caches.rb | 2 ++ .../storage_control_pause_anywhere_cache.rb | 5 +++- .../storage_control_resume_anywhere_cache.rb | 5 +++- .../storage_control_update_anywhere_cache.rb | 4 ++- 7 files changed, 34 insertions(+), 16 deletions(-) diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index f7d56cb95058..ba524b3ebdb1 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -37,6 +37,9 @@ def create_anywhere_cache bucket_name:, zone: parent: parent, anywhere_cache: anywhere_cache ) + # The request creates a new cache in the specified zone. + # The cache is created in the specified bucket. + # The cache is created in the specified zone. # Call the create_anywhere_cache method. result = storage_control_client.create_anywhere_cache request diff --git a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb index e3e20e288a0b..70fc197579f7 100644 --- a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb @@ -31,10 +31,13 @@ def disable_anywhere_cache bucket_name:, anywhere_cache_id: request = Google::Cloud::Storage::Control::V2::DisableAnywhereCacheRequest.new( name: name ) + # The request disables the cache, but does not delete it. + # The cache can be re-enabled later. # Call the disable_anywhere_cache method. result = storage_control_client.disable_anywhere_cache request puts "AnywhereCache #{result.name} #{result.state}" end # [END storage_control_disable_anywhere_cache] -disable_anywhere_cache bucket_name: ARGV.shift, zone: ARGV.shift if $PROGRAM_NAME == __FILE__ +disable_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ + diff --git a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb index 3220104bc8f1..af52cc09c031 100644 --- a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb @@ -13,29 +13,31 @@ # limitations under the License. # [START storage_control_get_anywhere_cache] -def get_anywhere_cache bucket_name:, zone: +def get_anywhere_cache bucket_name:, anywhere_cache_id: + require "google/cloud/storage/control/v2" + # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - # Zone where you want to create cache - # zone = "your-zone-name" - - require "google/cloud/storage/control/v2" + # A value that, along with the bucket's name, uniquely identifies the cache + # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache # Create a client object. The client can be reused for multiple calls. - client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new parent = "projects/_/buckets/#{bucket_name}" - name = "#{parent}/anywhereCaches/#{zone}" + name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" # Create a request. Replace the placeholder values with actual data. request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( name: name ) - # Call the create_anywhere_cache method. - - result = client.get_anywhere_cache request - puts result + # The request retrieves the cache in the specified bucket. + # The cache is identified by the specified ID. + # The cache is in the specified bucket. + # Call the get_anywhere_cache method. + result = storage_control_client.get_anywhere_cache request + puts "AnywhereCache #{result.name}" end # [END storage_control_get_anywhere_cache] -get_anywhere_cache bucket_name: ARGV.shift, zone: ARGV.shift if $PROGRAM_NAME == __FILE__ \ No newline at end of file +get_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb index 5babbc8dce32..03335ff74e82 100644 --- a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb +++ b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb @@ -26,6 +26,8 @@ def list_anywhere_caches bucket_name: request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new( parent: parent ) + # The request lists all caches in the specified bucket. + # The caches are identified by the specified bucket name. # Call the list_anywhere_caches method. result = storage_control_client.list_anywhere_caches request diff --git a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb index 0f163c197153..a404caceb7c1 100644 --- a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb @@ -31,10 +31,13 @@ def pause_anywhere_cache bucket_name:, anywhere_cache_id: request = Google::Cloud::Storage::Control::V2::PauseAnywhereCacheRequest.new( name: name ) + # The request pauses the cache, but does not delete it. + # The cache can be resumed later. + # The cache is paused in the specified bucket. # Call the pause_anywhere_cache method. result = storage_control_client.pause_anywhere_cache request puts "AnywhereCache #{result.name} #{result.state}" end # [END storage_control_pause_anywhere_cache] -pause_anywhere_cache bucket_name: ARGV.shift, zone: ARGV.shift if $PROGRAM_NAME == __FILE__ +pause_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb index a38fc7f21d0d..5c40fb535aba 100644 --- a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb @@ -31,10 +31,13 @@ def resume_anywhere_cache bucket_name:, anywhere_cache_id: request = Google::Cloud::Storage::Control::V2::ResumeAnywhereCacheRequest.new( name: name ) + # The request resumes the cache, which was previously paused. + # The cache is resumed in the specified bucket. + # The cache is identified by the specified ID. # Call the resume_anywhere_cache method. result = client.resume_anywhere_cache request puts "AnywhereCache #{result.name} #{result.state}" end # [END storage_control_resume_anywhere_cache] -resume_anywhere_cache bucket_name: ARGV.shift, zone: ARGV.shift if $PROGRAM_NAME == __FILE__ +resume_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb index 8d0ce8e4817a..e577b4fa3369 100644 --- a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb @@ -37,6 +37,8 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id: anywhere_cache: anywhere_cache, update_mask: mask ) + # The request updates the cache in the specified bucket. + # The cache is identified by the specified ID. # Call the update_anywhere_cache method. result = storage_control_client.update_anywhere_cache request @@ -48,4 +50,4 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id: end # [END storage_control_update_anywhere_cache] -update_anywhere_cache bucket_name: ARGV.shift, zone: ARGV.shift if $PROGRAM_NAME == __FILE__ +update_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ From bd0b9cde90d5e7f01f908cd401b1adcf7a32a11c Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 3 Jul 2025 14:00:08 +0530 Subject: [PATCH 10/35] Update storage_control_create_anywhere_cache.rb --- .../samples/storage_control_create_anywhere_cache.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index ba524b3ebdb1..564e4b052084 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -39,7 +39,6 @@ def create_anywhere_cache bucket_name:, zone: ) # The request creates a new cache in the specified zone. # The cache is created in the specified bucket. - # The cache is created in the specified zone. # Call the create_anywhere_cache method. result = storage_control_client.create_anywhere_cache request From 3b9cda3069fce2d7460947134d72b644a43441f4 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 3 Jul 2025 14:01:03 +0530 Subject: [PATCH 11/35] Update storage_control_disable_anywhere_cache.rb --- .../samples/storage_control_disable_anywhere_cache.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb index 70fc197579f7..e898d70b7e8a 100644 --- a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb @@ -40,4 +40,3 @@ def disable_anywhere_cache bucket_name:, anywhere_cache_id: # [END storage_control_disable_anywhere_cache] disable_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ - From feb8f47cb88887c1b2a54c6bd846a1a259398b37 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 3 Jul 2025 08:34:08 +0000 Subject: [PATCH 12/35] updates --- .../samples/storage_control_disable_anywhere_cache.rb | 1 - .../samples/storage_control_get_anywhere_cache.rb | 1 - .../samples/storage_control_pause_anywhere_cache.rb | 1 - .../samples/storage_control_resume_anywhere_cache.rb | 1 - .../samples/storage_control_update_anywhere_cache.rb | 1 - 5 files changed, 5 deletions(-) diff --git a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb index e898d70b7e8a..85c2962d8777 100644 --- a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb @@ -38,5 +38,4 @@ def disable_anywhere_cache bucket_name:, anywhere_cache_id: puts "AnywhereCache #{result.name} #{result.state}" end # [END storage_control_disable_anywhere_cache] - disable_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb index af52cc09c031..f25a8362b183 100644 --- a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb @@ -39,5 +39,4 @@ def get_anywhere_cache bucket_name:, anywhere_cache_id: puts "AnywhereCache #{result.name}" end # [END storage_control_get_anywhere_cache] - get_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb index a404caceb7c1..bd77ab36f87f 100644 --- a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb @@ -39,5 +39,4 @@ def pause_anywhere_cache bucket_name:, anywhere_cache_id: puts "AnywhereCache #{result.name} #{result.state}" end # [END storage_control_pause_anywhere_cache] - pause_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb index 5c40fb535aba..f00ce446926c 100644 --- a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb @@ -39,5 +39,4 @@ def resume_anywhere_cache bucket_name:, anywhere_cache_id: puts "AnywhereCache #{result.name} #{result.state}" end # [END storage_control_resume_anywhere_cache] - resume_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb index e577b4fa3369..7184920ab8c9 100644 --- a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb @@ -49,5 +49,4 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id: end end # [END storage_control_update_anywhere_cache] - update_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ From af3c7ef340ffc9b5cfec152c0dc36b0543d287ac Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 4 Jul 2025 05:16:40 +0000 Subject: [PATCH 13/35] updates --- .../samples/storage_control_create_anywhere_cache.rb | 3 +-- .../samples/storage_control_disable_anywhere_cache.rb | 3 +-- .../samples/storage_control_get_anywhere_cache.rb | 3 +-- .../samples/storage_control_list_anywhere_caches.rb | 1 - .../samples/storage_control_pause_anywhere_cache.rb | 3 +-- .../samples/storage_control_resume_anywhere_cache.rb | 7 +++---- .../samples/storage_control_update_anywhere_cache.rb | 3 +-- 7 files changed, 8 insertions(+), 15 deletions(-) diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index 564e4b052084..0df38df93e1c 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -14,13 +14,12 @@ # [START storage_control_create_anywhere_cache] def create_anywhere_cache bucket_name:, zone: - require "google/cloud/storage/control/v2" - # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" # Zone where you want to create cache # zone = "your-zone-name" + require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new diff --git a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb index 85c2962d8777..1d7bdc1ab091 100644 --- a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb @@ -14,13 +14,12 @@ # [START storage_control_disable_anywhere_cache] def disable_anywhere_cache bucket_name:, anywhere_cache_id: - require "google/cloud/storage/control/v2" - # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache + require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new diff --git a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb index f25a8362b183..f7420739187e 100644 --- a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb @@ -14,13 +14,12 @@ # [START storage_control_get_anywhere_cache] def get_anywhere_cache bucket_name:, anywhere_cache_id: - require "google/cloud/storage/control/v2" - # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache + require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new diff --git a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb index 03335ff74e82..4e17cea3d53a 100644 --- a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb +++ b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb @@ -16,7 +16,6 @@ def list_anywhere_caches bucket_name: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. diff --git a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb index bd77ab36f87f..16fd0d60a1d0 100644 --- a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb @@ -14,13 +14,12 @@ # [START storage_control_create_anywhere_cache] def pause_anywhere_cache bucket_name:, anywhere_cache_id: - require "google/cloud/storage/control/v2" - # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache + require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new diff --git a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb index f00ce446926c..dba458215b1c 100644 --- a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb @@ -14,16 +14,15 @@ # [START storage_control_resume_anywhere_cache] def resume_anywhere_cache bucket_name:, anywhere_cache_id: - require "google/cloud/storage/control/v2" - # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache + require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. - client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new parent = "projects/_/buckets/#{bucket_name}" name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" @@ -35,7 +34,7 @@ def resume_anywhere_cache bucket_name:, anywhere_cache_id: # The cache is resumed in the specified bucket. # The cache is identified by the specified ID. # Call the resume_anywhere_cache method. - result = client.resume_anywhere_cache request + result = storage_control_client.resume_anywhere_cache request puts "AnywhereCache #{result.name} #{result.state}" end # [END storage_control_resume_anywhere_cache] diff --git a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb index 7184920ab8c9..5ab886753c96 100644 --- a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb @@ -14,13 +14,12 @@ # [START storage_control_update_anywhere_cache] def update_anywhere_cache bucket_name:, anywhere_cache_id: - require "google/cloud/storage/control/v2" - # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache + require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new From e69000b9a36825e6073cf6c606f5141445701b21 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 4 Jul 2025 14:26:00 +0530 Subject: [PATCH 14/35] Update storage_control_create_anywhere_cache.rb --- .../samples/storage_control_create_anywhere_cache.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index 0df38df93e1c..faa75b841bfa 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -41,7 +41,7 @@ def create_anywhere_cache bucket_name:, zone: # Call the create_anywhere_cache method. result = storage_control_client.create_anywhere_cache request - if result.instance_of?(Gapic::Operation) + if result.instance_of? Gapic::Operation puts "AnywhereCache created - #{result.name}" else puts "operation failed" From 808d1e95d42a331f3df0455cc2ff37f2e9383a8f Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 4 Jul 2025 14:34:20 +0530 Subject: [PATCH 15/35] Update storage_control_pause_anywhere_cache.rb --- .../samples/storage_control_pause_anywhere_cache.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb index 16fd0d60a1d0..36201dd34280 100644 --- a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# [START storage_control_create_anywhere_cache] +# [START storage_control_pause_anywhere_cache] def pause_anywhere_cache bucket_name:, anywhere_cache_id: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" From 54f2c1444da63fb211faf094e773890909b165fc Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 4 Jul 2025 10:59:17 +0000 Subject: [PATCH 16/35] updating --- .../samples/storage_control_disable_anywhere_cache.rb | 2 +- .../samples/storage_control_get_anywhere_cache.rb | 2 +- .../samples/storage_control_pause_anywhere_cache.rb | 2 +- .../samples/storage_control_resume_anywhere_cache.rb | 2 +- .../samples/storage_control_update_anywhere_cache.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb index 1d7bdc1ab091..2b258df6d344 100644 --- a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb @@ -18,7 +18,7 @@ def disable_anywhere_cache bucket_name:, anywhere_cache_id: # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache - # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache + # anywhere_cache_id = "us-east1-b" require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. diff --git a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb index f7420739187e..961b55893391 100644 --- a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb @@ -18,7 +18,7 @@ def get_anywhere_cache bucket_name:, anywhere_cache_id: # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache - # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache + # anywhere_cache_id = "us-east1-b" require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. diff --git a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb index 36201dd34280..7b8a9e1cb12a 100644 --- a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb @@ -18,7 +18,7 @@ def pause_anywhere_cache bucket_name:, anywhere_cache_id: # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache - # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache + # anywhere_cache_id = "us-east1-b" require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. diff --git a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb index dba458215b1c..dec58b50c16c 100644 --- a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb @@ -18,7 +18,7 @@ def resume_anywhere_cache bucket_name:, anywhere_cache_id: # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache - # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache + # anywhere_cache_id = "us-east1-b" require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. diff --git a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb index 5ab886753c96..bf3a911d815d 100644 --- a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb @@ -18,7 +18,7 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id: # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache - # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache + # anywhere_cache_id = "us-east1-b" require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. From 7edf04da491f69d6690e344e432678d0edf23a29 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 11 Jul 2025 11:44:39 +0000 Subject: [PATCH 17/35] removing reference for V2 library --- google-cloud-storage-control/README.md | 5 +++++ .../storage_control_create_anywhere_cache.rb | 18 ++++++++---------- .../storage_control_disable_anywhere_cache.rb | 16 ++++++++++------ .../storage_control_get_anywhere_cache.rb | 15 ++++++++++----- .../storage_control_list_anywhere_caches.rb | 17 ++++++++++------- .../storage_control_pause_anywhere_cache.rb | 14 +++++++++----- .../storage_control_resume_anywhere_cache.rb | 16 ++++++++++------ .../storage_control_update_anywhere_cache.rb | 16 ++++++++-------- 8 files changed, 70 insertions(+), 47 deletions(-) diff --git a/google-cloud-storage-control/README.md b/google-cloud-storage-control/README.md index d93efd496b40..7dab4f4c40d7 100644 --- a/google-cloud-storage-control/README.md +++ b/google-cloud-storage-control/README.md @@ -132,3 +132,8 @@ The `google-apis-` clients have wide coverage across Google services, so you might need to use one if there is no modern client available for the service. However, if a modern client is available, we generally recommend it over the older `google-apis-` clients. + +## Note + +Tests for Anywhere cache Sample are not included due to the long operation times typical for cache operations. + diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index faa75b841bfa..9bc1f977af1f 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -13,16 +13,17 @@ # limitations under the License. # [START storage_control_create_anywhere_cache] +require "google/cloud/storage/control" + def create_anywhere_cache bucket_name:, zone: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" # Zone where you want to create cache # zone = "your-zone-name" - require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. - storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + storage_control_client = Google::Cloud::Storage::Control.storage_control parent = "projects/_/buckets/#{bucket_name}" name = "#{parent}/anywhereCaches/#{zone}" @@ -30,21 +31,18 @@ def create_anywhere_cache bucket_name:, zone: name: name, zone: zone ) - - # Create a request. Replace the placeholder values with actual data. + # Create a request. request = Google::Cloud::Storage::Control::V2::CreateAnywhereCacheRequest.new( parent: parent, anywhere_cache: anywhere_cache ) # The request creates a new cache in the specified zone. # The cache is created in the specified bucket. - # Call the create_anywhere_cache method. - result = storage_control_client.create_anywhere_cache request - - if result.instance_of? Gapic::Operation + begin + result = storage_control_client.create_anywhere_cache request puts "AnywhereCache created - #{result.name}" - else - puts "operation failed" + rescue StandardError => e + puts "Error creating AnywhereCache: #{e.message}" end end # [END storage_control_create_anywhere_cache] diff --git a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb index 2b258df6d344..4b60c0853f33 100644 --- a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb @@ -13,28 +13,32 @@ # limitations under the License. # [START storage_control_disable_anywhere_cache] +require "google/cloud/storage/control" + def disable_anywhere_cache bucket_name:, anywhere_cache_id: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache # anywhere_cache_id = "us-east1-b" - require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. - storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + storage_control_client = Google::Cloud::Storage::Control.storage_control parent = "projects/_/buckets/#{bucket_name}" name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" - # Create a request. Replace the placeholder values with actual data. + # Create a request. request = Google::Cloud::Storage::Control::V2::DisableAnywhereCacheRequest.new( name: name ) # The request disables the cache, but does not delete it. # The cache can be re-enabled later. - # Call the disable_anywhere_cache method. - result = storage_control_client.disable_anywhere_cache request - puts "AnywhereCache #{result.name} #{result.state}" + begin + result = storage_control_client.disable_anywhere_cache request + puts "AnywhereCache #{result.name} #{result.state}" + rescue StandardError => e + puts "Error disabling AnywhereCache: #{e.message}" + end end # [END storage_control_disable_anywhere_cache] disable_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb index 961b55893391..16003168343e 100644 --- a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb @@ -13,16 +13,17 @@ # limitations under the License. # [START storage_control_get_anywhere_cache] +require "google/cloud/storage/control" + def get_anywhere_cache bucket_name:, anywhere_cache_id: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache # anywhere_cache_id = "us-east1-b" - require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. - storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + storage_control_client = Google::Cloud::Storage::Control.storage_control parent = "projects/_/buckets/#{bucket_name}" name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" @@ -33,9 +34,13 @@ def get_anywhere_cache bucket_name:, anywhere_cache_id: # The request retrieves the cache in the specified bucket. # The cache is identified by the specified ID. # The cache is in the specified bucket. - # Call the get_anywhere_cache method. - result = storage_control_client.get_anywhere_cache request - puts "AnywhereCache #{result.name}" + + begin + result = storage_control_client.get_anywhere_cache request + puts "AnywhereCache fetched - #{result.name}" + rescue StandardError => e + puts "Error fetching AnywhereCache: #{e.message}" + end end # [END storage_control_get_anywhere_cache] get_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb index 4e17cea3d53a..e97bfa494bdd 100644 --- a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb +++ b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb @@ -13,13 +13,14 @@ # limitations under the License. # [START storage_control_list_anywhere_caches] +require "google/cloud/storage/control" + def list_anywhere_caches bucket_name: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. - storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + storage_control_client = Google::Cloud::Storage::Control.storage_control parent = "projects/_/buckets/#{bucket_name}" request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new( @@ -27,11 +28,13 @@ def list_anywhere_caches bucket_name: ) # The request lists all caches in the specified bucket. # The caches are identified by the specified bucket name. - # Call the list_anywhere_caches method. - result = storage_control_client.list_anywhere_caches request - - result.response.anywhere_caches.each do |item| - puts item.name + begin + result = storage_control_client.list_anywhere_caches request + result.response.anywhere_caches.each do |item| + puts item.name + end + rescue StandardError => e + puts "Error listing AnywhereCaches: #{e.message}" end end # [END storage_control_list_anywhere_caches] diff --git a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb index 7b8a9e1cb12a..c8ec52d798d9 100644 --- a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb @@ -13,16 +13,17 @@ # limitations under the License. # [START storage_control_pause_anywhere_cache] +require "google/cloud/storage/control" + def pause_anywhere_cache bucket_name:, anywhere_cache_id: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache # anywhere_cache_id = "us-east1-b" - require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. - storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + storage_control_client = Google::Cloud::Storage::Control.storage_control parent = "projects/_/buckets/#{bucket_name}" name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" @@ -33,9 +34,12 @@ def pause_anywhere_cache bucket_name:, anywhere_cache_id: # The request pauses the cache, but does not delete it. # The cache can be resumed later. # The cache is paused in the specified bucket. - # Call the pause_anywhere_cache method. - result = storage_control_client.pause_anywhere_cache request - puts "AnywhereCache #{result.name} #{result.state}" + begin + result = storage_control_client.pause_anywhere_cache request + puts "AnywhereCache #{result.name} #{result.state}" + rescue StandardError => e + puts "Error pausing AnywhereCache: #{e.message}" + end end # [END storage_control_pause_anywhere_cache] pause_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb index dec58b50c16c..ab05838de4b3 100644 --- a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb @@ -13,29 +13,33 @@ # limitations under the License. # [START storage_control_resume_anywhere_cache] +require "google/cloud/storage/control" + def resume_anywhere_cache bucket_name:, anywhere_cache_id: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache # anywhere_cache_id = "us-east1-b" - require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. - storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + storage_control_client = Google::Cloud::Storage::Control.storage_control parent = "projects/_/buckets/#{bucket_name}" name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" - # Create a request. Replace the placeholder values with actual data. + # Create a request. request = Google::Cloud::Storage::Control::V2::ResumeAnywhereCacheRequest.new( name: name ) # The request resumes the cache, which was previously paused. # The cache is resumed in the specified bucket. # The cache is identified by the specified ID. - # Call the resume_anywhere_cache method. - result = storage_control_client.resume_anywhere_cache request - puts "AnywhereCache #{result.name} #{result.state}" + begin + result = storage_control_client.resume_anywhere_cache request + puts "AnywhereCache #{result.name} #{result.state}" + rescue StandardError => e + puts "Error resuming AnywhereCache: #{e.message}" + end end # [END storage_control_resume_anywhere_cache] resume_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ diff --git a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb index bf3a911d815d..e9621c3b15a7 100644 --- a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb @@ -13,6 +13,8 @@ # limitations under the License. # [START storage_control_update_anywhere_cache] +require "google/cloud/storage/control" + def update_anywhere_cache bucket_name:, anywhere_cache_id: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" @@ -22,7 +24,7 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id: require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. - storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new + storage_control_client = Google::Cloud::Storage::Control.storage_control parent = "projects/_/buckets/#{bucket_name}" name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" @@ -31,20 +33,18 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id: ttl: 7200 ) mask = Google::Protobuf::FieldMask.new paths: ["ttl"] - # Create a request. Replace the placeholder values with actual data. + # Create a request. request = Google::Cloud::Storage::Control::V2::UpdateAnywhereCacheRequest.new( anywhere_cache: anywhere_cache, update_mask: mask ) # The request updates the cache in the specified bucket. # The cache is identified by the specified ID. - # Call the update_anywhere_cache method. - result = storage_control_client.update_anywhere_cache request - - if result.instance_of? Gapic::Operation + begin + result = storage_control_client.update_anywhere_cache request puts "AnywhereCache updated - #{result.name}" - else - puts "operation failed" + rescue StandardError => e + puts "Error updating AnywhereCache: #{e.message}" end end # [END storage_control_update_anywhere_cache] From 4b4d0a68acd0019dfe447db4e1416c3d842067ce Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 15 Jul 2025 07:59:56 +0000 Subject: [PATCH 18/35] fix lint --- .../samples/storage_control_list_anywhere_caches.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb index e97bfa494bdd..fa9bc2cd25d6 100644 --- a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb +++ b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb @@ -29,10 +29,10 @@ def list_anywhere_caches bucket_name: # The request lists all caches in the specified bucket. # The caches are identified by the specified bucket name. begin - result = storage_control_client.list_anywhere_caches request - result.response.anywhere_caches.each do |item| - puts item.name - end + result = storage_control_client.list_anywhere_caches request + result.response.anywhere_caches.each do |item| + puts item.name + end rescue StandardError => e puts "Error listing AnywhereCaches: #{e.message}" end From 90f3a0bbb966896559d2156dfef4f8e95cbff570 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 1 Aug 2025 13:34:26 +0530 Subject: [PATCH 19/35] Update storage_control_update_anywhere_cache.rb --- .../samples/storage_control_update_anywhere_cache.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb index e9621c3b15a7..4496a56fe003 100644 --- a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb @@ -18,7 +18,6 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" - # A value that, along with the bucket's name, uniquely identifies the cache # anywhere_cache_id = "us-east1-b" require "google/cloud/storage/control/v2" From 93af0da8c4364e2ba2a9bcb48e0dcaeb548eab39 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 2 Sep 2025 13:20:50 +0000 Subject: [PATCH 20/35] try refreshing operation status --- .../storage_control_anywhere_cache_test.rb | 89 +++++++++++++++++++ .../storage_control_create_anywhere_cache.rb | 11 ++- 2 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb diff --git a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb new file mode 100644 index 000000000000..1daf50b3fa22 --- /dev/null +++ b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb @@ -0,0 +1,89 @@ +# Copyright 2025 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 +# +# http://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. + +require_relative "helper" +require_relative "../storage_control_create_anywhere_cache" +require_relative "../storage_control_list_anywhere_caches" +require_relative "../storage_control_get_anywhere_cache" +require_relative "../storage_control_update_anywhere_cache" +require_relative "../storage_control_pause_anywhere_cache" +require_relative "../storage_control_resume_anywhere_cache" +require_relative "../storage_control_disable_anywhere_cache" + +# require 'pry' + +describe "Storage Control Anywhere Cache" do + let(:bucket_name) { random_bucket_name } + let(:storage_client) { Google::Cloud::Storage.new } + let(:zone) {'us-east1-b'} +# let(:zone) {@bucket.location} + + before :all do + @bucket= storage_client.bucket bucket_name + @bucket = create_bucket_helper bucket_name + end + + # after do + # delete_bucket_helper bucket_name + # end + + it "create Anywhere cache" do + create_anywhere_cache bucket_name: bucket_name, zone: zone + end + + # it "list Anywhere cache" do + # # create_anywhere_cache bucket_name: bucket_name, zone: zone + + # out, _err = capture_io do + # list_anywhere_caches bucket_name: bucket_name + # end + + # assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" + # end + + # it "Get Anywhere cache" do + # out, _err = capture_io do + # get_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone + # end + # assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" + # end + + # it "Pause Anywhere cache" do + # out, _err = capture_io do + # pause_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone + # end + # assert_includes out, "#{bucket_name}/anywhereCaches/#{zone} paused" + # end + + # it "Resume Anywhere cache" do + # out, _err = capture_io do + # resume_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone + # end + # assert_includes out, "#{bucket_name}/anywhereCaches/#{zone} running" + # end + + # it "Disable Anywhere cache" do + # out, _err = capture_io do + # disable_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone + # end + # assert_includes out, "#{bucket_name}/anywhereCaches/#{zone} disabled" + # end + + # it "Update Anywhere cache" do + # out, _err = capture_io do + # update_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone + # end + # assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" + # end +end \ No newline at end of file diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index 9bc1f977af1f..c6f36400bd11 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -39,8 +39,15 @@ def create_anywhere_cache bucket_name:, zone: # The request creates a new cache in the specified zone. # The cache is created in the specified bucket. begin - result = storage_control_client.create_anywhere_cache request - puts "AnywhereCache created - #{result.name}" + operation = storage_control_client.create_anywhere_cache request + + puts "********************AnywhereCache operation created - #{operation.name}" + while !operation.done? + sleep 3600 # Wait for 1 hour before checking again + operation.refresh! + end + puts "********************AnywhereCache create operation completed - #{operation.name}" + rescue StandardError => e puts "Error creating AnywhereCache: #{e.message}" end From 2b29efc3f5ebcb543a110819afb70ab3d6c252c2 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 2 Sep 2025 13:59:46 +0000 Subject: [PATCH 21/35] try operation refresh --- .../samples/storage_control_create_anywhere_cache.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index c6f36400bd11..b849885879f7 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -43,8 +43,10 @@ def create_anywhere_cache bucket_name:, zone: puts "********************AnywhereCache operation created - #{operation.name}" while !operation.done? - sleep 3600 # Wait for 1 hour before checking again + sleep 1800 # Wait for 1/2 hour before checking again operation.refresh! + puts "********************AnywhereCache operation refreshed" + puts "********************AnywhereCache operation status check retried" end puts "********************AnywhereCache create operation completed - #{operation.name}" From b78928fd6857f442e29d5c33acacff4d3202ecc0 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 2 Sep 2025 17:28:11 +0000 Subject: [PATCH 22/35] try get request --- .../storage_control_create_anywhere_cache.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index b849885879f7..f701e1746678 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -40,13 +40,20 @@ def create_anywhere_cache bucket_name:, zone: # The cache is created in the specified bucket. begin operation = storage_control_client.create_anywhere_cache request + if operation.response? == false puts "********************AnywhereCache operation created - #{operation.name}" - while !operation.done? - sleep 1800 # Wait for 1/2 hour before checking again - operation.refresh! - puts "********************AnywhereCache operation refreshed" - puts "********************AnywhereCache operation status check retried" + if !operation.done? + get_request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( + name: name + ) + result = storage_control_client.get_anywhere_cache get_request + while result.state == "creating" + sleep 1800 # Wait for 1/2 hour before checking again + result = storage_control_client.get_anywhere_cache get_request + puts "********************AnywhereCache operation refreshed" + puts "********************AnywhereCache operation status check retried" + end end puts "********************AnywhereCache create operation completed - #{operation.name}" From b6020d3c1a55dc7aaef96a9e581013b968a4c9ab Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 3 Sep 2025 04:34:09 +0000 Subject: [PATCH 23/35] fix syntax error --- .../storage_control_create_anywhere_cache.rb | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index f701e1746678..f52fca0f994b 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -42,17 +42,18 @@ def create_anywhere_cache bucket_name:, zone: operation = storage_control_client.create_anywhere_cache request if operation.response? == false - puts "********************AnywhereCache operation created - #{operation.name}" - if !operation.done? - get_request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( - name: name - ) - result = storage_control_client.get_anywhere_cache get_request - while result.state == "creating" - sleep 1800 # Wait for 1/2 hour before checking again + puts "********************AnywhereCache operation created - #{operation.name}" + if !operation.done? + get_request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( + name: name + ) result = storage_control_client.get_anywhere_cache get_request - puts "********************AnywhereCache operation refreshed" - puts "********************AnywhereCache operation status check retried" + while result.state == "creating" + sleep 1800 # Wait for 1/2 hour before checking again + result = storage_control_client.get_anywhere_cache get_request + puts "********************AnywhereCache operation refreshed" + puts "********************AnywhereCache operation status check retried" + end end end puts "********************AnywhereCache create operation completed - #{operation.name}" From fecdaa6302b74e2e3decafd44874d19b9b47bb5f Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Sun, 7 Sep 2025 20:48:02 +0000 Subject: [PATCH 24/35] updating test cases with delay --- google-cloud-storage-control/README.md | 4 - .../storage_control_anywhere_cache_test.rb | 100 +++++++++--------- .../storage_control_create_anywhere_cache.rb | 28 +++-- .../storage_control_disable_anywhere_cache.rb | 5 +- .../storage_control_get_anywhere_cache.rb | 7 +- .../storage_control_list_anywhere_caches.rb | 4 +- .../storage_control_pause_anywhere_cache.rb | 5 +- .../storage_control_resume_anywhere_cache.rb | 1 + .../storage_control_update_anywhere_cache.rb | 19 +++- 9 files changed, 91 insertions(+), 82 deletions(-) diff --git a/google-cloud-storage-control/README.md b/google-cloud-storage-control/README.md index 7dab4f4c40d7..323ec9eee31d 100644 --- a/google-cloud-storage-control/README.md +++ b/google-cloud-storage-control/README.md @@ -133,7 +133,3 @@ might need to use one if there is no modern client available for the service. However, if a modern client is available, we generally recommend it over the older `google-apis-` clients. -## Note - -Tests for Anywhere cache Sample are not included due to the long operation times typical for cache operations. - diff --git a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb index 1daf50b3fa22..1783119eca7a 100644 --- a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb +++ b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb @@ -13,6 +13,7 @@ # limitations under the License. require_relative "helper" +require "google/cloud/storage/control" require_relative "../storage_control_create_anywhere_cache" require_relative "../storage_control_list_anywhere_caches" require_relative "../storage_control_get_anywhere_cache" @@ -21,69 +22,66 @@ require_relative "../storage_control_resume_anywhere_cache" require_relative "../storage_control_disable_anywhere_cache" -# require 'pry' - describe "Storage Control Anywhere Cache" do let(:bucket_name) { random_bucket_name } - let(:storage_client) { Google::Cloud::Storage.new } - let(:zone) {'us-east1-b'} -# let(:zone) {@bucket.location} + let(:zone) { "us-east1-b" } + # Set project to "_" to signify global bucket + let(:anywhere_cache_name) { "projects/_/buckets/#{bucket_name}/anywhereCaches/#{zone}" } before :all do - @bucket= storage_client.bucket bucket_name - @bucket = create_bucket_helper bucket_name + @bucket = create_bucket_helper bucket_name end - # after do - # delete_bucket_helper bucket_name - # end - - it "create Anywhere cache" do - create_anywhere_cache bucket_name: bucket_name, zone: zone + after do + delete_bucket_helper bucket_name until count_anywhere_caches bucket_name == 0 end - # it "list Anywhere cache" do - # # create_anywhere_cache bucket_name: bucket_name, zone: zone + it "handles Anywhere cache lifecycle in sequence" do + out_create, _err = capture_io do + create_anywhere_cache bucket_name: bucket_name, zone: zone + end + assert_includes out_create, "AnywhereCache created - #{anywhere_cache_name}" - # out, _err = capture_io do - # list_anywhere_caches bucket_name: bucket_name - # end + out_list, _err = capture_io do + list_anywhere_caches bucket_name: bucket_name + end + assert_includes out_list, "AnywhereCache #{anywhere_cache_name} found in list" - # assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" - # end + out_get, _err = capture_io do + get_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone + end + assert_includes out_get, "AnywhereCache #{anywhere_cache_name} fetched" - # it "Get Anywhere cache" do - # out, _err = capture_io do - # get_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone - # end - # assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" - # end + out_update, _err = capture_io do + update_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone + end + assert_includes out_update, "AnywhereCache #{anywhere_cache_name} updated" - # it "Pause Anywhere cache" do - # out, _err = capture_io do - # pause_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone - # end - # assert_includes out, "#{bucket_name}/anywhereCaches/#{zone} paused" - # end + out_pause, _err = capture_io do + pause_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone + end + assert_includes out_pause, "AnywhereCache #{anywhere_cache_name} paused" - # it "Resume Anywhere cache" do - # out, _err = capture_io do - # resume_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone - # end - # assert_includes out, "#{bucket_name}/anywhereCaches/#{zone} running" - # end + out_resume, _err = capture_io do + resume_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone + end + assert_includes out_resume, "AnywhereCache #{anywhere_cache_name} running" - # it "Disable Anywhere cache" do - # out, _err = capture_io do - # disable_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone - # end - # assert_includes out, "#{bucket_name}/anywhereCaches/#{zone} disabled" - # end + out_disable, _err = capture_io do + disable_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone + end + assert_includes out_disable, "AnywhereCache #{anywhere_cache_name} disabled" + end +end - # it "Update Anywhere cache" do - # out, _err = capture_io do - # update_anywhere_cache bucket_name: bucket_name, anywhere_cache_id: zone - # end - # assert_includes out, "#{bucket_name}/anywhereCaches/#{zone}" - # end -end \ No newline at end of file +def count_anywhere_caches bucket_name + sleep 900 + storage_control_client = Google::Cloud::Storage::Control.storage_control + # Set project to "_" to signify global bucket + parent = "projects/_/buckets/#{bucket_name}" + request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new( + parent: parent + ) + result = storage_control_client.list_anywhere_caches request + result.response.anywhere_caches.count +end diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index f52fca0f994b..4954e8316855 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -24,6 +24,7 @@ def create_anywhere_cache bucket_name:, zone: # Create a client object. The client can be reused for multiple calls. storage_control_client = Google::Cloud::Storage::Control.storage_control + # Set project to "_" to signify global bucket parent = "projects/_/buckets/#{bucket_name}" name = "#{parent}/anywhereCaches/#{zone}" @@ -40,24 +41,21 @@ def create_anywhere_cache bucket_name:, zone: # The cache is created in the specified bucket. begin operation = storage_control_client.create_anywhere_cache request - if operation.response? == false - - puts "********************AnywhereCache operation created - #{operation.name}" - if !operation.done? - get_request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( - name: name - ) + if operation.class == Gapic::Operation + puts "AnywhereCache operation created - #{operation.name}" + get_request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( + name: name + ) + result = storage_control_client.get_anywhere_cache get_request + until result.state == "running" + sleep 1800 # Wait for 1/2 hour before checking again result = storage_control_client.get_anywhere_cache get_request - while result.state == "creating" - sleep 1800 # Wait for 1/2 hour before checking again - result = storage_control_client.get_anywhere_cache get_request - puts "********************AnywhereCache operation refreshed" - puts "********************AnywhereCache operation status check retried" - end + puts "AnywhereCache status check retried" end + puts "AnywhereCache created - #{result.name}" + else + puts "AnywhereCache create operation failed" end - puts "********************AnywhereCache create operation completed - #{operation.name}" - rescue StandardError => e puts "Error creating AnywhereCache: #{e.message}" end diff --git a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb index 4b60c0853f33..808de2531f57 100644 --- a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb @@ -24,8 +24,9 @@ def disable_anywhere_cache bucket_name:, anywhere_cache_id: # Create a client object. The client can be reused for multiple calls. storage_control_client = Google::Cloud::Storage::Control.storage_control + # Set project to "_" to signify global bucket parent = "projects/_/buckets/#{bucket_name}" - name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" + name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" # Create a request. request = Google::Cloud::Storage::Control::V2::DisableAnywhereCacheRequest.new( @@ -35,7 +36,7 @@ def disable_anywhere_cache bucket_name:, anywhere_cache_id: # The cache can be re-enabled later. begin result = storage_control_client.disable_anywhere_cache request - puts "AnywhereCache #{result.name} #{result.state}" + puts "AnywhereCache #{result.name} #{result.state} " rescue StandardError => e puts "Error disabling AnywhereCache: #{e.message}" end diff --git a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb index 16003168343e..b5ac9195a829 100644 --- a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb @@ -24,10 +24,11 @@ def get_anywhere_cache bucket_name:, anywhere_cache_id: # Create a client object. The client can be reused for multiple calls. storage_control_client = Google::Cloud::Storage::Control.storage_control + # Set project to "_" to signify global bucket parent = "projects/_/buckets/#{bucket_name}" - name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" + name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" - # Create a request. Replace the placeholder values with actual data. + # Create a request. request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( name: name ) @@ -37,7 +38,7 @@ def get_anywhere_cache bucket_name:, anywhere_cache_id: begin result = storage_control_client.get_anywhere_cache request - puts "AnywhereCache fetched - #{result.name}" + puts "AnywhereCache #{result.name} fetched" rescue StandardError => e puts "Error fetching AnywhereCache: #{e.message}" end diff --git a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb index fa9bc2cd25d6..3a4aec820cb5 100644 --- a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb +++ b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb @@ -21,8 +21,10 @@ def list_anywhere_caches bucket_name: # Create a client object. The client can be reused for multiple calls. storage_control_client = Google::Cloud::Storage::Control.storage_control + # Set project to "_" to signify global bucket parent = "projects/_/buckets/#{bucket_name}" + # Create a request. request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new( parent: parent ) @@ -31,7 +33,7 @@ def list_anywhere_caches bucket_name: begin result = storage_control_client.list_anywhere_caches request result.response.anywhere_caches.each do |item| - puts item.name + puts "AnywhereCache #{item.name} found in list" end rescue StandardError => e puts "Error listing AnywhereCaches: #{e.message}" diff --git a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb index c8ec52d798d9..0a48f7691a61 100644 --- a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb @@ -24,10 +24,11 @@ def pause_anywhere_cache bucket_name:, anywhere_cache_id: # Create a client object. The client can be reused for multiple calls. storage_control_client = Google::Cloud::Storage::Control.storage_control + # Set project to "_" to signify global bucket parent = "projects/_/buckets/#{bucket_name}" - name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" + name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" - # Create a request. Replace the placeholder values with actual data. + # Create a request. request = Google::Cloud::Storage::Control::V2::PauseAnywhereCacheRequest.new( name: name ) diff --git a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb index ab05838de4b3..a9154bb68247 100644 --- a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb @@ -25,6 +25,7 @@ def resume_anywhere_cache bucket_name:, anywhere_cache_id: # Create a client object. The client can be reused for multiple calls. storage_control_client = Google::Cloud::Storage::Control.storage_control parent = "projects/_/buckets/#{bucket_name}" + # Set project to "_" to signify global bucket name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" # Create a request. diff --git a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb index 4496a56fe003..97317c4d9907 100644 --- a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb @@ -14,22 +14,24 @@ # [START storage_control_update_anywhere_cache] require "google/cloud/storage/control" +require "google/cloud/storage/control/v2" def update_anywhere_cache bucket_name:, anywhere_cache_id: # The ID of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache # anywhere_cache_id = "us-east1-b" - require "google/cloud/storage/control/v2" # Create a client object. The client can be reused for multiple calls. storage_control_client = Google::Cloud::Storage::Control.storage_control + # Set project to "_" to signify global bucket parent = "projects/_/buckets/#{bucket_name}" name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" + ttl_in_seconds= 7200 anywhere_cache = Google::Cloud::Storage::Control::V2::AnywhereCache.new( name: name, - ttl: 7200 + ttl: ttl_in_seconds ) mask = Google::Protobuf::FieldMask.new paths: ["ttl"] # Create a request. @@ -40,8 +42,17 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id: # The request updates the cache in the specified bucket. # The cache is identified by the specified ID. begin - result = storage_control_client.update_anywhere_cache request - puts "AnywhereCache updated - #{result.name}" + operation = storage_control_client.update_anywhere_cache request + if operation.class == Gapic::Operation + puts "AnywhereCache operation created - #{operation.name}" + get_request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( + name: name + ) + result = storage_control_client.get_anywhere_cache get_request + puts "AnywhereCache #{result.name} updated" if operation.class == Gapic::Operation + else + puts "AnywhereCache update operation failed" + end rescue StandardError => e puts "Error updating AnywhereCache: #{e.message}" end From 78b6dbf6b4b041c222350610ab0e252b43de4331 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Sun, 7 Sep 2025 20:58:29 +0000 Subject: [PATCH 25/35] fix lint issue --- .../acceptance/storage_control_anywhere_cache_test.rb | 2 +- .../samples/storage_control_create_anywhere_cache.rb | 2 +- .../samples/storage_control_update_anywhere_cache.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb index 1783119eca7a..9d4287929849 100644 --- a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb +++ b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb @@ -33,7 +33,7 @@ end after do - delete_bucket_helper bucket_name until count_anywhere_caches bucket_name == 0 + delete_bucket_helper(bucket_name) until count_anywhere_caches(bucket_name) == 0 end it "handles Anywhere cache lifecycle in sequence" do diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index 4954e8316855..6fb9f60fee5f 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -41,7 +41,7 @@ def create_anywhere_cache bucket_name:, zone: # The cache is created in the specified bucket. begin operation = storage_control_client.create_anywhere_cache request - if operation.class == Gapic::Operation + if operation.instance_of?(Gapic::Operation) puts "AnywhereCache operation created - #{operation.name}" get_request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( name: name diff --git a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb index 97317c4d9907..0aaacf03e49b 100644 --- a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb @@ -27,7 +27,7 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id: # Set project to "_" to signify global bucket parent = "projects/_/buckets/#{bucket_name}" name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" - ttl_in_seconds= 7200 + ttl_in_seconds = 7200 anywhere_cache = Google::Cloud::Storage::Control::V2::AnywhereCache.new( name: name, @@ -43,13 +43,13 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id: # The cache is identified by the specified ID. begin operation = storage_control_client.update_anywhere_cache request - if operation.class == Gapic::Operation + if operation.instance_of?(Gapic::Operation) puts "AnywhereCache operation created - #{operation.name}" get_request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( name: name ) result = storage_control_client.get_anywhere_cache get_request - puts "AnywhereCache #{result.name} updated" if operation.class == Gapic::Operation + puts "AnywhereCache #{result.name} updated" else puts "AnywhereCache update operation failed" end From cecd6d922f8a8a5427bbafb8c543932d2dbcdd54 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Sun, 7 Sep 2025 21:03:46 +0000 Subject: [PATCH 26/35] lint fix --- .../samples/acceptance/storage_control_anywhere_cache_test.rb | 2 +- .../samples/storage_control_create_anywhere_cache.rb | 2 +- .../samples/storage_control_update_anywhere_cache.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb index 9d4287929849..ac4f07be954e 100644 --- a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb +++ b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb @@ -33,7 +33,7 @@ end after do - delete_bucket_helper(bucket_name) until count_anywhere_caches(bucket_name) == 0 + delete_bucket_helper bucket_name until count_anywhere_caches(bucket_name).zero? end it "handles Anywhere cache lifecycle in sequence" do diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index 6fb9f60fee5f..4eb4aa172523 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -41,7 +41,7 @@ def create_anywhere_cache bucket_name:, zone: # The cache is created in the specified bucket. begin operation = storage_control_client.create_anywhere_cache request - if operation.instance_of?(Gapic::Operation) + if operation.instance_of? Gapic::Operation puts "AnywhereCache operation created - #{operation.name}" get_request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( name: name diff --git a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb index 0aaacf03e49b..1527c809e33d 100644 --- a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb @@ -43,13 +43,13 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id: # The cache is identified by the specified ID. begin operation = storage_control_client.update_anywhere_cache request - if operation.instance_of?(Gapic::Operation) + if operation.instance_of? Gapic::Operation puts "AnywhereCache operation created - #{operation.name}" get_request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( name: name ) result = storage_control_client.get_anywhere_cache get_request - puts "AnywhereCache #{result.name} updated" + puts "AnywhereCache #{result.name} updated" else puts "AnywhereCache update operation failed" end From 6415ed657aaee4b13afc08e1aa31cc12b7c5a15b Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 19 Sep 2025 07:13:47 +0000 Subject: [PATCH 27/35] wip --- .../control/v2/storage_control/operations.rb | 2 +- .../samples/acceptance/helper.rb | 5 ++-- .../storage_control_anywhere_cache_test.rb | 29 ++++++++++--------- .../storage_control_create_anywhere_cache.rb | 11 ++++--- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb b/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb index 11dcdec21af8..9a1a796e7745 100644 --- a/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb +++ b/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb @@ -283,6 +283,7 @@ def get_operation request, options = nil # Customize the options with defaults metadata = @config.rpcs.get_operation.metadata.to_h + binding.pry # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ @@ -304,7 +305,6 @@ def get_operation request, options = nil retry_policy: @config.rpcs.get_operation.retry_policy options.apply_defaults timeout: @config.timeout, - metadata: @config.metadata, retry_policy: @config.retry_policy @operations_stub.call_rpc :get_operation, request, options: options do |response, operation| diff --git a/google-cloud-storage-control/samples/acceptance/helper.rb b/google-cloud-storage-control/samples/acceptance/helper.rb index 8bdba8fefaeb..6c531d726aac 100644 --- a/google-cloud-storage-control/samples/acceptance/helper.rb +++ b/google-cloud-storage-control/samples/acceptance/helper.rb @@ -26,9 +26,11 @@ def random_folder_name prefix: "ruby-storage-control-folder-samples-test-" t = Time.now.utc.iso8601.gsub ":", "-" "#{prefix}-#{t}-#{SecureRandom.hex 4}".downcase end +def storage_client + @storage_client ||= Google::Cloud::Storage.new +end def create_bucket_helper bucket_name, uniform_bucket_level_access: nil, hierarchical_namespace: nil - storage_client = Google::Cloud::Storage.new retry_resource_exhaustion do storage_client.create_bucket bucket_name do |b| b.uniform_bucket_level_access = uniform_bucket_level_access @@ -38,7 +40,6 @@ def create_bucket_helper bucket_name, uniform_bucket_level_access: nil, hierarch end def delete_bucket_helper bucket_name - storage_client = Google::Cloud::Storage.new retry_resource_exhaustion do bucket = storage_client.bucket bucket_name return unless bucket diff --git a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb index ac4f07be954e..917cf60077eb 100644 --- a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb +++ b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb @@ -21,6 +21,7 @@ require_relative "../storage_control_pause_anywhere_cache" require_relative "../storage_control_resume_anywhere_cache" require_relative "../storage_control_disable_anywhere_cache" +require 'pry' describe "Storage Control Anywhere Cache" do let(:bucket_name) { random_bucket_name } @@ -29,11 +30,11 @@ let(:anywhere_cache_name) { "projects/_/buckets/#{bucket_name}/anywhereCaches/#{zone}" } before :all do - @bucket = create_bucket_helper bucket_name + bucket = create_bucket_helper bucket_name end - after do - delete_bucket_helper bucket_name until count_anywhere_caches(bucket_name).zero? + after :all do + delete_bucket_helper bucket_name #{}until count_anywhere_caches(bucket_name).zero? end it "handles Anywhere cache lifecycle in sequence" do @@ -74,14 +75,14 @@ end end -def count_anywhere_caches bucket_name - sleep 900 - storage_control_client = Google::Cloud::Storage::Control.storage_control - # Set project to "_" to signify global bucket - parent = "projects/_/buckets/#{bucket_name}" - request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new( - parent: parent - ) - result = storage_control_client.list_anywhere_caches request - result.response.anywhere_caches.count -end +# def count_anywhere_caches bucket_name +# sleep 900 +# storage_control_client = Google::Cloud::Storage::Control.storage_control +# # Set project to "_" to signify global bucket +# parent = "projects/_/buckets/#{bucket_name}" +# request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new( +# parent: parent +# ) +# result = storage_control_client.list_anywhere_caches request +# result.response.anywhere_caches.count +# end diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index 4eb4aa172523..2cba7f4ffae3 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -47,16 +47,19 @@ def create_anywhere_cache bucket_name:, zone: name: name ) result = storage_control_client.get_anywhere_cache get_request - until result.state == "running" - sleep 1800 # Wait for 1/2 hour before checking again + min_delay = 900 # 15 minutes + max_delay = 1800 # 30 minutes + while result.state != "running" + puts "Cache not running yet, current state is #{result.state}. Retrying in #{min_delay} seconds." + sleep min_delay + min_delay = [min_delay * 2, max_delay].min # Exponential backoff with a max delay result = storage_control_client.get_anywhere_cache get_request - puts "AnywhereCache status check retried" end puts "AnywhereCache created - #{result.name}" else puts "AnywhereCache create operation failed" end - rescue StandardError => e + rescue Google::Cloud::Error=> e puts "Error creating AnywhereCache: #{e.message}" end end From 5f992f0e8998406fdf02fc37c2398a33041849d8 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 19 Sep 2025 09:05:19 +0000 Subject: [PATCH 28/35] updated --- .../samples/acceptance/helper.rb | 31 ++++++++++++++++++ .../storage_control_anywhere_cache_test.rb | 18 ++--------- .../storage_control_create_anywhere_cache.rb | 32 ++++++++----------- .../storage_control_disable_anywhere_cache.rb | 4 +-- .../storage_control_get_anywhere_cache.rb | 4 +-- .../storage_control_list_anywhere_caches.rb | 4 +-- .../storage_control_pause_anywhere_cache.rb | 4 +-- .../storage_control_resume_anywhere_cache.rb | 4 +-- .../storage_control_update_anywhere_cache.rb | 25 +++++++++------ 9 files changed, 72 insertions(+), 54 deletions(-) diff --git a/google-cloud-storage-control/samples/acceptance/helper.rb b/google-cloud-storage-control/samples/acceptance/helper.rb index 6c531d726aac..a2e2ebaf426a 100644 --- a/google-cloud-storage-control/samples/acceptance/helper.rb +++ b/google-cloud-storage-control/samples/acceptance/helper.rb @@ -16,6 +16,7 @@ require "minitest/autorun" require "minitest/focus" require "minitest/hooks/default" +require "google/cloud/storage/control" def random_bucket_name t = Time.now.utc.iso8601.gsub ":", "-" @@ -61,3 +62,33 @@ def retry_resource_exhaustion end raise Google::Cloud::ResourceExhaustedError, "Maybe take a break from creating and deleting buckets for a bit" end + +# Waits until all Anywhere Caches for a given bucket are deleted. +# +# This method polls the Storage Control API, listing the Anywhere Caches +# associated with the specified bucket. If caches are found, it waits and +# retries with an exponential backoff strategy until no caches remain. +# +# @param bucket_name [String] The name of the Google Cloud Storage bucket. +# @return [Integer] The final count of Anywhere Caches, which will be 0 +# the method completes successfully after all caches are deleted. +def count_anywhere_caches bucket_name = nil + storage_control_client = Google::Cloud::Storage::Control.storage_control + + # Set project to "_" to signify global bucket + parent = "projects/_/buckets/#{bucket_name}" + request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new( + parent: parent + ) + result = storage_control_client.list_anywhere_caches request + min_delay = 180 # 3 minutes + max_delay = 900 # 15 minutes + while result.response.anywhere_caches.count != 0 + puts "Cache not deleted yet, Retrying in #{min_delay} seconds." + sleep min_delay + min_delay = [min_delay * 2, max_delay].min # Exponential backoff with a max delay + result = storage_control_client.list_anywhere_caches request + end + + result.response.anywhere_caches.count +end diff --git a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb index 917cf60077eb..1926882d15e0 100644 --- a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb +++ b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb @@ -13,7 +13,6 @@ # limitations under the License. require_relative "helper" -require "google/cloud/storage/control" require_relative "../storage_control_create_anywhere_cache" require_relative "../storage_control_list_anywhere_caches" require_relative "../storage_control_get_anywhere_cache" @@ -21,7 +20,6 @@ require_relative "../storage_control_pause_anywhere_cache" require_relative "../storage_control_resume_anywhere_cache" require_relative "../storage_control_disable_anywhere_cache" -require 'pry' describe "Storage Control Anywhere Cache" do let(:bucket_name) { random_bucket_name } @@ -30,11 +28,11 @@ let(:anywhere_cache_name) { "projects/_/buckets/#{bucket_name}/anywhereCaches/#{zone}" } before :all do - bucket = create_bucket_helper bucket_name + create_bucket_helper bucket_name end after :all do - delete_bucket_helper bucket_name #{}until count_anywhere_caches(bucket_name).zero? + delete_bucket_helper bucket_name until count_anywhere_caches(bucket_name).zero? end it "handles Anywhere cache lifecycle in sequence" do @@ -74,15 +72,3 @@ assert_includes out_disable, "AnywhereCache #{anywhere_cache_name} disabled" end end - -# def count_anywhere_caches bucket_name -# sleep 900 -# storage_control_client = Google::Cloud::Storage::Control.storage_control -# # Set project to "_" to signify global bucket -# parent = "projects/_/buckets/#{bucket_name}" -# request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new( -# parent: parent -# ) -# result = storage_control_client.list_anywhere_caches request -# result.response.anywhere_caches.count -# end diff --git a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb index 2cba7f4ffae3..8bf99bc0af61 100644 --- a/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb @@ -16,7 +16,7 @@ require "google/cloud/storage/control" def create_anywhere_cache bucket_name:, zone: - # The ID of your GCS bucket + # The Name of your GCS bucket # bucket_name = "your-unique-bucket-name" # Zone where you want to create cache @@ -41,25 +41,21 @@ def create_anywhere_cache bucket_name:, zone: # The cache is created in the specified bucket. begin operation = storage_control_client.create_anywhere_cache request - if operation.instance_of? Gapic::Operation - puts "AnywhereCache operation created - #{operation.name}" - get_request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( - name: name - ) + puts "AnywhereCache operation created - #{operation.name}" + get_request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( + name: name + ) + result = storage_control_client.get_anywhere_cache get_request + min_delay = 180 # 3 minutes + max_delay = 900 # 15 minutes + while result.state != "running" + puts "Cache not running yet, current state is #{result.state}. Retrying in #{min_delay} seconds." + sleep min_delay + min_delay = [min_delay * 2, max_delay].min # Exponential backoff with a max delay result = storage_control_client.get_anywhere_cache get_request - min_delay = 900 # 15 minutes - max_delay = 1800 # 30 minutes - while result.state != "running" - puts "Cache not running yet, current state is #{result.state}. Retrying in #{min_delay} seconds." - sleep min_delay - min_delay = [min_delay * 2, max_delay].min # Exponential backoff with a max delay - result = storage_control_client.get_anywhere_cache get_request - end - puts "AnywhereCache created - #{result.name}" - else - puts "AnywhereCache create operation failed" end - rescue Google::Cloud::Error=> e + puts "AnywhereCache created - #{result.name}" + rescue Google::Cloud::Error => e puts "Error creating AnywhereCache: #{e.message}" end end diff --git a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb index 808de2531f57..1561e9e250ca 100644 --- a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb @@ -16,7 +16,7 @@ require "google/cloud/storage/control" def disable_anywhere_cache bucket_name:, anywhere_cache_id: - # The ID of your GCS bucket + # The Name of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache @@ -37,7 +37,7 @@ def disable_anywhere_cache bucket_name:, anywhere_cache_id: begin result = storage_control_client.disable_anywhere_cache request puts "AnywhereCache #{result.name} #{result.state} " - rescue StandardError => e + rescue Google::Cloud::Error => e puts "Error disabling AnywhereCache: #{e.message}" end end diff --git a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb index b5ac9195a829..65b321fc0ccf 100644 --- a/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb @@ -16,7 +16,7 @@ require "google/cloud/storage/control" def get_anywhere_cache bucket_name:, anywhere_cache_id: - # The ID of your GCS bucket + # The Name of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache @@ -39,7 +39,7 @@ def get_anywhere_cache bucket_name:, anywhere_cache_id: begin result = storage_control_client.get_anywhere_cache request puts "AnywhereCache #{result.name} fetched" - rescue StandardError => e + rescue Google::Cloud::Error => e puts "Error fetching AnywhereCache: #{e.message}" end end diff --git a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb index 3a4aec820cb5..397401531118 100644 --- a/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb +++ b/google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb @@ -16,7 +16,7 @@ require "google/cloud/storage/control" def list_anywhere_caches bucket_name: - # The ID of your GCS bucket + # The Name of your GCS bucket # bucket_name = "your-unique-bucket-name" # Create a client object. The client can be reused for multiple calls. @@ -35,7 +35,7 @@ def list_anywhere_caches bucket_name: result.response.anywhere_caches.each do |item| puts "AnywhereCache #{item.name} found in list" end - rescue StandardError => e + rescue Google::Cloud::Error => e puts "Error listing AnywhereCaches: #{e.message}" end end diff --git a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb index 0a48f7691a61..6c48d53e62a9 100644 --- a/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb @@ -16,7 +16,7 @@ require "google/cloud/storage/control" def pause_anywhere_cache bucket_name:, anywhere_cache_id: - # The ID of your GCS bucket + # The Name of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache @@ -38,7 +38,7 @@ def pause_anywhere_cache bucket_name:, anywhere_cache_id: begin result = storage_control_client.pause_anywhere_cache request puts "AnywhereCache #{result.name} #{result.state}" - rescue StandardError => e + rescue Google::Cloud::Error => e puts "Error pausing AnywhereCache: #{e.message}" end end diff --git a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb index a9154bb68247..f8a1ef59fab7 100644 --- a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb @@ -16,7 +16,7 @@ require "google/cloud/storage/control" def resume_anywhere_cache bucket_name:, anywhere_cache_id: - # The ID of your GCS bucket + # The Name of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache @@ -38,7 +38,7 @@ def resume_anywhere_cache bucket_name:, anywhere_cache_id: begin result = storage_control_client.resume_anywhere_cache request puts "AnywhereCache #{result.name} #{result.state}" - rescue StandardError => e + rescue Google::Cloud::Error => e puts "Error resuming AnywhereCache: #{e.message}" end end diff --git a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb index 1527c809e33d..d3ca35951c2c 100644 --- a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb @@ -17,7 +17,7 @@ require "google/cloud/storage/control/v2" def update_anywhere_cache bucket_name:, anywhere_cache_id: - # The ID of your GCS bucket + # The Name of your GCS bucket # bucket_name = "your-unique-bucket-name" # A value that, along with the bucket's name, uniquely identifies the cache # anywhere_cache_id = "us-east1-b" @@ -43,17 +43,22 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id: # The cache is identified by the specified ID. begin operation = storage_control_client.update_anywhere_cache request - if operation.instance_of? Gapic::Operation - puts "AnywhereCache operation created - #{operation.name}" - get_request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( - name: name - ) + puts "AnywhereCache operation created - #{operation.name}" + get_request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( + name: name + ) + result = storage_control_client.get_anywhere_cache get_request + min_delay = 120 # 2 minutes + max_delay = 600 # 10 minutes + while result.state != "running" + puts "Cache not running yet, current state is #{result.state}. Retrying in #{min_delay} seconds." + sleep min_delay + min_delay = [min_delay * 2, max_delay].min # Exponential backoff with a max delay result = storage_control_client.get_anywhere_cache get_request - puts "AnywhereCache #{result.name} updated" - else - puts "AnywhereCache update operation failed" end - rescue StandardError => e + puts "AnywhereCache #{result.name} updated" + + rescue Google::Cloud::Error => e puts "Error updating AnywhereCache: #{e.message}" end end From 306948c09b7a716a4cd14cdac262bd88d4a34826 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 19 Sep 2025 09:15:06 +0000 Subject: [PATCH 29/35] updated --- .../cloud/storage/control/v2/storage_control/operations.rb | 2 -- google-cloud-storage-control/samples/acceptance/helper.rb | 2 +- .../samples/acceptance/storage_control_anywhere_cache_test.rb | 3 ++- .../samples/storage_control_resume_anywhere_cache.rb | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb b/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb index 9a1a796e7745..36e5f6d4f947 100644 --- a/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb +++ b/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb @@ -283,8 +283,6 @@ def get_operation request, options = nil # Customize the options with defaults metadata = @config.rpcs.get_operation.metadata.to_h - binding.pry - # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, diff --git a/google-cloud-storage-control/samples/acceptance/helper.rb b/google-cloud-storage-control/samples/acceptance/helper.rb index a2e2ebaf426a..853d201af519 100644 --- a/google-cloud-storage-control/samples/acceptance/helper.rb +++ b/google-cloud-storage-control/samples/acceptance/helper.rb @@ -72,7 +72,7 @@ def retry_resource_exhaustion # @param bucket_name [String] The name of the Google Cloud Storage bucket. # @return [Integer] The final count of Anywhere Caches, which will be 0 # the method completes successfully after all caches are deleted. -def count_anywhere_caches bucket_name = nil +def count_anywhere_caches bucket_name storage_control_client = Google::Cloud::Storage::Control.storage_control # Set project to "_" to signify global bucket diff --git a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb index 1926882d15e0..0e42b17feee1 100644 --- a/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb +++ b/google-cloud-storage-control/samples/acceptance/storage_control_anywhere_cache_test.rb @@ -32,7 +32,8 @@ end after :all do - delete_bucket_helper bucket_name until count_anywhere_caches(bucket_name).zero? + count_anywhere_caches bucket_name # Ensure all caches are deleted before deleting bucket + delete_bucket_helper bucket_name end it "handles Anywhere cache lifecycle in sequence" do diff --git a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb index f8a1ef59fab7..43dce8488410 100644 --- a/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb @@ -24,8 +24,8 @@ def resume_anywhere_cache bucket_name:, anywhere_cache_id: # Create a client object. The client can be reused for multiple calls. storage_control_client = Google::Cloud::Storage::Control.storage_control - parent = "projects/_/buckets/#{bucket_name}" # Set project to "_" to signify global bucket + parent = "projects/_/buckets/#{bucket_name}" name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" # Create a request. From c9d1c6b9024b0fb040b1372d199d921cdf453efc Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 19 Sep 2025 12:58:47 +0000 Subject: [PATCH 30/35] update --- .../cloud/storage/control/v2/storage_control/operations.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb b/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb index 36e5f6d4f947..59501a6a9a9b 100644 --- a/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb +++ b/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb @@ -303,6 +303,7 @@ def get_operation request, options = nil retry_policy: @config.rpcs.get_operation.retry_policy options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, retry_policy: @config.retry_policy @operations_stub.call_rpc :get_operation, request, options: options do |response, operation| From 6181f5998fdd0a3e909594fdb70700b5c39e9fe9 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 19 Sep 2025 12:59:32 +0000 Subject: [PATCH 31/35] try --- .../cloud/storage/control/v2/storage_control/operations.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb b/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb index 59501a6a9a9b..cb373212acc5 100644 --- a/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb +++ b/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb @@ -284,6 +284,7 @@ def get_operation request, options = nil # Customize the options with defaults metadata = @config.rpcs.get_operation.metadata.to_h # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Storage::Control::V2::VERSION From f3e8775ee041724918f78db7912173b2bdefad69 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 19 Sep 2025 13:00:34 +0000 Subject: [PATCH 32/35] try --- .../cloud/storage/control/v2/storage_control/operations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb b/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb index cb373212acc5..15ea9757915a 100644 --- a/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb +++ b/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb @@ -283,8 +283,8 @@ def get_operation request, options = nil # Customize the options with defaults metadata = @config.rpcs.get_operation.metadata.to_h - # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers + # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Storage::Control::V2::VERSION From 4209f80bf4f496d1271f6b15a844478f736cbfbe Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 19 Sep 2025 13:02:20 +0000 Subject: [PATCH 33/35] try --- .../cloud/storage/control/v2/storage_control/operations.rb | 2 +- google-cloud-storage-control/samples/acceptance/helper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb b/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb index 15ea9757915a..11dcdec21af8 100644 --- a/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb +++ b/google-cloud-storage-control-v2/lib/google/cloud/storage/control/v2/storage_control/operations.rb @@ -283,7 +283,7 @@ def get_operation request, options = nil # Customize the options with defaults metadata = @config.rpcs.get_operation.metadata.to_h - + # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, diff --git a/google-cloud-storage-control/samples/acceptance/helper.rb b/google-cloud-storage-control/samples/acceptance/helper.rb index 853d201af519..927522be8565 100644 --- a/google-cloud-storage-control/samples/acceptance/helper.rb +++ b/google-cloud-storage-control/samples/acceptance/helper.rb @@ -72,7 +72,7 @@ def retry_resource_exhaustion # @param bucket_name [String] The name of the Google Cloud Storage bucket. # @return [Integer] The final count of Anywhere Caches, which will be 0 # the method completes successfully after all caches are deleted. -def count_anywhere_caches bucket_name +def count_anywhere_caches bucket_name storage_control_client = Google::Cloud::Storage::Control.storage_control # Set project to "_" to signify global bucket From 976451e4b41cce78c943650185ff13ea0db27f65 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 19 Sep 2025 13:03:27 +0000 Subject: [PATCH 34/35] try --- google-cloud-storage-control/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-storage-control/README.md b/google-cloud-storage-control/README.md index de20c0a224c7..88feeb7b2a53 100644 --- a/google-cloud-storage-control/README.md +++ b/google-cloud-storage-control/README.md @@ -140,4 +140,3 @@ The `google-apis-` clients have wide coverage across Google services, so you might need to use one if there is no modern client available for the service. However, if a modern client is available, we generally recommend it over the older `google-apis-` clients. - From 57adc0c9d8dbdfe826ff2b641a681275d504e66c Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 19 Sep 2025 13:07:32 +0000 Subject: [PATCH 35/35] try --- .../samples/storage_control_disable_anywhere_cache.rb | 2 +- .../samples/storage_control_update_anywhere_cache.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb index 1561e9e250ca..03d6b7c09cf5 100644 --- a/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb @@ -36,7 +36,7 @@ def disable_anywhere_cache bucket_name:, anywhere_cache_id: # The cache can be re-enabled later. begin result = storage_control_client.disable_anywhere_cache request - puts "AnywhereCache #{result.name} #{result.state} " + puts "AnywhereCache #{result.name} #{result.state}" rescue Google::Cloud::Error => e puts "Error disabling AnywhereCache: #{e.message}" end diff --git a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb index d3ca35951c2c..8dd3c5a43cac 100644 --- a/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb +++ b/google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb @@ -14,7 +14,6 @@ # [START storage_control_update_anywhere_cache] require "google/cloud/storage/control" -require "google/cloud/storage/control/v2" def update_anywhere_cache bucket_name:, anywhere_cache_id: # The Name of your GCS bucket @@ -57,7 +56,6 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id: result = storage_control_client.get_anywhere_cache get_request end puts "AnywhereCache #{result.name} updated" - rescue Google::Cloud::Error => e puts "Error updating AnywhereCache: #{e.message}" end