是否可以启动两个 dev_appserver.py 连接到同一个谷歌云数据存储模拟器? [英] Is it possible to start two dev_appserver.py connecting to the same google cloud datastore emulator?

查看:15
本文介绍了是否可以启动两个 dev_appserver.py 连接到同一个谷歌云数据存储模拟器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用例:我正在用 python 开发一个 appengine 标准应用程序,另一个在 go 中.我想在同一个数据存储中拥有来自两个应用程序的实体.这可能吗?

Use case: I am developing an appengine standard application in python, and another one in go. I'd like to have the entities from both the applications in the same datastore. Is that possible?

当我使用标志 --support_datastore_emulator=true 和特定的 --datastore_path 启动第一个 dev_appserver.py 时,gcloud beta 模拟器数据存储env-init 命令失败并显示<代码>错误:(gcloud.beta.emulators.datastore.env-init) 无法在 data_dir [~/.config/gcloud/emulators/datastore] 中找到 env.yaml.请确保您已启动适当的模拟器.

When I start the first dev_appserver.py with the flag --support_datastore_emulator=true, and with a specific --datastore_path, the gcloud beta emulators datastore env-init command fails with a ERROR: (gcloud.beta.emulators.datastore.env-init) Unable to find env.yaml in the data_dir [~/.config/gcloud/emulators/datastore]. Please ensure you have started the appropriate emulator.

推荐答案

是的,有可能,但你需要仔细设置.

Yes, it is possible, but you need to carefully set it up.

首先要记住的是,只有一个仿真进程(无论是仿真器本身还是开发服务器)应该处理某个数据存储仿真目录,同时运行多个它们很可能会导致数据损坏,因为您可能已经观察到尝试运行 2 个共享相同 --datastore_path 配置的开发服务器.

First thing to keep in mind is that only one emulation process (be it the emulator itself or the development server) should handle a certain datastore emulation dir, running multiple of them simultaneously will most likely cause corruption of the data, as you may have observed trying to run 2 development servers sharing the same --datastore_path config.

所以您只需要一个数据存储模拟器进程来处理存储目录.您不希望开发服务器(它们也有能力或运行自己的数据存储模拟,但以独立方式)也处理该存储目录,因此您不应使用 --datastore_path 选项.开发服务器应该只与数据存储模拟器进程对话以获取所有数据存储访问.

So you want just one datastore emulator process handling the storage dir. You do not want the development server(s) - which are also capable or running their own datastore emulation, but in a standalone manner - to also handle that storage dir, so you shouldn't be using the --datastore_path option for them. The development server(s) should instead just talk to the datastore emulator process for all their datastore accesses.

当您启动数据存储模拟器进程时,您将在其日志中看到一行指定 DATASTORE_EMULATOR_HOST 环境变量,您需要将其传递给要共享该数据存储模拟实例的所有开发服务器:

When you start the datastore emulator process you'll see in its log a line specifying the DATASTORE_EMULATOR_HOST environment variable that you need to pass to all the development servers that you want to share that datastore emulation instance:

[datastore] API endpoint: http://0.0.0.0:5555
[datastore] If you are using a library that supports the DATASTORE_EMULATOR_HOST environment variable, run:
[datastore] 
[datastore]   export DATASTORE_EMULATOR_HOST=0.0.0.0:5555
[datastore] 
[datastore] Dev App Server is now running.

因此,在要启动开发服务器的 shell 中设置该环境变量,然后仅使用这些与数据存储相关的选项启动服务器:

So set that environment variable in the shell(s) where you want to start your development server(s), then start the servers with just these datastore related options:

export DATASTORE_EMULATOR_HOST=0.0.0.0:555
[.../]dev_appserver.py --support_datastore_emulator=true ...

这个环境变量是唯一不需要的东西,你不需要在这里运行 gcloud beta emulators datastore env-init,在服务器的日志中,您应该看到如下一行:

This env var is the only thing needed you don't need to run gcloud beta emulators datastore env-init here, In the server's log you should see a line like this:

WARNING 2018-06-14 13:54:41,238 api_server.py:581] 检测到环境变量 DATASTORE_EMULATOR_HOST=0.0.0.0:5555,dev_appserver 将与在此地址上运行的 Cloud Datastore 模拟器对话.datastore_path/some_path_you_may_have_used_before/datastore.db 将被忽略.如果您希望数据存储存储在/some_path_you_may_have_used_before/datastore.db,请从环境变量中删除 DATASTORE_EMULATOR_HOST 并重新启动 dev_appserver

WARNING 2018-06-14 13:54:41,238 api_server.py:581] Detected environment variable DATASTORE_EMULATOR_HOST=0.0.0.0:5555, dev_appserver will speak to the Cloud Datastore emulator running on this address. The datastore_path /some_path_you_may_have_used_before/datastore.db will be neglected. If you want datastore to store on /some_path_you_may_have_used_before/datastore.db, remove DATASTORE_EMULATOR_HOST from environment variables and restart dev_appserver

当开发服务器首次访问数据存储时,您会在数据存储模拟器日志中看到一些条目,如下所示:

When a development server makes its first datastore access you'll see a few entries in the datastore emulator log, like these:

[datastore] Jun 14, 2018 10:02:53 AM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
[datastore] INFO: Adding handler(s) to newly registered Channel.
[datastore] Jun 14, 2018 10:02:53 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[datastore] INFO: Detected HTTP/2 connection.

如果 DATASTORE_EMULATOR_HOST 没有指向正在运行的数据存储模拟器进程(或者与它的通信有问题),您将在开发服务器的日志中看到错误,可能与这些类似:

If the DATASTORE_EMULATOR_HOST doesn't point to a running datastore emulator process (or there's something wrong with the communication with it) you'll see errors in the development server's logs, probably similar with these:

ERROR    2018-06-14 14:39:08,026 api_server.py:373] Exception while handling datastore_v3.Get()
Traceback (most recent call last):
  File "/home/usr_local/google-cloud-sdk-204.0.0/platform/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 333, in _handle_POST
    response = service_stub.MakeSyncCallForRemoteApi(request)
  File "/home/usr_local/google-cloud-sdk-204.0.0/platform/google_appengine/google/appengine/tools/devappserver2/datastore_grpc_stub.py", line 190, in MakeSyncCallForRemoteApi
    request_pb, _TIMEOUT)
  File "/home/usr_local/google-cloud-sdk-204.0.0/platform/google_appengine/lib/grpcio-1.9.1/grpc/_channel.py", line 487, in __call__
    return _end_unary_response_blocking(state, call, False, deadline)
  File "/home/usr_local/google-cloud-sdk-204.0.0/platform/google_appengine/lib/grpcio-1.9.1/grpc/_channel.py", line 437, in _end_unary_response_blocking
    raise _Rendezvous(state, None, None, deadline)
_Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE, Connect Failed)>

更多信息:

注意:(至少目前)只有 Google Cloud SDK 开发服务器(我使用 204.0.0 测试过的最新版本)支持与独立数据存储区通信模拟器,特定于 GAE 的 SDK 没有(或者至少我目前使用的 1.9.69 python 没有).从迁移到云数据存储模拟器:

NOTE: that (at least presently) only the Google Cloud SDK development server (a recent version, I tested with 204.0.0) supports talking to a standalone datastore emulator, the GAE-specific SDK ones don't (or at least the 1.9.69 python one I'm presently using doesn't). From Migrating to the Cloud Datastore Emulator:

注意:此迁移需要使用 基于Google Cloud SDK工具.

这篇关于是否可以启动两个 dev_appserver.py 连接到同一个谷歌云数据存储模拟器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆