Skip to content

Commit a008bb8

Browse files
authored
chore(bigtable): update bigtable example from java8 to java21 (#10159)
* chore(bigtable): update bigtable example from java8 to java21 * fix: add license header to settings.gradle * chore: set app-engine-apis to true * chore: use EE8 instead of EE10 * chore: upgrade dependencies * fix: region tag names and remove java 8 reference
1 parent 16a720a commit a008bb8

15 files changed

Lines changed: 1073 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Bigtable-hello-j21
2+
=================
3+
4+
<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=appengine-java21/ee8/bigtable/README.md">
5+
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>
6+
7+
Moves the Bigtable Hello World application to Google App Engine Standard for Java 21.
8+
9+
10+
* [Java 21](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
11+
* [Maven](https://maven.apache.org/download.cgi) (at least 3.3.9)
12+
* [Gradle](https://gradle.org)
13+
* [Google Cloud CLI](https://cloud.google.com/cli/) (aka gcloud)
14+
15+
Initialize the Google Cloud CLI using:
16+
17+
gcloud init
18+
19+
gcloud auth application-default login
20+
21+
Then you need to [Create a Cloud Bigtable Instance](https://cloud.google.com/bigtable/docs/creating-instance)
22+
23+
24+
## Using Maven
25+
26+
### Run Locally
27+
28+
mvn -Dbigtable.projectID=PROJECTID -Dbigtable.instanceID=INSTANCEID appengine:run
29+
30+
### Deploy to App Engine Standard for Java 21
31+
32+
mvn -Dbigtable.projectID=PROJECTID -Dbigtable.instanceID=INSTANCEID package appengine:deploy
33+
34+
### Run Integration Tests
35+
36+
mvn -Dbigtable.projectID=PROJECTID -Dbigtable.instanceID=INSTANCEID verify
37+
38+
## Using Gradle
39+
40+
### Run Locally
41+
42+
gradle -Dbigtable.projectID=PROJECTID -Dbigtable.instanceID=INSTANCEID appengineRun
43+
44+
### Integration Tests & Deploy to App Engine Standard for Java 21
45+
46+
gradle -Dbigtable.projectID=PROJECTID -Dbigtable.instanceID=INSTANCEID appengineDeploy
47+
48+
As you add / modify the source code (`src/main/java/...`) it's very useful to add
49+
[unit testing](https://cloud.google.com/appengine/docs/java/tools/localunittesting)
50+
to (`src/main/test/...`). The following resources are quite useful:
51+
52+
* [JUnit4](http://junit.org/junit4/)
53+
* [Mockito](http://mockito.org/)
54+
* [Truth](http://google.github.io/truth/)
55+
56+
### When done
57+
58+
Cloud Bigtable Instances should be [deleted](https://cloud.google.com/bigtable/docs/deleting-instance)
59+
when they are no longer being used as they use significant resources.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright 2017 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
// [START gae_java21_bigtable_gradle_file]
15+
buildscript { // Configuration for building
16+
repositories {
17+
jcenter() // Bintray's repository - a fast Maven Central mirror & more
18+
mavenCentral()
19+
}
20+
dependencies {
21+
classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.5.0'
22+
classpath 'org.akhikhl.gretty:gretty:+'
23+
}
24+
}
25+
26+
apply plugin: 'java'
27+
apply plugin: 'war'
28+
apply plugin: 'org.akhikhl.gretty' // To get webappcopy
29+
apply plugin: 'com.google.cloud.tools.appengine'
30+
31+
group = 'com.example.google.cloud.bigtable'
32+
version = '0.1-SNAPSHOT'
33+
34+
sourceCompatibility = 21
35+
targetCompatibility = 21
36+
37+
tasks.withType(JavaCompile) {
38+
options.encoding = 'UTF-8'
39+
}
40+
41+
repositories {
42+
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
43+
jcenter()
44+
mavenCentral()
45+
}
46+
47+
dependencies {
48+
compile group: 'com.google.cloud.bigtable', name: 'bigtable-hbase-1.2', version:'1.0.0-pre3'
49+
compile group: 'org.apache.hbase', name: 'hbase-client', version:'2.5.6'
50+
compile group: 'io.netty', name: 'netty-tcnative-boringssl-static', version:'2.0.62.Final'
51+
compile group: 'jakarta.servlet.jsp.jstl', name: 'jakarta.servlet.jsp.jstl-api', version:'1.2.7'
52+
53+
providedCompile group: 'jakarta.servlet', name: 'jakarta.servlet-api', version:'4.0.4'
54+
55+
testCompile group: 'com.google.truth', name: 'truth', version:'1.4.4'
56+
testCompile group: 'junit', name: 'junit', version:'4.13.2'
57+
testCompile group: 'org.mockito', name: 'mockito-core', version:'4.11.0'
58+
}
59+
60+
import org.apache.tools.ant.filters.ReplaceTokens
61+
gretty {
62+
contextPath = '/'
63+
servletContainer = 'jetty9'
64+
65+
jvmArgs = [ '-DBIGTABLE_PROJECT=' + System.getProperty("bigtable.projectID"),
66+
'-DBIGTABLE_INSTANCE=' + System.getProperty("bigtable.instanceID")]
67+
68+
webappCopy {
69+
// Enable filtering on all xml files in WEB-INF
70+
filesMatching "**/WEB-INF/*.xml", { FileCopyDetails fileDetails ->
71+
logger.lifecycle 'File filtered: {}', fileDetails.path
72+
filter (ReplaceTokens, tokens: [
73+
'bigtable.projectID' : System.getProperty("bigtable.projectID"),
74+
'bigtable.instanceID': System.getProperty("bigtable.instanceID")
75+
])
76+
}
77+
}
78+
}
79+
80+
// Always run unit tests
81+
appengineDeploy.dependsOn test
82+
83+
// [START gae_java21_bigtable_gradle_model]
84+
appengine {
85+
run {
86+
87+
}
88+
deploy { // deploy configuration
89+
stopPreviousVersion = true // default - stop the current version
90+
promote = true // default - & make this the current version
91+
}
92+
}
93+
94+
test {
95+
useJUnit()
96+
testLogging.showStandardStreams = true
97+
98+
systemProperty 'BIGTABLE_PROJECT', System.getProperty("bigtable.projectID")
99+
systemProperty 'BIGTABLE_INSTANCE',System.getProperty("bigtable.instanceID")
100+
101+
beforeTest { descriptor ->
102+
logger.lifecycle("test: " + descriptor + " Running")
103+
}
104+
105+
onOutput { descriptor, event ->
106+
logger.lifecycle("test: " + descriptor + ": " + event.message )
107+
}
108+
afterTest { descriptor, result ->
109+
logger.lifecycle("test: " + descriptor + ": " + result )
110+
}
111+
}
112+
// [END gae_java21_bigtable_gradle_model]
113+
// [END gae_java21_bigtable_gradle_file]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Mon Apr 03 21:11:48 PDT 2017
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip

appengine-java21/ee8/bigtable/gradlew

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)