Class: Google::Cloud::Bigtable::Cluster

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/bigtable/cluster.rb,
lib/google/cloud/bigtable/cluster/job.rb,
lib/google/cloud/bigtable/cluster/list.rb

Overview

Cluster

A configuration object describing how Cloud Bigtable should treat traffic from a particular end user application.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"

# Update
cluster.nodes = 3
cluster.save

# Delete
cluster.delete

Defined Under Namespace

Classes: Job, List

Instance Method Summary collapse

Instance Method Details

#backup(backup_id) ⇒ Google::Cloud::Bigtable::Backup?

Gets a backup in the cluster.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"

backup = cluster.backup "my-backup"

if backup
  puts backup.backup_id
end

Parameters:

  • backup_id (String)

    The unique ID of the requested backup.

Returns:



289
290
291
292
293
294
# File 'lib/google/cloud/bigtable/cluster.rb', line 289

def backup backup_id
  grpc = service.get_backup instance_id, cluster_id, backup_id
  Backup.from_grpc grpc, service
rescue Google::Cloud::NotFoundError
  nil
end

#backupsArray<Google::Cloud::Bigtable::Backup>

Lists all backups in the cluster.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"

cluster.backups.all do |backup|
  puts backup.backup_id
end

Returns:



313
314
315
316
# File 'lib/google/cloud/bigtable/cluster.rb', line 313

def backups
  grpc = service.list_backups instance_id, cluster_id
  Backup::List.from_grpc grpc, service
end

#cluster_idString

The unique identifier for the cluster.

Returns:

  • (String)


82
83
84
# File 'lib/google/cloud/bigtable/cluster.rb', line 82

def cluster_id
  @grpc.name.split("/")[5]
end

#create_backup(source_table, backup_id, expire_time) ⇒ Google::Cloud::Bigtable::Backup::Job

Creates a new Cloud Bigtable Backup.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"
table = instance.table "my-table"

expire_time = Time.now + 60 * 60 * 7
job = cluster.create_backup table, "my-backup", expire_time

job.wait_until_done!
job.done? #=> true

if job.error?
  status = job.error
else
  backup = job.backup
end

Parameters:

  • source_table (Table, String)

    The table object, or the name of the table, from which the backup is to be created. The table needs to be in the same instance as the backup. Required.

  • backup_id (String)

    The id of the backup to be created. This string must be between 1 and 50 characters in length and match the regex [_a-zA-Z0-9][-_.a-zA-Z0-9]*. Required.

  • expire_time (Time)

    The expiration time of the backup, with microseconds granularity that must be at least 6 hours and at most 30 days from the time the request is received. Once the expire_time has passed, Cloud Bigtable will delete the backup and free the resources used by the backup. Required.

Returns:



258
259
260
261
262
263
264
265
266
# File 'lib/google/cloud/bigtable/cluster.rb', line 258

def create_backup source_table, backup_id, expire_time
  source_table_id = source_table.respond_to?(:name) ? source_table.name : source_table
  grpc = service.create_backup instance_id:     instance_id,
                               cluster_id:      cluster_id,
                               backup_id:       backup_id,
                               source_table_id: source_table_id,
                               expire_time:     expire_time
  Backup::Job.from_grpc grpc, service
end

#creating?Boolean

The cluster is currently being created, and may be destroyed if the creation process encounters an error.

Returns:

  • (Boolean)


122
123
124
# File 'lib/google/cloud/bigtable/cluster.rb', line 122

def creating?
  state == :CREATING
end

#deleteBoolean

Permanently deletes the cluster.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"
cluster.delete

Returns:

  • (Boolean)

    Returns true if the cluster was deleted.



380
381
382
383
384
# File 'lib/google/cloud/bigtable/cluster.rb', line 380

def delete
  ensure_service!
  service.delete_cluster instance_id, cluster_id
  true
end

#disabled?Boolean

The cluster has no backing nodes. The data (tables) still exist, but no operations can be performed on the cluster.

Returns:

  • (Boolean)


145
146
147
# File 'lib/google/cloud/bigtable/cluster.rb', line 145

def disabled?
  state == :DISABLED
end

#instance_idString

The unique identifier for the instance to which the cluster belongs.

Returns:

  • (String)


73
74
75
# File 'lib/google/cloud/bigtable/cluster.rb', line 73

def instance_id
  @grpc.name.split("/")[3]
end

#kms_keyString?

The full name of the Cloud KMS encryption key for the cluster, if it is CMEK-protected, in the format projects/{key_project_id}/locations/{location}/keyRings/{ring_name}/cryptoKeys/{key_name}.

The requirements for this key are:

  1. The Cloud Bigtable service account associated with the project that contains this cluster must be granted the cloudkms.cryptoKeyEncrypterDecrypter role on the CMEK key.
  2. Only regional keys can be used and the region of the CMEK key must match the region of the cluster.
  3. All clusters within an instance must use the same CMEK key.

Returns:

  • (String, nil)

    The full name of the Cloud KMS encryption key, or nil if the cluster is not CMEK-protected.



216
217
218
# File 'lib/google/cloud/bigtable/cluster.rb', line 216

def kms_key
  @grpc.encryption_config&.kms_key_name
end

#locationString

Cluster location. For example, "us-east1-b"

Returns:

  • (String)


188
189
190
# File 'lib/google/cloud/bigtable/cluster.rb', line 188

def location
  @grpc.location.split("/")[3]
end

#location_pathString

Cluster location path in form of projects/<project_id>/locations/<zone>

Returns:

  • (String)


198
199
200
# File 'lib/google/cloud/bigtable/cluster.rb', line 198

def location_path
  @grpc.location
end

#nodesInteger

The number of nodes allocated to this cluster.

Returns:

  • (Integer)


154
155
156
# File 'lib/google/cloud/bigtable/cluster.rb', line 154

def nodes
  @grpc.serve_nodes
end

#nodes=(serve_nodes) ⇒ Object

The number of nodes allocated to this cluster. More nodes enable higher throughput and more consistent performance.

Parameters:

  • serve_nodes (Integer)

    Number of nodes



164
165
166
# File 'lib/google/cloud/bigtable/cluster.rb', line 164

def nodes= serve_nodes
  @grpc.serve_nodes = serve_nodes
end

#pathString

The unique name of the cluster. Value in the form projects/<project_id>/instances/<instance_id>/clusters/<cluster_id>.

Returns:

  • (String)


92
93
94
# File 'lib/google/cloud/bigtable/cluster.rb', line 92

def path
  @grpc.name
end

#project_idString

The unique identifier for the project to which the cluster belongs.

Returns:

  • (String)


64
65
66
# File 'lib/google/cloud/bigtable/cluster.rb', line 64

def project_id
  @grpc.name.split("/")[1]
end

#ready?Boolean

The cluster has been successfully created and is ready to serve requests.

Returns:

  • (Boolean)


112
113
114
# File 'lib/google/cloud/bigtable/cluster.rb', line 112

def ready?
  state == :READY
end

#reload!Google::Cloud::Bigtable::Cluster

Reloads cluster data.



361
362
363
364
# File 'lib/google/cloud/bigtable/cluster.rb', line 361

def reload!
  @grpc = service.get_cluster instance_id, cluster_id
  self
end

#resizing?Boolean

The cluster is currently being resized, and may revert to its previous node count if the process encounters an error. A cluster is still capable of serving requests while being resized, but may perform as if its number of allocated nodes is between the starting and requested states.

Returns:

  • (Boolean)


135
136
137
# File 'lib/google/cloud/bigtable/cluster.rb', line 135

def resizing?
  state == :RESIZING
end

#saveGoogle::Cloud::Bigtable::Cluster::Job Also known as: update

Updates the cluster.

serve_nodes is the only updatable field.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"
cluster.nodes = 3
job = cluster.save

job.done? #=> false

# To block until the operation completes.
job.wait_until_done!
job.done? #=> true

if job.error?
  status = job.error
else
  cluster = job.cluster
end

Returns:



349
350
351
352
353
# File 'lib/google/cloud/bigtable/cluster.rb', line 349

def save
  ensure_service!
  grpc = service.update_cluster instance_id, cluster_id, location_path, nodes
  Cluster::Job.from_grpc grpc, service
end

#stateSymbol

The current state of the cluster. Possible values are :CREATING, :READY, :STATE_NOT_KNOWN, :RESIZING, :DISABLED.

Returns:

  • (Symbol)


103
104
105
# File 'lib/google/cloud/bigtable/cluster.rb', line 103

def state
  @grpc.state
end

#storage_typeSymbol

The type of storage used by this cluster to serve its parent instance's tables, unless explicitly overridden. Valid values are:

  • :SSD - Flash (SSD) storage should be used.
  • :HDD - Magnetic drive (HDD) storage should be used.

Returns:

  • (Symbol)


178
179
180
# File 'lib/google/cloud/bigtable/cluster.rb', line 178

def storage_type
  @grpc.default_storage_type
end