|
21 | 21 | import com.google.api.core.ApiFunction; |
22 | 22 | import com.google.api.core.ApiFuture; |
23 | 23 | import com.google.api.core.ApiFutures; |
24 | | -import com.google.api.core.BetaApi; |
25 | 24 | import com.google.bigtable.admin.v2.CheckConsistencyResponse; |
26 | 25 | import com.google.bigtable.admin.v2.DeleteTableRequest; |
27 | 26 | import com.google.bigtable.admin.v2.DropRowRangeRequest; |
|
40 | 39 | import com.google.cloud.bigtable.admin.v2.models.TableAdminResponses.ConsistencyToken; |
41 | 40 | import com.google.cloud.bigtable.admin.v2.models.TableAdminResponses.Table; |
42 | 41 | import com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStub; |
43 | | -import com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStubSettings; |
44 | 42 | import com.google.common.annotations.VisibleForTesting; |
45 | 43 | import com.google.common.base.Preconditions; |
46 | 44 | import com.google.protobuf.ByteString; |
47 | 45 | import com.google.protobuf.Empty; |
| 46 | +import javax.annotation.Nonnull; |
48 | 47 |
|
49 | 48 | /** |
50 | 49 | * Client for creating, configuring, and deleting Cloud Bigtable tables |
|
64 | 63 | * .addSplit(ByteString.copyFromUtf8("b")) |
65 | 64 | * .addSplit(ByteString.copyFromUtf8("q")); |
66 | 65 | * client.createTable(createTableReq); |
67 | | - * } |
68 | | - * }</pre> |
| 66 | + * } |
| 67 | + * }</pre> |
69 | 68 | * |
70 | | - * <p>Note: close() needs to be called on the bigtableTableAdminClient object to clean up resources |
71 | | - * such as threads. In the example above, try-with-resources is used, which automatically calls |
72 | | - * close(). |
| 69 | + * <p>Note: close() needs to be called on the client object to clean up resources such as threads. |
| 70 | + * In the example above, try-with-resources is used, which automatically calls close(). |
73 | 71 | * |
74 | | - * <p>This class can be customized by passing in a custom instance of BigtableTableAdminSettings to |
| 72 | + * <p>This class can be customized by passing in a custom instance of TableAdminSettings to |
75 | 73 | * create(). For example: |
76 | 74 | * |
77 | 75 | * <p>To customize credentials: |
78 | 76 | * |
79 | 77 | * <pre>{@code |
80 | | - * BigtableTableAdminSettings bigtableTableAdminSettings = |
81 | | - * BigtableTableAdminSettings.newBuilder() |
| 78 | + * TableAdminSettings tableAdminSettings = TableAdminSettings.newBuilder() |
| 79 | + * .setInstanceName(InstanceName.of("[PROJECT]", "[INSTANCE]")) |
82 | 80 | * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) |
83 | 81 | * .build(); |
| 82 | + * |
84 | 83 | * TableAdminClient client = |
85 | | - * TableAdminClient.create(InstanceName.of("[PROJECT]", "[INSTANCE]"), bigtableTableAdminSettings); |
| 84 | + * TableAdminClient.create(tableAdminSettings); |
86 | 85 | * }</pre> |
87 | 86 | * |
88 | 87 | * To customize the endpoint: |
89 | 88 | * |
90 | 89 | * <pre>{@code |
91 | | - * BigtableTableAdminSettings bigtableTableAdminSettings = |
92 | | - * BigtableTableAdminSettings.newBuilder().setEndpoint(myEndpoint).build(); |
93 | | - * TableAdminClient client = |
94 | | - * TableAdminClient.create(InstanceName.of("[PROJECT]", "[INSTANCE]"), bigtableTableAdminSettings); |
| 90 | + * TableAdminSettings tableAdminSettings = TableAdminSettings.newBuilder() |
| 91 | + * .setInstanceName(InstanceName.of("[PROJECT]", "[INSTANCE]")) |
| 92 | + * .setEndpoint(myEndpoint).build(); |
| 93 | + * |
| 94 | + * TableAdminClient client = TableAdminClient.create(tableAdminSettings); |
95 | 95 | * }</pre> |
96 | 96 | */ |
97 | | -@BetaApi |
98 | 97 | public class TableAdminClient implements AutoCloseable { |
99 | 98 | private final BigtableTableAdminStub stub; |
100 | 99 | private final InstanceName instanceName; |
101 | 100 |
|
102 | | - /** |
103 | | - * Constructs an instance of TableAdminClient with the given instanceName |
104 | | - * |
105 | | - * @param instanceName |
106 | | - * @throws IOException |
107 | | - */ |
108 | | - public static TableAdminClient create(InstanceName instanceName) throws IOException { |
109 | | - return new TableAdminClient(instanceName, BigtableTableAdminSettings.newBuilder().build()); |
| 101 | + /** Constructs an instance of TableAdminClient with the given instanceName. */ |
| 102 | + public static TableAdminClient create(@Nonnull InstanceName instanceName) throws IOException { |
| 103 | + return create(TableAdminSettings.newBuilder().setInstanceName(instanceName).build()); |
110 | 104 | } |
111 | 105 |
|
112 | | - /** |
113 | | - * Constructs an instance of TableAdminClient with the given instanceName and |
114 | | - * bigtableTableAdminSettings |
115 | | - * |
116 | | - * @param instanceName |
117 | | - * @param adminSettings |
118 | | - * @throws IOException |
119 | | - */ |
120 | | - public static TableAdminClient create( |
121 | | - InstanceName instanceName, BigtableTableAdminSettings adminSettings) throws IOException { |
122 | | - return new TableAdminClient(instanceName, adminSettings); |
| 106 | + /** Constructs an instance of TableAdminClient with the given settings. */ |
| 107 | + public static TableAdminClient create(@Nonnull TableAdminSettings settings) throws IOException { |
| 108 | + return create(settings.getInstanceName(), settings.getStubSettings().createStub()); |
123 | 109 | } |
124 | 110 |
|
125 | | - /** |
126 | | - * Constructs an instance of TableAdminClient with the given instanceName and |
127 | | - * bigtableTableAdminStub |
128 | | - * |
129 | | - * @param instanceName |
130 | | - * @param stub |
131 | | - * @throws IOException |
132 | | - */ |
133 | | - public static TableAdminClient create(InstanceName instanceName, BigtableTableAdminStub stub) |
134 | | - throws IOException { |
| 111 | + /** Constructs an instance of TableAdminClient with the given instanceName and stub. */ |
| 112 | + public static TableAdminClient create(@Nonnull InstanceName instanceName, @Nonnull BigtableTableAdminStub stub) { |
135 | 113 | return new TableAdminClient(instanceName, stub); |
136 | 114 | } |
137 | 115 |
|
138 | | - private TableAdminClient(InstanceName instanceName, BigtableTableAdminSettings adminSettings) |
139 | | - throws IOException { |
140 | | - this( |
141 | | - instanceName, |
142 | | - ((BigtableTableAdminStubSettings) adminSettings.getStubSettings()).createStub()); |
143 | | - } |
144 | | - |
145 | | - private TableAdminClient(InstanceName instanceName, BigtableTableAdminStub stub) |
146 | | - throws IOException { |
| 116 | + private TableAdminClient(@Nonnull InstanceName instanceName, @Nonnull BigtableTableAdminStub stub) { |
147 | 117 | Preconditions.checkNotNull(instanceName); |
148 | 118 | Preconditions.checkNotNull(stub); |
149 | 119 | this.instanceName = instanceName; |
150 | 120 | this.stub = stub; |
151 | 121 | } |
152 | 122 |
|
153 | | - /** |
154 | | - * Gets the instanceName this client is associated to |
155 | | - */ |
| 123 | + /** Gets the instanceName this client is associated with. */ |
156 | 124 | public InstanceName getInstanceName() { |
157 | 125 | return instanceName; |
158 | 126 | } |
@@ -188,9 +156,9 @@ public Table createTable(CreateTable createTable) { |
188 | 156 |
|
189 | 157 | /** |
190 | 158 | * Creates a new table with the specified configuration asynchronously |
191 | | - * |
| 159 | + * |
192 | 160 | * <p>Sample code: |
193 | | - * |
| 161 | + * |
194 | 162 | * <pre>{@code |
195 | 163 | * try(TableAdminClient client = TableAdminClient.create(InstanceName.of("[PROJECT]", "[INSTANCE]"))) { |
196 | 164 | * CreateTable createTableReq = |
@@ -343,7 +311,7 @@ public Table getTable(String tableId) { |
343 | 311 | * Gets the Table by tableId |
344 | 312 | * |
345 | 313 | * <p>Sample code: |
346 | | - * |
| 314 | + * |
347 | 315 | * <pre>{@code |
348 | 316 | * try(TableAdminClient client = TableAdminClient.create(InstanceName.of("[PROJECT]", "[INSTANCE]"))) { |
349 | 317 | * client.getTableAsync("tableId"); |
|
0 commit comments