如何将GAE应用程序和GCE应用程序连接到本地的同一数据存储区? [英] How to connect a GAE app and a GCE app to the same datastore locally?

查看:82
本文介绍了如何将GAE应用程序和GCE应用程序连接到本地的同一数据存储区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到类似此问题一个。我有一个GAE应用程序和一个GCE应用程序,似乎在云中运行良好,但我无法让本地环境正常工作,因此它们都可以访问相同的数据存储区。

我已经设置了本地数据存储,如上面的链接所述,除了我的代码看起来像这样(我必须以这种方式构建它才能让它在云中工作):

  print(正在连接到数据存储 - + datasetId); 

//获取GCE的凭证,如果不是本地的。
Credential computeEngineCredential = DatastoreHelper.getComputeEngineCredential(); (computeEngineCredential!= null)
{
print(Compute Engine Credetianls are not null!Access token:+ computeEngineCredential.getAccessToken());




DatastoreOptions options = DatastoreHelper.getOptionsfromEnv()。credential(DatastoreHelper.getComputeEngineCredential())。dataset(datasetId).build();

print(Connection Host:+ options.getHost());
print(Connection Dataset:+ options.getDataset());

datastore = DatastoreFactory.get()。create(options);

当我在本地运行GCE应用程序并尝试连接到正在运行的GAE数据存储库时,我已经在下面的输出中用myDatasetId替换了实际的数据集ID):
$ b


连接到数据存储 - myDatasetId



连线主机: http:// localhost:8888



连接数据集:myDatasetId



com.google.api.services.datastore.client.DatastoreFactory makeClient



警告:不使用任何凭据

运行查询时出现问题:错误:
runQuery错误404

错误
404


com.google.api.services.datastore.client.DatastoreException:错误404

错误
404


at com .google.api.services.datastore.client.RemoteRpc.makeException(RemoteRpc.java:114)
,位于com.google.api.services。 datastore.client.RemoteRpc.call(RemoteRpc.java:80)
,位于com.google.api.services.datastore.client.Datastore.runQuery(Datastore.java:109)


我的GAE控制台会打印出来(我可以在8888端口访问管理控制台):


com.google.appengine.tools.development.AbstractModule启动

信息:管理控制台正在 http:// localhost:8888 / _ah / admin

com.google。

/ datastore / v1beta2 / datasets /myDatasetId/ runQuery

我已验证GCE应用程序和GAE应用程序匹配中的数据集标识。我已经能够成功地自行运行每个应用程序本地,并且它们都能够正确连接到本地数据存储(这是在使用GCE应用程序的gcd.cmd工具时)。根据上面链接中的答案,听起来像这是可能的,我做错了什么?



更新



不知道这是否相关,但启动GCD工具时出现以下错误:


< SEVERE:无法加载App Engine dev代理。安全限制
不会被完全模拟。 java.lang.RuntimeException:
在投射期间发生意外异常。
at com.google.apphosting.utils.clearcast.ClearCast $ CasterImpl.cast(ClearCast.java:385)
at com.google.apphosting.utils.clearcast.ClearCast.staticCast(ClearCast.java: 252)
,位于com.google.apphosting.utils.clearcast.ClearCast.staticCast(ClearCast.java:263)
位于com.google.appengine.tools.development.agent.AppEngineDevAgent.premain(AppEngineDevAgent。 java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown源)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Unknown
Source)
at sun.instrument.InstrumentationImpl .loadClassAndCallPremain(Unknown
Source)引起:java.lang.IllegalAccessException:Class
com.google.apphosting.utils .clearcast.ClearCast $ CasterImpl不能交换
类的成员
com.google.appengine.tools.development.agent。$ Proxy0带修饰符
public
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(Unknown
Source)
at java.lang.reflect.AccessibleObject.checkAccess(Unknown Source )
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.google.apphosting.utils.clearcast.ClearCast $ CasterImpl.cast(ClearCast.java:383)
... 9 more


如果这个初始化正确,我可以以何种方式将我的GAE App连接到GCD Tool数据存储?所以很困惑。

解决方案

Java Development Server dev_appserver.sh )和本地云数据存储工具 gcd.sh )。

但是,如果您的应用程序是用Java编写的,则可以使用描述的解决方法 here 并指向 dev_appserver.sh 生成的数据文件 gcd.sh 通过指定 -Ddatastore.backing_store =< project dir> /WEB-INF/appengine-generated/local_db.bin 选项。


I am running into an issue similar to this one. I have a GAE app and a GCE app that seem to work fine once in the cloud but I am having trouble getting my local environment working so that both of them access the same datastore.

I have setup the local datastore as described in the link above except my code looks like this (I had to build it this way in order to get it working in the cloud):

print("Connecting to datastore - " + datasetId);

// Get credentials form GCE if not local.
Credential computeEngineCredential = DatastoreHelper.getComputeEngineCredential();

if(computeEngineCredential != null)
{
    print("Compute Engine Credetianls are not null! Access token: " + computeEngineCredential.getAccessToken());
}

DatastoreOptions options = DatastoreHelper.getOptionsfromEnv().credential(DatastoreHelper.getComputeEngineCredential()).dataset(datasetId).build();

print("Connection Host: " + options.getHost());
print("Connection Dataset: " + options.getDataset());

datastore = DatastoreFactory.get().create(options);

When I run the GCE app locally and try to connect to the running GAE datastore I get the following (I have replaced the actual data set id with "myDatasetId" in the output below):

Connecting to datastore - "myDatasetId"

Connection Host: http://localhost:8888

Connection Dataset: "myDatasetId"

com.google.api.services.datastore.client.DatastoreFactory makeClient

WARNING: Not using any credentials

There was a problem running query: Error: runQuery Error 404

Error 404

com.google.api.services.datastore.client.DatastoreException: Error 404

Error 404

at com.google.api.services.datastore.client.RemoteRpc.makeException(RemoteRpc.java:114) at com.google.api.services.datastore.client.RemoteRpc.call(RemoteRpc.java:80) at com.google.api.services.datastore.client.Datastore.runQuery(Datastore.java:109)

My GAE console prints this out (I can access the admin console in the 8888 port just fine):

com.google.appengine.tools.development.AbstractModule startup

INFO: The admin console is running at http://localhost:8888/_ah/admin

com.google.appengine.tools.development.LocalResourceFileServlet doGet

WARNING: No file found for:

/datastore/v1beta2/datasets/"myDatasetId"/runQuery

I have verified the dataset ID in the GCE app and the GAE app match. I have been able to successfully run each app localy on their own and they both are able to properly connect to the local Datastore (this is while using the gcd.cmd tool for the GCE app). Based on the answer in the link above, it sounds like this is possible, am I doing something wrong?

Update

Not sure if this is related but I am getting the following error when starting up the GCD Tool:

SEVERE: Unable to load the App Engine dev agent. Security restrictions will not be completely emulated. java.lang.RuntimeException: Unexpected exception during cast. at com.google.apphosting.utils.clearcast.ClearCast$CasterImpl.cast(ClearCast.java:385) at com.google.apphosting.utils.clearcast.ClearCast.staticCast(ClearCast.java:252) at com.google.apphosting.utils.clearcast.ClearCast.staticCast(ClearCast.java:263) at com.google.appengine.tools.development.agent.AppEngineDevAgent.premain(AppEngineDevAgent.java:61) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Unknown Source) at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(Unknown Source) Caused by: java.lang.IllegalAccessException: Class com.google.apphosting.utils.clearcast.ClearCast$CasterImpl can not ac cess a member of class com.google.appengine.tools.development.agent.$Proxy0 with modifiers "public" at sun.reflect.Reflection.ensureMemberAccess(Unknown Source) at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(Unknown Source) at java.lang.reflect.AccessibleObject.checkAccess(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.google.apphosting.utils.clearcast.ClearCast$CasterImpl.cast(ClearCast.java:383) ... 9 more

If this initialized properly, could I somehow connect my GAE App to the GCD Tool datastore? So confused.

解决方案

There's no officially supported way to share Datastore data between the Java Development Server (dev_appserver.sh) and the local Cloud Datastore tool (gcd.sh).

However, if your app is written in Java, you may be able to use the workaround described here and point dev_appserver.sh to the data file generated by gcd.sh by specifying the -Ddatastore.backing_store=<project dir>/WEB-INF/appengine-generated/local_db.bin option.

这篇关于如何将GAE应用程序和GCE应用程序连接到本地的同一数据存储区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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