Skip to content

Commit

Permalink
samples fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
elisheva-qlogic committed Dec 6, 2018
1 parent 5782c53 commit 514b3ab
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void main(String... args) throws Exception {
}

// [START connecting_to_bigtable]
// create the settings to configure a bigtable data client
// Create the settings to configure a bigtable data client
BigtableDataSettings settings = BigtableDataSettings.newBuilder()
.setInstanceName(InstanceName.of(GCLOUD_PROJECT_ID, INSTANCE_ID)).build();

Expand Down Expand Up @@ -87,17 +87,28 @@ public static void main(String... args) throws Exception {
public static Table createTable(BigtableTableAdminClient adminClient, String TABLE_ID,
String COLUMN_FAMILY_ID) {
// [START creating_a_table]
Table table = null;
Table table;
if (!adminClient.exists(TABLE_ID)) {
CreateTableRequest createTableRequest =
CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY_ID);
System.out.println("Creating table: " + TABLE_ID);
table = adminClient.createTable(createTableRequest);
table = creatingTable(adminClient, TABLE_ID, COLUMN_FAMILY_ID);
} else {
// Delete and recreate table
System.out.println("Deleting existing table and creating new one");
adminClient.deleteTable(TABLE_ID);
table = creatingTable(adminClient, TABLE_ID, COLUMN_FAMILY_ID);
}
return table;
// [END creating_a_table]
}

private static Table creatingTable(BigtableTableAdminClient adminClient, String TABLE_ID,
String COLUMN_FAMILY_ID) {
CreateTableRequest createTableRequest =
CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY_ID);
System.out.println("Creating table: " + TABLE_ID);
Table table = adminClient.createTable(createTableRequest);
return table;
}

public static RowMutation writeToTable(BigtableDataClient dataClient, String TABLE_ID,
String ROW_KEY_PREFIX, String COLUMN_FAMILY_ID, String COLUMN_QUALIFIER) {
// [START writing_rows]
Expand Down Expand Up @@ -169,4 +180,4 @@ public static void deleteTable(BigtableTableAdminClient adminClient, String TABL
}
// [END deleting_a_table]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ public static Instance createProdInstance(BigtableInstanceAdminClient adminClien
} catch (Exception e) {
System.out.println("Error checking if instance exists: " + e.getMessage());
}
// [END bigtable_check_instance_exists]

Instance instance = null;
// Create instance if does not exists
// Create an instance if does not exists
if (!found) {
System.out.println("Instance does not exist, creating a PRODUCTION instance:");
// [START bigtable_create_prod_instance]
// Creates a Production Instance with the ID "ssd-instance"
// with cluster id "ssd-cluster", 3 nodes and location us-central1-f
// Create a Production Instance with the ID "ssd-instance"
// cluster id "ssd-cluster", 3 nodes and location us-central1-f
CreateInstanceRequest createInstanceRequest = CreateInstanceRequest.of(instanceID)
.addCluster(clusterID, "us-central1-f", 3, StorageType.SSD).setType(Type.PRODUCTION)
.addLabel("example", "instance_admin");
Expand Down Expand Up @@ -203,7 +204,6 @@ public static Cluster addCluster(BigtableInstanceAdminClient adminClient, String

public static void deleteCluster(BigtableInstanceAdminClient adminClient, String instanceID,
String clusterID) {
// [START bigtable_delete_cluster]
System.out.println("\nDeleting Cluster");
// [START bigtable_delete_cluster]
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public static void afterClass() throws Exception {
@Test
public void testCreateAndDeleteTable() {
// Create table
Table table = TableAdmin.createTable(adminClient, "fake-table");
Table table = HelloWorld.createTable(adminClient, "fake-table", "fake-column-family-id");
assertNotNull(table);

// Delete table
TableAdmin.deleteTable(adminClient, "fake-table");
HelloWorld.deleteTable(adminClient, "fake-table");
assertTrue(!adminClient.exists("fake-table"));
}

Expand Down

0 comments on commit 514b3ab

Please sign in to comment.