とりあえずローカル環境でCloudDatastoreを利用してみようと試行錯誤したのでメモ。
記事に誤りがありました
※GoogleAppEngine SDKによるgoapp実行だけでCloudDatastoreはつかえました。
そのため、GoogleAppEngine SDKを入れてる方はCloudSDKを入れなくてもCloudDatastoreは利用可能でした。すみません。
CloudSDKによるCloudDatastoreでの利用方法として、一応記事は残しておきます。
CloudSDKのインストール
GoogleAppEngine SDKにはDatastoreは入っていなかったので、CloudSDK( https://cloud.google.com/sdk/ )をインストール。
SDKのインストール手順はこちらを参照
https://cloud.google.com/sdk/docs/quickstart-windows
SDKのインストールが完了したら、環境変数にパスを通しておく。
SDKの初期設定を行う。(SDKのインストール直後に行っていれば不要)
>gcloud init
Datastoreの起動
ドキュメントを読んでると、Datastoreのエミュレータを起動するにはbetaコンポーネントを入れないといけない事が判明。
>gcloud components install beta
別Windowが立ち上がり勝手に入ります。
さらにもう一つコンポーネントを要求されるのでこちらもインストール。
>gcloud components install cloud-datastore-emulator
別Windowが立ち上がり勝手に入ります。(再
これでやっと実行可能。
それではDatastoreを起動してみます。
>gcloud beta emulators datastore start
こんな感じのログが流れて起動完了。
Executing: cmd /c C:\GCP\Cloud_SDK\google-cloud-sdk\platform\cloud-datastore-emulator\cloud_datastore_emulator.cmd create --project_id=******* C:\Users\*****\AppData\Roaming\gcloud\emulators\datastore
[datastore] 11 02, 2016 1:13:15 ?? com.google.cloud.datastore.emulator.CloudDatastore$CreateAction$1 apply
[datastore] ??: Provided project_id to Cloud Datastore emulator create command, which is no longer necessary.
[datastore] Created new Cloud Datastore project in 'C:\Users\*****\AppData\Roaming\gcloud\emulators\datastore'.
Executing: cmd /c C:\GCP\Cloud_SDK\google-cloud-sdk\platform\cloud-datastore-emulator\cloud_datastore_emulator.cmd start --host=localhost --port=8394 --store_on_disk=True --consistency=0.9 --allow_remote_shutdown C:\Users\*****\AppData\Roaming\gcloud\emulators\datastore
[datastore] 11 02, 2016 1:13:15 ?? com.google.cloud.datastore.emulator.CloudDatastore$FakeDatastoreAction$7 apply
[datastore] ??: Provided --allow_remote_shutdown to start command which is no longer necessary.
[datastore] 11 02, 2016 1:13:15 ?? com.google.cloud.datastore.emulator.impl.LocalDatastoreFileStub <init>
[datastore] ??: Local Datastore initialized:
[datastore] Type: High Replication
[datastore] Storage: C:\Users\*****\AppData\Roaming\gcloud\emulators\datastore\WEB-INF\appengine-generated\local_db.bin
[datastore] 11 02, 2016 1:13:16 ?? io.grpc.internal.ManagedChannelImpl <init>
[datastore] ??: [ManagedChannelImpl@71d15f18] Created with target localhost:8394
[datastore] 11 02, 2016 1:13:16 ?? com.google.cloud.datastore.emulator.impl.LocalDatastoreFileStub load
[datastore] ??: The backing store, C:\Users\*****\AppData\Roaming\gcloud\emulators\datastore\WEB-INF\appengine-generated\local_db.bin, does not exist. It will be created.
[datastore] 11 02, 2016 1:13:16 ?? io.gapi.emulators.netty.NettyUtil applyJava7LongHostnameWorkaround
[datastore] ??: Unable to apply Java 7 long hostname workaround.
[datastore] API endpoint: http://localhost:8394
[datastore] If you are using a library that supports the DATASTORE_EMULATOR_HOST environment variable, run:
[datastore]
[datastore] export DATASTORE_EMULATOR_HOST=localhost:8394
[datastore]
[datastore] Dev App Server is now running.
http://localhost:8394
でアクセスすると「Ok」と表示されます。
いろいろ触ってみたいけど今日はここまで。
(週末にでもローカルGAEからローカルDatastoreにPUT/GETして遊ぶ予定。たぶん記事にします。)