-
Notifications
You must be signed in to change notification settings - Fork 1.2k
samples(storagecontrol): add samples for anywhere cache #3207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mahendra-google
wants to merge
6
commits into
GoogleCloudPlatform:main
Choose a base branch
from
mahendra-google:anywherecache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2a32c52
Update README.md
mahendra-google d2f0102
samples(storagecontrol): add samples for anywhere cache
mahendra-google 8743ade
samples(storagecontrol): modify zone name in anywhere cache samples
mahendra-google b2ca875
samples(storagecontrol): add pageSize parameter in listAnywhereCache
mahendra-google 26c8713
samples(storagecontrol): modify list anywhere cache to iterate over a…
mahendra-google 6528bf6
tests(Storage): Skip ACL test
mahendra-google File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // 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 | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // [START storage_control_create_anywhere_cache] | ||
|
|
||
| using Google.Cloud.Storage.Control.V2; | ||
| using Google.LongRunning; | ||
| using System; | ||
|
|
||
| public class StorageControlCreateAnywhereCacheSample | ||
| { | ||
| /// <summary>Creates an anywhere cache instance in the specified bucket.</summary> | ||
| /// <param name="bucketName">The name of the bucket.</param> | ||
| /// <param name="zoneName">The name of the zone in which the cache instance will run.</param> | ||
| public Operation<AnywhereCache, CreateAnywhereCacheMetadata> StorageControlCreateAnywhereCache(string bucketName = "your-unique-bucket-name", | ||
| string zoneName = "us-east1-b") | ||
| { | ||
| StorageControlClient storageControlClient = StorageControlClient.Create(); | ||
|
|
||
| // Set project to "_" to signify globally scoped bucket. | ||
| string parent = $"projects/_/buckets/{bucketName}"; | ||
|
|
||
| AnywhereCache anywhereCache = new AnywhereCache | ||
| { | ||
| Zone = zoneName | ||
| }; | ||
|
|
||
| var request = new CreateAnywhereCacheRequest | ||
| { | ||
| AnywhereCache = anywhereCache, | ||
| Parent = parent | ||
| }; | ||
|
|
||
| // Start a long-running operation (LRO). | ||
| Operation<AnywhereCache, CreateAnywhereCacheMetadata> createdCacheOperation = storageControlClient.CreateAnywhereCache(request); | ||
|
|
||
| // Await the LROs completion. | ||
| var createdCache = createdCacheOperation.PollUntilCompleted(); | ||
|
|
||
| Console.WriteLine($"Created Anywhere Cache Instance: {createdCache.Result.AnywhereCacheName}"); | ||
|
|
||
| return createdCache; | ||
| } | ||
| } | ||
| // [END storage_control_create_anywhere_cache] |
45 changes: 45 additions & 0 deletions
45
storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // [START storage_control_disable_anywhere_cache] | ||
|
|
||
| using Google.Cloud.Storage.Control.V2; | ||
| using System; | ||
|
|
||
| public class StorageControlDisableAnywhereCacheSample | ||
| { | ||
| /// <summary>Disables the anywhere cache instance in the specified bucket.</summary> | ||
| /// <param name="bucketName">The name of the bucket that owns the anywhere cache instance.</param> | ||
| /// <param name="anywhereCacheId">The unique identifier of the cache instance to disable.</param> | ||
| public AnywhereCache StorageControlDisableAnywhereCache(string bucketName = "your-unique-bucket-name", | ||
| string anywhereCacheId = "us-east1-b") | ||
| { | ||
| StorageControlClient storageControlClient = StorageControlClient.Create(); | ||
|
|
||
| // Set project to "_" to signify globally scoped bucket. | ||
| string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; | ||
|
|
||
| var request = new DisableAnywhereCacheRequest | ||
| { | ||
| Name = anywhereCacheName | ||
| }; | ||
|
|
||
| AnywhereCache disabledCache = storageControlClient.DisableAnywhereCache(request); | ||
|
|
||
| Console.WriteLine($"Disabled Anywhere Cache Instance: {disabledCache.Name}"); | ||
|
|
||
| return disabledCache; | ||
| } | ||
| } | ||
| // [END storage_control_disable_anywhere_cache] |
45 changes: 45 additions & 0 deletions
45
storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // [START storage_control_get_anywhere_cache] | ||
|
|
||
| using Google.Cloud.Storage.Control.V2; | ||
| using System; | ||
|
|
||
| public class StorageControlGetAnywhereCacheSample | ||
| { | ||
| /// <summary>Gets an anywhere cache instance for the specified bucket.</summary> | ||
| /// <param name="bucketName">The name of the bucket that owns the anywhere cache instance.</param> | ||
| /// <param name="anywhereCacheId">The unique identifier of the cache instance.</param> | ||
| public AnywhereCache StorageControlGetAnywhereCache(string bucketName = "your-unique-bucket-name", | ||
| string anywhereCacheId = "us-east1-b") | ||
| { | ||
| StorageControlClient storageControlClient = StorageControlClient.Create(); | ||
|
|
||
| // Set project to "_" to signify globally scoped bucket. | ||
| string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; | ||
|
|
||
| var request = new GetAnywhereCacheRequest | ||
| { | ||
| Name = anywhereCacheName | ||
| }; | ||
|
|
||
| AnywhereCache retrievedCache = storageControlClient.GetAnywhereCache(request); | ||
|
|
||
| Console.WriteLine($"Got Anywhere Cache Instance: {retrievedCache.Name}"); | ||
|
|
||
| return retrievedCache; | ||
| } | ||
| } | ||
| // [END storage_control_get_anywhere_cache] |
73 changes: 73 additions & 0 deletions
73
storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // 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 | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // [START storage_control_list_anywhere_caches] | ||
|
|
||
| using Google.Api.Gax; | ||
| using Google.Cloud.Storage.Control.V2; | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| public class StorageControlListAnywhereCachesSample | ||
| { | ||
| /// <summary>Lists all anywhere cache instances for the specified bucket.</summary> | ||
| /// <param name="bucketName">The name of the bucket that owns the anywhere cache instance.</param> | ||
| /// <param name="pageSize">The maximum number of anywhere cache instances to return in a single response.</param> | ||
| public IEnumerable<AnywhereCache> StorageControlListAnywhereCaches(string bucketName = "your-unique-bucket-name", int pageSize = 10) | ||
| { | ||
| StorageControlClient storageControlClient = StorageControlClient.Create(); | ||
|
|
||
| // Set project to "_" to signify globally scoped bucket. | ||
| string parent = $"projects/_/buckets/{bucketName}"; | ||
|
|
||
| var request = new ListAnywhereCachesRequest | ||
| { | ||
| Parent = parent, | ||
| PageSize = pageSize | ||
| }; | ||
|
|
||
| PagedEnumerable<ListAnywhereCachesResponse, AnywhereCache> anywhereCaches = storageControlClient.ListAnywhereCaches(request); | ||
|
|
||
| Console.WriteLine($"The Names of Anywhere Cache Instances are as follows:"); | ||
|
|
||
| foreach (AnywhereCache cache in anywhereCaches) | ||
| { | ||
| Console.WriteLine($"Anywhere Cache Instance: {cache.Name}"); | ||
| } | ||
|
|
||
| Console.WriteLine($"The Names of Anywhere Cache Instances Over All Pages are as follows:"); | ||
|
|
||
| // Iterate over all pages | ||
| foreach (ListAnywhereCachesResponse page in anywhereCaches.AsRawResponses()) | ||
| { | ||
| foreach (AnywhereCache cache in page) | ||
| { | ||
| Console.WriteLine($"Anywhere Cache Instance: {cache.Name}"); | ||
| } | ||
| } | ||
|
|
||
| // Retrieve a single page of page size (unless it's the final page) | ||
| Page<AnywhereCache> singlePage = anywhereCaches.ReadPage(pageSize); | ||
|
|
||
| Console.WriteLine($"The Names of Anywhere Cache Instances in the First Page of Page Size {pageSize} are as follows:"); | ||
|
|
||
| foreach (AnywhereCache cache in singlePage) | ||
| { | ||
| Console.WriteLine($"Anywhere Cache Instance: {cache.Name}"); | ||
| } | ||
|
|
||
| return anywhereCaches; | ||
| } | ||
| } | ||
| // [END storage_control_list_anywhere_caches] | ||
45 changes: 45 additions & 0 deletions
45
storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // [START storage_control_pause_anywhere_cache] | ||
|
|
||
| using Google.Cloud.Storage.Control.V2; | ||
| using System; | ||
|
|
||
| public class StorageControlPauseAnywhereCacheSample | ||
| { | ||
| /// <summary>Pauses an anywhere cache instance in the specified bucket.</summary> | ||
| /// <param name="bucketName">The name of the bucket that owns the anywhere cache instance.</param> | ||
| /// <param name="anywhereCacheId">The unique identifier of the cache instance to pause.</param> | ||
| public AnywhereCache StorageControlPauseAnywhereCache(string bucketName = "your-unique-bucket-name", | ||
| string anywhereCacheId = "us-east1-b") | ||
mahendra-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| StorageControlClient storageControlClient = StorageControlClient.Create(); | ||
|
|
||
| // Set project to "_" to signify globally scoped bucket. | ||
| string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; | ||
|
|
||
| var request = new PauseAnywhereCacheRequest | ||
| { | ||
| Name = anywhereCacheName | ||
| }; | ||
|
|
||
| AnywhereCache pausedCache = storageControlClient.PauseAnywhereCache(request); | ||
|
|
||
| Console.WriteLine($"Paused Anywhere Cache Instance: {pausedCache.Name}"); | ||
|
|
||
| return pausedCache; | ||
| } | ||
| } | ||
| // [END storage_control_pause_anywhere_cache] | ||
45 changes: 45 additions & 0 deletions
45
storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // [START storage_control_resume_anywhere_cache] | ||
|
|
||
| using Google.Cloud.Storage.Control.V2; | ||
| using System; | ||
|
|
||
| public class StorageControlResumeAnywhereCacheSample | ||
| { | ||
| /// <summary>Resumes the disabled or paused anywhere cache instance in the specified bucket.</summary> | ||
| /// <param name="bucketName">The name of the bucket that owns the anywhere cache instance.</param> | ||
| /// <param name="anywhereCacheId">The unique identifier of the cache instance to resume.</param> | ||
| public AnywhereCache StorageControlResumeAnywhereCache(string bucketName = "your-unique-bucket-name", | ||
| string anywhereCacheId = "us-east1-b") | ||
| { | ||
| StorageControlClient storageControlClient = StorageControlClient.Create(); | ||
|
|
||
| // Set project to "_" to signify globally scoped bucket. | ||
| string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; | ||
|
|
||
| var request = new ResumeAnywhereCacheRequest | ||
| { | ||
| Name = anywhereCacheName | ||
| }; | ||
|
|
||
| AnywhereCache resumedCache = storageControlClient.ResumeAnywhereCache(request); | ||
|
|
||
| Console.WriteLine($"Resumed Anywhere Cache Instance: {resumedCache.Name}"); | ||
|
|
||
| return resumedCache; | ||
| } | ||
| } | ||
| // [END storage_control_resume_anywhere_cache] |
61 changes: 61 additions & 0 deletions
61
storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // 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 | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // [START storage_control_update_anywhere_cache] | ||
|
|
||
| using Google.Cloud.Storage.Control.V2; | ||
| using Google.LongRunning; | ||
| using Google.Protobuf.WellKnownTypes; | ||
| using System; | ||
|
|
||
| public class StorageControlUpdateAnywhereCacheSample | ||
| { | ||
| /// <summary>Updates the running anywhere cache instance for the specified bucket.</summary> | ||
| /// <param name="bucketName">The name of the bucket that owns the anywhere cache instance.</param> | ||
| /// <param name="anywhereCacheId">The unique identifier of the cache instance to update.</param> | ||
| /// <param name="admissionPolicy"> The cache's admission policy. Values can be admit-on-first-miss or admit-on-second-miss. If not specified, it defaults to admit-on-first-miss.</param> | ||
| public Operation<AnywhereCache, UpdateAnywhereCacheMetadata> StorageControlUpdateAnywhereCache(string bucketName = "your-bucket-name", | ||
| string anywhereCacheId = "us-east1-b", | ||
| string admissionPolicy = "admit-on-first-miss") | ||
| { | ||
| StorageControlClient storageControlClient = StorageControlClient.Create(); | ||
|
|
||
| // Set project to "_" to signify globally scoped bucket. | ||
| string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; | ||
|
|
||
| var anywhereCache = new AnywhereCache | ||
| { | ||
| Name = anywhereCacheName, | ||
| AdmissionPolicy = admissionPolicy | ||
| }; | ||
| FieldMask fieldMask = new FieldMask { Paths = { "admission_policy" } }; | ||
|
|
||
| var request = new UpdateAnywhereCacheRequest | ||
| { | ||
| AnywhereCache = anywhereCache, | ||
| UpdateMask = fieldMask | ||
| }; | ||
|
|
||
| // Start a long-running operation (LRO). | ||
| Operation<AnywhereCache, UpdateAnywhereCacheMetadata> updatedCacheOperation = storageControlClient.UpdateAnywhereCache(request); | ||
|
|
||
| // Await the LROs completion. | ||
| var updatedCache = updatedCacheOperation.PollUntilCompleted(); | ||
|
|
||
| Console.WriteLine($"Updated Anywhere Cache Instance: {updatedCache.Result.Name}, New Cache Admission Policy: {updatedCache.Result.AdmissionPolicy}"); | ||
|
|
||
| return updatedCache; | ||
| } | ||
| } | ||
| // [END storage_control_update_anywhere_cache] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.