Class: Google::Cloud::Spanner::Instance
- Inherits:
-
Object
- Object
- Google::Cloud::Spanner::Instance
- Defined in:
- lib/google/cloud/spanner/instance.rb,
lib/google/cloud/spanner/instance/job.rb,
lib/google/cloud/spanner/instance/list.rb,
lib/google/cloud/spanner/instance/config.rb,
lib/google/cloud/spanner/instance/config/list.rb
Overview
Instance
Represents a Cloud Spanner instance. Instances are dedicated Cloud Spanner serving and storage resources to be used by Cloud Spanner databases. Instances offer isolation: problems with databases in one instance will not affect other instances. However, within an instance databases can affect each other. For example, if one database in an instance receives a lot of requests and consumes most of the instance resources, fewer resources are available for other databases in that instance, and their performance may suffer.
See Project#instances, Project#instance, and Project#create_instance.
Defined Under Namespace
Instance Method Summary collapse
-
#config ⇒ Instance::Config
The instance configuration resource.
-
#create_database(database_id, statements: []) ⇒ Database::Job
Creates a database and starts preparing it to begin serving.
-
#creating? ⇒ Boolean
The instance is still being created.
-
#database(database_id) ⇒ Google::Cloud::Spanner::Database?
Retrieves a database belonging to the instance by identifier.
-
#databases(token: nil, max: nil) ⇒ Array<Google::Cloud::Spanner::Database>
Retrieves the list of databases for the given instance.
-
#delete ⇒ Boolean
Permanently deletes the instance.
-
#instance_id ⇒ String
The unique identifier for the instance.
-
#labels ⇒ Hash{String=>String}
Cloud Labels are a flexible and lightweight mechanism for organizing cloud resources into groups that reflect a customer's organizational needs and deployment strategies.
-
#labels=(labels) ⇒ Object
Updates the Cloud Labels.
-
#name ⇒ String
(also: #display_name)
The descriptive name for this instance as it appears in UIs.
-
#name=(display_name) ⇒ Object
(also: #display_name=)
Updates the descriptive name for this instance as it appears in UIs.
-
#nodes ⇒ Integer
(also: #node_count)
The number of nodes allocated to this instance.
-
#nodes=(nodes) ⇒ Object
(also: #node_count=)
Updates the number of nodes allocated to this instance.
-
#path ⇒ String
The full path for the instance resource.
-
#policy {|policy| ... } ⇒ Policy
Gets the Cloud IAM access control policy for this instance.
-
#project_id ⇒ String
The unique identifier for the project.
-
#ready? ⇒ Boolean
The instance is fully created and ready to do work such as creating databases.
- #save ⇒ Object (also: #update)
-
#state ⇒ Symbol
The current instance state.
-
#test_permissions(*permissions) ⇒ Array<Strings>
Tests the specified permissions against the Cloud IAM access control policy.
-
#update_policy(new_policy) ⇒ Policy
(also: #policy=)
Updates the Cloud IAM access control policy for this instance.
Instance Method Details
#config ⇒ Instance::Config
The instance configuration resource.
105 106 107 108 109 110 111 |
# File 'lib/google/cloud/spanner/instance.rb', line 105 def config ensure_service! config_grpc = service.get_instance_config @grpc.config Instance::Config.from_grpc config_grpc rescue Google::Cloud::NotFoundError @grpc.config end |
#create_database(database_id, statements: []) ⇒ Database::Job
Creates a database and starts preparing it to begin serving.
See Database::Job.
331 332 333 334 335 |
# File 'lib/google/cloud/spanner/instance.rb', line 331 def create_database database_id, statements: [] grpc = service.create_database instance_id, database_id, statements: statements Database::Job.from_grpc grpc, service end |
#creating? ⇒ Boolean
The instance is still being created. Resources may not be available yet, and operations such as database creation may not work.
149 150 151 |
# File 'lib/google/cloud/spanner/instance.rb', line 149 def creating? state == :CREATING end |
#database(database_id) ⇒ Google::Cloud::Spanner::Database?
Retrieves a database belonging to the instance by identifier.
287 288 289 290 291 292 293 |
# File 'lib/google/cloud/spanner/instance.rb', line 287 def database database_id ensure_service! grpc = service.get_database instance_id, database_id Database.from_grpc grpc, service rescue Google::Cloud::NotFoundError nil end |
#databases(token: nil, max: nil) ⇒ Array<Google::Cloud::Spanner::Database>
Retrieves the list of databases for the given instance.
259 260 261 262 263 |
# File 'lib/google/cloud/spanner/instance.rb', line 259 def databases token: nil, max: nil ensure_service! grpc = service.list_databases instance_id, token: token, max: max Database::List.from_grpc grpc, service, instance_id, max end |
#delete ⇒ Boolean
Permanently deletes the instance.
Immediately upon completion of the request:
- Billing ceases for all of the instance's reserved resources.
Soon afterward:
- The instance and all of its databases immediately and irrevocably disappear from the API. All data in the databases is permanently deleted.
220 221 222 223 224 |
# File 'lib/google/cloud/spanner/instance.rb', line 220 def delete ensure_service! service.delete_instance path true end |
#instance_id ⇒ String
The unique identifier for the instance.
81 82 83 |
# File 'lib/google/cloud/spanner/instance.rb', line 81 def instance_id @grpc.name.split("/")[3] end |
#labels ⇒ Hash{String=>String}
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. They can be used to control how resource metrics are aggregated. And they can be used 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.
177 178 179 |
# File 'lib/google/cloud/spanner/instance.rb', line 177 def labels @grpc.labels end |
#labels=(labels) ⇒ Object
Updates the Cloud Labels.
184 185 186 187 188 189 |
# File 'lib/google/cloud/spanner/instance.rb', line 184 def labels= labels @grpc.labels = Google::Protobuf::Map.new( :string, :string, Hash[labels.map { |k, v| [String(k), String(v)] }] ) end |
#name ⇒ String Also known as: display_name
The descriptive name for this instance as it appears in UIs. Must be unique per project and between 4 and 30 characters in length.
97 98 99 |
# File 'lib/google/cloud/spanner/instance.rb', line 97 def name @grpc.display_name end |
#name=(display_name) ⇒ Object Also known as: display_name=
Updates the descriptive name for this instance as it appears in UIs.
116 117 118 |
# File 'lib/google/cloud/spanner/instance.rb', line 116 def name= display_name @grpc.display_name = display_name end |
#nodes ⇒ Integer Also known as: node_count
The number of nodes allocated to this instance.
124 125 126 |
# File 'lib/google/cloud/spanner/instance.rb', line 124 def nodes @grpc.node_count end |
#nodes=(nodes) ⇒ Object Also known as: node_count=
Updates the number of nodes allocated to this instance.
132 133 134 |
# File 'lib/google/cloud/spanner/instance.rb', line 132 def nodes= nodes @grpc.node_count = nodes end |
#path ⇒ String
The full path for the instance resource. Values are of the form
projects/<project_id>/instances/<instance_id>
.
89 90 91 |
# File 'lib/google/cloud/spanner/instance.rb', line 89 def path @grpc.name end |
#policy {|policy| ... } ⇒ Policy
Gets the Cloud IAM access control policy for this instance.
371 372 373 374 375 376 377 378 |
# File 'lib/google/cloud/spanner/instance.rb', line 371 def policy ensure_service! grpc = service.get_instance_policy path policy = Policy.from_grpc grpc return policy unless block_given? yield policy update_policy policy end |
#project_id ⇒ String
The unique identifier for the project.
75 76 77 |
# File 'lib/google/cloud/spanner/instance.rb', line 75 def project_id @grpc.name.split("/")[1] end |
#ready? ⇒ Boolean
The instance is fully created and ready to do work such as creating databases.
157 158 159 |
# File 'lib/google/cloud/spanner/instance.rb', line 157 def ready? state == :READY end |
#save ⇒ Object Also known as: update
191 192 193 194 |
# File 'lib/google/cloud/spanner/instance.rb', line 191 def save job_grpc = service.update_instance @grpc Instance::Job.from_grpc job_grpc, service end |
#state ⇒ Symbol
The current instance state. Possible values are :CREATING
and
:READY
.
141 142 143 |
# File 'lib/google/cloud/spanner/instance.rb', line 141 def state @grpc.state end |
#test_permissions(*permissions) ⇒ Array<Strings>
Tests the specified permissions against the Cloud IAM access control policy.
449 450 451 452 453 454 455 |
# File 'lib/google/cloud/spanner/instance.rb', line 449 def * = Array().flatten = Array().flatten ensure_service! grpc = service. path, grpc. 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.
409 410 411 412 413 |
# File 'lib/google/cloud/spanner/instance.rb', line 409 def update_policy new_policy ensure_service! grpc = service.set_instance_policy path, new_policy.to_grpc Policy.from_grpc grpc end |