Skip to content

Commit a201399

Browse files
removing reference for V2 library
1 parent ba13118 commit a201399

8 files changed

Lines changed: 70 additions & 47 deletions

google-cloud-storage-control/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,8 @@ The `google-apis-` clients have wide coverage across Google services, so you
140140
might need to use one if there is no modern client available for the service.
141141
However, if a modern client is available, we generally recommend it over the
142142
older `google-apis-` clients.
143+
144+
## Note
145+
146+
Tests for Anywhere cache Sample are not included due to the long operation times typical for cache operations.
147+

google-cloud-storage-control/samples/storage_control_create_anywhere_cache.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,36 @@
1313
# limitations under the License.
1414

1515
# [START storage_control_create_anywhere_cache]
16+
require "google/cloud/storage/control"
17+
1618
def create_anywhere_cache bucket_name:, zone:
1719
# The ID of your GCS bucket
1820
# bucket_name = "your-unique-bucket-name"
1921

2022
# Zone where you want to create cache
2123
# zone = "your-zone-name"
22-
require "google/cloud/storage/control/v2"
2324

2425
# Create a client object. The client can be reused for multiple calls.
25-
storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new
26+
storage_control_client = Google::Cloud::Storage::Control.storage_control
2627
parent = "projects/_/buckets/#{bucket_name}"
2728
name = "#{parent}/anywhereCaches/#{zone}"
2829

2930
anywhere_cache = Google::Cloud::Storage::Control::V2::AnywhereCache.new(
3031
name: name,
3132
zone: zone
3233
)
33-
34-
# Create a request. Replace the placeholder values with actual data.
34+
# Create a request.
3535
request = Google::Cloud::Storage::Control::V2::CreateAnywhereCacheRequest.new(
3636
parent: parent,
3737
anywhere_cache: anywhere_cache
3838
)
3939
# The request creates a new cache in the specified zone.
4040
# The cache is created in the specified bucket.
41-
# Call the create_anywhere_cache method.
42-
result = storage_control_client.create_anywhere_cache request
43-
44-
if result.instance_of? Gapic::Operation
41+
begin
42+
result = storage_control_client.create_anywhere_cache request
4543
puts "AnywhereCache created - #{result.name}"
46-
else
47-
puts "operation failed"
44+
rescue StandardError => e
45+
puts "Error creating AnywhereCache: #{e.message}"
4846
end
4947
end
5048
# [END storage_control_create_anywhere_cache]

google-cloud-storage-control/samples/storage_control_disable_anywhere_cache.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,32 @@
1313
# limitations under the License.
1414

1515
# [START storage_control_disable_anywhere_cache]
16+
require "google/cloud/storage/control"
17+
1618
def disable_anywhere_cache bucket_name:, anywhere_cache_id:
1719
# The ID of your GCS bucket
1820
# bucket_name = "your-unique-bucket-name"
1921

2022
# A value that, along with the bucket's name, uniquely identifies the cache
2123
# anywhere_cache_id = "us-east1-b"
22-
require "google/cloud/storage/control/v2"
2324

2425
# Create a client object. The client can be reused for multiple calls.
25-
storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new
26+
storage_control_client = Google::Cloud::Storage::Control.storage_control
2627
parent = "projects/_/buckets/#{bucket_name}"
2728
name = "#{parent}/anywhereCaches/#{anywhere_cache_id}"
2829

29-
# Create a request. Replace the placeholder values with actual data.
30+
# Create a request.
3031
request = Google::Cloud::Storage::Control::V2::DisableAnywhereCacheRequest.new(
3132
name: name
3233
)
3334
# The request disables the cache, but does not delete it.
3435
# The cache can be re-enabled later.
35-
# Call the disable_anywhere_cache method.
36-
result = storage_control_client.disable_anywhere_cache request
37-
puts "AnywhereCache #{result.name} #{result.state}"
36+
begin
37+
result = storage_control_client.disable_anywhere_cache request
38+
puts "AnywhereCache #{result.name} #{result.state}"
39+
rescue StandardError => e
40+
puts "Error disabling AnywhereCache: #{e.message}"
41+
end
3842
end
3943
# [END storage_control_disable_anywhere_cache]
4044
disable_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__

google-cloud-storage-control/samples/storage_control_get_anywhere_cache.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
# limitations under the License.
1414

1515
# [START storage_control_get_anywhere_cache]
16+
require "google/cloud/storage/control"
17+
1618
def get_anywhere_cache bucket_name:, anywhere_cache_id:
1719
# The ID of your GCS bucket
1820
# bucket_name = "your-unique-bucket-name"
1921

2022
# A value that, along with the bucket's name, uniquely identifies the cache
2123
# anywhere_cache_id = "us-east1-b"
22-
require "google/cloud/storage/control/v2"
2324

2425
# Create a client object. The client can be reused for multiple calls.
25-
storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new
26+
storage_control_client = Google::Cloud::Storage::Control.storage_control
2627
parent = "projects/_/buckets/#{bucket_name}"
2728
name = "#{parent}/anywhereCaches/#{anywhere_cache_id}"
2829

@@ -33,9 +34,13 @@ def get_anywhere_cache bucket_name:, anywhere_cache_id:
3334
# The request retrieves the cache in the specified bucket.
3435
# The cache is identified by the specified ID.
3536
# The cache is in the specified bucket.
36-
# Call the get_anywhere_cache method.
37-
result = storage_control_client.get_anywhere_cache request
38-
puts "AnywhereCache #{result.name}"
37+
38+
begin
39+
result = storage_control_client.get_anywhere_cache request
40+
puts "AnywhereCache fetched - #{result.name}"
41+
rescue StandardError => e
42+
puts "Error fetching AnywhereCache: #{e.message}"
43+
end
3944
end
4045
# [END storage_control_get_anywhere_cache]
4146
get_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__

google-cloud-storage-control/samples/storage_control_list_anywhere_caches.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,28 @@
1313
# limitations under the License.
1414

1515
# [START storage_control_list_anywhere_caches]
16+
require "google/cloud/storage/control"
17+
1618
def list_anywhere_caches bucket_name:
1719
# The ID of your GCS bucket
1820
# bucket_name = "your-unique-bucket-name"
19-
require "google/cloud/storage/control/v2"
2021

2122
# Create a client object. The client can be reused for multiple calls.
22-
storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new
23+
storage_control_client = Google::Cloud::Storage::Control.storage_control
2324
parent = "projects/_/buckets/#{bucket_name}"
2425

2526
request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new(
2627
parent: parent
2728
)
2829
# The request lists all caches in the specified bucket.
2930
# The caches are identified by the specified bucket name.
30-
# Call the list_anywhere_caches method.
31-
result = storage_control_client.list_anywhere_caches request
32-
33-
result.response.anywhere_caches.each do |item|
34-
puts item.name
31+
begin
32+
result = storage_control_client.list_anywhere_caches request
33+
result.response.anywhere_caches.each do |item|
34+
puts item.name
35+
end
36+
rescue StandardError => e
37+
puts "Error listing AnywhereCaches: #{e.message}"
3538
end
3639
end
3740
# [END storage_control_list_anywhere_caches]

google-cloud-storage-control/samples/storage_control_pause_anywhere_cache.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
# limitations under the License.
1414

1515
# [START storage_control_pause_anywhere_cache]
16+
require "google/cloud/storage/control"
17+
1618
def pause_anywhere_cache bucket_name:, anywhere_cache_id:
1719
# The ID of your GCS bucket
1820
# bucket_name = "your-unique-bucket-name"
1921

2022
# A value that, along with the bucket's name, uniquely identifies the cache
2123
# anywhere_cache_id = "us-east1-b"
22-
require "google/cloud/storage/control/v2"
2324

2425
# Create a client object. The client can be reused for multiple calls.
25-
storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new
26+
storage_control_client = Google::Cloud::Storage::Control.storage_control
2627
parent = "projects/_/buckets/#{bucket_name}"
2728
name = "#{parent}/anywhereCaches/#{anywhere_cache_id}"
2829

@@ -33,9 +34,12 @@ def pause_anywhere_cache bucket_name:, anywhere_cache_id:
3334
# The request pauses the cache, but does not delete it.
3435
# The cache can be resumed later.
3536
# The cache is paused in the specified bucket.
36-
# Call the pause_anywhere_cache method.
37-
result = storage_control_client.pause_anywhere_cache request
38-
puts "AnywhereCache #{result.name} #{result.state}"
37+
begin
38+
result = storage_control_client.pause_anywhere_cache request
39+
puts "AnywhereCache #{result.name} #{result.state}"
40+
rescue StandardError => e
41+
puts "Error pausing AnywhereCache: #{e.message}"
42+
end
3943
end
4044
# [END storage_control_pause_anywhere_cache]
4145
pause_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__

google-cloud-storage-control/samples/storage_control_resume_anywhere_cache.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,33 @@
1313
# limitations under the License.
1414

1515
# [START storage_control_resume_anywhere_cache]
16+
require "google/cloud/storage/control"
17+
1618
def resume_anywhere_cache bucket_name:, anywhere_cache_id:
1719
# The ID of your GCS bucket
1820
# bucket_name = "your-unique-bucket-name"
1921

2022
# A value that, along with the bucket's name, uniquely identifies the cache
2123
# anywhere_cache_id = "us-east1-b"
22-
require "google/cloud/storage/control/v2"
2324

2425
# Create a client object. The client can be reused for multiple calls.
25-
storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new
26+
storage_control_client = Google::Cloud::Storage::Control.storage_control
2627
parent = "projects/_/buckets/#{bucket_name}"
2728
name = "#{parent}/anywhereCaches/#{anywhere_cache_id}"
2829

29-
# Create a request. Replace the placeholder values with actual data.
30+
# Create a request.
3031
request = Google::Cloud::Storage::Control::V2::ResumeAnywhereCacheRequest.new(
3132
name: name
3233
)
3334
# The request resumes the cache, which was previously paused.
3435
# The cache is resumed in the specified bucket.
3536
# The cache is identified by the specified ID.
36-
# Call the resume_anywhere_cache method.
37-
result = storage_control_client.resume_anywhere_cache request
38-
puts "AnywhereCache #{result.name} #{result.state}"
37+
begin
38+
result = storage_control_client.resume_anywhere_cache request
39+
puts "AnywhereCache #{result.name} #{result.state}"
40+
rescue StandardError => e
41+
puts "Error resuming AnywhereCache: #{e.message}"
42+
end
3943
end
4044
# [END storage_control_resume_anywhere_cache]
4145
resume_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__

google-cloud-storage-control/samples/storage_control_update_anywhere_cache.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# limitations under the License.
1414

1515
# [START storage_control_update_anywhere_cache]
16+
require "google/cloud/storage/control"
17+
1618
def update_anywhere_cache bucket_name:, anywhere_cache_id:
1719
# The ID of your GCS bucket
1820
# bucket_name = "your-unique-bucket-name"
@@ -22,7 +24,7 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id:
2224
require "google/cloud/storage/control/v2"
2325

2426
# Create a client object. The client can be reused for multiple calls.
25-
storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new
27+
storage_control_client = Google::Cloud::Storage::Control.storage_control
2628
parent = "projects/_/buckets/#{bucket_name}"
2729
name = "#{parent}/anywhereCaches/#{anywhere_cache_id}"
2830

@@ -31,20 +33,18 @@ def update_anywhere_cache bucket_name:, anywhere_cache_id:
3133
ttl: 7200
3234
)
3335
mask = Google::Protobuf::FieldMask.new paths: ["ttl"]
34-
# Create a request. Replace the placeholder values with actual data.
36+
# Create a request.
3537
request = Google::Cloud::Storage::Control::V2::UpdateAnywhereCacheRequest.new(
3638
anywhere_cache: anywhere_cache,
3739
update_mask: mask
3840
)
3941
# The request updates the cache in the specified bucket.
4042
# The cache is identified by the specified ID.
41-
# Call the update_anywhere_cache method.
42-
result = storage_control_client.update_anywhere_cache request
43-
44-
if result.instance_of? Gapic::Operation
43+
begin
44+
result = storage_control_client.update_anywhere_cache request
4545
puts "AnywhereCache updated - #{result.name}"
46-
else
47-
puts "operation failed"
46+
rescue StandardError => e
47+
puts "Error updating AnywhereCache: #{e.message}"
4848
end
4949
end
5050
# [END storage_control_update_anywhere_cache]

0 commit comments

Comments
 (0)