FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

samples(storagecontrol): add AnywhereCache samples by BenWhitehead · Pull Request #3123 · googleapis/java-storage · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (8) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
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,55 @@
/*
* 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.
*/

package com.example.storage.control.v2;

// [START storage_control_create_anywhere_cache]
import com.google.api.gax.longrunning.OperationFuture;
import com.google.storage.control.v2.AnywhereCache;
import com.google.storage.control.v2.BucketName;
import com.google.storage.control.v2.CreateAnywhereCacheMetadata;
import com.google.storage.control.v2.CreateAnywhereCacheRequest;
import com.google.storage.control.v2.StorageControlClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public final class AnywhereCacheCreate {

public static void anywhereCacheCreate(String bucketName, String cacheName, String zoneName)
throws InterruptedException, ExecutionException, IOException {
try (StorageControlClient storageControl = StorageControlClient.create()) {

CreateAnywhereCacheRequest request = CreateAnywhereCacheRequest.newBuilder()
// Set project to "_" to signify globally scoped bucket
.setParent(BucketName.format("_", bucketName))
.setAnywhereCache(AnywhereCache.newBuilder()
.setName(cacheName)
.setZone(zoneName)
.build())
.build();

// Start a long-running operation (LRO).
OperationFuture<AnywhereCache, CreateAnywhereCacheMetadata> operation =
storageControl.createAnywhereCacheAsync(request);

// Await the LROs completion.
AnywhereCache anywhereCache = operation.get();
System.out.printf("Created anywhere cache: %s%n", anywhereCache.getName());
}
}

}
// [END storage_control_create_anywhere_cache]
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,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.
*/

package com.example.storage.control.v2;

// [START storage_control_disable_anywhere_cache]

import com.google.storage.control.v2.AnywhereCache;
import com.google.storage.control.v2.DisableAnywhereCacheRequest;
import com.google.storage.control.v2.StorageControlClient;
import java.io.IOException;

public final class AnywhereCacheDisable {

public static void anywhereCacheDisable(String cacheName) throws IOException {
try (StorageControlClient storageControl = StorageControlClient.create()) {

DisableAnywhereCacheRequest request = DisableAnywhereCacheRequest.newBuilder()
.setName(cacheName)
.build();

AnywhereCache anywhereCache = storageControl.disableAnywhereCache(request);

System.out.printf("Disabled anywhere cache: %s%n", anywhereCache.getName());
}
}

}
// [END storage_control_disable_anywhere_cache]
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,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.
*/

package com.example.storage.control.v2;

// [START storage_control_get_anywhere_cache]

import com.google.storage.control.v2.AnywhereCache;
import com.google.storage.control.v2.GetAnywhereCacheRequest;
import com.google.storage.control.v2.StorageControlClient;
import java.io.IOException;

public final class AnywhereCacheGet {

public static void anywhereCacheGet(String cacheName) throws IOException {
try (StorageControlClient storageControl = StorageControlClient.create()) {

GetAnywhereCacheRequest request = GetAnywhereCacheRequest.newBuilder()
.setName(cacheName)
.build();

AnywhereCache anywhereCache = storageControl.getAnywhereCache(request);

System.out.printf("Got anywhere cache: %s%n", anywhereCache.getName());
}
}

}
// [END storage_control_get_anywhere_cache]
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
*
* 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.
*/

package com.example.storage.control.v2;

// [START storage_control_list_anywhere_cache]

import com.google.storage.control.v2.AnywhereCache;
import com.google.storage.control.v2.BucketName;
import com.google.storage.control.v2.ListAnywhereCachesRequest;
import com.google.storage.control.v2.StorageControlClient;
import com.google.storage.control.v2.StorageControlClient.ListAnywhereCachesPagedResponse;
import java.io.IOException;

public final class AnywhereCacheList {

public static void anywhereCacheList(String bucketName) throws IOException {
try (StorageControlClient storageControl = StorageControlClient.create()) {

ListAnywhereCachesRequest request = ListAnywhereCachesRequest.newBuilder()
.setParent(BucketName.format("_", bucketName))
.build();

ListAnywhereCachesPagedResponse page = storageControl.listAnywhereCaches(request);
for (AnywhereCache anywhereCache : page.iterateAll()) {
System.out.println(anywhereCache.getName());
}
}
}

}
// [END storage_control_list_anywhere_cache]
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,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.
*/

package com.example.storage.control.v2;

// [START storage_control_pause_anywhere_cache]

import com.google.storage.control.v2.AnywhereCache;
import com.google.storage.control.v2.PauseAnywhereCacheRequest;
import com.google.storage.control.v2.StorageControlClient;
import java.io.IOException;

public final class AnywhereCachePause {

public static void anywhereCachePause(String cacheName) throws IOException {
try (StorageControlClient storageControl = StorageControlClient.create()) {

PauseAnywhereCacheRequest request = PauseAnywhereCacheRequest.newBuilder()
.setName(cacheName)
.build();

AnywhereCache anywhereCache = storageControl.pauseAnywhereCache(request);

System.out.printf("Paused anywhere cache: %s%n", anywhereCache.getName());
}
}

}
// [END storage_control_pause_anywhere_cache]
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,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.
*/

package com.example.storage.control.v2;

// [START storage_control_resume_anywhere_cache]

import com.google.storage.control.v2.AnywhereCache;
import com.google.storage.control.v2.ResumeAnywhereCacheRequest;
import com.google.storage.control.v2.StorageControlClient;
import java.io.IOException;

public final class AnywhereCacheResume {

public static void anywhereCacheResume(String cacheName) throws IOException {
try (StorageControlClient storageControl = StorageControlClient.create()) {

ResumeAnywhereCacheRequest request = ResumeAnywhereCacheRequest.newBuilder()
.setName(cacheName)
.build();

AnywhereCache anywhereCache = storageControl.resumeAnywhereCache(request);

System.out.printf("Resumed anywhere cache: %s%n", anywhereCache.getName());
}
}

}
// [END storage_control_resume_anywhere_cache]
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
*
* 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.
*/

package com.example.storage.control.v2;

// [START storage_control_update_anywhere_cache]

import com.google.api.gax.longrunning.OperationFuture;
import com.google.protobuf.FieldMask;
import com.google.storage.control.v2.AnywhereCache;
import com.google.storage.control.v2.StorageControlClient;
import com.google.storage.control.v2.UpdateAnywhereCacheMetadata;
import com.google.storage.control.v2.UpdateAnywhereCacheRequest;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public final class AnywhereCacheUpdate {

public static void anywhereCacheUpdate(String cacheName, String admissionPolicy)
throws InterruptedException, ExecutionException, IOException {
try (StorageControlClient storageControl = StorageControlClient.create()) {

AnywhereCache pendingUpdate = AnywhereCache.newBuilder()
.setName(cacheName)
.setAdmissionPolicy(admissionPolicy)
.build();

UpdateAnywhereCacheRequest request = UpdateAnywhereCacheRequest.newBuilder()
.setAnywhereCache(pendingUpdate)
.setUpdateMask(
FieldMask.newBuilder()
.addPaths("admission_policy")
.build()
)
.build();

// Start a long-running operation (LRO).
OperationFuture<AnywhereCache, UpdateAnywhereCacheMetadata> operation =
storageControl.updateAnywhereCacheAsync(request);

// Await the LROs completion.
AnywhereCache updatedAnywhereCache = operation.get();
System.out.printf("Updated anywhere cache: %s%n", updatedAnywhereCache.getName());
}
}

}
// [END storage_control_update_anywhere_cache]
Loading

Back | FazBrowse Home | New Git URL