-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Another step in continuing the work in: https://github.com/spollapally/google-cloud-java/tree/instance-admin-client/google-cloud-clients/google-cloud-bigtable
- Loading branch information
1 parent
9cbc0ef
commit f01e813
Showing
5 changed files
with
658 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
125 changes: 125 additions & 0 deletions
125
...e-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateClusterRequest.java
This file contains 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,125 @@ | ||
/* | ||
* Copyright 2018 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 | ||
* | ||
* https://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.google.cloud.bigtable.admin.v2.models; | ||
|
||
import com.google.api.core.InternalApi; | ||
import com.google.bigtable.admin.v2.InstanceName; | ||
import com.google.bigtable.admin.v2.LocationName; | ||
import com.google.bigtable.admin.v2.ProjectName; | ||
import com.google.bigtable.admin.v2.StorageType; | ||
|
||
/** | ||
* Parameters for creating a new Bigtable cluster. | ||
* | ||
* <p>A cluster represents the actual Cloud Bigtable service. Each cluster belongs to a single Cloud | ||
* Bigtable instance. When your application sends requests to a Cloud Bigtable instance, those | ||
* requests are actually handled by one of the clusters in the instance. | ||
* | ||
* <p>Each cluster is located in a single zone. An instance's clusters must be in unique zones that | ||
* are within the same region. For example, if the first cluster is in us-east1-b, then us-east1-c | ||
* is a valid zone for the second cluster. For a list of zones and regions where Cloud Bigtable is | ||
* available, see <a href="https://cloud.google.com/bigtable/docs/locations">Cloud Bigtable Locations</a>. | ||
* | ||
* | ||
* Examples: | ||
* | ||
* <pre>{@code | ||
* // Small production instance: | ||
* CreateClusterRequest clusterRequest = CreateClusterRequest.of("my-existing-instance", "my-cluster") | ||
* .setZone("us-east1-c") | ||
* .setServeNodes(3) | ||
* .setStorageType(StorageType.SSD); | ||
* }</pre> | ||
* | ||
* @see <a href="https://cloud.google.com/bigtable/docs/instances-clusters-nodes#clusters">For more details</a> | ||
*/ | ||
public final class CreateClusterRequest { | ||
private final com.google.bigtable.admin.v2.CreateClusterRequest.Builder proto = com.google.bigtable.admin.v2.CreateClusterRequest | ||
.newBuilder(); | ||
private final String instanceId; | ||
private String zone; | ||
|
||
|
||
/** | ||
* Builds a new request to create a new cluster to the specified instance with the specified | ||
* cluster id. */ | ||
public static CreateClusterRequest of(String instanceId, String clusterId) { | ||
return new CreateClusterRequest(instanceId, clusterId); | ||
} | ||
|
||
private CreateClusterRequest(String instanceId, String clusterId) { | ||
this.instanceId = instanceId; | ||
proto.setClusterId(clusterId); | ||
proto.getClusterBuilder().setDefaultStorageType(StorageType.SSD); | ||
} | ||
|
||
/** | ||
* Sets the zone where the new cluster will be located. Must be different from the existing | ||
* cluster. | ||
*/ | ||
public CreateClusterRequest setZone(String zone) { | ||
this.zone = zone; | ||
return this; | ||
} | ||
|
||
/** Sets the type of storage used by this cluster to serve its parent instance's tables. */ | ||
public CreateClusterRequest setServeNodes(int numNodes) { | ||
proto.getClusterBuilder().setServeNodes(numNodes); | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the type of storage used by this cluster to serve its parent instance's tables. | ||
* Defaults to {@code SSD}. | ||
*/ | ||
// TODO(igorbernstein2): try to avoid leaking protobuf generated enums | ||
public CreateClusterRequest setStorageType(StorageType storageType) { | ||
proto.getClusterBuilder().setDefaultStorageType(storageType); | ||
return this; | ||
} | ||
|
||
/** | ||
* Creates the request protobuf. This method is considered an internal implementation detail and | ||
* not meant to be used by applications. | ||
*/ | ||
@InternalApi | ||
public com.google.bigtable.admin.v2.CreateClusterRequest toProto(ProjectName projectName) { | ||
proto.setParent(InstanceName.of(projectName.getProject(), instanceId).toString()); | ||
proto.getClusterBuilder().setLocation(LocationName.of(projectName.getProject(), zone).toString()); | ||
|
||
return proto.build(); | ||
} | ||
|
||
/** | ||
* Gets the clusterId. This method is meant to be used by {@link CreateClusterRequest} and is | ||
* considered an internal implementation detail and not meant to be used by applications. | ||
*/ | ||
@InternalApi | ||
String getClusterId() { | ||
return proto.getClusterId(); | ||
} | ||
|
||
/** | ||
* Creates the request protobuf. This method is considered an internal implementation detail and | ||
* not meant to be used by applications. | ||
*/ | ||
@InternalApi | ||
com.google.bigtable.admin.v2.Cluster toEmbeddedProto(ProjectName projectName) { | ||
proto.getClusterBuilder().setLocation(LocationName.of(projectName.getProject(), zone).toString()); | ||
|
||
return proto.getClusterBuilder().build(); | ||
} | ||
} |
Oops, something went wrong.