Skip to content

Commit 8142046

Browse files
authored
Merge pull request #178 from GoogleCloudPlatform/tswast-java-hello
Add detailed instructions for running the Java hello world sample.
2 parents 1c9b8b4 + 8d93fce commit 8142046

File tree

1 file changed

+156
-19
lines changed

1 file changed

+156
-19
lines changed

java/hello-world/README.md

Lines changed: 156 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,150 @@
33
This is a simple application that demonstrates using the native HBase API
44
to connect to and interact with Cloud Bigtable.
55

6-
## Provision a cluster
6+
See the [documentation for this
7+
sample](https://cloud.google.com/bigtable/docs/samples-java-hello) for a brief
8+
explanation of the code.
79

8-
Follow the instructions in the [user documentation](https://cloud.google.com/bigtable/docs/creating-cluster)
9-
to create a Google Cloud Platform project and Cloud Bigtable cluster if necessary.
10-
You'll need to reference your project id, zone and cluster id to run the application.
10+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
11+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
12+
**Table of Contents**
1113

12-
## Run the application
14+
- [Downloading the sample](#downloading-the-sample)
15+
- [Costs](#costs)
16+
- [Before you begin](#before-you-begin)
17+
- [Installing Maven](#installing-maven)
18+
- [Creating a Project in the Google Cloud Platform Console](#creating-a-project-in-the-google-cloud-platform-console)
19+
- [Enabling billing for your project.](#enabling-billing-for-your-project)
20+
- [Install the Google Cloud SDK.](#install-the-google-cloud-sdk)
21+
- [Setting Google Application Default Credentials](#setting-google-application-default-credentials)
22+
- [Provisioning a cluster](#provisioning-a-cluster)
23+
- [Running the application](#running-the-application)
24+
- [Cleaning up](#cleaning-up)
1325

14-
First, set your [Google Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials)
15-
and [install Maven](http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html) if necessary.
26+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1627

1728

18-
$ mvn package
19-
$ mvn exec:java -Dbigtable.projectID=<myProject> -Dbigtable.clusterID=<myCluster> -Dbigtable.zone=<myZone>
29+
## Downloading the sample
30+
31+
Download the sample app and navigate into the app directory:
32+
33+
1. Clone the [Cloud Bigtable examples repository][github-repo], to your local
34+
machine:
35+
36+
git clone https://github.com/GoogleCloudPlatform/cloud-bigtable-examples.git
37+
38+
Alternatively, you can [download the sample][github-zip] as a zip file and
39+
extract it.
40+
41+
2. Change to the Hello World code sample directory.
42+
43+
cd cloud-bigtable-examples/java/hello-world
44+
45+
[github-repo]: https://github.com/GoogleCloudPlatform/cloud-bigtable-examples
46+
[github-zip]: https://github.com/GoogleCloudPlatform/cloud-bigtable-examples/archive/master.zip
47+
48+
49+
## Costs
50+
51+
This sample uses billable components of Cloud Platform, including:
52+
53+
+ Google Cloud Bigtable
54+
55+
Use the [Pricing Calculator][bigtable-pricing] to generate a cost estimate
56+
based on your projected usage. New Cloud Platform users might be eligible for
57+
a [free trial][free-trial].
58+
59+
[bigtable-pricing]: https://cloud.google.com/products/calculator/#id=1eb47664-13a2-4be1-9d16-6722902a7572
60+
[free-trial]: https://cloud.google.com/free-trial
61+
62+
63+
## Before you begin
64+
65+
This sample assumes you have [Java 8][java8] installed.
66+
67+
[java8]: http://www.oracle.com/technetwork/java/javase/downloads/
68+
69+
### Installing Maven
70+
71+
These samples use the [Apache Maven][maven] build system. Before getting
72+
started, be sure to [download][maven-download] and [install][maven-install] it.
73+
When you use Maven as described here, it will automatically download the needed
74+
client libraries.
75+
76+
[maven]: https://maven.apache.org
77+
[maven-download]: https://maven.apache.org/download.cgi
78+
[maven-install]: https://maven.apache.org/install.html
79+
80+
### Creating a Project in the Google Cloud Platform Console
81+
82+
If you haven't already created a project, create one now. Projects enable you to
83+
manage all Google Cloud Platform resources for your app, including deployment,
84+
access control, billing, and services.
85+
86+
1. Open the [Cloud Platform Console][cloud-console].
87+
1. In the drop-down menu at the top, select **Create a project**.
88+
1. Give your project a name.
89+
1. Make a note of the project ID, which might be different from the project
90+
name. The project ID is used in commands and in configurations.
91+
92+
[cloud-console]: https://console.cloud.google.com/
93+
94+
### Enabling billing for your project.
95+
96+
If you haven't already enabled billing for your project, [enable
97+
billing][enable-billing] now. Enabling billing allows the application to
98+
consume billable resources such as running instances and storing data.
99+
100+
[enable-billing]: https://console.cloud.google.com/project/_/settings
101+
102+
### Install the Google Cloud SDK.
103+
104+
If you haven't already installed the Google Cloud SDK, [install the Google
105+
Cloud SDK][cloud-sdk] now. The SDK contains tools and libraries that enable you
106+
to create and manage resources on Google Cloud Platform.
107+
108+
[cloud-sdk]: https://cloud.google.com/sdk/
109+
110+
### Setting Google Application Default Credentials
111+
112+
Set your [Google Application Default
113+
Credentials][application-default-credentials] by [initializing the Google Cloud
114+
SDK][cloud-sdk-init] with the command:
115+
116+
gcloud init
117+
118+
Alternatively, create a service account key and set the
119+
`GOOGLE_APPLICATION_CREDENTIALS` environment variable to the service account
120+
key file path.
121+
122+
[cloud-sdk-init]: https://cloud.google.com/sdk/docs/initializing
123+
[application-default-credentials]: https://developers.google.com/identity/protocols/application-default-credentials
124+
125+
126+
## Provisioning a cluster
127+
128+
Follow the instructions in the [user
129+
documentation](https://cloud.google.com/bigtable/docs/creating-cluster) to
130+
create a Google Cloud Platform project and Cloud Bigtable cluster if necessary.
131+
You'll need to reference your project id, zone and cluster id to run the
132+
application.
133+
134+
135+
## Running the application
136+
137+
Set the following environment variables or replace them with the appropriate
138+
values in the `mvn` commands. Set:
139+
140+
+ `GCLOUD_PROJECT` to the project ID,
141+
+ `BIGTABLE_CLUSTER` to the Bigtable cluster ID,
142+
+ `BIGTABLE_ZONE` to the Bigtable compute zone (example: us-central1-b).
143+
144+
Build and run the sample using Maven.
145+
146+
mvn package
147+
mvn exec:java -Dbigtable.projectID=${GCLOUD_PROJECT} \
148+
-Dbigtable.clusterID=${BIGTABLE_CLUSTER} \
149+
-Dbigtable.zone=${BIGTABLE_ZONE}
20150

21151
You will see output resembling the following, interspersed with informational logging
22152
from the underlying libraries:
@@ -29,15 +159,22 @@ from the underlying libraries:
29159
Hello HBase!
30160
HelloWorld: Delete the table
31161

32-
## Understanding the code
33162

34-
This application leverages the [HBase Native API](http://hbase.apache.org/book.html#hbase_apis)
35-
to make calls to Cloud Bigtable. It demonstrates several basic concepts of working with
36-
Cloud Bigtable via this API:
163+
## Cleaning up
164+
165+
To avoid incurring extra charges to your Google Cloud Platform account, remove
166+
the resources created for this sample.
167+
168+
1. Go to the Clusters page in the [Cloud
169+
Console](https://console.cloud.google.com).
170+
171+
[Go to the Clusters page](https://console.cloud.google.com/project/_/bigtable/clusters)
172+
173+
1. Click the cluster name.
174+
175+
1. Click **Delete**.
176+
177+
![Delete](https://cloud.google.com/bigtable/img/delete-quickstart-cluster.png)
178+
179+
1. Type the cluster ID, then click **Delete** to delete the cluster.
37180

38-
* Creating a Connection to Cloud Bigtable via `BigtableConfiguration`, a Cloud Bigtable extension
39-
to the native API
40-
* Using the `Admin` interface to create, disable and delete a `Table`
41-
* Using the `Connection` to get a `Table`
42-
* Using the `Table` to write rows via a `Put`, lookup a row via a `Get`, and scan across
43-
multiple rows using a `Scan`

0 commit comments

Comments
 (0)