11/**
22 * Copyright 2016 Google Inc. All Rights Reserved.
33 *
4- * Licensed to the Apache Software Foundation (ASF) under one
5- * or more contributor license agreements. See the NOTICE file
6- * distributed with this work for additional information
7- * regarding copyright ownership. The ASF licenses this file
8- * to you under the Apache License, Version 2.0 (the
9- * "License"); you may not use this file except in compliance
10- * with the License. You may obtain a copy of the License at
4+ * <p>Licensed to the Apache Software Foundation (ASF) under one or more contributor license
5+ * agreements. See the NOTICE file distributed with this work for additional information regarding
6+ * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
7+ * "License"); you may not use this file except in compliance with the License. You may obtain a
8+ * copy of the License at
119 *
12- * http://www.apache.org/licenses/LICENSE-2.0
10+ * <p> http://www.apache.org/licenses/LICENSE-2.0
1311 *
14- * Unless required by applicable law or agreed to in writing, software
15- * distributed under the License is distributed on an "AS IS" BASIS,
16- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17- * See the License for the specific language governing permissions and
12+ * <p>Unless required by applicable law or agreed to in writing, software distributed under the
13+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+ * express or implied. See the License for the specific language governing permissions and
1815 * limitations under the License.
1916 */
20- package com .example .cloud . bigtable . helloworld ;
17+ package com .example .bigtable ;
2118
2219// [START bigtable_hw_imports_hbase]
2320import com .google .cloud .bigtable .hbase .BigtableConfiguration ;
24-
21+ import java .io .IOException ;
22+ // [END bigtable_hw_imports_hbase]
2523import org .apache .hadoop .hbase .HColumnDescriptor ;
2624import org .apache .hadoop .hbase .HTableDescriptor ;
2725import org .apache .hadoop .hbase .TableName ;
3533import org .apache .hadoop .hbase .client .Table ;
3634import org .apache .hadoop .hbase .util .Bytes ;
3735
38- import java .io .IOException ;
39- // [END bigtable_hw_imports_hbase]
40-
4136/**
4237 * A minimal application that connects to Cloud Bigtable using the native HBase API and performs
4338 * some basic operations.
@@ -55,7 +50,7 @@ public class HelloWorld {
5550 };
5651
5752 /** Connects to Cloud Bigtable, runs some basic operations and prints the results. */
58- private static void doHelloWorld (String projectId , String instanceId ) {
53+ protected static void doHelloWorld (String projectId , String instanceId ) {
5954
6055 // [START bigtable_hw_connect_hbase]
6156 // Create the Bigtable connection, use try-with-resources to make sure it gets closed
@@ -71,7 +66,7 @@ private static void doHelloWorld(String projectId, String instanceId) {
7166 HTableDescriptor descriptor = new HTableDescriptor (TableName .valueOf (TABLE_NAME ));
7267 descriptor .addFamily (new HColumnDescriptor (COLUMN_FAMILY_NAME ));
7368
74- print ( " Create table " + descriptor .getNameAsString ());
69+ System . out . println ( "HelloWorld: Create table " + descriptor .getNameAsString ());
7570 admin .createTable (descriptor );
7671 // [END bigtable_hw_create_table_hbase]
7772
@@ -80,7 +75,7 @@ private static void doHelloWorld(String projectId, String instanceId) {
8075 Table table = connection .getTable (TableName .valueOf (TABLE_NAME ));
8176
8277 // Write some rows to the table
83- print ( " Write some greetings to the table" );
78+ System . out . println ( "HelloWorld: Write some greetings to the table" );
8479 for (int i = 0 ; i < GREETINGS .length ; i ++) {
8580 // Each row has a unique row key.
8681 //
@@ -115,7 +110,7 @@ private static void doHelloWorld(String projectId, String instanceId) {
115110 // Now scan across all rows.
116111 Scan scan = new Scan ();
117112
118- print ( " Scan for all greetings:" );
113+ System . out . println ( "HelloWorld: Scan for all greetings:" );
119114 ResultScanner scanner = table .getScanner (scan );
120115 for (Result row : scanner ) {
121116 byte [] valueBytes = row .getValue (COLUMN_FAMILY_NAME , COLUMN_NAME );
@@ -125,13 +120,13 @@ private static void doHelloWorld(String projectId, String instanceId) {
125120
126121 // [START bigtable_hw_delete_table_hbase]
127122 // Clean up by disabling and then deleting the table
128- print ( " Delete the table" );
123+ System . out . println ( "HelloWorld: Delete the table" );
129124 admin .disableTable (table .getName ());
130125 admin .deleteTable (table .getName ());
131126 // [END bigtable_hw_delete_table_hbase]
132127 } catch (IOException e ) {
133128 if (admin .tableExists (TableName .valueOf (TABLE_NAME ))) {
134- print ( " Cleaning up table" );
129+ System . out . println ( "HelloWorld: Cleaning up table" );
135130 admin .disableTable (TableName .valueOf (TABLE_NAME ));
136131 admin .deleteTable (TableName .valueOf (TABLE_NAME ));
137132 }
@@ -140,15 +135,7 @@ private static void doHelloWorld(String projectId, String instanceId) {
140135 } catch (IOException e ) {
141136 System .err .println ("Exception while running HelloWorld: " + e .getMessage ());
142137 e .printStackTrace ();
143-
144- System .exit (1 );
145138 }
146-
147- System .exit (0 );
148- }
149-
150- private static void print (String msg ) {
151- System .out .println ("HelloWorld: " + msg );
152139 }
153140
154141 public static void main (String [] args ) {
0 commit comments