Storage Control Resume Anywhere Cache

Storage Control Resume Anywhere Cache

Explorar mais

Para ver documentação detalhada que inclui este exemplo de código, consulte o seguinte:

Exemplo de código

C++

Para mais informações, consulte a documentação de referência da API C++ Cloud Storage.

Para se autenticar no Cloud Storage, configure as Credenciais padrão da aplicação. Para mais informações, consulte o artigo Configure a autenticação para bibliotecas de cliente.

namespace storagecontrol = google::cloud::storagecontrol_v2;
[](storagecontrol::StorageControlClient client,
   std::string const& cache_name) {
  auto anywhere_cache = client.ResumeAnywhereCache(cache_name);
  if (!anywhere_cache) throw std::move(anywhere_cache).status();
  std::cout << "Resumed anywhere cache: " << anywhere_cache->name() << "\n";
}

Java

Para mais informações, consulte a documentação de referência da API Java Cloud Storage.

Para se autenticar no Cloud Storage, configure as Credenciais padrão da aplicação. Para mais informações, consulte o artigo Configure a autenticação para bibliotecas de cliente.


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());
    }
  }
}

PHP

Para mais informações, consulte a documentação de referência da API PHP Cloud Storage.

Para se autenticar no Cloud Storage, configure as Credenciais padrão da aplicação. Para mais informações, consulte o artigo Configure a autenticação para bibliotecas de cliente.

use Google\Cloud\Storage\Control\V2\Client\StorageControlClient;
use Google\Cloud\Storage\Control\V2\ResumeAnywhereCacheRequest;

/**
 * Resumes a disabled or paused Anywhere Cache instance.
 *
 * @param string $bucketName The name of your Cloud Storage bucket.
 *        (e.g. 'my-bucket')
 * @param string $anywhereCacheId Uniquely identifies the cache.
 *        (e.g. 'us-east1-b')
 */
function resume_anywhere_cache(string $bucketName, string $anywhereCacheId): void
{
    $storageControlClient = new StorageControlClient();

    // Set project to "_" to signify global bucket
    $formattedName = $storageControlClient->anywhereCacheName('_', $bucketName, $anywhereCacheId);

    $request = new ResumeAnywhereCacheRequest([
        'name' => $formattedName
    ]);

    $response = $storageControlClient->resumeAnywhereCache($request);

    printf('Resumed anywhere cache: %s', $response->getName());
}

Ruby

Para mais informações, consulte a documentação de referência da API Ruby Cloud Storage.

Para se autenticar no Cloud Storage, configure as Credenciais padrão da aplicação. Para mais informações, consulte o artigo Configure a autenticação para bibliotecas de cliente.

require "google/cloud/storage/control"

# Resumes a paused Anywhere Cache instance.
#
# This method sends a request to the Storage Control API to resume a
# specific Anywhere Cache that was previously paused.
#
# @param bucket_name [String] The name of the bucket
#   containing the cache.
# @param anywhere_cache_id [String] The unique identifier for the Anywhere
#   Cache instance within the bucket. For example: "us-east1-b".
#
# @example
#   resume_anywhere_cache(
#     bucket_name: "your-unique-bucket-name",
#     anywhere_cache_id: "us-east1-b"
#   )
#
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
  # Set project to "_" to signify global bucket
  parent = "projects/_/buckets/#{bucket_name}"
  name = "#{parent}/anywhereCaches/#{anywhere_cache_id}"

  # 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.
  begin
    result = storage_control_client.resume_anywhere_cache request
    puts "Successfully resumed anywhereCache - #{result.name}."
  rescue Google::Cloud::Error => e
    puts "Failed to resume AnywhereCache. Error: #{e.message}"
  end
end

O que se segue?

Para pesquisar e filtrar exemplos de código para outros Google Cloud produtos, consulte o Google Cloud navegador de exemplos.