Class: Google::Cloud::Bigtable::Instance
- Inherits:
-
Object
- Object
- Google::Cloud::Bigtable::Instance
- Defined in:
- lib/google/cloud/bigtable/instance.rb,
lib/google/cloud/bigtable/instance/job.rb,
lib/google/cloud/bigtable/instance/list.rb,
lib/google/cloud/bigtable/instance/cluster_map.rb
Overview
Instance
Represents a Bigtable instance. Instances are dedicated Bigtable storage resources that Bigtable tables.
See Project#instances, Project#instance, and Project#create_instance.
Defined Under Namespace
Classes: ClusterMap, Job, List
Instance Method Summary collapse
-
#app_profile(app_profile_id) ⇒ Google::Cloud::Bigtable::AppProfile?
Get app profile.
-
#app_profiles ⇒ Array<Google::Cloud::Bigtable::AppProfile>
List all app profiles.
-
#cluster(cluster_id) ⇒ Google::Cloud::Bigtable::Cluster?
Gets cluster information.
-
#clusters(token: nil) ⇒ Array<Google::Cloud::Bigtable::Cluster>
Lists information about clusters in an instance.
-
#create_app_profile(name, routing_policy, description: nil, etag: nil, ignore_warnings: false) ⇒ Google::Cloud::Bigtable::AppProfile
Create app profile for an instance with a routing policy.
-
#create_cluster(cluster_id, location, nodes: nil, storage_type: nil) ⇒ Google::Cloud::Bigtable::Cluster::Job
Creates a cluster within an instance.
-
#create_table(name, column_families: nil, granularity: nil, initial_splits: nil) {|column_families| ... } ⇒ Google::Cloud::Bigtable::Table
Create table.
-
#creating? ⇒ Boolean
The instance is currently being created and may be destroyed if the creation process encounters an error.
-
#delete ⇒ Boolean
Permanently deletes the instance from a project.
-
#development? ⇒ Boolean
The instance is meant for development and testing purposes only; it has no performance or uptime guarantees and is not covered by SLA.
-
#display_name ⇒ String
The descriptive name for this instance as it appears in UIs.
-
#display_name=(value) ⇒ Object
Updates the descriptive name for this instance as it appears in UIs.
-
#instance_id ⇒ String
The unique identifier for the instance.
-
#labels ⇒ Hash{String=>String}
Get instance labels.
-
#labels=(labels) ⇒ Object
Set the Cloud Labels.
-
#path ⇒ String
The full path for the instance resource.
-
#policy {|policy| ... } ⇒ Policy
Gets the Cloud IAM access control policy for this instance.
-
#production? ⇒ Boolean
An instance meant for production use.
-
#project_id ⇒ String
The unique identifier for the project.
-
#ready? ⇒ Boolean
The instance has been successfully created and can serve requests to its tables.
-
#reload! ⇒ Google::Cloud::Bigtable::Instance
Reload instance information.
-
#save ⇒ Google::Cloud::Bigtable::Instance::Job
(also: #update)
Update instance.
-
#state ⇒ Symbol
The current instance state.
-
#table(table_id, view: nil, perform_lookup: nil, app_profile_id: nil) ⇒ Google::Cloud::Bigtable::Table
Get metadata information of table.
-
#tables ⇒ Array<Google::Cloud::Bigtable::Table>
List all tables.
-
#test_iam_permissions(*permissions) ⇒ Array<Strings>
Tests the specified permissions against the Cloud IAM access control policy.
-
#type ⇒ Symbol
Instance type.
-
#type=(instance_type) ⇒ Object
Set instance type.
-
#update_policy(new_policy) ⇒ Policy
(also: #policy=)
Updates the Cloud IAM access control policy for this instance.
Instance Method Details
#app_profile(app_profile_id) ⇒ Google::Cloud::Bigtable::AppProfile?
Get app profile.
See to delete app_profile AppProfile#delete and update app_profile AppProfile#save.
740 741 742 743 744 745 746 |
# File 'lib/google/cloud/bigtable/instance.rb', line 740 def app_profile app_profile_id ensure_service! grpc = service.get_app_profile(instance_id, app_profile_id) AppProfile.from_grpc(grpc, service) rescue Google::Cloud::NotFoundError nil end |
#app_profiles ⇒ Array<Google::Cloud::Bigtable::AppProfile>
List all app profiles
See to delete app_profile AppProfile#delete and update app_profile AppProfile#save.
767 768 769 770 771 |
# File 'lib/google/cloud/bigtable/instance.rb', line 767 def app_profiles ensure_service! grpc = service.list_app_profiles(instance_id) AppProfile::List.from_grpc(grpc, service) end |
#cluster(cluster_id) ⇒ Google::Cloud::Bigtable::Cluster?
Gets cluster information.
See to delete Cluster#delete and update cluster Cluster#save.
343 344 345 346 347 348 349 |
# File 'lib/google/cloud/bigtable/instance.rb', line 343 def cluster cluster_id ensure_service! grpc = service.get_cluster(instance_id, cluster_id) Cluster.from_grpc(grpc, service) rescue Google::Cloud::NotFoundError nil end |
#clusters(token: nil) ⇒ Array<Google::Cloud::Bigtable::Cluster>
Lists information about clusters in an instance.
See to delete Cluster#delete and update cluster Cluster#save.
319 320 321 322 323 |
# File 'lib/google/cloud/bigtable/instance.rb', line 319 def clusters token: nil ensure_service! grpc = service.list_clusters(instance_id, token: token) Cluster::List.from_grpc(grpc, service, instance_id: instance_id) end |
#create_app_profile(name, routing_policy, description: nil, etag: nil, ignore_warnings: false) ⇒ Google::Cloud::Bigtable::AppProfile
Create app profile for an instance with a routing policy. Only one routing policy can applied to app profile. The policy can be multi-cluster routing or single cluster routing.
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 |
# File 'lib/google/cloud/bigtable/instance.rb', line 688 def create_app_profile \ name, routing_policy, description: nil, etag: nil, ignore_warnings: false ensure_service! if routing_policy.is_a?(Google::Bigtable::Admin::V2::AppProfile:: \ MultiClusterRoutingUseAny) multi_cluster_routing = routing_policy else single_cluster_routing = routing_policy end app_profile_attrs = { multi_cluster_routing_use_any: multi_cluster_routing, single_cluster_routing: single_cluster_routing, description: description, etag: etag }.delete_if { |_, v| v.nil? } grpc = service.create_app_profile( instance_id, name, Google::Bigtable::Admin::V2::AppProfile.new(app_profile_attrs), ignore_warnings: ignore_warnings ) AppProfile.from_grpc(grpc, service) end |
#create_cluster(cluster_id, location, nodes: nil, storage_type: nil) ⇒ Google::Cloud::Bigtable::Cluster::Job
Creates a cluster within an instance.
395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'lib/google/cloud/bigtable/instance.rb', line 395 def create_cluster cluster_id, location, nodes: nil, storage_type: nil ensure_service! attrs = { serve_nodes: nodes, default_storage_type: storage_type, location: location }.delete_if { |_, v| v.nil? } cluster = Google::Bigtable::Admin::V2::Cluster.new(attrs) grpc = service.create_cluster(instance_id, cluster_id, cluster) Cluster::Job.from_grpc(grpc, service) end |
#create_table(name, column_families: nil, granularity: nil, initial_splits: nil) {|column_families| ... } ⇒ Google::Cloud::Bigtable::Table
Create table
The table can be created with a full set of initial column families, specified in the request.
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
# File 'lib/google/cloud/bigtable/instance.rb', line 586 def create_table \ name, column_families: nil, granularity: nil, initial_splits: nil, &block ensure_service! Table.create( service, instance_id, name, column_families: column_families, granularity: granularity, initial_splits: initial_splits, &block ) end |
#creating? ⇒ Boolean
The instance is currently being created and may be destroyed if the creation process encounters an error.
142 143 144 |
# File 'lib/google/cloud/bigtable/instance.rb', line 142 def creating? state == :CREATING end |
#delete ⇒ Boolean
Permanently deletes the instance from a project.
291 292 293 294 295 |
# File 'lib/google/cloud/bigtable/instance.rb', line 291 def delete ensure_service! service.delete_instance(instance_id) true end |
#development? ⇒ Boolean
The instance is meant for development and testing purposes only; it has
no performance or uptime guarantees and is not covered by SLA.
After a development instance is created, it can be upgraded by
updating the instance to type PRODUCTION
. An instance created
as a production instance cannot be changed to a development instance.
When creating a development instance, serve_nodes
on the cluster must
not be set.
165 166 167 |
# File 'lib/google/cloud/bigtable/instance.rb', line 165 def development? type == :DEVELOPMENT end |
#display_name ⇒ String
The descriptive name for this instance as it appears in UIs. Must be unique per project and between 4 and 30 characters long.
96 97 98 |
# File 'lib/google/cloud/bigtable/instance.rb', line 96 def display_name @grpc.display_name end |
#display_name=(value) ⇒ Object
Updates the descriptive name for this instance as it appears in UIs. Can be changed at any time, but should be kept globally unique to avoid confusion.
106 107 108 |
# File 'lib/google/cloud/bigtable/instance.rb', line 106 def display_name= value @grpc.display_name = value end |
#instance_id ⇒ String
The unique identifier for the instance.
87 88 89 |
# File 'lib/google/cloud/bigtable/instance.rb', line 87 def instance_id @grpc.name.split("/")[3] end |
#labels ⇒ Hash{String=>String}
Get instance labels.
Cloud Labels are a flexible and lightweight mechanism for organizing cloud resources into groups that reflect a customer's organizational needs and deployment strategies. Cloud Labels can be used to filter collections of resources, to control how resource metrics are aggregated, and as arguments to policy management rules (e.g., route, firewall, load balancing, etc.).
- Label keys must be between 1 and 63 characters long and must conform
to the following regular expression:
[a-z]([-a-z0-9]*[a-z0-9])?
. - Label values must be between 0 and 63 characters long and must
conform to the regular expression
([a-z]([-a-z0-9]*[a-z0-9])?)?
. - No more than 64 labels can be associated with a given resource.
209 210 211 |
# File 'lib/google/cloud/bigtable/instance.rb', line 209 def labels @grpc.labels end |
#labels=(labels) ⇒ Object
Set the Cloud Labels.
217 218 219 220 221 222 223 |
# File 'lib/google/cloud/bigtable/instance.rb', line 217 def labels= labels labels ||= {} @grpc.labels = Google::Protobuf::Map.new( :string, :string, Hash[labels.map { |k, v| [String(k), String(v)] }] ) end |
#path ⇒ String
The full path for the instance resource. Values are of the form
projects/<project_id>/instances/<instance_id>
.
115 116 117 |
# File 'lib/google/cloud/bigtable/instance.rb', line 115 def path @grpc.name end |
#policy {|policy| ... } ⇒ Policy
Gets the Cloud IAM access control policy for this instance.
805 806 807 808 809 810 811 812 |
# File 'lib/google/cloud/bigtable/instance.rb', line 805 def policy ensure_service! grpc = service.get_instance_policy(instance_id) policy = Policy.from_grpc(grpc) return policy unless block_given? yield policy update_policy policy end |
#production? ⇒ Boolean
An instance meant for production use. serve_nodes
must be set
on the cluster.
174 175 176 |
# File 'lib/google/cloud/bigtable/instance.rb', line 174 def production? type == :PRODUCTION end |
#project_id ⇒ String
The unique identifier for the project.
79 80 81 |
# File 'lib/google/cloud/bigtable/instance.rb', line 79 def project_id @grpc.name.split("/")[1] end |
#ready? ⇒ Boolean
The instance has been successfully created and can serve requests to its tables.
133 134 135 |
# File 'lib/google/cloud/bigtable/instance.rb', line 133 def ready? state == :READY end |
#reload! ⇒ Google::Cloud::Bigtable::Instance
Reload instance information.
274 275 276 277 |
# File 'lib/google/cloud/bigtable/instance.rb', line 274 def reload! @grpc = service.get_instance(instance_id) self end |
#save ⇒ Google::Cloud::Bigtable::Instance::Job Also known as: update
Update instance.
Updatable attributes are :
display_name
- The descriptive name for this instance.type
-:DEVELOPMENT
type instance can be upgraded to:PRODUCTION
instance. An instance created as a production instance cannot be changed to a development instance.labels
- Cloud Labels are a flexible and lightweight mechanism for organizing cloud resources.
260 261 262 263 264 265 266 267 |
# File 'lib/google/cloud/bigtable/instance.rb', line 260 def save ensure_service! update_mask = Google::Protobuf::FieldMask.new( paths: %w[labels display_name type] ) grpc = service.partial_update_instance(@grpc, update_mask) Instance::Job.from_grpc(grpc, service) end |
#state ⇒ Symbol
The current instance state. Possible values are :CREATING
,
:READY
, :STATE_NOT_KNOWN
.
124 125 126 |
# File 'lib/google/cloud/bigtable/instance.rb', line 124 def state @grpc.state end |
#table(table_id, view: nil, perform_lookup: nil, app_profile_id: nil) ⇒ Google::Cloud::Bigtable::Table
Get metadata information of table.
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/google/cloud/bigtable/instance.rb', line 494 def table table_id, view: nil, perform_lookup: nil, app_profile_id: nil ensure_service! table = if perform_lookup grpc = service.get_table(instance_id, table_id, view: view) Table.from_grpc(grpc, service, view: view) else Table.from_path( service.table_path(instance_id, table_id), service ) end table.app_profile_id = app_profile_id table rescue Google::Cloud::NotFoundError nil end |
#tables ⇒ Array<Google::Cloud::Bigtable::Table>
List all tables.
See to delete table Table#delete and update table Table#save.
434 435 436 437 438 |
# File 'lib/google/cloud/bigtable/instance.rb', line 434 def tables ensure_service! grpc = service.list_tables(instance_id) Table::List.from_grpc(grpc, service) end |
#test_iam_permissions(*permissions) ⇒ Array<Strings>
Tests the specified permissions against the Cloud IAM access control policy.
883 884 885 886 887 888 889 890 |
# File 'lib/google/cloud/bigtable/instance.rb', line 883 def * ensure_service! grpc = service.( instance_id, Array().flatten ) grpc. end |
#type ⇒ Symbol
Instance type. Possible values are :DEVELOPMENT
, :PRODUCTION
,
:TYPE_UNSPECIFIED
151 152 153 |
# File 'lib/google/cloud/bigtable/instance.rb', line 151 def type @grpc.type end |
#type=(instance_type) ⇒ Object
Set instance type.
Valid values are :DEVELOPMENT
, :PRODUCTION
.
After a development instance is created, it can be upgraded
by updating the instance to type PRODUCTION
.
An instance created as a production instance cannot be changed to a
development instance.
188 189 190 |
# File 'lib/google/cloud/bigtable/instance.rb', line 188 def type= instance_type @grpc.type = instance_type end |
#update_policy(new_policy) ⇒ Policy Also known as: policy=
Updates the Cloud IAM access control
policy for this instance. The policy should be read from #policy.
See Policy for an explanation of the policy
etag
property and how to modify policies.
You can also update the policy by passing a block to #policy, which will call this method internally after the block completes.
840 841 842 843 844 |
# File 'lib/google/cloud/bigtable/instance.rb', line 840 def update_policy new_policy ensure_service! grpc = service.set_instance_policy(instance_id, new_policy.to_grpc) Policy.from_grpc(grpc) end |