是否可以启动两个dev_appserver.py连接到相同的Google Cloud Datastore模拟器? [英] Is it possible to start two dev_appserver.py connecting to the same google cloud datastore emulator?

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

问题描述

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

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 emulators datastore env-init命令失败,并显示一个 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.

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:

警告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)>

更多信息,位于:

  • Running the Cloud Datastore Emulator
  • Migrating to the Cloud Datastore Emulator

注意: :(至少目前)只有Google Cloud SDK开发服务器(我用204.0.0测试过的最新版本)支持与独立的数据存储模拟器,即GAE专用SDK进行对话不会的(或者至少我目前使用的1.9.69 python不会).从迁移到Cloud Datastore Emulator :

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 工具.

Note: This migration requires the use of the Google Cloud SDK-based tooling.

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

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