App Engine linked Datastore
appEngineIntegrationMode
App Engine 初期化
code:sh
WARNING: Creating an App Engine application for a project is irreversible and the region
cannot be changed. More information about regions is at
Please choose the region where you want your App Engine application located:
1 asia-east1 (supports standard and flexible) 2 asia-east2 (supports standard and flexible and search_api) 3 asia-northeast1 (supports standard and flexible and search_api) 4 asia-northeast2 (supports standard and flexible and search_api) 5 asia-northeast3 (supports standard and flexible and search_api) 6 asia-south1 (supports standard and flexible and search_api) 7 asia-southeast1 (supports standard and flexible) 8 asia-southeast2 (supports standard and flexible and search_api) 9 australia-southeast1 (supports standard and flexible and search_api) 10 europe-central2 (supports standard and flexible) 11 europe-west (supports standard and flexible and search_api) 12 europe-west2 (supports standard and flexible and search_api) 13 europe-west3 (supports standard and flexible and search_api) 14 europe-west6 (supports standard and flexible and search_api) 15 northamerica-northeast1 (supports standard and flexible and search_api) 16 southamerica-east1 (supports standard and flexible and search_api) 17 us-central (supports standard and flexible and search_api) 18 us-east1 (supports standard and flexible and search_api) 19 us-east4 (supports standard and flexible and search_api) 20 us-west1 (supports standard and flexible) 21 us-west2 (supports standard and flexible and search_api) 22 us-west3 (supports standard and flexible and search_api) 23 us-west4 (supports standard and flexible and search_api) Please enter your numeric choice: 17
Success! The app is now created. Please use gcloud app deploy to deploy your first app.
Java 21 インストール
SDKMAN をつかう
code:sh
sdk install java 21.0.2-amzn
code:sh
$ java -version
openjdk version "21.0.2" 2024-01-16 LTS
OpenJDK Runtime Environment Corretto-21.0.2.13.1 (build 21.0.2+13-LTS)
OpenJDK 64-Bit Server VM Corretto-21.0.2.13.1 (build 21.0.2+13-LTS, mixed mode, sharing)
Quarkus を使ってみる
まずは quarkus コマンドをインストールする
JBang を使ってインストールするか、SDKMAN を使ってインストールする
quarkus create コマンドを叩くと、code-with-quarkus 以下に maven で quarkus app が作成される
今回は gradle で作成してみる
gradle で作りたい場合
code:sh
quarkus create app --gradle --java=21
その他オプション
--name=projectName
--output-directory=directory
デフォルトだと code-with-quarkus というディレクトリ名になる
--wrapper --no-wrapper デフォルトだと wrapper 相当っぽい
quarkus コマンドを使って起動してみる
code:sh
cd code-with-quarkus
quarkus dev
ソースコードを見ると
src/main/java/org/acme/GreetingResource というところに /hello というエンドポイントが実装されている
Datastore の確認
"appEngineIntegrationMode": "ENABLED"
code:json
{
"databases": [
{
"name": "projects/kintai-378808/databases/(default)",
"uid": "0fb2da29-d97a-4916-ae17-1fc81b638f37",
"createTime": "2024-04-20T01:44:18.701879Z",
"updateTime": "2024-04-20T01:44:18.701879Z",
"locationId": "nam5",
"type": "DATASTORE_MODE",
"concurrencyMode": "PESSIMISTIC",
"versionRetentionPeriod": "3600s",
"earliestVersionTime": "2024-04-20T08:55:56.503676Z",
"appEngineIntegrationMode": "ENABLED",
"keyPrefix": "s",
"pointInTimeRecoveryEnablement": "POINT_IN_TIME_RECOVERY_DISABLED",
"deleteProtectionState": "DELETE_PROTECTION_DISABLED",
"etag": "IIXDpK/D0IUDMLes4r3Vz4UD"
}
]
}
試しに database を作り直してみると "appEngineIntegrationMode": "DISABLED" になる
code:json
{
"databases": [
{
"name": "projects/kintai-378808/databases/(default)",
"uid": "026ef2ed-21bd-4352-9d01-030616c5d6be",
"createTime": "2024-04-20T10:03:37.392830Z",
"updateTime": "2024-04-20T10:03:37.392830Z",
"locationId": "nam5",
"type": "DATASTORE_MODE",
"concurrencyMode": "PESSIMISTIC",
"versionRetentionPeriod": "3600s",
"earliestVersionTime": "2024-04-20T10:03:37.392830Z",
"appEngineIntegrationMode": "DISABLED",
"keyPrefix": "s",
"pointInTimeRecoveryEnablement": "POINT_IN_TIME_RECOVERY_DISABLED",
"deleteProtectionState": "DELETE_PROTECTION_DISABLED",
"etag": "ILzHwpXF0IUDML7dl4vF0IUD"
}
]
}
gradle にデプロイしてみる
code:src/main/appengine/app.yaml
runtime: java21
code:sh
./gradlew build
gcloud auth login
gcloud app deploy build/code-with-quarkus-1.0.0-SNAPSHOT-runner.jar
エラー
code:sh
Step #0 - "fetch": Access to bucket staging.kintai-378808.appspot.com denied. You must grant Storage Object Viewer permission to 594257163006@cloudbuild.gserviceaccount.com. gcloud auth login してないのが原因だった
これでデプロイはできたが、URL にアクセスするとエラー
-44 すれば Java のバージョンらしい
65.0 = Java 21
61.0 = Java 17
code:sh
Caused by: java.lang.UnsupportedClassVersionError: org/acme/GreetingResource has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0
GAE 上で runtime が java 17 になってしまっているっぽい
ランタイムについて
quarkus のサンプルもある
でもこれは maven
runtime などの設定をしている app.yaml があるディレクトリでデプロイコマンドを叩かないとダメっぽい
アプリケーションのサービスをデプロイするには、サービスの app.yaml ファイルが存在するディレクトリから次のコマンドを実行します。
app.yaml のディレクトリで叩いても一緒だった...
gcloud app deployコマンドを叩いた時に、そのディレクトリに app.yaml があればその内容が反映されるっぽい
gcloud app deploy app.yamlってすることもできるっぽい
ただ、 この状態で gcloud app deploy build/code-with-quarkus-1.0.0-SNAPSHOT-runner.jar しても app.yaml の内容は反映されず、java 17 に戻ってしまうっぽい
Objectify の導入
datastore について
datastore emulator
インストール
code:sh
gcloud components install cloud-datastore-emulator
起動
code:sh
$ gcloud beta emulators datastore start
...
export DATASTORE_EMULATOR_HOST=localhost:8081
...
ログに port 情報が出てくるので実行
code:sh
export DATASTORE_EMULATOR_HOST=localhost:8081
quarkus dev
sample request
code:sh