Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
59 changes: 59 additions & 0 deletions appengine-java21/ee8/bigtable/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Bigtable-hello-j21
=================

<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">
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>

Moves the Bigtable Hello World application to Google App Engine Standard for Java 21.


* [Java 21](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
* [Maven](https://maven.apache.org/download.cgi) (at least 3.3.9)
* [Gradle](https://gradle.org)
* [Google Cloud CLI](https://cloud.google.com/cli/) (aka gcloud)

Initialize the Google Cloud CLI using:

gcloud init

gcloud auth application-default login

Then you need to [Create a Cloud Bigtable Instance](https://cloud.google.com/bigtable/docs/creating-instance)


## Using Maven

### Run Locally

mvn -Dbigtable.projectID=PROJECTID -Dbigtable.instanceID=INSTANCEID appengine:run

### Deploy to App Engine Standard for Java 21

mvn -Dbigtable.projectID=PROJECTID -Dbigtable.instanceID=INSTANCEID package appengine:deploy

### Run Integration Tests

mvn -Dbigtable.projectID=PROJECTID -Dbigtable.instanceID=INSTANCEID verify

## Using Gradle

### Run Locally

gradle -Dbigtable.projectID=PROJECTID -Dbigtable.instanceID=INSTANCEID appengineRun

### Integration Tests & Deploy to App Engine Standard for Java 21

gradle -Dbigtable.projectID=PROJECTID -Dbigtable.instanceID=INSTANCEID appengineDeploy

As you add / modify the source code (`src/main/java/...`) it's very useful to add
[unit testing](https://cloud.google.com/appengine/docs/java/tools/localunittesting)
to (`src/main/test/...`). The following resources are quite useful:

* [JUnit4](http://junit.org/junit4/)
* [Mockito](http://mockito.org/)
* [Truth](http://google.github.io/truth/)

### When done

Cloud Bigtable Instances should be [deleted](https://cloud.google.com/bigtable/docs/deleting-instance)
when they are no longer being used as they use significant resources.
113 changes: 113 additions & 0 deletions appengine-java21/ee8/bigtable/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright 2017 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
//
// http://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.
// [START gae_java21_bigtable_gradle_file]
buildscript { // Configuration for building
repositories {
jcenter() // Bintray's repository - a fast Maven Central mirror & more
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.5.0'
classpath 'org.akhikhl.gretty:gretty:+'
}
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty' // To get webappcopy
apply plugin: 'com.google.cloud.tools.appengine'

group = 'com.example.google.cloud.bigtable'
version = '0.1-SNAPSHOT'

sourceCompatibility = 21
targetCompatibility = 21

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
jcenter()
mavenCentral()
}

dependencies {
compile group: 'com.google.cloud.bigtable', name: 'bigtable-hbase-1.2', version:'1.0.0-pre3'
compile group: 'org.apache.hbase', name: 'hbase-client', version:'2.5.6'
compile group: 'io.netty', name: 'netty-tcnative-boringssl-static', version:'2.0.62.Final'
compile group: 'jakarta.servlet.jsp.jstl', name: 'jakarta.servlet.jsp.jstl-api', version:'1.2.7'

providedCompile group: 'jakarta.servlet', name: 'jakarta.servlet-api', version:'4.0.4'

testCompile group: 'com.google.truth', name: 'truth', version:'1.4.4'
testCompile group: 'junit', name: 'junit', version:'4.13.2'
testCompile group: 'org.mockito', name: 'mockito-core', version:'4.11.0'
}

import org.apache.tools.ant.filters.ReplaceTokens
gretty {
contextPath = '/'
servletContainer = 'jetty9'

jvmArgs = [ '-DBIGTABLE_PROJECT=' + System.getProperty("bigtable.projectID"),
'-DBIGTABLE_INSTANCE=' + System.getProperty("bigtable.instanceID")]

webappCopy {
// Enable filtering on all xml files in WEB-INF
filesMatching "**/WEB-INF/*.xml", { FileCopyDetails fileDetails ->
logger.lifecycle 'File filtered: {}', fileDetails.path
filter (ReplaceTokens, tokens: [
'bigtable.projectID' : System.getProperty("bigtable.projectID"),
'bigtable.instanceID': System.getProperty("bigtable.instanceID")
])
}
}
}

// Always run unit tests
appengineDeploy.dependsOn test

// [START gae_java21_bigtable_gradle_model]
appengine {
run {

}
deploy { // deploy configuration
stopPreviousVersion = true // default - stop the current version
promote = true // default - & make this the current version
}
}

test {
useJUnit()
testLogging.showStandardStreams = true

systemProperty 'BIGTABLE_PROJECT', System.getProperty("bigtable.projectID")
systemProperty 'BIGTABLE_INSTANCE',System.getProperty("bigtable.instanceID")

beforeTest { descriptor ->
logger.lifecycle("test: " + descriptor + " Running")
}

onOutput { descriptor, event ->
logger.lifecycle("test: " + descriptor + ": " + event.message )
}
afterTest { descriptor, result ->
logger.lifecycle("test: " + descriptor + ": " + result )
}
}
// [END gae_java21_bigtable_gradle_model]
// [END gae_java21_bigtable_gradle_file]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Mon Apr 03 21:11:48 PDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
172 changes: 172 additions & 0 deletions appengine-java21/ee8/bigtable/gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading