diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Cluster.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Cluster.java
index 19ef7a026b69..a3812e91f0eb 100644
--- a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Cluster.java
+++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Cluster.java
@@ -16,10 +16,8 @@
package com.google.cloud.bigtable.admin.v2.models;
import com.google.api.core.InternalApi;
-import com.google.bigtable.admin.v2.Cluster.State;
import com.google.bigtable.admin.v2.ClusterName;
import com.google.bigtable.admin.v2.LocationName;
-import com.google.bigtable.admin.v2.StorageType;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Verify;
@@ -32,8 +30,63 @@
* in the instance.
*/
public class Cluster {
+ public enum State {
+ /** The state of the cluster could not be determined. */
+ NOT_KNOWN(com.google.bigtable.admin.v2.Cluster.State.STATE_NOT_KNOWN),
+ /** The cluster has been successfully created and is ready to serve requests. */
+ READY(com.google.bigtable.admin.v2.Cluster.State.READY),
+ /**
+ * The cluster is currently being created, and may be destroyed if the creation process
+ * encounters an error. A cluster may not be able to serve requests while being created.
+ */
+ CREATING(com.google.bigtable.admin.v2.Cluster.State.CREATING),
+ /**
+ * 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 exhibit performance as if its number of allocated nodes is between the
+ * starting and requested states.
+ */
+ RESIZING(com.google.bigtable.admin.v2.Cluster.State.RESIZING),
+ /**
+ * The cluster has no backing nodes. The data (tables) still exist, but no operations can be
+ * performed on the cluster.
+ */
+ DISABLED(com.google.bigtable.admin.v2.Cluster.State.DISABLED),
+ /** The state of the cluster is not known by this client. Please upgrade your client. */
+ UNRECOGNIZED(com.google.bigtable.admin.v2.Cluster.State.UNRECOGNIZED);
+
+ private final com.google.bigtable.admin.v2.Cluster.State proto;
+
+ /**
+ * Wraps the protobuf. This method is considered an internal implementation detail and not meant
+ * to be used by applications.
+ */
+ @InternalApi
+ public static State fromProto(com.google.bigtable.admin.v2.Cluster.State proto) {
+ for (State state : values()) {
+ if (state.proto.equals(proto)) {
+ return state;
+ }
+ }
+ return UNRECOGNIZED;
+ }
+
+ State(com.google.bigtable.admin.v2.Cluster.State proto) {
+ this.proto = proto;
+ }
+
+ /**
+ * 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.Cluster.State toProto() {
+ return proto;
+ }
+ }
+
@Nonnull
- private final com.google.bigtable.admin.v2.Cluster proto;
+ private final com.google.bigtable.admin.v2.Cluster stateProto;
/**
* Wraps a protobuf response.
@@ -49,7 +102,7 @@ public static Cluster fromProto(com.google.bigtable.admin.v2.Cluster proto) {
private Cluster(@Nonnull com.google.bigtable.admin.v2.Cluster proto) {
Preconditions.checkNotNull(proto);
Preconditions.checkArgument(!proto.getName().isEmpty(), "Name must be set");
- this.proto = proto;
+ this.stateProto = proto;
}
@@ -58,7 +111,7 @@ private Cluster(@Nonnull com.google.bigtable.admin.v2.Cluster proto) {
public String getId() {
// Constructor ensures that name is not null
ClusterName fullName = Verify.verifyNotNull(
- ClusterName.parse(proto.getName()),
+ ClusterName.parse(stateProto.getName()),
"Name can never be null");
//noinspection ConstantConditions
return fullName.getCluster();
@@ -69,7 +122,7 @@ public String getId() {
public String getInstanceId() {
// Constructor ensures that name is not null
ClusterName fullName = Verify.verifyNotNull(
- ClusterName.parse(proto.getName()),
+ ClusterName.parse(stateProto.getName()),
"Name can never be null");
//noinspection ConstantConditions
return fullName.getInstance();
@@ -80,16 +133,15 @@ public String getInstanceId() {
/** Get the zone where this cluster is located. */
@SuppressWarnings("WeakerAccess")
public String getZone() {
- LocationName location = Verify.verifyNotNull(LocationName.parse(proto.getLocation()));
+ LocationName location = Verify.verifyNotNull(LocationName.parse(stateProto.getLocation()));
//noinspection ConstantConditions
return location.getLocation();
}
/** Gets the current state of the cluster */
- // TODO(igorbernstein2): try to avoid exposing proto enums
@SuppressWarnings("WeakerAccess")
public State getState() {
- return proto.getState();
+ return State.fromProto(stateProto.getState());
}
/**
@@ -98,17 +150,16 @@ public State getState() {
*/
@SuppressWarnings("WeakerAccess")
public int getServeNodes() {
- return proto.getServeNodes();
+ return stateProto.getServeNodes();
}
/**
* The type of storage used by this cluster to serve its parent instance's tables, unless
* explicitly overridden.
*/
- // TODO(igorbernstein2): try to avoid exposing proto enums
@SuppressWarnings("WeakerAccess")
public StorageType getStorageType() {
- return proto.getDefaultStorageType();
+ return StorageType.fromProto(stateProto.getDefaultStorageType());
}
@Override
@@ -120,11 +171,11 @@ public boolean equals(Object o) {
return false;
}
Cluster cluster = (Cluster) o;
- return Objects.equal(proto, cluster.proto);
+ return Objects.equal(stateProto, cluster.stateProto);
}
@Override
public int hashCode() {
- return Objects.hashCode(proto);
+ return Objects.hashCode(stateProto);
}
}
diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateClusterRequest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateClusterRequest.java
index aefccd3f692b..477aaf83d790 100644
--- a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateClusterRequest.java
+++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateClusterRequest.java
@@ -15,23 +15,27 @@
*/
package com.google.cloud.bigtable.admin.v2.models;
+import static com.google.cloud.bigtable.admin.v2.models.StorageType.SSD;
+
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;
+import com.google.common.base.Preconditions;
+import javax.annotation.Nonnull;
/**
* Parameters for creating a new Bigtable cluster.
*
- *
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
+ *
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.
*
*
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 Cloud Bigtable Locations.
+ * available, see Cloud Bigtable
+ * Locations.
*
*
* Examples:
@@ -44,7 +48,8 @@
* .setStorageType(StorageType.SSD);
* }
*
- * @see For more details
+ * @see For more
+ * details
*/
public final class CreateClusterRequest {
private final com.google.bigtable.admin.v2.CreateClusterRequest.Builder proto = com.google.bigtable.admin.v2.CreateClusterRequest
@@ -57,7 +62,8 @@ public final class CreateClusterRequest {
/**
* Builds a new request to create a new cluster to the specified instance with the specified
- * cluster id. */
+ * cluster id.
+ */
public static CreateClusterRequest of(String instanceId, String clusterId) {
return new CreateClusterRequest(instanceId, clusterId);
}
@@ -65,7 +71,7 @@ public static CreateClusterRequest of(String instanceId, String clusterId) {
private CreateClusterRequest(String instanceId, String clusterId) {
this.instanceId = instanceId;
proto.setClusterId(clusterId);
- proto.getClusterBuilder().setDefaultStorageType(StorageType.SSD);
+ proto.getClusterBuilder().setDefaultStorageType(SSD.toProto());
}
/**
@@ -78,8 +84,10 @@ public CreateClusterRequest setZone(String zone) {
return this;
}
- /** Sets the number of nodes allocated to this cluster. More nodes enable higher throughput and
- * more consistent performance. */
+ /**
+ * Sets the number of nodes allocated to this cluster. More nodes enable higher throughput and
+ * more consistent performance.
+ */
@SuppressWarnings("WeakerAccess")
public CreateClusterRequest setServeNodes(int numNodes) {
proto.getClusterBuilder().setServeNodes(numNodes);
@@ -87,13 +95,16 @@ public CreateClusterRequest setServeNodes(int numNodes) {
}
/**
- * Sets the type of storage used by this cluster to serve its parent instance's tables.
- * Defaults to {@code SSD}.
+ * 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
@SuppressWarnings("WeakerAccess")
- public CreateClusterRequest setStorageType(StorageType storageType) {
- proto.getClusterBuilder().setDefaultStorageType(storageType);
+ public CreateClusterRequest setStorageType(@Nonnull StorageType storageType) {
+ Preconditions.checkNotNull(storageType);
+ Preconditions.checkArgument(storageType != StorageType.UNRECOGNIZED,
+ "StorageType can't be UNRECOGNIZED");
+
+ proto.getClusterBuilder().setDefaultStorageType(storageType.toProto());
return this;
}
@@ -104,7 +115,8 @@ public CreateClusterRequest setStorageType(StorageType storageType) {
@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());
+ proto.getClusterBuilder()
+ .setLocation(LocationName.of(projectName.getProject(), zone).toString());
return proto.build();
}
@@ -130,7 +142,8 @@ String getClusterId() {
*/
@InternalApi
com.google.bigtable.admin.v2.Cluster toEmbeddedProto(ProjectName projectName) {
- proto.getClusterBuilder().setLocation(LocationName.of(projectName.getProject(), zone).toString());
+ proto.getClusterBuilder()
+ .setLocation(LocationName.of(projectName.getProject(), zone).toString());
return proto.getClusterBuilder().build();
}
diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateInstanceRequest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateInstanceRequest.java
index 3def1a20ca8e..0fab41754555 100644
--- a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateInstanceRequest.java
+++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateInstanceRequest.java
@@ -18,7 +18,6 @@
import com.google.api.core.InternalApi;
import com.google.bigtable.admin.v2.Instance.Type;
import com.google.bigtable.admin.v2.ProjectName;
-import com.google.bigtable.admin.v2.StorageType;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.List;
@@ -31,13 +30,13 @@
* which do all of the real work. Instances come in 2 flavors:
*
*
- * - Production
- *
- A standard instance with either 1 or 2 clusters, as well as 3 or more nodes in each cluster.
- * You cannot downgrade a production instance to a development instance.
+ *
- Production
+ *
- A standard instance with either 1 or 2 clusters, as well as 3 or more nodes in each cluster.
+ * You cannot downgrade a production instance to a development instance.
*
- *
- Development
- *
- A low-cost instance for development and testing, with performance limited to the equivalent
- * of a 1-node cluster. Development instances only support a single 1 node cluster.
+ *
- Development
+ *
- A low-cost instance for development and testing, with performance limited to the equivalent
+ * of a 1-node cluster. Development instances only support a single 1 node cluster.
*
*
* When creating an Instance, you must create at least one cluster in it.
@@ -56,7 +55,8 @@
*
* }
*
- * @see For more details
+ * @see For more
+ * details
*/
public final class CreateInstanceRequest {
private final com.google.bigtable.admin.v2.CreateInstanceRequest.Builder builder =
@@ -93,11 +93,11 @@ public CreateInstanceRequest setDisplayName(@Nonnull String displayName) {
* Can be either DEVELOPMENT or PRODUCTION. Defaults to PRODUCTION.
* Please see class javadoc for details.
*/
- // TODO(igorbernstein2): try to avoid leaking protobuf generated enums
@SuppressWarnings("WeakerAccess")
- public CreateInstanceRequest setType(@Nonnull Type type) {
+ public CreateInstanceRequest setType(@Nonnull Instance.Type type) {
Preconditions.checkNotNull(type);
- builder.getInstanceBuilder().setType(type);
+ Preconditions.checkArgument(type != Instance.Type.UNRECOGNIZED, "Type is unrecognized");
+ builder.getInstanceBuilder().setType(type.toProto());
return this;
}
@@ -107,7 +107,8 @@ public CreateInstanceRequest setType(@Nonnull Type type) {
*
Labels are key-value pairs that you can use to group related instances and store metadata
* about an instance.
*
- * @see For more details
+ * @see For more
+ * details
*/
@SuppressWarnings("WeakerAccess")
public CreateInstanceRequest addLabel(@Nonnull String key, @Nonnull String value) {
@@ -125,12 +126,14 @@ public CreateInstanceRequest addLabel(@Nonnull String key, @Nonnull String value
*
* @param clusterId The name of the cluster.
* @param zone The zone where the cluster will be created.
- * @param serveNodes The number of nodes that cluster will contain. DEVELOPMENT instance clusters must have exactly one node.
- * @param storageType The type of storage used by this cluster to serve its parent instance's tables.
+ * @param serveNodes The number of nodes that cluster will contain. DEVELOPMENT instance clusters
+ * must have exactly one node.
+ * @param storageType The type of storage used by this cluster to serve its parent instance's
+ * tables.
*/
- // TODO(igorbernstein2): try to avoid leaking protobuf generated enums
@SuppressWarnings("WeakerAccess")
- public CreateInstanceRequest addCluster(@Nonnull String clusterId, @Nonnull String zone, int serveNodes, @Nonnull StorageType storageType) {
+ public CreateInstanceRequest addCluster(@Nonnull String clusterId, @Nonnull String zone,
+ int serveNodes, @Nonnull StorageType storageType) {
CreateClusterRequest clusterRequest = CreateClusterRequest
.of("ignored-instance-id", clusterId)
.setZone(zone)
@@ -152,7 +155,8 @@ public com.google.bigtable.admin.v2.CreateInstanceRequest toProto(ProjectName pr
.clearClusters();
for (CreateClusterRequest clusterRequest : clusterRequests) {
- builder.putClusters(clusterRequest.getClusterId(), clusterRequest.toEmbeddedProto(projectName));
+ builder
+ .putClusters(clusterRequest.getClusterId(), clusterRequest.toEmbeddedProto(projectName));
}
return builder.build();
diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Instance.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Instance.java
index 5d067aaaa24e..f928afcaa964 100644
--- a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Instance.java
+++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Instance.java
@@ -16,8 +16,6 @@
package com.google.cloud.bigtable.admin.v2.models;
import com.google.api.core.InternalApi;
-import com.google.bigtable.admin.v2.Instance.State;
-import com.google.bigtable.admin.v2.Instance.Type;
import com.google.bigtable.admin.v2.InstanceName;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
@@ -32,6 +30,91 @@
* all of the real work.
*/
public final class Instance {
+ public enum Type {
+ /** An instance meant for production use. `serve_nodes` must be set on the cluster. */
+ PRODUCTION(com.google.bigtable.admin.v2.Instance.Type.PRODUCTION),
+ /** The instance is meant for development and testing purposes only. */
+ DEVELOPMENT(com.google.bigtable.admin.v2.Instance.Type.DEVELOPMENT),
+ /** The type of instance is not known by this client. Please upgrade your client. */
+ UNRECOGNIZED(com.google.bigtable.admin.v2.Instance.Type.UNRECOGNIZED);
+
+ private final com.google.bigtable.admin.v2.Instance.Type proto;
+
+ /**
+ * Wraps the protobuf. This method is considered an internal implementation detail and not meant
+ * to be used by applications.
+ */
+ @InternalApi
+ public static Type fromProto(com.google.bigtable.admin.v2.Instance.Type proto) {
+ Preconditions.checkNotNull(proto);
+ Preconditions.checkArgument(proto != com.google.bigtable.admin.v2.Instance.Type.TYPE_UNSPECIFIED,
+ "Server instance type must always be specified");
+ for (Type type : values()) {
+ if (type.proto.equals(proto)) {
+ return type;
+ }
+ }
+ return UNRECOGNIZED;
+ }
+
+ Type(com.google.bigtable.admin.v2.Instance.Type proto) {
+ this.proto = proto;
+ }
+
+ /**
+ * 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.Instance.Type toProto() {
+ return proto;
+ }
+ }
+
+ public enum State {
+ /** The state of the instance could not be determined by the server. */
+ NOT_KNOWN(com.google.bigtable.admin.v2.Instance.State.STATE_NOT_KNOWN),
+ /** The instance has been successfully created and can serve requests to its tables. */
+ READY(com.google.bigtable.admin.v2.Instance.State.READY),
+ /**
+ * The instance is currently being created, and may be destroyed if the creation process
+ * encounters an error.
+ */
+ CREATING(com.google.bigtable.admin.v2.Instance.State.CREATING),
+ /** The state of instance is not known by this client. Please upgrade your client. */
+ UNRECOGNIZED(com.google.bigtable.admin.v2.Instance.State.UNRECOGNIZED);
+
+ private final com.google.bigtable.admin.v2.Instance.State proto;
+
+ /**
+ * Wraps the protobuf. This method is considered an internal implementation detail and not meant
+ * to be used by applications.
+ */
+ @InternalApi
+ public static State fromProto(com.google.bigtable.admin.v2.Instance.State proto) {
+ Preconditions.checkNotNull(proto);
+ for (State state : values()) {
+ if (state.proto.equals(proto)) {
+ return state;
+ }
+ }
+ return UNRECOGNIZED;
+ }
+
+ State(com.google.bigtable.admin.v2.Instance.State proto) {
+ this.proto = proto;
+ }
+
+ /**
+ * 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.Instance.State toProto() {
+ return proto;
+ }
+ }
+
@Nonnull
private final com.google.bigtable.admin.v2.Instance proto;
@@ -71,7 +154,7 @@ public String getDisplayName() {
/** Gets the instance's current type. Can be DEVELOPMENT or PRODUCTION. */
@SuppressWarnings("WeakerAccess")
public Type getType() {
- return proto.getType();
+ return Type.fromProto(proto.getType());
}
/**
@@ -87,10 +170,9 @@ public Map getLabels() {
/** The current state of the instance. */
- // TODO(igorbernstein2): Try to avoid leaking protobuf enums
@SuppressWarnings("WeakerAccess")
public State getState() {
- return proto.getState();
+ return State.fromProto(proto.getState());
}
@Override
diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/StorageType.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/StorageType.java
new file mode 100644
index 000000000000..b5dbd34c4ebe
--- /dev/null
+++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/StorageType.java
@@ -0,0 +1,62 @@
+/*
+ * 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.common.base.Preconditions;
+
+/** Storage media types for persisting Bigtable data. */
+public enum StorageType {
+ /** Flash (SSD) storage should be used. */
+ HDD(com.google.bigtable.admin.v2.StorageType.HDD),
+ /** Magnetic drive (HDD) storage should be used. */
+ SSD(com.google.bigtable.admin.v2.StorageType.SSD),
+ /** The storage type is not known by this client. Please upgrade your client. */
+ UNRECOGNIZED(com.google.bigtable.admin.v2.StorageType.UNRECOGNIZED);
+
+ private final com.google.bigtable.admin.v2.StorageType proto;
+
+ /**
+ * Wraps the protobuf. This method is considered an internal implementation detail and not meant
+ * to be used by applications.
+ */
+ @InternalApi
+ public static StorageType fromProto(com.google.bigtable.admin.v2.StorageType proto) {
+ Preconditions.checkNotNull(proto);
+ Preconditions.checkArgument(proto != com.google.bigtable.admin.v2.StorageType.STORAGE_TYPE_UNSPECIFIED,
+ "Storage type must be specified");
+
+ for (StorageType type : values()) {
+ if (type.proto.equals(proto)) {
+ return type;
+ }
+ }
+ return UNRECOGNIZED;
+ }
+
+ /**
+ * Creates the request protobuf. This method is considered an internal implementation detail and
+ * not meant to be used by applications.
+ */
+ @InternalApi
+ StorageType(com.google.bigtable.admin.v2.StorageType proto) {
+ this.proto = proto;
+ }
+
+ public com.google.bigtable.admin.v2.StorageType toProto() {
+ return proto;
+ }
+}
diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java
index 0a9733c32c51..215e62090f78 100644
--- a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java
+++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/models/Table.java
@@ -16,9 +16,9 @@
package com.google.cloud.bigtable.admin.v2.models;
import com.google.api.core.InternalApi;
-import com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState;
import com.google.bigtable.admin.v2.TableName;
import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.List;
@@ -28,6 +28,67 @@
/** Wrapper for {@link Table} protocol buffer object */
public final class Table {
+ public enum ReplicationState {
+ /** The replication state of the table is unknown in this cluster. */
+ NOT_KNOWN(com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.STATE_NOT_KNOWN),
+ /**
+ * The cluster was recently created, and the table must finish copying over pre-existing data
+ * from other clusters before it can begin receiving live replication updates and serving Data
+ * API requests.
+ */
+ INITIALIZING(com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.INITIALIZING),
+ /**
+ * The table is temporarily unable to serve Data API requests from this cluster due to planned
+ * internal maintenance.
+ */
+ PLANNED_MAINTENANCE(com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.PLANNED_MAINTENANCE),
+ /**
+ * The table is temporarily unable to serve Data API requests from this cluster due to unplanned
+ * or emergency maintenance.
+ */
+ UNPLANNED_MAINTENANCE(com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.UNPLANNED_MAINTENANCE),
+ /**
+ * The table can serve Data API requests from this cluster. Depending on replication delay,
+ * reads may not immediately reflect the state of the table in other clusters.
+ */
+ READY(com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.READY),
+
+ /** The replication state of table is not known by this client. Please upgrade your client. */
+ UNRECOGNIZED(com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.UNRECOGNIZED);
+
+
+ private final com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState proto;
+
+ /**
+ * Wraps the protobuf. This method is considered an internal implementation detail and not meant
+ * to be used by applications.
+ */
+ @InternalApi
+ public static ReplicationState fromProto(com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState proto) {
+ Preconditions.checkNotNull(proto);
+
+ for (ReplicationState state : values()) {
+ if (state.proto.equals(proto)) {
+ return state;
+ }
+ }
+ return UNRECOGNIZED;
+ }
+
+ ReplicationState(com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState proto) {
+ this.proto = proto;
+ }
+
+ /**
+ * 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.Table.ClusterState.ReplicationState toProto() {
+ return proto;
+ }
+ }
+
private final String id;
private final String instanceId;
private final Map replicationStatesByClusterId;
@@ -38,7 +99,7 @@ public static Table fromProto(@Nonnull com.google.bigtable.admin.v2.Table proto)
ImmutableMap.Builder replicationStates = ImmutableMap.builder();
for (Entry entry : proto.getClusterStatesMap().entrySet()) {
- replicationStates.put(entry.getKey(), entry.getValue().getReplicationState());
+ replicationStates.put(entry.getKey(), ReplicationState.fromProto(entry.getValue().getReplicationState()));
}
ImmutableList.Builder columnFamilies = ImmutableList.builder();
diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java
index afee494a1449..dadaa71d355c 100644
--- a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java
+++ b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTest.java
@@ -29,11 +29,9 @@
import com.google.bigtable.admin.v2.AppProfileName;
import com.google.bigtable.admin.v2.ClusterName;
import com.google.bigtable.admin.v2.CreateInstanceMetadata;
-import com.google.bigtable.admin.v2.Instance.Type;
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;
import com.google.bigtable.admin.v2.UpdateClusterMetadata;
import com.google.bigtable.admin.v2.UpdateInstanceMetadata;
import com.google.cloud.Identity;
@@ -50,6 +48,7 @@
import com.google.cloud.bigtable.admin.v2.models.Instance;
import com.google.cloud.bigtable.admin.v2.models.PartialListClustersException;
import com.google.cloud.bigtable.admin.v2.models.PartialListInstancesException;
+import com.google.cloud.bigtable.admin.v2.models.StorageType;
import com.google.cloud.bigtable.admin.v2.models.UpdateAppProfileRequest;
import com.google.cloud.bigtable.admin.v2.models.UpdateInstanceRequest;
import com.google.cloud.bigtable.admin.v2.stub.BigtableInstanceAdminStub;
@@ -176,13 +175,13 @@ public void testCreateInstance() {
.setInstanceId(INSTANCE_NAME.getInstance())
.setInstance(
com.google.bigtable.admin.v2.Instance.newBuilder()
- .setType(Type.DEVELOPMENT)
+ .setType(com.google.bigtable.admin.v2.Instance.Type.DEVELOPMENT)
.setDisplayName(INSTANCE_NAME.getInstance())
)
.putClusters("cluster1", com.google.bigtable.admin.v2.Cluster.newBuilder()
.setLocation("projects/my-project/locations/us-east1-c")
.setServeNodes(1)
- .setDefaultStorageType(StorageType.SSD)
+ .setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD)
.build()
)
.build();
@@ -197,7 +196,7 @@ public void testCreateInstance() {
// Execute
Instance actualResult = adminClient.createInstance(
CreateInstanceRequest.of(INSTANCE_NAME.getInstance())
- .setType(Type.DEVELOPMENT)
+ .setType(Instance.Type.DEVELOPMENT)
.addCluster("cluster1", "us-east1-c", 1, StorageType.SSD)
);
@@ -374,7 +373,7 @@ public void testCreateCluster() {
com.google.bigtable.admin.v2.Cluster.newBuilder()
.setLocation("projects/my-project/locations/us-east1-c")
.setServeNodes(3)
- .setDefaultStorageType(StorageType.SSD)
+ .setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD)
)
.build();
com.google.bigtable.admin.v2.Cluster expectedResponse = com.google.bigtable.admin.v2.Cluster
diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/ClusterTest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/ClusterTest.java
index 76e158c7603d..a517739c3814 100644
--- a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/ClusterTest.java
+++ b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/ClusterTest.java
@@ -17,22 +17,23 @@
import static com.google.common.truth.Truth.assertThat;
-import com.google.bigtable.admin.v2.Cluster.State;
-import com.google.bigtable.admin.v2.StorageType;
+import com.google.common.collect.Lists;
+import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class ClusterTest {
+
@Test
public void testFromProto() {
com.google.bigtable.admin.v2.Cluster proto = com.google.bigtable.admin.v2.Cluster.newBuilder()
.setName("projects/my-project/instances/my-instance/clusters/my-cluster")
.setLocation("projects/my-project/locations/us-east1-c")
- .setState(State.READY)
+ .setState(com.google.bigtable.admin.v2.Cluster.State.READY)
.setServeNodes(30)
- .setDefaultStorageType(StorageType.SSD)
+ .setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD)
.build();
Cluster result = Cluster.fromProto(proto);
@@ -40,7 +41,7 @@ public void testFromProto() {
assertThat(result.getId()).isEqualTo("my-cluster");
assertThat(result.getInstanceId()).isEqualTo("my-instance");
assertThat(result.getZone()).isEqualTo("us-east1-c");
- assertThat(result.getState()).isEqualTo(State.READY);
+ assertThat(result.getState()).isEqualTo(Cluster.State.READY);
assertThat(result.getServeNodes()).isEqualTo(30);
assertThat(result.getStorageType()).isEqualTo(StorageType.SSD);
}
@@ -49,9 +50,9 @@ public void testFromProto() {
public void testRequiresName() {
com.google.bigtable.admin.v2.Cluster proto = com.google.bigtable.admin.v2.Cluster.newBuilder()
.setLocation("projects/my-project/locations/us-east1-c")
- .setState(State.READY)
+ .setState(com.google.bigtable.admin.v2.Cluster.State.READY)
.setServeNodes(30)
- .setDefaultStorageType(StorageType.SSD)
+ .setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD)
.build();
Exception actualException = null;
@@ -64,4 +65,21 @@ public void testRequiresName() {
assertThat(actualException).isInstanceOf(IllegalArgumentException.class);
}
+
+ @Test
+ public void testStateEnumUpToDate() {
+ List validProtoValues =
+ Lists.newArrayList(com.google.bigtable.admin.v2.Cluster.State.values());
+
+ List validModelValues = Lists.newArrayList(Cluster.State.values());
+
+ List actualModelValues = Lists.newArrayList();
+
+ for (com.google.bigtable.admin.v2.Cluster.State protoValue : validProtoValues) {
+ Cluster.State modelValue = Cluster.State.fromProto(protoValue);
+ actualModelValues.add(modelValue);
+ }
+
+ assertThat(actualModelValues).containsExactlyElementsIn(validModelValues);
+ }
}
diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateClusterRequestTest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateClusterRequestTest.java
index dd0c318bd559..bbf8249b1224 100644
--- a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateClusterRequestTest.java
+++ b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateClusterRequestTest.java
@@ -17,11 +17,7 @@
import static com.google.common.truth.Truth.assertThat;
-import com.google.bigtable.admin.v2.Cluster;
-import com.google.bigtable.admin.v2.Instance;
-import com.google.bigtable.admin.v2.Instance.Type;
import com.google.bigtable.admin.v2.ProjectName;
-import com.google.bigtable.admin.v2.StorageType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -31,7 +27,7 @@ public class CreateClusterRequestTest {
@Test
public void testProductionSingle() {
CreateInstanceRequest input = CreateInstanceRequest.of("my-instance")
- .setType(Type.PRODUCTION)
+ .setType(Instance.Type.PRODUCTION)
.addCluster("cluster1", "us-east1-c", 3, StorageType.SSD);
com.google.bigtable.admin.v2.CreateInstanceRequest actual = input
@@ -42,15 +38,15 @@ public void testProductionSingle() {
.setParent(ProjectName.of("my-project").toString())
.setInstanceId("my-instance")
.setInstance(
- Instance.newBuilder()
+ com.google.bigtable.admin.v2.Instance.newBuilder()
.setDisplayName("my-instance")
- .setType(Type.PRODUCTION)
+ .setType(com.google.bigtable.admin.v2.Instance.Type.PRODUCTION)
)
.putClusters("cluster1",
- Cluster.newBuilder()
+ com.google.bigtable.admin.v2.Cluster.newBuilder()
.setLocation("projects/my-project/locations/us-east1-c")
.setServeNodes(3)
- .setDefaultStorageType(StorageType.SSD)
+ .setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD)
.build()
)
.build();
@@ -61,7 +57,7 @@ public void testProductionSingle() {
@Test
public void testProductionReplication() {
CreateInstanceRequest input = CreateInstanceRequest.of("my-instance")
- .setType(Type.PRODUCTION)
+ .setType(Instance.Type.PRODUCTION)
.addCluster("cluster1", "us-east1-c", 3, StorageType.SSD)
.addCluster("cluster2", "us-east1-a", 3, StorageType.SSD);
@@ -73,22 +69,22 @@ public void testProductionReplication() {
.setParent(ProjectName.of("my-project").toString())
.setInstanceId("my-instance")
.setInstance(
- Instance.newBuilder()
+ com.google.bigtable.admin.v2.Instance.newBuilder()
.setDisplayName("my-instance")
- .setType(Type.PRODUCTION)
+ .setType(com.google.bigtable.admin.v2.Instance.Type.PRODUCTION)
)
.putClusters("cluster1",
- Cluster.newBuilder()
+ com.google.bigtable.admin.v2.Cluster.newBuilder()
.setLocation("projects/my-project/locations/us-east1-c")
.setServeNodes(3)
- .setDefaultStorageType(StorageType.SSD)
+ .setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD)
.build()
)
.putClusters("cluster2",
- Cluster.newBuilder()
+ com.google.bigtable.admin.v2.Cluster.newBuilder()
.setLocation("projects/my-project/locations/us-east1-a")
.setServeNodes(3)
- .setDefaultStorageType(StorageType.SSD)
+ .setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD)
.build()
)
.build();
@@ -99,7 +95,7 @@ public void testProductionReplication() {
@Test
public void testDevelopment() {
CreateInstanceRequest input = CreateInstanceRequest.of("my-instance")
- .setType(Type.DEVELOPMENT)
+ .setType(Instance.Type.DEVELOPMENT)
.addCluster("cluster1", "us-east1-c", 1, StorageType.SSD);
com.google.bigtable.admin.v2.CreateInstanceRequest actual = input
@@ -110,15 +106,15 @@ public void testDevelopment() {
.setParent(ProjectName.of("my-project").toString())
.setInstanceId("my-instance")
.setInstance(
- Instance.newBuilder()
+ com.google.bigtable.admin.v2.Instance.newBuilder()
.setDisplayName("my-instance")
- .setType(Type.DEVELOPMENT)
+ .setType(com.google.bigtable.admin.v2.Instance.Type.DEVELOPMENT)
)
.putClusters("cluster1",
- Cluster.newBuilder()
+ com.google.bigtable.admin.v2.Cluster.newBuilder()
.setLocation("projects/my-project/locations/us-east1-c")
.setServeNodes(1)
- .setDefaultStorageType(StorageType.SSD)
+ .setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD)
.build()
)
.build();
@@ -132,7 +128,7 @@ public void testOptionalFields() {
.setDisplayName("custom display name")
.addLabel("my label", "with some value")
.addLabel("my other label", "with some value")
- .setType(Type.DEVELOPMENT)
+ .setType(Instance.Type.DEVELOPMENT)
.addCluster("cluster1", "us-east1-c", 1, StorageType.SSD);
com.google.bigtable.admin.v2.CreateInstanceRequest actual = input
@@ -143,17 +139,17 @@ public void testOptionalFields() {
.setParent(ProjectName.of("my-project").toString())
.setInstanceId("my-instance")
.setInstance(
- Instance.newBuilder()
+ com.google.bigtable.admin.v2.Instance.newBuilder()
.setDisplayName("custom display name")
.putLabels("my label", "with some value")
.putLabels("my other label", "with some value")
- .setType(Type.DEVELOPMENT)
+ .setType(com.google.bigtable.admin.v2.Instance.Type.DEVELOPMENT)
)
.putClusters("cluster1",
- Cluster.newBuilder()
+ com.google.bigtable.admin.v2.Cluster.newBuilder()
.setLocation("projects/my-project/locations/us-east1-c")
.setServeNodes(1)
- .setDefaultStorageType(StorageType.SSD)
+ .setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD)
.build()
)
.build();
diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/InstanceTest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/InstanceTest.java
index 3d63bab16d0c..4687bbae8767 100644
--- a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/InstanceTest.java
+++ b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/InstanceTest.java
@@ -17,21 +17,22 @@
import static com.google.common.truth.Truth.assertThat;
-import com.google.bigtable.admin.v2.Instance.State;
-import com.google.bigtable.admin.v2.Instance.Type;
+import com.google.common.collect.Lists;
+import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class InstanceTest {
+
@Test
public void testFromProto() {
com.google.bigtable.admin.v2.Instance proto = com.google.bigtable.admin.v2.Instance.newBuilder()
.setName("projects/my-project/instances/my-instance")
.setDisplayName("my display name")
- .setType(Type.PRODUCTION)
- .setState(State.READY)
+ .setType(com.google.bigtable.admin.v2.Instance.Type.PRODUCTION)
+ .setState(com.google.bigtable.admin.v2.Instance.State.READY)
.putLabels("label1", "value1")
.putLabels("label2", "value2")
.build();
@@ -40,8 +41,8 @@ public void testFromProto() {
assertThat(result.getId()).isEqualTo("my-instance");
assertThat(result.getDisplayName()).isEqualTo("my display name");
- assertThat(result.getType()).isEqualTo(Type.PRODUCTION);
- assertThat(result.getState()).isEqualTo(State.READY);
+ assertThat(result.getType()).isEqualTo(Instance.Type.PRODUCTION);
+ assertThat(result.getState()).isEqualTo(Instance.State.READY);
assertThat(result.getLabels()).containsExactly(
"label1", "value1",
"label2", "value2"
@@ -52,8 +53,8 @@ public void testFromProto() {
public void testRequiresName() {
com.google.bigtable.admin.v2.Instance proto = com.google.bigtable.admin.v2.Instance.newBuilder()
.setDisplayName("my display name")
- .setType(Type.PRODUCTION)
- .setState(State.READY)
+ .setType(com.google.bigtable.admin.v2.Instance.Type.PRODUCTION)
+ .setState(com.google.bigtable.admin.v2.Instance.State.READY)
.putLabels("label1", "value1")
.putLabels("label2", "value2")
.build();
@@ -68,4 +69,47 @@ public void testRequiresName() {
assertThat(actualException).isInstanceOf(IllegalArgumentException.class);
}
+
+ @Test
+ public void testTypeEnumUpToDate() {
+ List validProtoValues =
+ Lists.newArrayList(com.google.bigtable.admin.v2.Instance.Type.values());
+
+ // TYPE_UNSPECIFIED is not surfaced
+ validProtoValues.remove(com.google.bigtable.admin.v2.Instance.Type.TYPE_UNSPECIFIED);
+
+ Exception actualError = null;
+ try {
+ Instance.Type.fromProto(com.google.bigtable.admin.v2.Instance.Type.TYPE_UNSPECIFIED);
+ } catch (Exception e) {
+ actualError = e;
+ }
+ assertThat(actualError).isInstanceOf(IllegalArgumentException.class);
+
+ List validModelValues = Lists.newArrayList(Instance.Type.values());
+
+ List actualModelValues = Lists.newArrayList();
+ for (com.google.bigtable.admin.v2.Instance.Type protoValue : validProtoValues) {
+ actualModelValues.add(Instance.Type.fromProto(protoValue));
+ }
+
+ assertThat(actualModelValues).containsExactlyElementsIn(validModelValues);
+ }
+
+ @Test
+ public void testStateEnumUpToDate() {
+ List validProtoValues =
+ Lists.newArrayList(com.google.bigtable.admin.v2.Instance.State.values());
+
+ List validModelValues = Lists.newArrayList(Instance.State.values());
+
+ List actualModelValues = Lists.newArrayList();
+
+ for (com.google.bigtable.admin.v2.Instance.State protoValue : validProtoValues) {
+ Instance.State modelValue = Instance.State.fromProto(protoValue);
+ actualModelValues.add(modelValue);
+ }
+
+ assertThat(actualModelValues).containsExactlyElementsIn(validModelValues);
+ }
}
diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/StorageTypeTest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/StorageTypeTest.java
new file mode 100644
index 000000000000..fd704a7ee486
--- /dev/null
+++ b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/StorageTypeTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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 static com.google.common.truth.Truth.assertThat;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class StorageTypeTest {
+ @Test
+ public void testUpToDate() {
+ List validProtoValues =
+ Lists.newArrayList(com.google.bigtable.admin.v2.StorageType.values());
+
+ // TYPE_UNSPECIFIED is not surfaced
+ validProtoValues.remove(com.google.bigtable.admin.v2.StorageType.STORAGE_TYPE_UNSPECIFIED);
+
+ Exception actualError = null;
+ try {
+ StorageType.fromProto(com.google.bigtable.admin.v2.StorageType.STORAGE_TYPE_UNSPECIFIED);
+ } catch (Exception e) {
+ actualError = e;
+ }
+ assertThat(actualError).isInstanceOf(IllegalArgumentException.class);
+
+
+ List validModelValues = Lists.newArrayList(StorageType.values());
+
+ List actualModelValues = Lists.newArrayList();
+
+ for (com.google.bigtable.admin.v2.StorageType protoValue : validProtoValues) {
+ StorageType modelValue = StorageType.fromProto(protoValue);
+ actualModelValues.add(modelValue);
+ }
+
+ assertThat(actualModelValues).containsExactlyElementsIn(validModelValues);
+ }
+}
\ No newline at end of file
diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/TableTest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/TableTest.java
index 3ebe004f51d4..b5140a31eda7 100644
--- a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/TableTest.java
+++ b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/models/TableTest.java
@@ -15,13 +15,14 @@
*/
package com.google.cloud.bigtable.admin.v2.models;
+import static com.google.common.truth.Truth.assertThat;
+
import com.google.bigtable.admin.v2.ColumnFamily;
import com.google.bigtable.admin.v2.GcRule;
-import com.google.bigtable.admin.v2.Table.ClusterState;
-import com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState;
import com.google.bigtable.admin.v2.Table.TimestampGranularity;
import com.google.bigtable.admin.v2.TableName;
-import com.google.common.truth.Truth;
+import com.google.common.collect.Lists;
+import java.util.List;
import java.util.Map.Entry;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -39,12 +40,18 @@ public void testFromProto() {
.setGranularity(TimestampGranularity.MILLIS)
.putClusterStates(
"cluster1",
- ClusterState.newBuilder().setReplicationState(ReplicationState.READY).build())
+ com.google.bigtable.admin.v2.Table.ClusterState.newBuilder()
+ .setReplicationState(
+ com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.READY
+ ).build()
+ )
.putClusterStates(
"cluster2",
- ClusterState.newBuilder()
- .setReplicationState(ReplicationState.INITIALIZING)
- .build())
+ com.google.bigtable.admin.v2.Table.ClusterState.newBuilder()
+ .setReplicationState(
+ com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.INITIALIZING
+ ).build()
+ )
.putColumnFamilies("cf1", ColumnFamily.newBuilder().build())
.putColumnFamilies(
"cf2",
@@ -65,18 +72,38 @@ public void testFromProto() {
Table result = Table.fromProto(proto);
- Truth.assertThat(result.getInstanceId()).isEqualTo("my-instance");
- Truth.assertThat(result.getId()).isEqualTo("my-table");
- Truth.assertThat(result.getReplicationStatesByClusterId()).containsExactly(
- "cluster1", ReplicationState.READY,
- "cluster2", ReplicationState.INITIALIZING
+ assertThat(result.getInstanceId()).isEqualTo("my-instance");
+ assertThat(result.getId()).isEqualTo("my-table");
+ assertThat(result.getReplicationStatesByClusterId()).containsExactly(
+ "cluster1", Table.ReplicationState.READY,
+ "cluster2", Table.ReplicationState.INITIALIZING
);
- Truth.assertThat(result.getColumnFamilies()).hasSize(3);
+ assertThat(result.getColumnFamilies()).hasSize(3);
for (Entry entry : proto.getColumnFamiliesMap().entrySet()) {
- Truth.assertThat(result.getColumnFamilies()).contains(
- com.google.cloud.bigtable.admin.v2.models.ColumnFamily.fromProto(entry.getKey(), entry.getValue())
+ assertThat(result.getColumnFamilies()).contains(
+ com.google.cloud.bigtable.admin.v2.models.ColumnFamily
+ .fromProto(entry.getKey(), entry.getValue())
);
}
}
+
+ @Test
+ public void testReplicationStateEnumUpToDate() {
+ List validProtoValues =
+ Lists.newArrayList(
+ com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.values());
+
+ List validModelValues = Lists
+ .newArrayList(Table.ReplicationState.values());
+
+ List actualModelValues = Lists.newArrayList();
+
+ for (com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState protoValue : validProtoValues) {
+ Table.ReplicationState modelValue = Table.ReplicationState.fromProto(protoValue);
+ actualModelValues.add(modelValue);
+ }
+
+ assertThat(actualModelValues).containsExactlyElementsIn(validModelValues);
+ }
}