简体   繁体   English

使用google云数据存储模拟器与dev_appserver

[英]Using google cloud datastore emulator with dev_appserver

I've been reading between the lines and trying to interface dev_appserver.py with the new 'non-legacy' google cloud datastore emulator. 我一直在阅读这些内容,并试图将dev_appserver.py与新的“非遗留”谷歌云数据存储模拟器相连接。

My main motivation is to integrate my appengine projects with my google cloud dataflow pipeline while I am developing on my local machine. 我的主要动机是在我在本地计算机上进行开发时将我的appengine项目与我的google云数据流管道集成。

This is the procedure to setup the integration, as far as I understand: 据我所知,这是设置集成的过程:

  • Install the googledatastore library with pip (you may need to force an upgrade of six with easy_install particularly if you are using system python El Capitan) 使用pip安装googledatastore库(如果使用的是系统python El Capitan,则可能需要使用easy_install强制升级six
  • Using the google cloud sdk tools run the google cloud datastore emulator: 使用谷歌云sdk工具运行谷歌云数据存储模拟器:

     gcloud beta emulators datastore start --no-legacy 
  • In the terminal where dev_appserver will run the following command to set datastore environment variables: 在dev_appserver将运行以下命令以设置数据存储环境变量的终端中:

     $(gcloud beta emulators datastore env-init --no-legacy) 
  • If the project id in app.yaml does not match the currently select project id in the gcloud tools set the following environment variable in the same shell: 如果app.yaml中的项目ID与gcloud工具中当前选择的项目ID不匹配,请在同一个shell中设置以下环境变量:

     export DATASTORE_USE_PROJECT_ID_AS_APP_ID=true 
  • Run dev_appserver.py and navigate to http://localhost:8000/datastore which should let you navigate the emulator's datastore data. 运行dev_appserver.py并导航到http:// localhost:8000 / datastore ,它可以让您导航模拟器的数据存储区数据。

However this does not work so smoothly when I navigate to the url I get: 但是当我导航到我得到的网址时,这并不是那么顺利:

BadArgumentError: Could not import googledatastore.
This library must be installed with version >= 4.0.0.b1 to use the Cloud Datastore 
API.

This is strange because if I open a python shell and run import googledatastore no error occurs. 这很奇怪,因为如果我打开python shell并运行import googledatastore不会发生错误。

If I dig a bit deeper and instrument the import code in dev_appserver and log the error here I get the following traceback: 如果我深入挖掘并检测dev_appserver中的导入代码并在此处记录错误我将得到以下回溯:

Traceback (most recent call last):
  File "/usr/local/google-cloud-sdk/platform/google_appengine/google/appengine/datastore/datastore_pbs.py", line 52, in <module>
    import googledatastore
  File "/Library/Python/2.7/site-packages/googledatastore/__init__.py", line 21, in <module>
    from . import helper
  File "/Library/Python/2.7/site-packages/googledatastore/helper.py", line 25, in <module>
    from google.datastore.v1beta3 import entity_pb2
ImportError: No module named datastore.v1beta3 

I also have no issue importing google.datastore.v1beta3 in a regular python shell. 我也没有在常规python shell中导入google.datastore.v1beta3问题。

Even stranger if I run PYTHONINSPECT=x dev_appserver.py app.yaml and drop out into the shell executing these imports runs without error. 如果我运行PYTHONINSPECT=x dev_appserver.py app.yaml并退出执行这些导入的shell运行没有错误, PYTHONINSPECT=x dev_appserver.py app.yaml了。 Perhaps there is something odd going on with the python path while dev_appserver.py is starting? 也许dev_appserver.py正在启动时,python路径有些奇怪吗?

Can anybody tell me how to get this feature working? 任何人都可以告诉我如何使这个功能工作?

UPDATE: I reproduced this problem on ubuntu 14.04 (system python 2.7.6, pip 8.1.2 via easy_install, gcloud-sdk 118.0.0, app-engine-python 1.9.38) as well as OS X (gcloud sdk 114.0.0, app-engine-python 1.9.38, system python 2.7.10). 更新:我在ubuntu 14.04(系统python 2.7.6,pip 8.1.2,通过easy_install,gcloud-sdk 118.0.0,app-engine-python 1.9.38)以及OS X(gcloud sdk 114.0.0)上重现了这个问题,app-engine-python 1.9.38,system python 2.7.10)。

We recently ran into this same issue. 我们最近遇到了同样的问题。 One thing to look at is the output of the command: 要注意的一件事是命令的输出:

(gcloud beta emulators datastore env-init --no-legacy)

The problem we had was that when we ran the emulator the emulator was choosing say port 8607 but the env-init method was returning a different port 8328. 我们遇到的问题是,当我们运行模拟器时,模拟器选择了端口8607,但是env-init方法返回了另一个端口8328。

So, what I would recommend is to start the emulator and see what port it is running on: 所以,我建议的是启动模拟器并查看它运行的端口:

[datastore] Aug 04, 2016 3:50:50 PM com.google.appengine.tools.development.AbstractModule startup
[datastore] INFO: Module instance default is running at http://localhost:8607/
[datastore] Aug 04, 2016 3:50:50 PM com.google.appengine.tools.development.AbstractModule startup
[datastore] INFO: The admin console is running at http://localhost:8607/_ah/admin

In this case 8607 and then fire off the env-init method to get the syntax but validate the port. 在这种情况下,8607然后触发env-init方法以获取语法但验证端口。 In our case with the above server running the env-init returns 8328 在我们的情况下运行env-init的上述服务器返回8328

$ (gcloud beta emulators datastore env-init)
export DATASTORE_DATASET=my-app
export DATASTORE_EMULATOR_HOST_PATH=localhost:8328/datastore
export DATASTORE_EMULATOR_HOST=localhost:8328
export DATASTORE_HOST=http://localhost:8328
export DATASTORE_PROJECT_ID=my-app

So change this to the correct port: 所以将其更改为正确的端口:

export DATASTORE_DATASET=my-app
export DATASTORE_EMULATOR_HOST_PATH=localhost:8607/datastore
export DATASTORE_EMULATOR_HOST=localhost:8607
export DATASTORE_HOST=http://localhost:8607
export DATASTORE_PROJECT_ID=my-app

Then use this where your project is running and you should be good to go. 然后在项目运行的地方使用它,你应该很高兴。 This is what fixed it for us. 这就是为我们解决的问题。 Hope that helps! 希望有所帮助!

Actually gcloud datastore emulator and dev_appserver points to two different endpoints. 实际上,gcloud数据存储模拟器和dev_appserver指向两个不同的端点。 the localhost:8000 is the default dev_appserver admin console, while the datastore emulator have a different console url which could be found in print outs when it starts. localhost:8000是默认的dev_appserver管理控制台,而数据存储模拟器有一个不同的控制台URL,可以在启动时在打印输出中找到。

I assume the admin console you are accessing belongs to dev_appserver, then the issue should be within dev_appserver. 我假设您访问的管理控制台属于dev_appserver,那么问题应该在dev_appserver中。 Could you attach the code snippet(if there is any) using datastore api in dev_appserver? 你能在dev_appserver中使用数据存储api附加代码片段(如果有的话)吗? BTW it should be gcloud.datastore instead of appengine.ext.(n)db talking to gcloud datastore-emulator. 顺便说一句,它应该是gcloud.datastore而不是appengine.ext.(n)db与gcloud数据存储模拟器交谈。

Also, I'm curious what would happen if you do not start datastore-emulator with '--no-legacy', or even do not start datastore-emulator but just start dev_appserver? 另外,我很好奇如果你没有使用'--no-legacy'启动数据存储模拟器会发生什么,或者甚至不启动数据存储模拟器但只是启动dev_appserver?

Heads up folks, 抬起头来,

Using google cloud datastore emulator with dev_appserver is now available! 现在可以使用带有dev_appserver的谷歌云数据存储模拟器! ( link ) 链接

Update Google Cloud SDK, then run dev_appserver with '----support_datastore_emulator'. 更新Google Cloud SDK,然后使用'---- support_datastore_emulator'运行dev_appserver。

This feature is in Beta, welcome to try it! 此功能是测试版,欢迎试用! We are actively collecting feedback. 我们正积极收集反馈意见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM