Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bigtable Admin: Promote models to top level classes #3513

Merged
merged 6 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
import com.google.bigtable.admin.v2.InstanceName;
import com.google.bigtable.admin.v2.ListTablesRequest;
import com.google.bigtable.admin.v2.ListTablesResponse;
import com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest;
import com.google.bigtable.admin.v2.TableName;
import com.google.cloud.bigtable.admin.v2.models.TableAdminRequests.CreateTable;
import com.google.cloud.bigtable.admin.v2.models.TableAdminRequests.ModifyFamilies;
import com.google.cloud.bigtable.admin.v2.models.TableAdminResponses;
import com.google.cloud.bigtable.admin.v2.models.TableAdminResponses.ConsistencyToken;
import com.google.cloud.bigtable.admin.v2.models.TableAdminResponses.Table;
import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest;
import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest;
import com.google.cloud.bigtable.admin.v2.models.ConsistencyToken;
import com.google.cloud.bigtable.admin.v2.models.Table;
import com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStub;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -146,12 +144,12 @@ public void close() {
*
* @param createTable
* @return the newly created table
* @see CreateTable for createTable configurations
* @see CreateTableRequest for createTable configurations
*/
public Table createTable(CreateTable createTable) {
public Table createTable(CreateTableRequest createTable) {

This comment was marked as spam.

This comment was marked as spam.

com.google.bigtable.admin.v2.Table table =
this.stub.createTableCallable().call(createTable.toProto(instanceName));
return TableAdminResponses.convertTable(table);
return Table.fromProto(table);
}

/**
Expand All @@ -170,9 +168,9 @@ public Table createTable(CreateTable createTable) {
*
* @param createTable
* @return the newly created table
* @see CreateTable for createTable configurations
* @see CreateTableRequest for createTable configurations

This comment was marked as spam.

*/
public ApiFuture<Table> createTableAsync(CreateTable createTable) {
public ApiFuture<Table> createTableAsync(CreateTableRequest createTable) {

This comment was marked as spam.

return transformToTableResponse(
this.stub.createTableCallable().futureCall(createTable.toProto(instanceName)));
}
Expand Down Expand Up @@ -207,13 +205,13 @@ public ApiFuture<Table> createTableAsync(CreateTable createTable) {
*
* @param modifyFamily
* @return the modified table
* @see ModifyFamilies for modifyFamily options
* @see ModifyColumnFamiliesRequest for modifyFamily options
*/
public Table modifyFamilies(ModifyFamilies modifyFamily) {
ModifyColumnFamiliesRequest modReq = modifyFamily.toProto(instanceName);
public Table modifyFamilies(ModifyColumnFamiliesRequest modifyFamily) {
com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest modReq = modifyFamily.toProto(instanceName);

This comment was marked as spam.

com.google.bigtable.admin.v2.Table table =
this.stub.modifyColumnFamiliesCallable().call(modReq);
return TableAdminResponses.convertTable(table);
return Table.fromProto(table);
}

/**
Expand Down Expand Up @@ -246,10 +244,10 @@ public Table modifyFamilies(ModifyFamilies modifyFamily) {
*
* @param modifyFamily
* @return Modified table
* @see ModifyFamilies for modifyFamily options
* @see ModifyColumnFamiliesRequest for modifyFamily options
*/
public ApiFuture<Table> modifyFamiliesAsync(ModifyFamilies modifyFamily) {
ModifyColumnFamiliesRequest modReq = modifyFamily.toProto(instanceName);
public ApiFuture<Table> modifyFamiliesAsync(ModifyColumnFamiliesRequest modifyFamily) {
com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest modReq = modifyFamily.toProto(instanceName);
return transformToTableResponse(this.stub.modifyColumnFamiliesCallable().futureCall(modReq));
}

Expand Down Expand Up @@ -304,7 +302,7 @@ public ApiFuture<Void> deleteTableAsync(String tableId) {
public Table getTable(String tableId) {
com.google.bigtable.admin.v2.Table table =
this.stub.getTableCallable().call(composeGetTableRequest(tableId));
return TableAdminResponses.convertTable(table);
return Table.fromProto(table);
}

/**
Expand Down Expand Up @@ -493,7 +491,7 @@ public ApiFuture<Void> dropAllRowsAsync(String tableId) {
* @param tableId
*/
public ConsistencyToken generateConsistencyToken(String tableId) {
return TableAdminResponses.convertTokenResponse(
return ConsistencyToken.fromProto(
this.stub
.generateConsistencyTokenCallable()
.call(composeGenerateConsistencyTokenRequest(tableId)));
Expand Down Expand Up @@ -524,7 +522,7 @@ public ApiFuture<ConsistencyToken> generateConsistencyTokenAsync(String tableId)
new ApiFunction<GenerateConsistencyTokenResponse, ConsistencyToken>() {
@Override
public ConsistencyToken apply(GenerateConsistencyTokenResponse input) {
return TableAdminResponses.convertTokenResponse(input);
return ConsistencyToken.fromProto(input);
}
});
}
Expand Down Expand Up @@ -622,7 +620,6 @@ DeleteTableRequest composeDeleteTableRequest(String tableId) {
*
* @param tableId
* @param rowKeyPrefix
* @param boolean dropAll
*/
@VisibleForTesting
DropRowRangeRequest composeDropRowRangeRequest(
Expand Down Expand Up @@ -675,7 +672,7 @@ static ApiFuture<Table> transformToTableResponse(
new ApiFunction<com.google.bigtable.admin.v2.Table, Table>() {
@Override
public Table apply(com.google.bigtable.admin.v2.Table table) {
return TableAdminResponses.convertTable(table);
return Table.fromProto(table);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState;
import com.google.common.base.MoreObjects;

/** Wrapper for {@link ClusterState} protocol buffer object */
public final class ClusterState {
private final String id;

This comment was marked as spam.

private final ReplicationState replicationState;

public static ClusterState fromProto(String clusterId, com.google.bigtable.admin.v2.Table.ClusterState proto) {
return new ClusterState(clusterId, proto.getReplicationState());
}

private ClusterState(String id, ReplicationState replicationState) {
this.id = id;
this.replicationState = replicationState;
}

/**
* Gets the cluster Id
*/
public String getId() {
return id;
}

/**
* Gets the ReplicationState of the table for this cluster

This comment was marked as spam.

*/
public ReplicationState getReplicationState() {
return replicationState;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("id", id)
.add("replicationState", replicationState)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.cloud.bigtable.admin.v2.models.GCRules.GCRULES;

import com.google.api.core.InternalApi;
import com.google.bigtable.admin.v2.GcRule;
import com.google.bigtable.admin.v2.GcRule.RuleCase;
import com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule;
import com.google.common.base.MoreObjects;

/** Wrapper for {@link ColumnFamily} protocol buffer object */
public final class ColumnFamily {
private final String id;

This comment was marked as spam.

private final GCRule rule;

@InternalApi
public static ColumnFamily fromProto(String id, com.google.bigtable.admin.v2.ColumnFamily proto) {
GcRule ruleProto = MoreObjects.firstNonNull(proto.getGcRule(), GcRule.getDefaultInstance());

This comment was marked as spam.


return new ColumnFamily(id, GCRULES.fromProto(ruleProto));
}

private ColumnFamily(String id, GCRule rule) {
this.id = id;
this.rule = rule;
}

/**
* Gets the columnfamily name
*/
public String getId() {
return id;
}

/**
* Get's the GCRule configured for the columnfamily
*/
public GCRule getGCRule() {
return rule;
}

/**
* Returns true if a GCRule has been configured for the family
*/
public boolean hasGCRule() {
return !RuleCase.RULE_NOT_SET.equals(rule.toProto().getRuleCase());
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("id", id).add("GCRule", rule).toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.CheckConsistencyRequest;
import com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;

/**
* Wrapper for {@link GenerateConsistencyTokenResponse#getConsistencyToken()}
*
* <p>Cannot be created. They are obtained by invoking {@link
* com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient#generateConsistencyToken(String)}
*/
public final class ConsistencyToken {
private final String token;

@InternalApi
public static ConsistencyToken fromProto(GenerateConsistencyTokenResponse proto) {
return new ConsistencyToken(proto.getConsistencyToken());
}

private ConsistencyToken(String token) {
this.token = token;
}

@InternalApi
public CheckConsistencyRequest toProto(String tableName) {

This comment was marked as spam.

return CheckConsistencyRequest.newBuilder()
.setName(tableName)
.setConsistencyToken(token)
.build();
}

@VisibleForTesting
String getToken() {
return token;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("token", token).toString();
}
}
Loading